From 27a5bae14d78938d1e18d1beeece220a7d4407ab Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Tue, 9 Jan 2018 15:40:34 +0000 Subject: [PATCH] Replace instances of 'nonce' with 'sequence' Signed-off-by: Silas Davis <silas@monax.io> --- account/account.go | 2 +- client/cmd/status.go | 2 +- client/cmd/transaction.go | 2 +- client/rpc/client.go | 30 +++++++++++++++--------------- client/rpc/client_test.go | 24 ++++++++++++------------ client/rpc/client_util.go | 20 ++++++++++---------- core/kernel.go | 2 +- docs/specs/api.md | 2 -- execution/execution.go | 2 +- execution/state_test.go | 4 ++-- execution/transactor.go | 2 +- rpc/tm/client/client_test.go | 8 ++++---- rpc/tm/client/shared.go | 26 +++++++++----------------- rpc/v0/json_service_test.go | 2 +- txs/tx_test.go | 4 ++-- txs/tx_utils.go | 26 +++++++++++++------------- 16 files changed, 74 insertions(+), 84 deletions(-) diff --git a/account/account.go b/account/account.go index 3aec5db8..4cb846ac 100644 --- a/account/account.go +++ b/account/account.go @@ -55,7 +55,7 @@ type Account interface { Balance() uint64 // The EVM byte code held by this account (or equivalently, this contract) Code() Bytecode - // The sequence number (or nonce) of this account, incremented each time a mutation of the + // The sequence number of this account, incremented each time a mutation of the // Account is persisted to the blockchain state Sequence() uint64 // The hash of all the values in this accounts storage (typically the root of some subtree diff --git a/client/cmd/status.go b/client/cmd/status.go index dac02391..555e9428 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -38,7 +38,7 @@ func buildStatusCommand() *cobra.Command { // TransactionCmd.PersistentFlags().StringVarP(&clientDo.PubkeyFlag, "pubkey", "", defaultPublicKey(), "specify the public key to sign with (defaults to $BURROW_CLIENT_PUBLIC_KEY)") // TransactionCmd.PersistentFlags().StringVarP(&clientDo.AddrFlag, "addr", "", defaultAddress(), "specify the account address (for which the public key can be found at monax-keys) (default respects $BURROW_CLIENT_ADDRESS)") // TransactionCmd.PersistentFlags().StringVarP(&clientDo.ChainidFlag, "chain-id", "", defaultChainId(), "specify the chainID (default respects $CHAIN_ID)") - // TransactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "nonce", "", "", "specify the nonce to use for the transaction (should equal the sender account's nonce + 1)") + // TransactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "sequence", "", "", "specify the sequence to use for the transaction (should equal the sender account's sequence + 1)") // // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.SignFlag, "sign", "s", false, "sign the transaction using the monax-keys daemon") // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.BroadcastFlag, "broadcast", "b", true, "broadcast the transaction to the blockchain") diff --git a/client/cmd/transaction.go b/client/cmd/transaction.go index 0bffd938..a5a1c0ac 100644 --- a/client/cmd/transaction.go +++ b/client/cmd/transaction.go @@ -145,7 +145,7 @@ func addTransactionPersistentFlags(transactionCmd *cobra.Command) { transactionCmd.PersistentFlags().StringVarP(&clientDo.NodeAddrFlag, "node-addr", "", defaultNodeRpcAddress(), "set the burrow node rpc server address (default respects $BURROW_CLIENT_NODE_ADDRESS)") transactionCmd.PersistentFlags().StringVarP(&clientDo.PubkeyFlag, "pubkey", "", defaultPublicKey(), "specify the public key to sign with (defaults to $BURROW_CLIENT_PUBLIC_KEY)") transactionCmd.PersistentFlags().StringVarP(&clientDo.AddrFlag, "addr", "", defaultAddress(), "specify the account address (for which the public key can be found at monax-keys) (default respects $BURROW_CLIENT_ADDRESS)") - transactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "nonce", "", "", "specify the nonce to use for the transaction (should equal the sender account's nonce + 1)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "sequence", "", "", "specify the sequence to use for the transaction (should equal the sender account's sequence + 1)") // transactionCmd.PersistentFlags().BoolVarP(&clientDo.SignFlag, "sign", "s", false, "sign the transaction using the monax-keys daemon") transactionCmd.PersistentFlags().BoolVarP(&clientDo.BroadcastFlag, "broadcast", "b", true, "broadcast the transaction to the blockchain") diff --git a/client/rpc/client.go b/client/rpc/client.go index a874a2ee..8e8f98e6 100644 --- a/client/rpc/client.go +++ b/client/rpc/client.go @@ -31,8 +31,8 @@ import ( // core functions with string args. // validates strings and forms transaction -func Send(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, toAddr, amtS, nonceS string) (*txs.SendTx, error) { - pub, amt, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, nonceS) +func Send(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, toAddr, amtS, sequenceS string) (*txs.SendTx, error) { + pub, amt, sequence, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, sequenceS) if err != nil { return nil, err } @@ -47,14 +47,14 @@ func Send(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, } tx := txs.NewSendTx() - tx.AddInputWithNonce(pub, amt, nonce) + tx.AddInputWithSequence(pub, amt, sequence) tx.AddOutput(toAddress, amt) return tx, nil } -func Call(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, toAddr, amtS, nonceS, gasS, feeS, data string) (*txs.CallTx, error) { - pub, amt, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, nonceS) +func Call(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, toAddr, amtS, sequenceS, gasS, feeS, data string) (*txs.CallTx, error) { + pub, amt, sequence, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, sequenceS) if err != nil { return nil, err } @@ -84,12 +84,12 @@ func Call(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, return nil, fmt.Errorf("data is bad hex: %v", err) } - tx := txs.NewCallTxWithNonce(pub, toAddress, dataBytes, amt, gas, fee, nonce) + tx := txs.NewCallTxWithSequence(pub, toAddress, dataBytes, amt, gas, fee, sequence) return tx, nil } -func Name(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, amtS, nonceS, feeS, name, data string) (*txs.NameTx, error) { - pub, amt, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, nonceS) +func Name(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, amtS, sequenceS, feeS, name, data string) (*txs.NameTx, error) { + pub, amt, sequence, err := checkCommon(nodeClient, keyClient, pubkey, addr, amtS, sequenceS) if err != nil { return nil, err } @@ -99,12 +99,12 @@ func Name(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, return nil, fmt.Errorf("fee is misformatted: %v", err) } - tx := txs.NewNameTxWithNonce(pub, name, data, amt, fee, nonce) + tx := txs.NewNameTxWithSequence(pub, name, data, amt, fee, sequence) return tx, nil } -func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addrS, nonceS, permFunc string, argsS []string) (*txs.PermissionsTx, error) { - pub, _, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addrS, "0", nonceS) +func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addrS, sequenceS, permFunc string, argsS []string) (*txs.PermissionsTx, error) { + pub, _, sequence, err := checkCommon(nodeClient, keyClient, pubkey, addrS, "0", sequenceS) if err != nil { return nil, err } @@ -163,13 +163,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, return nil, fmt.Errorf("invalid permission function for use in PermissionsTx: %s", permFunc) } // args := snativeArgs( - tx := txs.NewPermissionsTxWithNonce(pub, args, nonce) + tx := txs.NewPermissionsTxWithSequence(pub, args, sequence) return tx, nil } -func Bond(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, unbondAddr, amtS, nonceS string) (*txs.BondTx, error) { +func Bond(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, unbondAddr, amtS, sequenceS string) (*txs.BondTx, error) { return nil, fmt.Errorf("Bond Transaction formation to be implemented on 0.12.0") - // pub, amt, nonce, err := checkCommon(nodeAddr, signAddr, pubkey, "", amtS, nonceS) + // pub, amt, sequence, err := checkCommon(nodeAddr, signAddr, pubkey, "", amtS, sequenceS) // if err != nil { // return nil, err // } @@ -192,7 +192,7 @@ func Bond(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, unbond // if err != nil { // return nil, err // } - // tx.AddInputWithNonce(pub, amt, int(nonce)) + // tx.AddInputWithSequence(pub, amt, int(sequence)) // tx.AddOutput(unbondAddrBytes, amt) // return tx, nil diff --git a/client/rpc/client_test.go b/client/rpc/client_test.go index c731e491..a8cd5df5 100644 --- a/client/rpc/client_test.go +++ b/client/rpc/client_test.go @@ -52,11 +52,11 @@ func testSend(t *testing.T, toAddressString := keyClient.NewKey().String() // set an amount to transfer amountString := "1000" - // unset nonce so that we retrieve nonce from account - nonceString := "" + // unset sequence so that we retrieve sequence from account + sequenceString := "" _, err := Send(nodeClient, keyClient, publicKeyString, addressString, - toAddressString, amountString, nonceString) + toAddressString, amountString, sequenceString) require.NoError(t, err, "Error in Send") // assert.NotEqual(t, txSend) // TODO: test content of Transaction @@ -77,8 +77,8 @@ func testCall(t *testing.T, toAddressString := keyClient.NewKey().String() // set an amount to transfer amountString := "1000" - // unset nonce so that we retrieve nonce from account - nonceString := "" + // unset sequence so that we retrieve sequence from account + sequenceString := "" // set gas gasString := "1000" // set fee @@ -87,7 +87,7 @@ func testCall(t *testing.T, dataString := fmt.Sprintf("%X", "We are DOUG.") _, err := Call(nodeClient, keyClient, publicKeyString, addressString, - toAddressString, amountString, nonceString, gasString, feeString, dataString) + toAddressString, amountString, sequenceString, gasString, feeString, dataString) if err != nil { t.Logf("Error in CallTx: %s", err) t.Fail() @@ -108,8 +108,8 @@ func testName(t *testing.T, publicKeyString := "" // set an amount to transfer amountString := "1000" - // unset nonce so that we retrieve nonce from account - nonceString := "" + // unset sequence so that we retrieve sequence from account + sequenceString := "" // set fee feeString := "100" // set data @@ -118,7 +118,7 @@ func testName(t *testing.T, nameString := "DOUG" _, err := Name(nodeClient, keyClient, publicKeyString, addressString, - amountString, nonceString, feeString, nameString, dataString) + amountString, sequenceString, feeString, nameString, dataString) if err != nil { t.Logf("Error in NameTx: %s", err) t.Fail() @@ -139,11 +139,11 @@ func testPermissions(t *testing.T, publicKeyString := "" // generate an additional address to set permissions for permAddressString := keyClient.NewKey().String() - // unset nonce so that we retrieve nonce from account - nonceString := "" + // unset sequence so that we retrieve sequence from account + sequenceString := "" _, err := Permissions(nodeClient, keyClient, publicKeyString, addressString, - nonceString, "setBase", []string{permAddressString, "root", "true"}) + sequenceString, "setBase", []string{permAddressString, "root", "true"}) if err != nil { t.Logf("Error in PermissionsTx: %s", err) t.Fail() diff --git a/client/rpc/client_util.go b/client/rpc/client_util.go index 02e6ae05..8ad34c26 100644 --- a/client/rpc/client_util.go +++ b/client/rpc/client_util.go @@ -92,7 +92,7 @@ func decodeAddressPermFlag(addrS, permFlagS string) (addr acm.Address, pFlag pty } func checkCommon(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, amtS, - nonceS string) (pub acm.PublicKey, amt uint64, nonce uint64, err error) { + sequenceS string) (pub acm.PublicKey, amt uint64, sequence uint64, err error) { if amtS == "" { err = fmt.Errorf("input must specify an amount with the --amt flag") @@ -145,25 +145,25 @@ func checkCommon(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, err = fmt.Errorf("amt is misformatted: %v", err) } - if nonceS == "" { + if sequenceS == "" { if nodeClient == nil { - err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or BURROW_CLIENT_NODE_ADDR) to fetch the nonce from a node") + err = fmt.Errorf("input must specify a sequence with the --sequence flag or use --node-addr (or BURROW_CLIENT_NODE_ADDR) to fetch the sequence from a node") return } - // fetch nonce from node + // fetch sequence from node account, err2 := nodeClient.GetAccount(address) if err2 != nil { - return pub, amt, nonce, err2 + return pub, amt, sequence, err2 } - nonce = account.Sequence() + 1 - logging.TraceMsg(nodeClient.Logger(), "Fetch nonce from node", - "nonce", nonce, + sequence = account.Sequence() + 1 + logging.TraceMsg(nodeClient.Logger(), "Fetch sequence from node", + "sequence", sequence, "account address", address, ) } else { - nonce, err = strconv.ParseUint(nonceS, 10, 64) + sequence, err = strconv.ParseUint(sequenceS, 10, 64) if err != nil { - err = fmt.Errorf("nonce is misformatted: %v", err) + err = fmt.Errorf("sequence is misformatted: %v", err) return } } diff --git a/core/kernel.go b/core/kernel.go index 81ddfce5..5465f046 100644 --- a/core/kernel.go +++ b/core/kernel.go @@ -89,7 +89,7 @@ func NewKernel(privValidator tm_types.PrivValidator, genesisDoc *genesis.Genesis // TODO: consider whether we need to be more explicit about pre-commit (check cache) versus committed (state) values // Note we pass the checker as the StateIterable to NewService which means the RPC layers will query the check // cache state. This is in line with previous behaviour of Burrow and chiefly serves to get provide a pre-commit - // view of nonce values on the node that a client is communicating with. + // view of sequence values on the node that a client is communicating with. // Since we don't currently execute EVM code in the checker possible conflicts are limited to account creation // which increments the creator's account Sequence and SendTxs service := rpc.NewService(state, eventEmitter, nameReg, blockchain, transactor, query.NewNodeView(tmNode, txCodec), diff --git a/docs/specs/api.md b/docs/specs/api.md index 41e33742..5f94b755 100644 --- a/docs/specs/api.md +++ b/docs/specs/api.md @@ -632,8 +632,6 @@ Parameter: ##### Additional info -Sequence is sometimes referred to as the "nonce". - There are two types of objects used to represent accounts, one is public accounts (like the one here), the other is private accounts, which only holds information about an accounts address, public and private key. *** diff --git a/execution/execution.go b/execution/execution.go index cf634233..103a8607 100644 --- a/execution/execution.go +++ b/execution/execution.go @@ -310,7 +310,7 @@ func (exe *executor) Execute(tx txs.Tx) error { // if you call an account that doesn't exist // or an account with no code then we take fees (sorry pal) // NOTE: it's fine to create a contract and call it within one - // block (nonce will prevent re-ordering of those txs) + // block (sequence number will prevent re-ordering of those txs) // but to create with one contract and call with another // you have to wait a block to avoid a re-ordering attack // that will take your fees diff --git a/execution/state_test.go b/execution/state_test.go index 909b77d0..8ffb5ff2 100644 --- a/execution/state_test.go +++ b/execution/state_test.go @@ -243,7 +243,7 @@ func TestTxSequence(t *testing.T) { for i := uint64(0); i < 3; i++ { sequence := acc0.Sequence() + i tx := txs.NewSendTx() - tx.AddInputWithNonce(acc0PubKey, 1, sequence) + tx.AddInputWithSequence(acc0PubKey, 1, sequence) tx.AddOutput(acc1.Address(), 1) tx.Inputs[0].Signature = acm.ChainSign(privAccounts[0], testChainID, tx) stateCopy := state.Copy() @@ -881,7 +881,7 @@ func TestSelfDestruct(t *testing.T) { state.UpdateAccount(newAcc1) // send call tx with no data, cause self-destruct - tx := txs.NewCallTxWithNonce(acc0PubKey, addressPtr(acc1), nil, sendingAmount, 1000, 0, acc0.Sequence()+1) + tx := txs.NewCallTxWithSequence(acc0PubKey, addressPtr(acc1), nil, sendingAmount, 1000, 0, acc0.Sequence()+1) tx.Input.Signature = acm.ChainSign(privAccounts[0], testChainID, tx) // we use cache instead of execTxWithState so we can run the tx twice diff --git a/execution/transactor.go b/execution/transactor.go index e9957310..fc917c07 100644 --- a/execution/transactor.go +++ b/execution/transactor.go @@ -391,7 +391,7 @@ func (trans *transactor) TransactNameReg(privKey []byte, name, data string, amou if acc == nil { sequence = acc.Sequence() + uint64(1) } - tx := txs.NewNameTxWithNonce(pa.PublicKey(), name, data, amount, fee, sequence) + tx := txs.NewNameTxWithSequence(pa.PublicKey(), name, data, amount, fee, sequence) // Got ourselves a tx. txS, errS := trans.SignTx(tx, []acm.PrivateAccount{pa}) if errS != nil { diff --git a/rpc/tm/client/client_test.go b/rpc/tm/client/client_test.go index 4140a215..fb3e37a9 100644 --- a/rpc/tm/client/client_test.go +++ b/rpc/tm/client/client_test.go @@ -250,8 +250,8 @@ func TestNameReg(t *testing.T) { assert.Equal(t, updatedData, entry.Data) // try to update as non owner, should fail - tx = txs.NewNameTxWithNonce(privateAccounts[1].PublicKey(), name, "never mind", amt, fee, - getNonce(t, client, privateAccounts[1].Address())+1) + tx = txs.NewNameTxWithSequence(privateAccounts[1].PublicKey(), name, "never mind", amt, fee, + getSequence(t, client, privateAccounts[1].Address())+1) tx.Sign(genesisDoc.ChainID(), privateAccounts[1]) _, err := broadcastTxAndWaitForBlock(t, client, wsc, tx) @@ -267,8 +267,8 @@ func TestNameReg(t *testing.T) { //now the entry should be expired, so we can update as non owner const data2 = "this is not my beautiful house" - tx = txs.NewNameTxWithNonce(privateAccounts[1].PublicKey(), name, data2, amt, fee, - getNonce(t, client, privateAccounts[1].Address())+1) + tx = txs.NewNameTxWithSequence(privateAccounts[1].PublicKey(), name, data2, amt, fee, + getSequence(t, client, privateAccounts[1].Address())+1) tx.Sign(genesisDoc.ChainID(), privateAccounts[1]) _, err = broadcastTxAndWaitForBlock(t, client, wsc, tx) assert.NoError(t, err, "Should be able to update a previously expired name"+ diff --git a/rpc/tm/client/shared.go b/rpc/tm/client/shared.go index 0aaf157c..c0b946f2 100644 --- a/rpc/tm/client/shared.go +++ b/rpc/tm/client/shared.go @@ -126,9 +126,9 @@ func makePrivateAccounts(n int) []acm.PrivateAccount { // some default transaction functions func makeDefaultSendTx(t *testing.T, client RPCClient, addr acm.Address, amt uint64) *txs.SendTx { - nonce := getNonce(t, client, privateAccounts[0].Address()) + sequence := getSequence(t, client, privateAccounts[0].Address()) tx := txs.NewSendTx() - tx.AddInputWithNonce(privateAccounts[0].PublicKey(), amt, nonce+1) + tx.AddInputWithSequence(privateAccounts[0].PublicKey(), amt, sequence+1) tx.AddOutput(addr, amt) return tx } @@ -141,24 +141,16 @@ func makeDefaultSendTxSigned(t *testing.T, client RPCClient, addr acm.Address, a func makeDefaultCallTx(t *testing.T, client RPCClient, addr *acm.Address, code []byte, amt, gasLim, fee uint64) *txs.CallTx { - nonce := getNonce(t, client, privateAccounts[0].Address()) - tx := txs.NewCallTxWithNonce(privateAccounts[0].PublicKey(), addr, code, amt, gasLim, fee, - nonce+1) - tx.Sign(genesisDoc.ChainID(), privateAccounts[0]) - return tx -} - -func makeDefaultCallTxWithNonce(t *testing.T, addr *acm.Address, sequence uint64, code []byte, - amt, gasLim, fee uint64) *txs.CallTx { - - tx := txs.NewCallTxWithNonce(privateAccounts[0].PublicKey(), addr, code, amt, gasLim, fee, sequence) + sequence := getSequence(t, client, privateAccounts[0].Address()) + tx := txs.NewCallTxWithSequence(privateAccounts[0].PublicKey(), addr, code, amt, gasLim, fee, + sequence+1) tx.Sign(genesisDoc.ChainID(), privateAccounts[0]) return tx } func makeDefaultNameTx(t *testing.T, client RPCClient, name, value string, amt, fee uint64) *txs.NameTx { - nonce := getNonce(t, client, privateAccounts[0].Address()) - tx := txs.NewNameTxWithNonce(privateAccounts[0].PublicKey(), name, value, amt, fee, nonce+1) + sequence := getSequence(t, client, privateAccounts[0].Address()) + tx := txs.NewNameTxWithSequence(privateAccounts[0].PublicKey(), name, value, amt, fee, sequence+1) tx.Sign(genesisDoc.ChainID(), privateAccounts[0]) return tx } @@ -166,8 +158,8 @@ func makeDefaultNameTx(t *testing.T, client RPCClient, name, value string, amt, //------------------------------------------------------------------------------- // rpc call wrappers (fail on err) -// get an account's nonce -func getNonce(t *testing.T, client RPCClient, addr acm.Address) uint64 { +// get an account's sequence number +func getSequence(t *testing.T, client RPCClient, addr acm.Address) uint64 { acc, err := GetAccount(client, addr) if err != nil { t.Fatal(err) diff --git a/rpc/v0/json_service_test.go b/rpc/v0/json_service_test.go index 5428f94a..087b8969 100644 --- a/rpc/v0/json_service_test.go +++ b/rpc/v0/json_service_test.go @@ -33,7 +33,7 @@ func TestBroadcastTx(t *testing.T) { pubKey := account.GenPrivAccount().PubKey address := []byte{1} code := opcodes.Bytecode(opcodes.PUSH1, 1, opcodes.PUSH1, 1, opcodes.ADD) - var tx txs.Tx = txs.NewCallTxWithNonce(pubKey, address, code, 10, 2, + var tx txs.Tx = txs.NewCallTxWithSequence(pubKey, address, code, 10, 2, 1, 0) jsonBytes := wire.JSONBytesPretty(wrappedTx{tx}) request := rpc.NewRPCRequest("TestBroadcastTx", "BroadcastTx", jsonBytes) diff --git a/txs/tx_test.go b/txs/tx_test.go index 6bc2f110..c8c39a62 100644 --- a/txs/tx_test.go +++ b/txs/tx_test.go @@ -206,11 +206,11 @@ func TestTxWrapper_MarshalJSON(t *testing.T) { testTxMarshalJSON(t, callTx) } -func TestNewPermissionsTxWithNonce(t *testing.T) { +func TestNewPermissionsTxWithSequence(t *testing.T) { privateKey := acm.PrivateKeyFromSecret("Shhh...") args := ptypes.SetBaseArgs(privateKey.PublicKey().Address(), ptypes.HasRole, true) - permTx := NewPermissionsTxWithNonce(privateKey.PublicKey(), args, 1) + permTx := NewPermissionsTxWithSequence(privateKey.PublicKey(), args, 1) testTxMarshalJSON(t, permTx) } diff --git a/txs/tx_utils.go b/txs/tx_utils.go index c680a7f4..1b2d65fe 100644 --- a/txs/tx_utils.go +++ b/txs/tx_utils.go @@ -42,10 +42,10 @@ func (tx *SendTx) AddInput(st acm.Getter, pubkey acm.PublicKey, amt uint64) erro if acc == nil { return fmt.Errorf("invalid address %s from pubkey %s", addr, pubkey) } - return tx.AddInputWithNonce(pubkey, amt, acc.Sequence()+1) + return tx.AddInputWithSequence(pubkey, amt, acc.Sequence()+1) } -func (tx *SendTx) AddInputWithNonce(pubkey acm.PublicKey, amt uint64, sequence uint64) error { +func (tx *SendTx) AddInputWithSequence(pubkey acm.PublicKey, amt uint64, sequence uint64) error { addr := pubkey.Address() tx.Inputs = append(tx.Inputs, &TxInput{ Address: addr, @@ -89,11 +89,11 @@ func NewCallTx(st acm.Getter, from acm.PublicKey, to *acm.Address, data []byte, return nil, fmt.Errorf("invalid address %s from pubkey %s", addr, from) } - nonce := acc.Sequence() + 1 - return NewCallTxWithNonce(from, to, data, amt, gasLimit, fee, nonce), nil + sequence := acc.Sequence() + 1 + return NewCallTxWithSequence(from, to, data, amt, gasLimit, fee, sequence), nil } -func NewCallTxWithNonce(from acm.PublicKey, to *acm.Address, data []byte, +func NewCallTxWithSequence(from acm.PublicKey, to *acm.Address, data []byte, amt, gasLimit, fee, sequence uint64) *CallTx { input := &TxInput{ Address: from.Address(), @@ -130,11 +130,11 @@ func NewNameTx(st acm.Getter, from acm.PublicKey, name, data string, amt, fee ui return nil, fmt.Errorf("Invalid address %s from pubkey %s", addr, from) } - nonce := acc.Sequence() + 1 - return NewNameTxWithNonce(from, name, data, amt, fee, nonce), nil + sequence := acc.Sequence() + 1 + return NewNameTxWithSequence(from, name, data, amt, fee, sequence), nil } -func NewNameTxWithNonce(from acm.PublicKey, name, data string, amt, fee, sequence uint64) *NameTx { +func NewNameTxWithSequence(from acm.PublicKey, name, data string, amt, fee, sequence uint64) *NameTx { input := &TxInput{ Address: from.Address(), Amount: amt, @@ -176,10 +176,10 @@ func (tx *BondTx) AddInput(st acm.Getter, pubkey acm.PublicKey, amt uint64) erro if acc == nil { return fmt.Errorf("Invalid address %s from pubkey %s", addr, pubkey) } - return tx.AddInputWithNonce(pubkey, amt, acc.Sequence()+uint64(1)) + return tx.AddInputWithSequence(pubkey, amt, acc.Sequence()+uint64(1)) } -func (tx *BondTx) AddInputWithNonce(pubkey acm.PublicKey, amt uint64, sequence uint64) error { +func (tx *BondTx) AddInputWithSequence(pubkey acm.PublicKey, amt uint64, sequence uint64) error { tx.Inputs = append(tx.Inputs, &TxInput{ Address: pubkey.Address(), Amount: amt, @@ -253,11 +253,11 @@ func NewPermissionsTx(st acm.Getter, from acm.PublicKey, args *ptypes.PermArgs) return nil, fmt.Errorf("Invalid address %s from pubkey %s", addr, from) } - nonce := acc.Sequence() + 1 - return NewPermissionsTxWithNonce(from, args, nonce), nil + sequence := acc.Sequence() + 1 + return NewPermissionsTxWithSequence(from, args, sequence), nil } -func NewPermissionsTxWithNonce(from acm.PublicKey, args *ptypes.PermArgs, sequence uint64) *PermissionsTx { +func NewPermissionsTxWithSequence(from acm.PublicKey, args *ptypes.PermArgs, sequence uint64) *PermissionsTx { input := &TxInput{ Address: from.Address(), Amount: 1, // NOTE: amounts can't be 0 ... -- GitLab