aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ethchain/block.go11
-rw-r--r--ethchain/transaction.go6
-rw-r--r--ethpub/types.go17
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 {