Setup first tx, error code

This commit is contained in:
Ethan Frey 2017-08-06 21:21:52 +02:00
parent f4c45b6273
commit 9fe2f6b365
4 changed files with 71 additions and 0 deletions

23
modules/etc/errors.go Normal file
View File

@ -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)
}

6
modules/etc/handler.go Normal file
View File

@ -0,0 +1,6 @@
package etc
const (
// Name of the module for registering it
Name = "etc"
)

1
modules/etc/store.go Normal file
View File

@ -0,0 +1 @@
package etc

41
modules/etc/tx.go Normal file
View File

@ -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
}