diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-22 23:56:33 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-22 23:56:33 +0800 |
commit | cc8464ce805279735f637ac710b25e2fb264f9aa (patch) | |
tree | 00a8f39f76da20eec6fe4016e2e7f32955486b57 | |
parent | 230aafbf66ba747fb3796810adf3b1680f368e73 (diff) | |
download | dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar.gz dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar.bz2 dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar.lz dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar.xz dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.tar.zst dexon-cc8464ce805279735f637ac710b25e2fb264f9aa.zip |
Transaction querying
-rw-r--r-- | ethchain/block.go | 11 | ||||
-rw-r--r-- | ethchain/transaction.go | 6 | ||||
-rw-r--r-- | ethpub/types.go | 17 |
3 files changed, 30 insertions, 4 deletions
diff --git a/ethchain/block.go b/ethchain/block.go index c846516f4..73e29f878 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -1,6 +1,7 @@ package ethchain import ( + "bytes" "fmt" "github.com/ethereum/eth-go/ethutil" "math/big" @@ -161,6 +162,16 @@ func (block *Block) BlockInfo() BlockInfo { return bi } +func (self *Block) GetTransaction(hash []byte) *Transaction { + for _, receipt := range self.receipts { + if bytes.Compare(receipt.Tx.Hash(), hash) == 0 { + return receipt.Tx + } + } + + return nil +} + // Sync the block's state and contract respectively func (block *Block) Sync() { block.state.Sync() diff --git a/ethchain/transaction.go b/ethchain/transaction.go index 16ea312c0..6ae7e77e1 100644 --- a/ethchain/transaction.go +++ b/ethchain/transaction.go @@ -167,10 +167,10 @@ func (tx *Transaction) String() string { TX(%x) Contract: %v From: %x + To: %x Nonce: %v GasPrice: %v Gas: %v - To: %x Value: %v Data: 0x%x V: 0x%x @@ -178,12 +178,12 @@ func (tx *Transaction) String() string { S: 0x%x `, tx.Hash(), - len(tx.Recipient) > 1, + len(tx.Recipient) == 1, tx.Sender(), + tx.Recipient, tx.Nonce, tx.GasPrice, tx.Gas, - tx.Recipient, tx.Value, tx.Data, tx.v, diff --git a/ethpub/types.go b/ethpub/types.go index 7194de372..e8a2164a7 100644 --- a/ethpub/types.go +++ b/ethpub/types.go @@ -31,7 +31,18 @@ func (self *PBlock) ToString() string { return "" } +func (self *PBlock) GetTransaction(hash string) *PTx { + tx := self.ref.GetTransaction(ethutil.FromHex(hash)) + if tx == nil { + return nil + } + + return NewPTx(tx) +} + type PTx struct { + ref *ethchain.Transaction + Value, Hash, Address string Contract bool } @@ -41,7 +52,11 @@ func NewPTx(tx *ethchain.Transaction) *PTx { sender := hex.EncodeToString(tx.Recipient) isContract := len(tx.Data) > 0 - return &PTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} + return &PTx{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} +} + +func (self *PTx) ToString() string { + return self.ref.String() } type PKey struct { |