ErrTxParse->ErrTxDecode; check for empty bytes in account and tx

This commit is contained in:
Ethan Buchman
2018-03-21 02:44:17 +01:00
parent c529eccc6e
commit 723889570e
8 changed files with 20 additions and 10 deletions
+5 -1
View File
@@ -122,11 +122,15 @@ func MakeCodec() *wire.Codec {
func (app *BasecoinApp) txDecoder(txBytes []byte) (sdk.Tx, sdk.Error) {
var tx = sdk.StdTx{}
if len(txBytes) == 0 {
return nil, sdk.ErrTxDecode("txBytes are empty")
}
// StdTx.Msg is an interface. The concrete types
// are registered by MakeTxCodec in bank.RegisterWire.
err := app.cdc.UnmarshalBinary(txBytes, &tx)
if err != nil {
return nil, sdk.ErrTxParse("").TraceCause(err, "")
return nil, sdk.ErrTxDecode("").TraceCause(err, "")
}
return tx, nil
}
+3
View File
@@ -25,6 +25,9 @@ func (acc *AppAccount) SetName(name string) { acc.Name = name }
// Get the AccountDecoder function for the custom AppAccount
func GetAccountDecoder(cdc *wire.Codec) sdk.AccountDecoder {
return func(accBytes []byte) (res sdk.Account, err error) {
if len(accBytes) == 0 {
return nil, sdk.ErrTxDecode("accBytes are empty")
}
acct := new(AppAccount)
err = cdc.UnmarshalBinary(accBytes, &acct)
if err != nil {
+1 -1
View File
@@ -64,7 +64,7 @@ func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
k, v := split[0], split[1]
tx = kvstoreTx{k, v, txBytes}
} else {
return nil, sdk.ErrTxParse("too many =")
return nil, sdk.ErrTxDecode("too many =")
}
return tx, nil