ErrTxParse->ErrTxDecode; check for empty bytes in account and tx
This commit is contained in:
parent
c529eccc6e
commit
723889570e
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -77,7 +77,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
|
||||
|
||||
@ -141,7 +141,7 @@ func (st *iavlStore) ReverseIterator(start, end []byte) Iterator {
|
||||
func (st *iavlStore) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
||||
if len(req.Data) == 0 {
|
||||
msg := "Query cannot be zero length"
|
||||
return sdk.ErrTxParse(msg).Result().ToQuery()
|
||||
return sdk.ErrTxDecode(msg).Result().ToQuery()
|
||||
}
|
||||
|
||||
tree := st.tree
|
||||
|
||||
@ -21,7 +21,7 @@ func (code CodeType) IsOK() bool {
|
||||
const (
|
||||
CodeOK CodeType = 0
|
||||
CodeInternal CodeType = 1
|
||||
CodeTxParse CodeType = 2
|
||||
CodeTxDecode CodeType = 2
|
||||
CodeInvalidSequence CodeType = 3
|
||||
CodeUnauthorized CodeType = 4
|
||||
CodeInsufficientFunds CodeType = 5
|
||||
@ -40,7 +40,7 @@ func CodeToDefaultMsg(code CodeType) string {
|
||||
switch code {
|
||||
case CodeInternal:
|
||||
return "Internal error"
|
||||
case CodeTxParse:
|
||||
case CodeTxDecode:
|
||||
return "Tx parse error"
|
||||
case CodeGenesisParse:
|
||||
return "Genesis parse error"
|
||||
@ -75,8 +75,8 @@ func CodeToDefaultMsg(code CodeType) string {
|
||||
func ErrInternal(msg string) Error {
|
||||
return newError(CodeInternal, msg)
|
||||
}
|
||||
func ErrTxParse(msg string) Error {
|
||||
return newError(CodeTxParse, msg)
|
||||
func ErrTxDecode(msg string) Error {
|
||||
return newError(CodeTxDecode, msg)
|
||||
}
|
||||
func ErrGenesisParse(msg string) Error {
|
||||
return newError(CodeGenesisParse, msg)
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
var codeTypes = []CodeType{
|
||||
CodeInternal,
|
||||
CodeTxParse,
|
||||
CodeTxDecode,
|
||||
CodeInvalidSequence,
|
||||
CodeUnauthorized,
|
||||
CodeInsufficientFunds,
|
||||
@ -23,7 +23,7 @@ type errFn func(msg string) Error
|
||||
|
||||
var errFns = []errFn{
|
||||
ErrInternal,
|
||||
ErrTxParse,
|
||||
ErrTxDecode,
|
||||
ErrInvalidSequence,
|
||||
ErrUnauthorized,
|
||||
ErrInsufficientFunds,
|
||||
|
||||
@ -65,6 +65,9 @@ func (c commander) getAccountCmd(cmd *cobra.Command, args []string) error {
|
||||
key := sdk.Address(bz)
|
||||
|
||||
res, err := builder.Query(key, c.storeName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// decode the value
|
||||
account, err := c.decoder(res)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user