@@ -382,7 +382,7 @@ func (s *BlockChainAPI) GetTransactionAndReceiptProof(ctx context.Context, hash
382
382
func (s * BlockChainAPI ) GetBlockByNumber (ctx context.Context , blockNr rpc.BlockNumber , fullTx bool ) (map [string ]interface {}, error ) {
383
383
block , err := s .b .BlockByNumber (ctx , blockNr )
384
384
if block != nil {
385
- response , err := s .rpcOutputBlock (block , true , fullTx , ctx )
385
+ response , err := s .rpcOutputBlock (block , true , fullTx )
386
386
if err == nil && blockNr == rpc .PendingBlockNumber {
387
387
// Pending blocks need to nil out a few fields
388
388
for _ , field := range []string {"hash" , "nonce" , "miner" } {
@@ -399,7 +399,7 @@ func (s *BlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc.BlockN
399
399
func (s * BlockChainAPI ) GetBlockByHash (ctx context.Context , blockHash common.Hash , fullTx bool ) (map [string ]interface {}, error ) {
400
400
block , err := s .b .GetBlock (ctx , blockHash )
401
401
if block != nil {
402
- return s .rpcOutputBlock (block , true , fullTx , ctx )
402
+ return s .rpcOutputBlock (block , true , fullTx )
403
403
}
404
404
return nil , err
405
405
}
@@ -415,7 +415,7 @@ func (s *BlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, block
415
415
return nil , nil
416
416
}
417
417
block = types .NewBlockWithHeader (uncles [index ])
418
- return s .rpcOutputBlock (block , false , false , ctx )
418
+ return s .rpcOutputBlock (block , false , false )
419
419
}
420
420
return nil , err
421
421
}
@@ -432,7 +432,7 @@ func (s *BlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, blockHa
432
432
return nil , nil
433
433
}
434
434
block = types .NewBlockWithHeader (uncles [index ])
435
- return s .rpcOutputBlock (block , false , false , ctx )
435
+ return s .rpcOutputBlock (block , false , false )
436
436
}
437
437
return nil , err
438
438
}
@@ -1411,29 +1411,26 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
1411
1411
return result
1412
1412
}
1413
1413
1414
- // rpcOutputBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
1414
+ // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
1415
1415
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
1416
1416
// transaction hashes.
1417
- func ( s * BlockChainAPI ) rpcOutputBlock ( b * types.Block , inclTx bool , fullTx bool , ctx context. Context ) (map [string ]interface {}, error ) {
1417
+ func RPCMarshalBlock ( b * types.Block , inclTx bool , fullTx bool ) (map [string ]interface {}, error ) {
1418
1418
fields := RPCMarshalHeader (b .Header ())
1419
1419
fields ["size" ] = hexutil .Uint64 (b .Size ())
1420
- fields ["totalDifficulty" ] = (* hexutil .Big )(s .b .GetTd (context .Background (), b .Hash ()))
1421
1420
1422
1421
if inclTx {
1423
1422
formatTx := func (tx * types.Transaction ) (interface {}, error ) {
1424
1423
return tx .Hash (), nil
1425
1424
}
1426
-
1427
1425
if fullTx {
1428
1426
formatTx = func (tx * types.Transaction ) (interface {}, error ) {
1429
1427
return newRPCTransactionFromBlockHash (b , tx .Hash ()), nil
1430
1428
}
1431
1429
}
1432
-
1433
1430
txs := b .Transactions ()
1434
1431
transactions := make ([]interface {}, len (txs ))
1435
1432
var err error
1436
- for i , tx := range b . Transactions () {
1433
+ for i , tx := range txs {
1437
1434
if transactions [i ], err = formatTx (tx ); err != nil {
1438
1435
return nil , err
1439
1436
}
@@ -1447,9 +1444,21 @@ func (s *BlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx bool,
1447
1444
uncleHashes [i ] = uncle .Hash ()
1448
1445
}
1449
1446
fields ["uncles" ] = uncleHashes
1447
+
1450
1448
return fields , nil
1451
1449
}
1452
1450
1451
+ // rpcOutputBlock uses the generalized output filler, then adds the total difficulty field, which requires
1452
+ // a `BlockChainAPI`.
1453
+ func (s * BlockChainAPI ) rpcOutputBlock (b * types.Block , inclTx bool , fullTx bool ) (map [string ]interface {}, error ) {
1454
+ fields , err := RPCMarshalBlock (b , inclTx , fullTx )
1455
+ if err != nil {
1456
+ return nil , err
1457
+ }
1458
+ fields ["totalDifficulty" ] = (* hexutil .Big )(s .b .GetTd (context .Background (), b .Hash ()))
1459
+ return fields , err
1460
+ }
1461
+
1453
1462
// findNearestSignedBlock finds the nearest checkpoint from input block
1454
1463
func (s * BlockChainAPI ) findNearestSignedBlock (ctx context.Context , b * types.Block ) * types.Block {
1455
1464
if b .Number ().Int64 () <= 0 {
0 commit comments