diff --git a/ethchain/block.go b/ethchain/block.go index c846516f4e..73e29f8783 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 16ea312c08..6ae7e77e1c 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 7194de372e..e8a2164a78 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 {