Merge pull request #895 from cosmos/sunny/remove-msg-get
Remove Get function from Msg interface
This commit is contained in:
commit
a674d75016
|
@ -42,6 +42,7 @@ BREAKING CHANGES
|
|||
* Removed redundancy in names (ex. stake.StakeKeeper -> stake.Keeper)
|
||||
* Removed SealedAccountMapper
|
||||
* gaiad init now requires use of `--name` flag
|
||||
* Removed Get from Msg interface
|
||||
|
||||
BUG FIXES
|
||||
* Gaia now uses stake, ported from github.com/cosmos/gaia
|
||||
|
|
|
@ -318,13 +318,12 @@ type testUpdatePowerTx struct {
|
|||
|
||||
const msgType = "testUpdatePowerTx"
|
||||
|
||||
func (tx testUpdatePowerTx) Type() string { return msgType }
|
||||
func (tx testUpdatePowerTx) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx }
|
||||
func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil }
|
||||
func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil }
|
||||
func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil }
|
||||
func (tx testUpdatePowerTx) GetSignatures() []sdk.StdSignature { return nil }
|
||||
func (tx testUpdatePowerTx) Type() string { return msgType }
|
||||
func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx }
|
||||
func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil }
|
||||
func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil }
|
||||
func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil }
|
||||
func (tx testUpdatePowerTx) GetSignatures() []sdk.StdSignature { return nil }
|
||||
|
||||
func TestValidatorChange(t *testing.T) {
|
||||
|
||||
|
|
|
@ -29,9 +29,6 @@ type Msg interface {
|
|||
// Must be alphanumeric or empty.
|
||||
Type() string
|
||||
|
||||
// Get some property of the Msg.
|
||||
Get(key interface{}) (value interface{})
|
||||
|
||||
// Get the canonical byte representation of the Msg.
|
||||
GetSignBytes() []byte
|
||||
|
||||
|
@ -63,9 +60,6 @@ Messages can specify basic self-consistency checks using the `ValidateBasic()`
|
|||
method to enforce that message contents are well formed before any actual logic
|
||||
begins.
|
||||
|
||||
Finally, messages can provide generic access to their contents via `Get(key)`,
|
||||
but this is mostly for convenience and not type-safe.
|
||||
|
||||
For instance, the `Basecoin` message types are defined in `x/bank/tx.go`:
|
||||
|
||||
```go
|
||||
|
|
|
@ -143,9 +143,6 @@ implementing the ``Msg`` interface:
|
|||
// Must be alphanumeric or empty.
|
||||
Type() string
|
||||
|
||||
// Get some property of the Msg.
|
||||
Get(key interface{}) (value interface{})
|
||||
|
||||
// Get the canonical byte representation of the Msg.
|
||||
GetSignBytes() []byte
|
||||
|
||||
|
@ -175,9 +172,6 @@ Messages can specify basic self-consistency checks using the ``ValidateBasic()``
|
|||
method to enforce that message contents are well formed before any actual logic
|
||||
begins.
|
||||
|
||||
Finally, messages can provide generic access to their contents via ``Get(key)``,
|
||||
but this is mostly for convenience and not type-safe.
|
||||
|
||||
For instance, the ``Basecoin`` message types are defined in ``x/bank/tx.go``:
|
||||
|
||||
::
|
||||
|
|
|
@ -32,9 +32,8 @@ func NewMsgSetTrend(sender sdk.Address, cool string) MsgSetTrend {
|
|||
var _ sdk.Msg = MsgSetTrend{}
|
||||
|
||||
// nolint
|
||||
func (msg MsgSetTrend) Type() string { return "cool" }
|
||||
func (msg MsgSetTrend) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgSetTrend) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgSetTrend) Type() string { return "cool" }
|
||||
func (msg MsgSetTrend) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgSetTrend) String() string {
|
||||
return fmt.Sprintf("MsgSetTrend{Sender: %v, Cool: %v}", msg.Sender, msg.Cool)
|
||||
}
|
||||
|
@ -83,9 +82,8 @@ func NewMsgQuiz(sender sdk.Address, coolerthancool string) MsgQuiz {
|
|||
var _ sdk.Msg = MsgQuiz{}
|
||||
|
||||
// nolint
|
||||
func (msg MsgQuiz) Type() string { return "cool" }
|
||||
func (msg MsgQuiz) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgQuiz) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgQuiz) Type() string { return "cool" }
|
||||
func (msg MsgQuiz) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgQuiz) String() string {
|
||||
return fmt.Sprintf("MsgQuiz{Sender: %v, CoolAnswer: %v}", msg.Sender, msg.CoolAnswer)
|
||||
}
|
||||
|
|
|
@ -31,9 +31,8 @@ func NewMsgMine(sender sdk.Address, difficulty uint64, count uint64, nonce uint6
|
|||
}
|
||||
|
||||
// nolint
|
||||
func (msg MsgMine) Type() string { return "pow" }
|
||||
func (msg MsgMine) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgMine) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgMine) Type() string { return "pow" }
|
||||
func (msg MsgMine) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
|
||||
func (msg MsgMine) String() string {
|
||||
return fmt.Sprintf("MsgMine{Sender: %v, Difficulty: %d, Count: %d, Nonce: %d, Proof: %s}", msg.Sender, msg.Difficulty, msg.Count, msg.Nonce, msg.Proof)
|
||||
}
|
||||
|
|
|
@ -58,13 +58,6 @@ func TestMsgMineString(t *testing.T) {
|
|||
assert.Equal(t, res, "MsgMine{Sender: 73656E646572, Difficulty: 0, Count: 0, Nonce: 0, Proof: abc}")
|
||||
}
|
||||
|
||||
func TestMsgMineGet(t *testing.T) {
|
||||
addr := sdk.Address([]byte("sender"))
|
||||
msg := MsgMine{addr, 0, 0, 0, []byte("")}
|
||||
res := msg.Get(nil)
|
||||
assert.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestMsgMineGetSignBytes(t *testing.T) {
|
||||
addr := sdk.Address([]byte("sender"))
|
||||
msg := MsgMine{addr, 1, 1, 1, []byte("abc")}
|
||||
|
|
|
@ -26,9 +26,8 @@ func NewMsgBond(addr sdk.Address, stake sdk.Coin, pubKey crypto.PubKey) MsgBond
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgBond) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgBond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
|
||||
func (msg MsgBond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgBond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
|
||||
|
||||
// basic validation of the bond message
|
||||
func (msg MsgBond) ValidateBasic() sdk.Error {
|
||||
|
@ -66,10 +65,9 @@ func NewMsgUnbond(addr sdk.Address) MsgUnbond {
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgUnbond) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
|
||||
func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil }
|
||||
func (msg MsgUnbond) Type() string { return moduleName } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.Address} }
|
||||
func (msg MsgUnbond) ValidateBasic() sdk.Error { return nil }
|
||||
|
||||
// get unbond message sign bytes
|
||||
func (msg MsgUnbond) GetSignBytes() []byte {
|
||||
|
|
|
@ -13,19 +13,6 @@ type kvstoreTx struct {
|
|||
bytes []byte
|
||||
}
|
||||
|
||||
func (tx kvstoreTx) Get(key interface{}) (value interface{}) {
|
||||
switch k := key.(type) {
|
||||
case string:
|
||||
switch k {
|
||||
case "key":
|
||||
return tx.key
|
||||
case "value":
|
||||
return tx.value
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx kvstoreTx) Type() string {
|
||||
return "kvstore"
|
||||
}
|
||||
|
|
13
mock/tx.go
13
mock/tx.go
|
@ -26,19 +26,6 @@ func NewTx(key, value string) kvstoreTx {
|
|||
}
|
||||
}
|
||||
|
||||
func (tx kvstoreTx) Get(key interface{}) (value interface{}) {
|
||||
switch k := key.(type) {
|
||||
case string:
|
||||
switch k {
|
||||
case "key":
|
||||
return tx.key
|
||||
case "value":
|
||||
return tx.value
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tx kvstoreTx) Type() string {
|
||||
return "kvstore"
|
||||
}
|
||||
|
|
|
@ -37,9 +37,6 @@ type Account interface {
|
|||
|
||||
GetCoins() Coins
|
||||
SetCoins(Coins) error
|
||||
|
||||
Get(key interface{}) (value interface{}, err error)
|
||||
Set(key interface{}, value interface{}) error
|
||||
}
|
||||
|
||||
// AccountMapper stores and retrieves accounts from stores
|
||||
|
|
|
@ -11,9 +11,6 @@ type Msg interface {
|
|||
// Must be alphanumeric or empty.
|
||||
Type() string
|
||||
|
||||
// Get some property of the Msg.
|
||||
Get(key interface{}) (value interface{})
|
||||
|
||||
// Get the canonical byte representation of the Msg.
|
||||
GetSignBytes() []byte
|
||||
|
||||
|
@ -174,8 +171,7 @@ func NewTestMsg(addrs ...Address) *TestMsg {
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg *TestMsg) Type() string { return "TestMsg" }
|
||||
func (msg *TestMsg) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg *TestMsg) Type() string { return "TestMsg" }
|
||||
func (msg *TestMsg) GetSignBytes() []byte {
|
||||
bz, err := json.Marshal(msg.signers)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,16 +30,6 @@ func NewBaseAccountWithAddress(addr sdk.Address) BaseAccount {
|
|||
}
|
||||
}
|
||||
|
||||
// Implements sdk.Account.
|
||||
func (acc BaseAccount) Get(key interface{}) (value interface{}, err error) {
|
||||
panic("not implemented yet")
|
||||
}
|
||||
|
||||
// Implements sdk.Account.
|
||||
func (acc *BaseAccount) Set(key interface{}, value interface{}) error {
|
||||
panic("not implemented yet")
|
||||
}
|
||||
|
||||
// Implements sdk.Account.
|
||||
func (acc BaseAccount) GetAddress() sdk.Address {
|
||||
return acc.Address
|
||||
|
|
|
@ -106,12 +106,3 @@ func TestBaseAccountMarshal(t *testing.T) {
|
|||
assert.NotNil(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestBaseAccountGetSet(t *testing.T) {
|
||||
_, _, addr := keyPubAddr()
|
||||
acc := NewBaseAccountWithAddress(addr)
|
||||
|
||||
// Get/Set are not yet defined - all values cause a panic.
|
||||
assert.Panics(t, func() { acc.Get("key") })
|
||||
assert.Panics(t, func() { acc.Set("key", "value") })
|
||||
}
|
||||
|
|
|
@ -53,11 +53,6 @@ func (msg MsgSend) ValidateBasic() sdk.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgSend) Get(key interface{}) (value interface{}) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgSend) GetSignBytes() []byte {
|
||||
b, err := json.Marshal(msg) // XXX: ensure some canonical form
|
||||
|
@ -107,11 +102,6 @@ func (msg MsgIssue) ValidateBasic() sdk.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgIssue) Get(key interface{}) (value interface{}) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgIssue) GetSignBytes() []byte {
|
||||
b, err := json.Marshal(msg) // XXX: ensure some canonical form
|
||||
|
|
|
@ -177,18 +177,6 @@ func TestMsgSendValidation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMsgSendGet(t *testing.T) {
|
||||
addr1 := sdk.Address([]byte("input"))
|
||||
addr2 := sdk.Address([]byte("output"))
|
||||
coins := sdk.Coins{{"atom", 10}}
|
||||
var msg = MsgSend{
|
||||
Inputs: []Input{NewInput(addr1, coins)},
|
||||
Outputs: []Output{NewOutput(addr2, coins)},
|
||||
}
|
||||
res := msg.Get(nil)
|
||||
assert.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestMsgSendGetSignBytes(t *testing.T) {
|
||||
addr1 := sdk.Address([]byte("input"))
|
||||
addr2 := sdk.Address([]byte("output"))
|
||||
|
@ -259,17 +247,6 @@ func TestMsgIssueValidation(t *testing.T) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
func TestMsgIssueGet(t *testing.T) {
|
||||
addr := sdk.Address([]byte("loan-from-bank"))
|
||||
coins := sdk.Coins{{"atom", 10}}
|
||||
var msg = MsgIssue{
|
||||
Banker: sdk.Address([]byte("input")),
|
||||
Outputs: []Output{NewOutput(addr, coins)},
|
||||
}
|
||||
res := msg.Get(nil)
|
||||
assert.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestMsgIssueGetSignBytes(t *testing.T) {
|
||||
addr := sdk.Address([]byte("loan-from-bank"))
|
||||
coins := sdk.Coins{{"atom", 10}}
|
||||
|
|
|
@ -53,8 +53,7 @@ type IBCTransferMsg struct {
|
|||
}
|
||||
|
||||
// nolint
|
||||
func (msg IBCTransferMsg) Type() string { return "ibc" }
|
||||
func (msg IBCTransferMsg) Get(key interface{}) interface{} { return nil }
|
||||
func (msg IBCTransferMsg) Type() string { return "ibc" }
|
||||
|
||||
// x/bank/tx.go MsgSend.GetSigners()
|
||||
func (msg IBCTransferMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.SrcAddr} }
|
||||
|
@ -87,9 +86,8 @@ type IBCReceiveMsg struct {
|
|||
}
|
||||
|
||||
// nolint
|
||||
func (msg IBCReceiveMsg) Type() string { return "ibc" }
|
||||
func (msg IBCReceiveMsg) Get(key interface{}) interface{} { return nil }
|
||||
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }
|
||||
func (msg IBCReceiveMsg) Type() string { return "ibc" }
|
||||
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }
|
||||
|
||||
// x/bank/tx.go MsgSend.GetSigners()
|
||||
func (msg IBCReceiveMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Relayer} }
|
||||
|
|
|
@ -40,9 +40,8 @@ func NewMsgDeclareCandidacy(candidateAddr sdk.Address, pubkey crypto.PubKey,
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgDeclareCandidacy) Type() string { return MsgType } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgDeclareCandidacy) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgDeclareCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
|
||||
func (msg MsgDeclareCandidacy) Type() string { return MsgType } //TODO update "stake/declarecandidacy"
|
||||
func (msg MsgDeclareCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
|
||||
|
||||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgDeclareCandidacy) GetSignBytes() []byte {
|
||||
|
@ -87,9 +86,8 @@ func NewMsgEditCandidacy(candidateAddr sdk.Address, description Description) Msg
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgEditCandidacy) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgEditCandidacy) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgEditCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
|
||||
func (msg MsgEditCandidacy) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgEditCandidacy) GetSigners() []sdk.Address { return []sdk.Address{msg.CandidateAddr} }
|
||||
|
||||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgEditCandidacy) GetSignBytes() []byte {
|
||||
|
@ -130,9 +128,8 @@ func NewMsgDelegate(delegatorAddr, candidateAddr sdk.Address, bond sdk.Coin) Msg
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgDelegate) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgDelegate) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgDelegate) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
|
||||
func (msg MsgDelegate) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgDelegate) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
|
||||
|
||||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgDelegate) GetSignBytes() []byte {
|
||||
|
@ -178,9 +175,8 @@ func NewMsgUnbond(delegatorAddr, candidateAddr sdk.Address, shares string) MsgUn
|
|||
}
|
||||
|
||||
//nolint
|
||||
func (msg MsgUnbond) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgUnbond) Get(key interface{}) (value interface{}) { return nil }
|
||||
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
|
||||
func (msg MsgUnbond) Type() string { return MsgType } //TODO update "stake/msgeditcandidacy"
|
||||
func (msg MsgUnbond) GetSigners() []sdk.Address { return []sdk.Address{msg.DelegatorAddr} }
|
||||
|
||||
// get the bytes for the message signer to sign on
|
||||
func (msg MsgUnbond) GetSignBytes() []byte {
|
||||
|
|
Loading…
Reference in New Issue