aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/transaction.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/types/transaction.go')
-rw-r--r--core/types/transaction.go121
1 files changed, 59 insertions, 62 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 3a87f7844..c2f7df7a7 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -1,11 +1,13 @@
package types
import (
+ "bytes"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/rlp"
"github.com/obscuren/secp256k1-go"
)
@@ -14,22 +16,22 @@ func IsContractAddr(addr []byte) bool {
}
type Transaction struct {
- nonce uint64
- recipient []byte
- value *big.Int
- gas *big.Int
- gasPrice *big.Int
- data []byte
- v byte
- r, s []byte
+ AccountNonce uint64
+ Recipient []byte
+ Amount *big.Int
+ GasAmount *big.Int
+ Price *big.Int
+ Payload []byte
+ V uint64
+ R, S []byte
}
-func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction {
- return &Transaction{recipient: nil, value: value, gas: gas, gasPrice: gasPrice, data: script}
+func NewContractCreationTx(Amount, gasAmount, price *big.Int, data []byte) *Transaction {
+ return NewTransactionMessage(nil, Amount, gasAmount, price, data)
}
-func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction {
- return &Transaction{recipient: to, value: value, gasPrice: gasPrice, gas: gas, data: data}
+func NewTransactionMessage(to []byte, Amount, gasAmount, price *big.Int, data []byte) *Transaction {
+ return &Transaction{Recipient: to, Amount: Amount, Price: price, GasAmount: gasAmount, Payload: data}
}
func NewTransactionFromBytes(data []byte) *Transaction {
@@ -39,7 +41,7 @@ func NewTransactionFromBytes(data []byte) *Transaction {
return tx
}
-func NewTransactionFromValue(val *ethutil.Value) *Transaction {
+func NewTransactionFromAmount(val *ethutil.Value) *Transaction {
tx := &Transaction{}
tx.RlpValueDecode(val)
@@ -47,33 +49,33 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
}
func (tx *Transaction) Hash() []byte {
- data := []interface{}{tx.nonce, tx.gasPrice, tx.gas, tx.recipient, tx.value, tx.data}
+ data := []interface{}{tx.AccountNonce, tx.Price, tx.GasAmount, tx.Recipient, tx.Amount, tx.Payload}
- return crypto.Sha3(ethutil.NewValue(data).Encode())
+ return crypto.Sha3(ethutil.Encode(data))
}
func (self *Transaction) Data() []byte {
- return self.data
+ return self.Payload
}
func (self *Transaction) Gas() *big.Int {
- return self.gas
+ return self.GasAmount
}
func (self *Transaction) GasPrice() *big.Int {
- return self.gasPrice
+ return self.Price
}
func (self *Transaction) Value() *big.Int {
- return self.value
+ return self.Amount
}
func (self *Transaction) Nonce() uint64 {
- return self.nonce
+ return self.AccountNonce
}
-func (self *Transaction) SetNonce(nonce uint64) {
- self.nonce = nonce
+func (self *Transaction) SetNonce(AccountNonce uint64) {
+ self.AccountNonce = AccountNonce
}
func (self *Transaction) From() []byte {
@@ -81,13 +83,13 @@ func (self *Transaction) From() []byte {
}
func (self *Transaction) To() []byte {
- return self.recipient
+ return self.Recipient
}
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
- v = tx.v
- r = ethutil.LeftPadBytes(tx.r, 32)
- s = ethutil.LeftPadBytes(tx.s, 32)
+ v = byte(tx.V)
+ r = ethutil.LeftPadBytes(tx.R, 32)
+ s = ethutil.LeftPadBytes(tx.S, 32)
return
}
@@ -130,42 +132,37 @@ func (tx *Transaction) Sign(privk []byte) error {
sig := tx.Signature(privk)
- tx.r = sig[:32]
- tx.s = sig[32:64]
- tx.v = sig[64] + 27
+ tx.R = sig[:32]
+ tx.S = sig[32:64]
+ tx.V = uint64(sig[64] + 27)
return nil
}
func (tx *Transaction) RlpData() interface{} {
- data := []interface{}{tx.nonce, tx.gasPrice, tx.gas, tx.recipient, tx.value, tx.data}
+ data := []interface{}{tx.AccountNonce, tx.Price, tx.GasAmount, tx.Recipient, tx.Amount, tx.Payload}
- return append(data, tx.v, new(big.Int).SetBytes(tx.r).Bytes(), new(big.Int).SetBytes(tx.s).Bytes())
-}
-
-func (tx *Transaction) RlpValue() *ethutil.Value {
- return ethutil.NewValue(tx.RlpData())
+ return append(data, tx.V, new(big.Int).SetBytes(tx.R).Bytes(), new(big.Int).SetBytes(tx.S).Bytes())
}
func (tx *Transaction) RlpEncode() []byte {
- return tx.RlpValue().Encode()
+ return ethutil.Encode(tx)
}
func (tx *Transaction) RlpDecode(data []byte) {
- tx.RlpValueDecode(ethutil.NewValueFromBytes(data))
+ rlp.Decode(bytes.NewReader(data), tx)
}
func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
- tx.nonce = decoder.Get(0).Uint()
- tx.gasPrice = decoder.Get(1).BigInt()
- tx.gas = decoder.Get(2).BigInt()
- tx.recipient = decoder.Get(3).Bytes()
- tx.value = decoder.Get(4).BigInt()
- tx.data = decoder.Get(5).Bytes()
- tx.v = byte(decoder.Get(6).Uint())
-
- tx.r = decoder.Get(7).Bytes()
- tx.s = decoder.Get(8).Bytes()
+ tx.AccountNonce = decoder.Get(0).Uint()
+ tx.Price = decoder.Get(1).BigInt()
+ tx.GasAmount = decoder.Get(2).BigInt()
+ tx.Recipient = decoder.Get(3).Bytes()
+ tx.Amount = decoder.Get(4).BigInt()
+ tx.Payload = decoder.Get(5).Bytes()
+ tx.V = decoder.Get(6).Uint()
+ tx.R = decoder.Get(7).Bytes()
+ tx.S = decoder.Get(8).Bytes()
}
func (tx *Transaction) String() string {
@@ -174,10 +171,10 @@ func (tx *Transaction) String() string {
Contract: %v
From: %x
To: %x
- Nonce: %v
- GasPrice: %v
- Gas: %v
- Value: %v
+ AccountNonce: %v
+ GasAmountPrice: %v
+ GasAmount: %v
+ Amount: %v
Data: 0x%x
V: 0x%x
R: 0x%x
@@ -185,17 +182,17 @@ func (tx *Transaction) String() string {
Hex: %x
`,
tx.Hash(),
- len(tx.recipient) == 0,
+ len(tx.Recipient) == 0,
tx.From(),
- tx.recipient,
- tx.nonce,
- tx.gasPrice,
- tx.gas,
- tx.value,
- tx.data,
- tx.v,
- tx.r,
- tx.s,
+ tx.Recipient,
+ tx.AccountNonce,
+ tx.Price,
+ tx.GasAmount,
+ tx.Amount,
+ tx.Payload,
+ tx.V,
+ tx.R,
+ tx.S,
ethutil.Encode(tx),
)
}
@@ -220,5 +217,5 @@ func (s Transactions) GetRlp(i int) []byte { return ethutil.Rlp(s[i]) }
type TxByNonce struct{ Transactions }
func (s TxByNonce) Less(i, j int) bool {
- return s.Transactions[i].nonce < s.Transactions[j].nonce
+ return s.Transactions[i].AccountNonce < s.Transactions[j].AccountNonce
}