diff options
author | obscuren <geffobscura@gmail.com> | 2014-03-28 02:49:47 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-03-28 02:49:47 +0800 |
commit | 00c5f9b9a67a6ab6f2850b756804dfa6efd8a824 (patch) | |
tree | c1e6e11524762cc1d26e3ffbe654b0fa9ba38593 /ethchain | |
parent | 7660e1ed907e213a53408fe60a63619a68fd817b (diff) | |
download | go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar.gz go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar.bz2 go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar.lz go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar.xz go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.tar.zst go-tangerine-00c5f9b9a67a6ab6f2850b756804dfa6efd8a824.zip |
Updated transaction model
Changed the behaviour of decoding rlp data. Something is considered to
be creating a contract if the 4th item is a list.
Changed constructors.
Diffstat (limited to 'ethchain')
-rw-r--r-- | ethchain/transaction.go | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/ethchain/transaction.go b/ethchain/transaction.go index 695071251..d71f9c7f7 100644 --- a/ethchain/transaction.go +++ b/ethchain/transaction.go @@ -2,6 +2,7 @@ package ethchain import ( "bytes" + "fmt" "github.com/ethereum/eth-go/ethutil" "github.com/obscuren/secp256k1-go" "math/big" @@ -23,33 +24,14 @@ type Transaction struct { contractCreation bool } -/* -func NewTransaction(to []byte, value *big.Int, data []string) *Transaction { - tx := Transaction{Recipient: to, Value: value, Nonce: 0, Data: data} - - return &tx -} -*/ - func NewContractCreationTx(value, gasprice *big.Int, data []string) *Transaction { return &Transaction{Value: value, Gasprice: gasprice, Data: data, contractCreation: true} } -func NewContractMessageTx(to []byte, value, gasprice, gas *big.Int, data []string) *Transaction { +func NewTransactionMessage(to []byte, value, gasprice, gas *big.Int, data []string) *Transaction { return &Transaction{Recipient: to, Value: value, Gasprice: gasprice, Gas: gas, Data: data} } -func NewTx(to []byte, value *big.Int, data []string) *Transaction { - return &Transaction{Recipient: to, Value: value, Gasprice: big.NewInt(0), Gas: big.NewInt(0), Nonce: 0, Data: data} -} - -/* -// XXX Deprecated -func NewTransactionFromData(data []byte) *Transaction { - return NewTransactionFromBytes(data) -} -*/ - func NewTransactionFromBytes(data []byte) *Transaction { tx := &Transaction{} tx.RlpDecode(data) @@ -131,16 +113,13 @@ func (tx *Transaction) Sign(privk []byte) error { } func (tx *Transaction) RlpData() interface{} { - // Prepare the transaction for serialization - return []interface{}{ - tx.Nonce, - tx.Recipient, - tx.Value, - ethutil.NewSliceValue(tx.Data).Slice(), - tx.v, - tx.r, - tx.s, + data := []interface{}{tx.Nonce, tx.Value, tx.Gasprice} + + if !tx.contractCreation { + data = append(data, tx.Recipient, tx.Gas) } + + return append(data, ethutil.NewSliceValue(tx.Data).Slice(), tx.v, tx.r, tx.s) } func (tx *Transaction) RlpValue() *ethutil.Value { @@ -156,14 +135,16 @@ func (tx *Transaction) RlpDecode(data []byte) { } // [ NONCE, VALUE, GASPRICE, TO, GAS, DATA, V, R, S ] +//["" "\x03\xe8" "" "\xaa" "\x03\xe8" [] '\x1c' "\x10C\x15\xfc\xe5\xd0\t\xe4\r\xe7\xefa\xf5aE\xd6\x14\xaed\xb5.\xf5\x18\xa1S_j\xe0A\xdc5U" "dQ\nqy\xf8\x17+\xbf\xd7Jx\xda-\xcb\xd7\xcfQ\x1bI\xb8_9\b\x80\xea듎i|\x1f"] func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) { + fmt.Println(decoder) tx.Nonce = decoder.Get(0).Uint() tx.Value = decoder.Get(1).BigInt() tx.Gasprice = decoder.Get(2).BigInt() // If the 4th item is a list(slice) this tx // is a contract creation tx - if decoder.Get(3).IsSlice() { + if decoder.Get(3).IsList() { d := decoder.Get(3) tx.Data = make([]string, d.Len()) for i := 0; i < d.Len(); i++ { @@ -173,6 +154,7 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) { tx.v = byte(decoder.Get(4).Uint()) tx.r = decoder.Get(5).Bytes() tx.s = decoder.Get(6).Bytes() + tx.contractCreation = true } else { tx.Recipient = decoder.Get(3).Bytes() |