@@ -792,10 +792,10 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes {
792
792
return formatted
793
793
}
794
794
795
- // rpcOutputBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
795
+ // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
796
796
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
797
797
// transaction hashes.
798
- func ( s * PublicBlockChainAPI ) rpcOutputBlock (b * types.Block , inclTx bool , fullTx bool ) (map [string ]interface {}, error ) {
798
+ func RPCMarshalBlock (b * types.Block , inclTx bool , fullTx bool ) (map [string ]interface {}, error ) {
799
799
head := b .Header () // copies the header once
800
800
fields := map [string ]interface {}{
801
801
"number" : (* hexutil .Big )(head .Number ),
@@ -808,7 +808,6 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
808
808
"stateRoot" : head .Root ,
809
809
"miner" : head .Coinbase ,
810
810
"difficulty" : (* hexutil .Big )(head .Difficulty ),
811
- "totalDifficulty" : (* hexutil .Big )(s .b .GetTd (b .Hash ())),
812
811
"extraData" : hexutil .Bytes (head .Extra ),
813
812
"size" : hexutil .Uint64 (b .Size ()),
814
813
"gasLimit" : hexutil .Uint64 (head .GasLimit ),
@@ -822,17 +821,15 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
822
821
formatTx := func (tx * types.Transaction ) (interface {}, error ) {
823
822
return tx .Hash (), nil
824
823
}
825
-
826
824
if fullTx {
827
825
formatTx = func (tx * types.Transaction ) (interface {}, error ) {
828
826
return newRPCTransactionFromBlockHash (b , tx .Hash ()), nil
829
827
}
830
828
}
831
-
832
829
txs := b .Transactions ()
833
830
transactions := make ([]interface {}, len (txs ))
834
831
var err error
835
- for i , tx := range b . Transactions () {
832
+ for i , tx := range txs {
836
833
if transactions [i ], err = formatTx (tx ); err != nil {
837
834
return nil , err
838
835
}
@@ -850,6 +847,17 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
850
847
return fields , nil
851
848
}
852
849
850
+ // rpcOutputBlock uses the generalized output filler, then adds the total difficulty field, which requires
851
+ // a `PublicBlockchainAPI`.
852
+ func (s * PublicBlockChainAPI ) rpcOutputBlock (b * types.Block , inclTx bool , fullTx bool ) (map [string ]interface {}, error ) {
853
+ fields , err := RPCMarshalBlock (b , inclTx , fullTx )
854
+ if err != nil {
855
+ return nil , err
856
+ }
857
+ fields ["totalDifficulty" ] = (* hexutil .Big )(s .b .GetTd (b .Hash ()))
858
+ return fields , err
859
+ }
860
+
853
861
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
854
862
type RPCTransaction struct {
855
863
BlockHash common.Hash `json:"blockHash"`
0 commit comments