Merge pull request #2799 from zsfelfoldi/api-nonce-fix2

core: added CheckNonce() to Message interface
This commit is contained in:
Péter Szilágyi 2016-07-12 16:07:15 +03:00 committed by GitHub
commit f970610c04
7 changed files with 17 additions and 8 deletions

@ -203,7 +203,8 @@ type callmsg struct {
func (m callmsg) From() (common.Address, error) { return m.from.Address(), nil } func (m callmsg) From() (common.Address, error) { return m.from.Address(), nil }
func (m callmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil }
func (m callmsg) Nonce() uint64 { return m.from.Nonce() } func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.to } func (m callmsg) To() *common.Address { return m.to }
func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
func (m callmsg) Gas() *big.Int { return m.gasLimit } func (m callmsg) Gas() *big.Int { return m.gasLimit }

@ -128,7 +128,10 @@ func (m callmsg) FromFrontier() (common.Address, error) {
return m.from.Address(), nil return m.from.Address(), nil
} }
func (m callmsg) Nonce() uint64 { func (m callmsg) Nonce() uint64 {
return m.from.Nonce() return 0
}
func (m callmsg) CheckNonce() bool {
return false
} }
func (m callmsg) To() *common.Address { func (m callmsg) To() *common.Address {
return m.to return m.to

@ -71,6 +71,7 @@ type Message interface {
Value() *big.Int Value() *big.Int
Nonce() uint64 Nonce() uint64
CheckNonce() bool
Data() []byte Data() []byte
} }
@ -208,8 +209,10 @@ func (self *StateTransition) preCheck() (err error) {
} }
// Make sure this transaction's nonce is correct // Make sure this transaction's nonce is correct
if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() { if msg.CheckNonce() {
return NonceError(msg.Nonce(), n) if n := self.state.GetNonce(sender.Address()); n != msg.Nonce() {
return NonceError(msg.Nonce(), n)
}
} }
// Pre-pay gas // Pre-pay gas

@ -113,6 +113,7 @@ func (tx *Transaction) Gas() *big.Int { return new(big.Int).Set(tx.data.Gas
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) } func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) }
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) } func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce } func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true }
func (tx *Transaction) To() *common.Address { func (tx *Transaction) To() *common.Address {
if tx.data.Recipient == nil { if tx.data.Recipient == nil {

@ -424,7 +424,6 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config *vm.Config) (b
// callmsg is the message type used for call transations. // callmsg is the message type used for call transations.
type callmsg struct { type callmsg struct {
addr common.Address addr common.Address
nonce uint64
to *common.Address to *common.Address
gas, gasPrice *big.Int gas, gasPrice *big.Int
value *big.Int value *big.Int
@ -434,7 +433,8 @@ type callmsg struct {
// accessor boilerplate to implement core.Message // accessor boilerplate to implement core.Message
func (m callmsg) From() (common.Address, error) { return m.addr, nil } func (m callmsg) From() (common.Address, error) { return m.addr, nil }
func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil }
func (m callmsg) Nonce() uint64 { return m.nonce } func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.to } func (m callmsg) To() *common.Address { return m.to }
func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
func (m callmsg) Gas() *big.Int { return m.gas } func (m callmsg) Gas() *big.Int { return m.gas }

@ -534,7 +534,6 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
// callmsg is the message type used for call transations. // callmsg is the message type used for call transations.
type callmsg struct { type callmsg struct {
addr common.Address addr common.Address
nonce uint64
to *common.Address to *common.Address
gas, gasPrice *big.Int gas, gasPrice *big.Int
value *big.Int value *big.Int
@ -544,7 +543,8 @@ type callmsg struct {
// accessor boilerplate to implement core.Message // accessor boilerplate to implement core.Message
func (m callmsg) From() (common.Address, error) { return m.addr, nil } func (m callmsg) From() (common.Address, error) { return m.addr, nil }
func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil } func (m callmsg) FromFrontier() (common.Address, error) { return m.addr, nil }
func (m callmsg) Nonce() uint64 { return m.nonce } func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.to } func (m callmsg) To() *common.Address { return m.to }
func (m callmsg) GasPrice() *big.Int { return m.gasPrice } func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
func (m callmsg) Gas() *big.Int { return m.gas } func (m callmsg) Gas() *big.Int { return m.gas }

@ -312,4 +312,5 @@ func (self Message) GasPrice() *big.Int { return self.price }
func (self Message) Gas() *big.Int { return self.gas } func (self Message) Gas() *big.Int { return self.gas }
func (self Message) Value() *big.Int { return self.value } func (self Message) Value() *big.Int { return self.value }
func (self Message) Nonce() uint64 { return self.nonce } func (self Message) Nonce() uint64 { return self.nonce }
func (self Message) CheckNonce() bool { return true }
func (self Message) Data() []byte { return self.data } func (self Message) Data() []byte { return self.data }