@@ -597,7 +597,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
597
597
"gasUsed" : rpc .NewHexNumber (head .GasUsed ),
598
598
"timestamp" : rpc .NewHexNumber (head .Time ),
599
599
"transactionsRoot" : head .TxHash ,
600
- "receiptsRoot" : head .ReceiptHash ,
600
+ "receiptsRoot" : head .ReceiptHash ,
601
601
}
602
602
603
603
if inclTx {
@@ -699,6 +699,16 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
699
699
return nil , nil
700
700
}
701
701
702
+ // newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
703
+ func newRPCRawTransactionFromBlockIndex (b * types.Block , txIndex int ) (rpc.HexBytes , error ) {
704
+ if txIndex >= 0 && txIndex < len (b .Transactions ()) {
705
+ tx := b .Transactions ()[txIndex ]
706
+ return rlp .EncodeToBytes (tx )
707
+ }
708
+
709
+ return nil , nil
710
+ }
711
+
702
712
// newRPCTransaction returns a transaction that will serialize to the RPC representation.
703
713
func newRPCTransaction (b * types.Block , txHash common.Hash ) (* RPCTransaction , error ) {
704
714
for idx , tx := range b .Transactions () {
@@ -770,6 +780,22 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
770
780
return nil , nil
771
781
}
772
782
783
+ // GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
784
+ func (s * PublicTransactionPoolAPI ) GetRawTransactionByBlockNumberAndIndex (ctx context.Context , blockNr rpc.BlockNumber , index rpc.HexNumber ) (rpc.HexBytes , error ) {
785
+ if block , _ := s .b .BlockByNumber (ctx , blockNr ); block != nil {
786
+ return newRPCRawTransactionFromBlockIndex (block , index .Int ())
787
+ }
788
+ return nil , nil
789
+ }
790
+
791
+ // GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
792
+ func (s * PublicTransactionPoolAPI ) GetRawTransactionByBlockHashAndIndex (ctx context.Context , blockHash common.Hash , index rpc.HexNumber ) (rpc.HexBytes , error ) {
793
+ if block , _ := s .b .GetBlock (ctx , blockHash ); block != nil {
794
+ return newRPCRawTransactionFromBlockIndex (block , index .Int ())
795
+ }
796
+ return nil , nil
797
+ }
798
+
773
799
// GetTransactionCount returns the number of transactions the given address has sent for the given block number
774
800
func (s * PublicTransactionPoolAPI ) GetTransactionCount (ctx context.Context , address common.Address , blockNr rpc.BlockNumber ) (* rpc.HexNumber , error ) {
775
801
state , _ , err := s .b .StateAndHeaderByNumber (blockNr )
@@ -835,6 +861,21 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
835
861
return nil , nil
836
862
}
837
863
864
+ // GetRawTransactionByHash returns the bytes of the transaction for the given hash.
865
+ func (s * PublicTransactionPoolAPI ) GetRawTransactionByHash (ctx context.Context , txHash common.Hash ) (rpc.HexBytes , error ) {
866
+ var tx * types.Transaction
867
+ var err error
868
+
869
+ if tx , _ , err = getTransaction (s .b .ChainDb (), s .b , txHash ); err != nil {
870
+ glog .V (logger .Debug ).Infof ("%v\n " , err )
871
+ return nil , nil
872
+ } else if tx == nil {
873
+ return nil , nil
874
+ }
875
+
876
+ return rlp .EncodeToBytes (tx )
877
+ }
878
+
838
879
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
839
880
func (s * PublicTransactionPoolAPI ) GetTransactionReceipt (txHash common.Hash ) (map [string ]interface {}, error ) {
840
881
receipt := core .GetReceipt (s .b .ChainDb (), txHash )
0 commit comments