Transaction querying
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
package ethchain
 | 
					package ethchain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethutil"
 | 
						"github.com/ethereum/eth-go/ethutil"
 | 
				
			||||||
	"math/big"
 | 
						"math/big"
 | 
				
			||||||
@@ -161,6 +162,16 @@ func (block *Block) BlockInfo() BlockInfo {
 | 
				
			|||||||
	return bi
 | 
						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
 | 
					// Sync the block's state and contract respectively
 | 
				
			||||||
func (block *Block) Sync() {
 | 
					func (block *Block) Sync() {
 | 
				
			||||||
	block.state.Sync()
 | 
						block.state.Sync()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,10 +167,10 @@ func (tx *Transaction) String() string {
 | 
				
			|||||||
	TX(%x)
 | 
						TX(%x)
 | 
				
			||||||
	Contract: %v
 | 
						Contract: %v
 | 
				
			||||||
	From:     %x
 | 
						From:     %x
 | 
				
			||||||
 | 
						To:       %x
 | 
				
			||||||
	Nonce:    %v
 | 
						Nonce:    %v
 | 
				
			||||||
	GasPrice: %v
 | 
						GasPrice: %v
 | 
				
			||||||
	Gas:      %v
 | 
						Gas:      %v
 | 
				
			||||||
	To:       %x
 | 
					 | 
				
			||||||
	Value:    %v
 | 
						Value:    %v
 | 
				
			||||||
	Data:     0x%x
 | 
						Data:     0x%x
 | 
				
			||||||
	V:        0x%x
 | 
						V:        0x%x
 | 
				
			||||||
@@ -178,12 +178,12 @@ func (tx *Transaction) String() string {
 | 
				
			|||||||
	S:        0x%x
 | 
						S:        0x%x
 | 
				
			||||||
	`,
 | 
						`,
 | 
				
			||||||
		tx.Hash(),
 | 
							tx.Hash(),
 | 
				
			||||||
		len(tx.Recipient) > 1,
 | 
							len(tx.Recipient) == 1,
 | 
				
			||||||
		tx.Sender(),
 | 
							tx.Sender(),
 | 
				
			||||||
 | 
							tx.Recipient,
 | 
				
			||||||
		tx.Nonce,
 | 
							tx.Nonce,
 | 
				
			||||||
		tx.GasPrice,
 | 
							tx.GasPrice,
 | 
				
			||||||
		tx.Gas,
 | 
							tx.Gas,
 | 
				
			||||||
		tx.Recipient,
 | 
					 | 
				
			||||||
		tx.Value,
 | 
							tx.Value,
 | 
				
			||||||
		tx.Data,
 | 
							tx.Data,
 | 
				
			||||||
		tx.v,
 | 
							tx.v,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,18 @@ func (self *PBlock) ToString() string {
 | 
				
			|||||||
	return ""
 | 
						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 {
 | 
					type PTx struct {
 | 
				
			||||||
 | 
						ref *ethchain.Transaction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Value, Hash, Address string
 | 
						Value, Hash, Address string
 | 
				
			||||||
	Contract             bool
 | 
						Contract             bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -41,7 +52,11 @@ func NewPTx(tx *ethchain.Transaction) *PTx {
 | 
				
			|||||||
	sender := hex.EncodeToString(tx.Recipient)
 | 
						sender := hex.EncodeToString(tx.Recipient)
 | 
				
			||||||
	isContract := len(tx.Data) > 0
 | 
						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 {
 | 
					type PKey struct {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user