aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/transaction.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-22 23:35:26 +0800
committerobscuren <geffobscura@gmail.com>2014-05-22 23:35:26 +0800
commit230aafbf66ba747fb3796810adf3b1680f368e73 (patch)
tree66aff77b70bf083cc1a7ce32ab108d39d82ac95d /ethchain/transaction.go
parent14787ac148274a84478aa06fd985407b9241cd50 (diff)
downloaddexon-230aafbf66ba747fb3796810adf3b1680f368e73.tar.gz
dexon-230aafbf66ba747fb3796810adf3b1680f368e73.tar.zst
dexon-230aafbf66ba747fb3796810adf3b1680f368e73.zip
Working on interop
* Receipts after each transaction * Fee structure * Applying fees to miners
Diffstat (limited to 'ethchain/transaction.go')
-rw-r--r--ethchain/transaction.go108
1 files changed, 90 insertions, 18 deletions
diff --git a/ethchain/transaction.go b/ethchain/transaction.go
index bd7a0e424..16ea312c0 100644
--- a/ethchain/transaction.go
+++ b/ethchain/transaction.go
@@ -1,6 +1,7 @@
package ethchain
import (
+ "fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
"math/big"
@@ -46,11 +47,13 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
}
func (tx *Transaction) Hash() []byte {
- data := []interface{}{tx.Nonce, tx.Value, tx.GasPrice, tx.Gas, tx.Recipient, tx.Data}
+ data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data}
- if tx.contractCreation {
- data = append(data, tx.Init)
- }
+ /*
+ if tx.contractCreation {
+ data = append(data, tx.Init)
+ }
+ */
return ethutil.Sha3Bin(ethutil.NewValue(data).Encode())
}
@@ -138,18 +141,87 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
tx.Recipient = decoder.Get(3).Bytes()
tx.Value = decoder.Get(4).BigInt()
tx.Data = decoder.Get(5).Bytes()
-
- // If the list is of length 10 it's a contract creation tx
- if decoder.Len() == 10 {
- tx.contractCreation = true
- tx.Init = decoder.Get(6).Bytes()
-
- tx.v = byte(decoder.Get(7).Uint())
- tx.r = decoder.Get(8).Bytes()
- tx.s = decoder.Get(9).Bytes()
- } else {
- tx.v = byte(decoder.Get(6).Uint())
- tx.r = decoder.Get(7).Bytes()
- tx.s = decoder.Get(8).Bytes()
- }
+ tx.v = byte(decoder.Get(6).Uint())
+ tx.r = decoder.Get(7).Bytes()
+ tx.s = decoder.Get(8).Bytes()
+
+ /*
+ // If the list is of length 10 it's a contract creation tx
+ if decoder.Len() == 10 {
+ tx.contractCreation = true
+ tx.Init = decoder.Get(6).Bytes()
+
+ tx.v = byte(decoder.Get(7).Uint())
+ tx.r = decoder.Get(8).Bytes()
+ tx.s = decoder.Get(9).Bytes()
+ } else {
+ tx.v = byte(decoder.Get(6).Uint())
+ tx.r = decoder.Get(7).Bytes()
+ tx.s = decoder.Get(8).Bytes()
+ }
+ */
+}
+
+func (tx *Transaction) String() string {
+ return fmt.Sprintf(`
+ TX(%x)
+ Contract: %v
+ From: %x
+ Nonce: %v
+ GasPrice: %v
+ Gas: %v
+ To: %x
+ Value: %v
+ Data: 0x%x
+ V: 0x%x
+ R: 0x%x
+ S: 0x%x
+ `,
+ tx.Hash(),
+ len(tx.Recipient) > 1,
+ tx.Sender(),
+ tx.Nonce,
+ tx.GasPrice,
+ tx.Gas,
+ tx.Recipient,
+ tx.Value,
+ tx.Data,
+ tx.v,
+ tx.r,
+ tx.s)
+}
+
+type Receipt struct {
+ Tx *Transaction
+ PostState []byte
+ CumulativeGasUsed *big.Int
+}
+
+func NewRecieptFromValue(val *ethutil.Value) *Receipt {
+ r := &Receipt{}
+ r.RlpValueDecode(val)
+
+ return r
+}
+
+func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
+ self.Tx = NewTransactionFromValue(decoder.Get(0))
+ self.PostState = decoder.Get(1).Bytes()
+ self.CumulativeGasUsed = decoder.Get(2).BigInt()
+}
+
+func (self *Receipt) RlpData() interface{} {
+ return []interface{}{self.Tx.RlpData(), self.PostState, self.CumulativeGasUsed}
+}
+
+func (self *Receipt) String() string {
+ return fmt.Sprintf(`
+ R
+ Tx:[ %v]
+ PostState: 0x%x
+ CumulativeGasUsed: %v
+ `,
+ self.Tx,
+ self.PostState,
+ self.CumulativeGasUsed)
}