Transaction querying

This commit is contained in:
obscuren 2014-05-22 17:56:33 +02:00
parent 230aafbf66
commit cc8464ce80
3 changed files with 30 additions and 4 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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 {