aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
diff options
context:
space:
mode:
authorKobi Gurkan <kobigurk@gmail.com>2016-10-07 06:38:00 +0800
committerKobi Gurkan <kobigurk@gmail.com>2016-10-10 17:57:15 +0800
commit1a6682c21d812fa2bd068d174d38978664814633 (patch)
tree030867a6ac0d0eb446c567f481269c68fa4c0ccf /internal/ethapi/api.go
parentc88e4357240d8c92d7866cb805781b792e166ec2 (diff)
downloadgo-tangerine-1a6682c21d812fa2bd068d174d38978664814633.tar.gz
go-tangerine-1a6682c21d812fa2bd068d174d38978664814633.tar.zst
go-tangerine-1a6682c21d812fa2bd068d174d38978664814633.zip
internal/ethapi, internal/web3ext: adds raw tx retrieval methods
Diffstat (limited to 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go43
1 files changed, 42 insertions, 1 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 53ea8d186..de88a5d1e 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -597,7 +597,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
"gasUsed": rpc.NewHexNumber(head.GasUsed),
"timestamp": rpc.NewHexNumber(head.Time),
"transactionsRoot": head.TxHash,
- "receiptsRoot": head.ReceiptHash,
+ "receiptsRoot": head.ReceiptHash,
}
if inclTx {
@@ -699,6 +699,16 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
return nil, nil
}
+// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
+func newRPCRawTransactionFromBlockIndex(b *types.Block, txIndex int) (rpc.HexBytes, error) {
+ if txIndex >= 0 && txIndex < len(b.Transactions()) {
+ tx := b.Transactions()[txIndex]
+ return rlp.EncodeToBytes(tx)
+ }
+
+ return nil, nil
+}
+
// newRPCTransaction returns a transaction that will serialize to the RPC representation.
func newRPCTransaction(b *types.Block, txHash common.Hash) (*RPCTransaction, error) {
for idx, tx := range b.Transactions() {
@@ -770,6 +780,22 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
return nil, nil
}
+// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
+func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index rpc.HexNumber) (rpc.HexBytes, error) {
+ if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
+ return newRPCRawTransactionFromBlockIndex(block, index.Int())
+ }
+ return nil, nil
+}
+
+// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
+func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index rpc.HexNumber) (rpc.HexBytes, error) {
+ if block, _ := s.b.GetBlock(ctx, blockHash); block != nil {
+ return newRPCRawTransactionFromBlockIndex(block, index.Int())
+ }
+ return nil, nil
+}
+
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*rpc.HexNumber, error) {
state, _, err := s.b.StateAndHeaderByNumber(blockNr)
@@ -835,6 +861,21 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
return nil, nil
}
+// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
+func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, txHash common.Hash) (rpc.HexBytes, error) {
+ var tx *types.Transaction
+ var err error
+
+ if tx, _, err = getTransaction(s.b.ChainDb(), s.b, txHash); err != nil {
+ glog.V(logger.Debug).Infof("%v\n", err)
+ return nil, nil
+ } else if tx == nil {
+ return nil, nil
+ }
+
+ return rlp.EncodeToBytes(tx)
+}
+
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (map[string]interface{}, error) {
receipt := core.GetReceipt(s.b.ChainDb(), txHash)