2017-08-07 10:21:07 -07:00
|
|
|
package eyes
|
2017-08-06 12:21:52 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tendermint/basecoin"
|
|
|
|
"github.com/tendermint/go-wire/data"
|
|
|
|
)
|
|
|
|
|
|
|
|
// nolint
|
|
|
|
const (
|
|
|
|
TypeSet = Name + "/set"
|
|
|
|
TypeRemove = Name + "/remove"
|
|
|
|
|
2017-08-06 13:34:27 -07:00
|
|
|
ByteSet = 0xF4
|
|
|
|
ByteRemove = 0xF5
|
2017-08-06 12:21:52 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
basecoin.TxMapper.
|
2017-08-06 13:23:17 -07:00
|
|
|
RegisterImplementation(SetTx{}, TypeSet, ByteSet).
|
|
|
|
RegisterImplementation(RemoveTx{}, TypeRemove, ByteRemove)
|
2017-08-06 12:21:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTx sets a key-value pair
|
|
|
|
type SetTx struct {
|
|
|
|
Key data.Bytes `json:"key"`
|
|
|
|
Value data.Bytes `json:"value"`
|
|
|
|
}
|
|
|
|
|
2017-08-06 13:51:07 -07:00
|
|
|
func NewSetTx(key, value []byte) basecoin.Tx {
|
|
|
|
return SetTx{Key: key, Value: value}.Wrap()
|
|
|
|
}
|
|
|
|
|
2017-08-06 12:21:52 -07:00
|
|
|
// 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
|
|
|
|
}
|
2017-08-06 13:23:17 -07:00
|
|
|
|
|
|
|
// RemoveTx deletes the value at this key, returns old value
|
|
|
|
type RemoveTx struct {
|
|
|
|
Key data.Bytes `json:"key"`
|
|
|
|
}
|
|
|
|
|
2017-08-06 13:51:07 -07:00
|
|
|
func NewRemoveTx(key []byte) basecoin.Tx {
|
|
|
|
return RemoveTx{Key: key}.Wrap()
|
|
|
|
}
|
|
|
|
|
2017-08-06 13:23:17 -07:00
|
|
|
// Wrap - fulfills TxInner interface
|
|
|
|
func (t RemoveTx) Wrap() basecoin.Tx {
|
|
|
|
return basecoin.Tx{t}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateBasic makes sure it is valid
|
|
|
|
func (t RemoveTx) ValidateBasic() error {
|
|
|
|
if len(t.Key) == 0 {
|
|
|
|
return ErrMissingData()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|