diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-17 08:34:18 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-17 08:34:18 +0800 |
commit | d5de6489d7275374a3bb269b07780d6c13b6c3b7 (patch) | |
tree | 6719229491ce2708d2e647bbeed0471f0bcf9aff /core/types/transaction.go | |
parent | ad78db4d62d392e9462ac4c1f8ac3d9718fdd0fc (diff) | |
download | dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar.gz dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar.bz2 dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar.lz dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar.xz dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.tar.zst dexon-d5de6489d7275374a3bb269b07780d6c13b6c3b7.zip |
core/types: fix Transaction.Hash and add support for encoding with package rlp
Diffstat (limited to 'core/types/transaction.go')
-rw-r--r-- | core/types/transaction.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index d55c5d5ae..7f1447ef8 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -3,6 +3,7 @@ package types import ( "bytes" "fmt" + "io" "math/big" "github.com/ethereum/go-ethereum/common" @@ -27,12 +28,12 @@ type Transaction struct { R, S []byte } -func NewContractCreationTx(Amount, gasAmount, price *big.Int, data []byte) *Transaction { - return NewTransactionMessage(common.Address{}, Amount, gasAmount, price, data) +func NewContractCreationTx(amount, gasAmount, price *big.Int, data []byte) *Transaction { + return NewTransactionMessage(common.Address{}, amount, gasAmount, price, data) } -func NewTransactionMessage(to common.Address, Amount, gasAmount, price *big.Int, data []byte) *Transaction { - return &Transaction{Recipient: to, Amount: Amount, Price: price, GasLimit: gasAmount, Payload: data} +func NewTransactionMessage(to common.Address, amount, gasAmount, price *big.Int, data []byte) *Transaction { + return &Transaction{Recipient: to, Amount: amount, Price: price, GasLimit: gasAmount, Payload: data} } func NewTransactionFromBytes(data []byte) *Transaction { @@ -44,7 +45,7 @@ func NewTransactionFromBytes(data []byte) *Transaction { func (tx *Transaction) Hash() (a common.Hash) { h := sha3.NewKeccak256() rlp.Encode(h, []interface{}{tx.AccountNonce, tx.Price, tx.GasLimit, tx.Recipient, tx.Amount, tx.Payload}) - h.Sum(a[:]) + h.Sum(a[:0]) return a } @@ -84,7 +85,6 @@ func (tx *Transaction) Curve() (v byte, r []byte, s []byte) { v = byte(tx.V) r = common.LeftPadBytes(tx.R, 32) s = common.LeftPadBytes(tx.S, 32) - return } @@ -124,6 +124,19 @@ func (tx *Transaction) SetSignatureValues(sig []byte) error { return nil } +func (tx Transaction) EncodeRLP(w io.Writer) error { + return rlp.Encode(w, []interface{}{ + tx.AccountNonce, + tx.Price, tx.GasLimit, + tx.Recipient, + tx.Amount, + tx.Payload, + tx.V, + tx.R, + tx.S, + }) +} + // TODO: remove func (tx *Transaction) RlpData() interface{} { data := []interface{}{tx.AccountNonce, tx.Price, tx.GasLimit, tx.Recipient, tx.Amount, tx.Payload} |