@@ -1169,6 +1169,17 @@ func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
11691169 return newRPCTransaction (tx , common.Hash {}, 0 , 0 )
11701170}
11711171
1172+ // newRPCTransactionsFromBlockIndex returns transactions that will serialize to the RPC representation.
1173+ func newRPCTransactionsFromBlockIndex (b * types.Block ) []* RPCTransaction {
1174+ txs := b .Transactions ()
1175+ result := make ([]* RPCTransaction , 0 , len (txs ))
1176+
1177+ for idx , tx := range txs {
1178+ result = append (result , newRPCTransaction (tx , b .Hash (), b .NumberU64 (), uint64 (idx )))
1179+ }
1180+ return result
1181+ }
1182+
11721183// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
11731184func newRPCTransactionFromBlockIndex (b * types.Block , index uint64 ) * RPCTransaction {
11741185 txs := b .Transactions ()
@@ -1227,6 +1238,14 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Co
12271238 return nil
12281239}
12291240
1241+ // GetTransactionsByBlockNumber returns all the transactions for the given block number.
1242+ func (s * PublicTransactionPoolAPI ) GetTransactionsByBlockNumber (ctx context.Context , blockNr rpc.BlockNumber ) []* RPCTransaction {
1243+ if block , _ := s .b .BlockByNumber (ctx , blockNr ); block != nil {
1244+ return newRPCTransactionsFromBlockIndex (block )
1245+ }
1246+ return nil
1247+ }
1248+
12301249// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
12311250func (s * PublicTransactionPoolAPI ) GetTransactionByBlockNumberAndIndex (ctx context.Context , blockNr rpc.BlockNumber , index hexutil.Uint ) * RPCTransaction {
12321251 if block , _ := s .b .BlockByNumber (ctx , blockNr ); block != nil {
@@ -1314,6 +1333,141 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context,
13141333 return rlp .EncodeToBytes (tx )
13151334}
13161335
1336+ // GetTransactionReceipt returns the transaction receipt for the given transaction hash.
1337+ func (s * PublicTransactionPoolAPI ) GetTransactionReceiptsByBlockNumber (ctx context.Context , blockNr rpc.BlockNumber ) ([]map [string ]interface {}, error ) {
1338+ blockNumber := uint64 (blockNr .Int64 ())
1339+ blockHash := rawdb .ReadCanonicalHash (s .b .ChainDb (), blockNumber )
1340+
1341+ receipts , err := s .b .GetReceipts (ctx , blockHash )
1342+ if err != nil {
1343+ return nil , err
1344+ }
1345+ block , err := s .b .BlockByHash (ctx , blockHash )
1346+ if err != nil {
1347+ return nil , err
1348+ }
1349+ txs := block .Transactions ()
1350+ if len (txs ) != len (receipts ) {
1351+ return nil , fmt .Errorf ("txs length doesn't equal to receipts' length" )
1352+ }
1353+
1354+ txReceipts := make ([]map [string ]interface {}, 0 , len (txs ))
1355+ for idx , receipt := range receipts {
1356+ tx := txs [idx ]
1357+ var signer types.Signer = types.FrontierSigner {}
1358+ if tx .Protected () {
1359+ signer = types .NewEIP155Signer (tx .ChainId ())
1360+ }
1361+ from , _ := types .Sender (signer , tx )
1362+
1363+ fields := map [string ]interface {}{
1364+ "blockHash" : blockHash ,
1365+ "blockNumber" : hexutil .Uint64 (blockNumber ),
1366+ "transactionHash" : tx .Hash (),
1367+ "transactionIndex" : hexutil .Uint64 (idx ),
1368+ "from" : from ,
1369+ "to" : tx .To (),
1370+ "gasUsed" : hexutil .Uint64 (receipt .GasUsed ),
1371+ "cumulativeGasUsed" : hexutil .Uint64 (receipt .CumulativeGasUsed ),
1372+ "contractAddress" : nil ,
1373+ "logs" : receipt .Logs ,
1374+ "logsBloom" : receipt .Bloom ,
1375+ }
1376+
1377+ // Assign receipt status or post state.
1378+ if len (receipt .PostState ) > 0 {
1379+ fields ["root" ] = hexutil .Bytes (receipt .PostState )
1380+ } else {
1381+ fields ["status" ] = hexutil .Uint (receipt .Status )
1382+ }
1383+ if receipt .Logs == nil {
1384+ fields ["logs" ] = [][]* types.Log {}
1385+ }
1386+ // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
1387+ if receipt .ContractAddress != (common.Address {}) {
1388+ fields ["contractAddress" ] = receipt .ContractAddress
1389+ }
1390+
1391+ txReceipts = append (txReceipts , fields )
1392+ }
1393+
1394+ return txReceipts , nil
1395+ }
1396+
1397+ // GetTransactionDataAndReceipt returns the original transaction data and transaction receipt for the given transaction hash.
1398+ func (s * PublicTransactionPoolAPI ) GetTransactionDataAndReceipt (ctx context.Context , hash common.Hash ) (map [string ]interface {}, error ) {
1399+ tx , blockHash , blockNumber , index := rawdb .ReadTransaction (s .b .ChainDb (), hash )
1400+ if tx == nil {
1401+ return nil , nil
1402+ }
1403+ receipts , err := s .b .GetReceipts (ctx , blockHash )
1404+ if err != nil {
1405+ return nil , err
1406+ }
1407+ if len (receipts ) <= int (index ) {
1408+ return nil , nil
1409+ }
1410+ receipt := receipts [index ]
1411+
1412+ var signer types.Signer = types.FrontierSigner {}
1413+ if tx .Protected () {
1414+ signer = types .NewEIP155Signer (tx .ChainId ())
1415+ }
1416+ from , _ := types .Sender (signer , tx )
1417+
1418+ rpcTransaction := newRPCTransaction (tx , blockHash , blockNumber , index )
1419+
1420+ txData := map [string ]interface {}{
1421+ "blockHash" : rpcTransaction .BlockHash .String (),
1422+ "blockNumber" : rpcTransaction .BlockNumber .String (),
1423+ "from" : rpcTransaction .From .String (),
1424+ "gas" : rpcTransaction .Gas .String (),
1425+ "gasPrice" : rpcTransaction .GasPrice .String (),
1426+ "hash" : rpcTransaction .Hash .String (),
1427+ "input" : rpcTransaction .Input .String (),
1428+ "nonce" : rpcTransaction .Nonce .String (),
1429+ "to" : rpcTransaction .To .String (),
1430+ "transactionIndex" : rpcTransaction .TransactionIndex .String (),
1431+ "value" : rpcTransaction .Value .String (),
1432+ "v" : rpcTransaction .V .String (),
1433+ "r" : rpcTransaction .R .String (),
1434+ "s" : rpcTransaction .S .String (),
1435+ }
1436+
1437+ fields := map [string ]interface {}{
1438+ "blockHash" : blockHash ,
1439+ "blockNumber" : hexutil .Uint64 (blockNumber ),
1440+ "transactionHash" : hash ,
1441+ "transactionIndex" : hexutil .Uint64 (index ),
1442+ "from" : from ,
1443+ "to" : tx .To (),
1444+ "gasUsed" : hexutil .Uint64 (receipt .GasUsed ),
1445+ "cumulativeGasUsed" : hexutil .Uint64 (receipt .CumulativeGasUsed ),
1446+ "contractAddress" : nil ,
1447+ "logs" : receipt .Logs ,
1448+ "logsBloom" : receipt .Bloom ,
1449+ }
1450+
1451+ // Assign receipt status or post state.
1452+ if len (receipt .PostState ) > 0 {
1453+ fields ["root" ] = hexutil .Bytes (receipt .PostState )
1454+ } else {
1455+ fields ["status" ] = hexutil .Uint (receipt .Status )
1456+ }
1457+ if receipt .Logs == nil {
1458+ fields ["logs" ] = [][]* types.Log {}
1459+ }
1460+ // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
1461+ if receipt .ContractAddress != (common.Address {}) {
1462+ fields ["contractAddress" ] = receipt .ContractAddress
1463+ }
1464+ result := map [string ]interface {}{
1465+ "txData" : txData ,
1466+ "receipt" : fields ,
1467+ }
1468+ return result , nil
1469+ }
1470+
13171471// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
13181472func (s * PublicTransactionPoolAPI ) GetTransactionReceipt (ctx context.Context , hash common.Hash ) (map [string ]interface {}, error ) {
13191473 tx , blockHash , blockNumber , index := rawdb .ReadTransaction (s .b .ChainDb (), hash )
0 commit comments