Setup first tx, error code
This commit is contained in:
parent
f4c45b6273
commit
9fe2f6b365
|
@ -0,0 +1,23 @@
|
|||
package etc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
|
||||
"github.com/tendermint/basecoin/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
errMissingData = fmt.Errorf("All tx fields must be filled")
|
||||
|
||||
malformed = abci.CodeType_EncodingError
|
||||
)
|
||||
|
||||
//nolint
|
||||
func ErrMissingData() errors.TMError {
|
||||
return errors.WithCode(errMissingData, malformed)
|
||||
}
|
||||
func IsMissingDataErr(err error) bool {
|
||||
return errors.IsSameError(errMissingData, err)
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package etc
|
||||
|
||||
const (
|
||||
// Name of the module for registering it
|
||||
Name = "etc"
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
package etc
|
|
@ -0,0 +1,41 @@
|
|||
package etc
|
||||
|
||||
import (
|
||||
"github.com/tendermint/basecoin"
|
||||
"github.com/tendermint/go-wire/data"
|
||||
)
|
||||
|
||||
// nolint
|
||||
const (
|
||||
TypeSet = Name + "/set"
|
||||
TypeGet = Name + "/get"
|
||||
TypeRemove = Name + "/remove"
|
||||
|
||||
ByteSet = 0xF0
|
||||
ByteGet = 0xF1
|
||||
ByteRemove = 0xF2
|
||||
)
|
||||
|
||||
func init() {
|
||||
basecoin.TxMapper.
|
||||
RegisterImplementation(SetTx{}, TypeSet, ByteSet)
|
||||
}
|
||||
|
||||
// SetTx sets a key-value pair
|
||||
type SetTx struct {
|
||||
Key data.Bytes `json:"key"`
|
||||
Value data.Bytes `json:"value"`
|
||||
}
|
||||
|
||||
// Wrap - fulfills TxInner interface
|
||||
func (t SetTx) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{t}
|
||||
}
|
||||
|
||||
// ValidateBasic makes sure it is valid
|
||||
func (t SetTx) ValidateBasic() error {
|
||||
if len(t.Key) == 0 || len(t.Value) == 0 {
|
||||
return ErrMissingData()
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue