x/bank: remove Sequence from Input
This commit is contained in:
parent
9b8db6b37c
commit
b906c141bd
|
@ -66,7 +66,18 @@ func (tx StdTx) GetMsg() Msg { return tx.Msg }
|
|||
func (tx StdTx) GetFeePayer() Address { return tx.Signatures[0].PubKey.Address() } // XXX but PubKey is optional!
|
||||
func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }
|
||||
|
||||
//__________________________________________________________
|
||||
// StdSignDoc is replay-prevention structure.
|
||||
// It includes the result of msg.GetSignBytes(),
|
||||
// as well as the ChainID (prevent cross chain replay)
|
||||
// and the Sequence (prevent inchain replay).
|
||||
type StdSignDoc struct {
|
||||
ChainID string `json:"chain_id"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
MsgBytes []byte `json:"msg_bytes"`
|
||||
AltBytes []byte `json:"alt_bytes"` // TODO: do we really want this ?
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// Application function variable used to unmarshal transaction bytes
|
||||
type TxDecoder func(txBytes []byte) (Tx, Error)
|
||||
|
|
19
x/bank/tx.go
19
x/bank/tx.go
|
@ -4,8 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
@ -142,11 +140,8 @@ func (msg IssueMsg) GetSigners() []sdk.Address {
|
|||
|
||||
// Transaction Output
|
||||
type Input struct {
|
||||
Address sdk.Address `json:"address"`
|
||||
Coins sdk.Coins `json:"coins"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
|
||||
signature crypto.Signature
|
||||
Address sdk.Address `json:"address"`
|
||||
Coins sdk.Coins `json:"coins"`
|
||||
}
|
||||
|
||||
// ValidateBasic - validate transaction input
|
||||
|
@ -154,9 +149,6 @@ func (in Input) ValidateBasic() sdk.Error {
|
|||
if len(in.Address) == 0 {
|
||||
return ErrInvalidAddress(in.Address.String())
|
||||
}
|
||||
if in.Sequence < 0 {
|
||||
return ErrInvalidSequence("negative sequence")
|
||||
}
|
||||
if !in.Coins.IsValid() {
|
||||
return ErrInvalidCoins(in.Coins.String())
|
||||
}
|
||||
|
@ -179,13 +171,6 @@ func NewInput(addr sdk.Address, coins sdk.Coins) Input {
|
|||
return input
|
||||
}
|
||||
|
||||
// NewInputWithSequence - create a transaction input, used with SendMsg
|
||||
func NewInputWithSequence(addr sdk.Address, coins sdk.Coins, seq int64) Input {
|
||||
input := NewInput(addr, coins)
|
||||
input.Sequence = seq
|
||||
return input
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
// Output
|
||||
|
||||
|
|
|
@ -13,20 +13,12 @@ func TestNewSendMsg(t *testing.T) {}
|
|||
|
||||
func TestSendMsgType(t *testing.T) {
|
||||
// Construct a SendMsg
|
||||
addr1 := sdk.Address([]byte("input"))
|
||||
addr2 := sdk.Address([]byte("output"))
|
||||
coins := sdk.Coins{{"atom", 10}}
|
||||
var msg = SendMsg{
|
||||
Inputs: []Input{
|
||||
{
|
||||
Address: sdk.Address([]byte("input")),
|
||||
Coins: sdk.Coins{{"atom", 10}},
|
||||
Sequence: 1,
|
||||
},
|
||||
},
|
||||
Outputs: []Output{
|
||||
{
|
||||
Address: sdk.Address([]byte("output")),
|
||||
Coins: sdk.Coins{{"atom", 10}},
|
||||
},
|
||||
},
|
||||
Inputs: []Input{NewInput(addr1, coins)},
|
||||
Outputs: []Output{NewOutput(addr2, coins)},
|
||||
}
|
||||
|
||||
// TODO some failures for bad result
|
||||
|
@ -53,18 +45,16 @@ func TestInputValidation(t *testing.T) {
|
|||
}{
|
||||
// auth works with different apps
|
||||
{true, NewInput(addr1, someCoins)},
|
||||
{true, NewInputWithSequence(addr1, someCoins, 100)},
|
||||
{true, NewInputWithSequence(addr2, someCoins, 100)},
|
||||
{true, NewInputWithSequence(addr2, multiCoins, 100)},
|
||||
{true, NewInput(addr2, someCoins)},
|
||||
{true, NewInput(addr2, multiCoins)},
|
||||
|
||||
{false, NewInput(emptyAddr, someCoins)}, // empty address
|
||||
{false, NewInputWithSequence(addr1, someCoins, -1)}, // negative sequence
|
||||
{false, NewInput(addr1, emptyCoins)}, // invalid coins
|
||||
{false, NewInput(addr1, emptyCoins2)}, // invalid coins
|
||||
{false, NewInput(addr1, someEmptyCoins)}, // invalid coins
|
||||
{false, NewInput(addr1, minusCoins)}, // negative coins
|
||||
{false, NewInput(addr1, someMinusCoins)}, // negative coins
|
||||
{false, NewInput(addr1, unsortedCoins)}, // unsorted coins
|
||||
{false, NewInput(emptyAddr, someCoins)}, // empty address
|
||||
{false, NewInput(addr1, emptyCoins)}, // invalid coins
|
||||
{false, NewInput(addr1, emptyCoins2)}, // invalid coins
|
||||
{false, NewInput(addr1, someEmptyCoins)}, // invalid coins
|
||||
{false, NewInput(addr1, minusCoins)}, // negative coins
|
||||
{false, NewInput(addr1, someMinusCoins)}, // negative coins
|
||||
{false, NewInput(addr1, unsortedCoins)}, // unsorted coins
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
@ -144,7 +134,7 @@ func TestSendMsgValidation(t *testing.T) {
|
|||
{false, SendMsg{Inputs: []Input{input1}}}, // just input
|
||||
{false, SendMsg{Outputs: []Output{output1}}}, // just ouput
|
||||
{false, SendMsg{
|
||||
Inputs: []Input{NewInputWithSequence(emptyAddr, atom123, 1)}, // invalid input
|
||||
Inputs: []Input{NewInput(emptyAddr, atom123)}, // invalid input
|
||||
Outputs: []Output{output1}}},
|
||||
{false, SendMsg{
|
||||
Inputs: []Input{input1},
|
||||
|
|
Loading…
Reference in New Issue