aboutsummaryrefslogtreecommitdiffstats
path: root/core/types
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-19 07:02:55 +0800
committerobscuren <geffobscura@gmail.com>2014-12-19 07:02:55 +0800
commit22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b (patch)
treea64a8336516fd28de2c019e8c787c90950267331 /core/types
parent0dc566124aee24cf3f01b4e586bde7752da89824 (diff)
parenta7f4ade7114ee962110cb7c140e7ce7bd3f6664f (diff)
downloaddexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar.gz
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar.bz2
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar.lz
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar.xz
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.tar.zst
dexon-22d29a6d52ade3ebcd4ecb341e3f5eafddb8e17b.zip
merge
Diffstat (limited to 'core/types')
-rw-r--r--core/types/transaction.go94
1 files changed, 46 insertions, 48 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 63edef756..c64fb69f0 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -6,37 +6,30 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
- "github.com/ethereum/go-ethereum/state"
"github.com/obscuren/secp256k1-go"
)
-var ContractAddr = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
-
func IsContractAddr(addr []byte) bool {
return len(addr) == 0
- //return bytes.Compare(addr, ContractAddr) == 0
}
type Transaction struct {
- Nonce uint64
- Recipient []byte
- Value *big.Int
- Gas *big.Int
- GasPrice *big.Int
- Data []byte
+ nonce uint64
+ recipient []byte
+ value *big.Int
+ gas *big.Int
+ gasPrice *big.Int
+ data []byte
v byte
r, s []byte
-
- // Indicates whether this tx is a contract creation transaction
- contractCreation bool
}
func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction {
- return &Transaction{Recipient: nil, Value: value, Gas: gas, GasPrice: gasPrice, Data: script, contractCreation: true}
+ return &Transaction{recipient: nil, value: value, gas: gas, gasPrice: gasPrice, data: script}
}
func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction {
- return &Transaction{Recipient: to, Value: value, GasPrice: gasPrice, Gas: gas, Data: data, contractCreation: IsContractAddr(to)}
+ return &Transaction{recipient: to, value: value, gasPrice: gasPrice, gas: gas, data: data}
}
func NewTransactionFromBytes(data []byte) *Transaction {
@@ -53,33 +46,42 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
return tx
}
-func (self *Transaction) GasValue() *big.Int {
- return new(big.Int).Mul(self.Gas, self.GasPrice)
+func (tx *Transaction) Hash() []byte {
+ data := []interface{}{tx.Nonce, tx.gasPrice, tx.gas, tx.recipient, tx.Value, tx.Data}
+
+ return crypto.Sha3(ethutil.NewValue(data).Encode())
}
-func (self *Transaction) TotalValue() *big.Int {
- v := self.GasValue()
- return v.Add(v, self.Value)
+func (self *Transaction) Data() []byte {
+ return self.data
}
-func (tx *Transaction) Hash() []byte {
- data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data}
+func (self *Transaction) Gas() *big.Int {
+ return self.gas
+}
- return crypto.Sha3(ethutil.NewValue(data).Encode())
+func (self *Transaction) GasPrice() *big.Int {
+ return self.gasPrice
+}
+
+func (self *Transaction) Value() *big.Int {
+ return self.value
}
-func (tx *Transaction) CreatesContract() bool {
- return tx.contractCreation
+func (self *Transaction) Nonce() uint64 {
+ return self.nonce
}
-/* Deprecated */
-func (tx *Transaction) IsContract() bool {
- return tx.CreatesContract()
+func (self *Transaction) SetNonce(nonce uint64) {
+ self.nonce = nonce
}
-func (tx *Transaction) CreationAddress(state *state.StateDB) []byte {
- // Generate a new address
- return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
+func (self *Transaction) From() []byte {
+ return self.Sender()
+}
+
+func (self *Transaction) To() []byte {
+ return self.recipient
}
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
@@ -136,7 +138,7 @@ func (tx *Transaction) Sign(privk []byte) error {
}
func (tx *Transaction) RlpData() interface{} {
- data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data}
+ data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.recipient, tx.Value, tx.Data}
// TODO Remove prefixing zero's
@@ -156,20 +158,16 @@ func (tx *Transaction) RlpDecode(data []byte) {
}
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.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()
-
- if IsContractAddr(tx.Recipient) {
- tx.contractCreation = true
- }
}
func (tx *Transaction) String() string {
@@ -188,12 +186,12 @@ func (tx *Transaction) String() string {
S: 0x%x
`,
tx.Hash(),
- len(tx.Recipient) == 0,
+ len(tx.recipient) == 0,
tx.Sender(),
- tx.Recipient,
- tx.Nonce,
- tx.GasPrice,
- tx.Gas,
+ tx.recipient,
+ tx.nonce,
+ tx.gasPrice,
+ tx.gas,
tx.Value,
tx.Data,
tx.v,
@@ -221,5 +219,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].nonce < s.Transactions[j].nonce
}