diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-11-13 19:47:27 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-01-03 20:45:35 +0800 |
commit | 6f69cdd109b1dd692b8dfb15e7c53d2051fbc946 (patch) | |
tree | c92974f8b82209073ad1ee3faec6e149f834bf69 /core/types/transaction.go | |
parent | b8caba97099ee5eed33c3b80dd4ea540722e7d8f (diff) | |
download | go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.gz go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.bz2 go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.lz go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.xz go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.zst go-tangerine-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.zip |
all: switch gas limits from big.Int to uint64
Diffstat (limited to 'core/types/transaction.go')
-rw-r--r-- | core/types/transaction.go | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index ee4140ce4..a7ed211e4 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -57,7 +57,7 @@ type Transaction struct { type txdata struct { AccountNonce uint64 `json:"nonce" gencodec:"required"` Price *big.Int `json:"gasPrice" gencodec:"required"` - GasLimit *big.Int `json:"gas" gencodec:"required"` + GasLimit uint64 `json:"gas" gencodec:"required"` Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation Amount *big.Int `json:"value" gencodec:"required"` Payload []byte `json:"input" gencodec:"required"` @@ -74,7 +74,7 @@ type txdata struct { type txdataMarshaling struct { AccountNonce hexutil.Uint64 Price *hexutil.Big - GasLimit *hexutil.Big + GasLimit hexutil.Uint64 Amount *hexutil.Big Payload hexutil.Bytes V *hexutil.Big @@ -82,15 +82,15 @@ type txdataMarshaling struct { S *hexutil.Big } -func NewTransaction(nonce uint64, to common.Address, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction { +func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data) } -func NewContractCreation(nonce uint64, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction { +func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data) } -func newTransaction(nonce uint64, to *common.Address, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction { +func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction { if len(data) > 0 { data = common.CopyBytes(data) } @@ -99,7 +99,7 @@ func newTransaction(nonce uint64, to *common.Address, amount, gasLimit, gasPrice Recipient: to, Payload: data, Amount: new(big.Int), - GasLimit: new(big.Int), + GasLimit: gasLimit, Price: new(big.Int), V: new(big.Int), R: new(big.Int), @@ -108,9 +108,6 @@ func newTransaction(nonce uint64, to *common.Address, amount, gasLimit, gasPrice if amount != nil { d.Amount.Set(amount) } - if gasLimit != nil { - d.GasLimit.Set(gasLimit) - } if gasPrice != nil { d.Price.Set(gasPrice) } @@ -182,7 +179,7 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error { } func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) } -func (tx *Transaction) Gas() *big.Int { return new(big.Int).Set(tx.data.GasLimit) } +func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit } 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) Nonce() uint64 { return tx.data.AccountNonce } @@ -227,8 +224,8 @@ func (tx *Transaction) Size() common.StorageSize { func (tx *Transaction) AsMessage(s Signer) (Message, error) { msg := Message{ nonce: tx.data.AccountNonce, - price: new(big.Int).Set(tx.data.Price), - gasLimit: new(big.Int).Set(tx.data.GasLimit), + gasLimit: tx.data.GasLimit, + gasPrice: new(big.Int).Set(tx.data.Price), to: tx.data.Recipient, amount: tx.data.Amount, data: tx.data.Payload, @@ -254,7 +251,7 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e // Cost returns amount + gasprice * gaslimit. func (tx *Transaction) Cost() *big.Int { - total := new(big.Int).Mul(tx.data.Price, tx.data.GasLimit) + total := new(big.Int).Mul(tx.data.Price, new(big.Int).SetUint64(tx.data.GasLimit)) total.Add(total, tx.data.Amount) return total } @@ -440,22 +437,24 @@ func (t *TransactionsByPriceAndNonce) Pop() { // // NOTE: In a future PR this will be removed. type Message struct { - to *common.Address - from common.Address - nonce uint64 - amount, price, gasLimit *big.Int - data []byte - checkNonce bool + to *common.Address + from common.Address + nonce uint64 + amount *big.Int + gasLimit uint64 + gasPrice *big.Int + data []byte + checkNonce bool } -func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, gasLimit, price *big.Int, data []byte, checkNonce bool) Message { +func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message { return Message{ from: from, to: to, nonce: nonce, amount: amount, - price: price, gasLimit: gasLimit, + gasPrice: gasPrice, data: data, checkNonce: checkNonce, } @@ -463,9 +462,9 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount, g func (m Message) From() common.Address { return m.from } func (m Message) To() *common.Address { return m.to } -func (m Message) GasPrice() *big.Int { return m.price } +func (m Message) GasPrice() *big.Int { return m.gasPrice } func (m Message) Value() *big.Int { return m.amount } -func (m Message) Gas() *big.Int { return m.gasLimit } +func (m Message) Gas() uint64 { return m.gasLimit } func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Data() []byte { return m.data } func (m Message) CheckNonce() bool { return m.checkNonce } |