diff --git a/internal/hmyapi/blockchain.go b/internal/hmyapi/blockchain.go index d753bea36..7e61a884c 100644 --- a/internal/hmyapi/blockchain.go +++ b/internal/hmyapi/blockchain.go @@ -48,6 +48,7 @@ type BlockArgs struct { InclTx bool `json:"inclTx"` FullTx bool `json:"fullTx"` Signers []string `json:"signers"` + InclStaking bool `json:"inclStaking"` } // GetBlockByNumber returns the requested block. When blockNr is -1 the chain head is returned. When fullTx is true all @@ -55,7 +56,7 @@ type BlockArgs struct { func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { block, err := s.b.BlockByNumber(ctx, blockNr) if block != nil { - blockArgs := BlockArgs{WithSigners: false, InclTx: true, FullTx: fullTx} + blockArgs := BlockArgs{WithSigners: false, InclTx: true, FullTx: fullTx, InclStaking: false} response, err := RPCMarshalBlock(block, blockArgs) if err == nil && blockNr == rpc.PendingBlockNumber { // Pending blocks need to nil out a few fields @@ -73,7 +74,7 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, blockNr rpc. func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) { block, err := s.b.GetBlock(ctx, blockHash) if block != nil { - blockArgs := BlockArgs{WithSigners: false, InclTx: true, FullTx: fullTx} + blockArgs := BlockArgs{WithSigners: false, InclTx: true, FullTx: fullTx, InclStaking: false} return RPCMarshalBlock(block, blockArgs) } return nil, err diff --git a/internal/hmyapi/types.go b/internal/hmyapi/types.go index 62c3858f3..005b9945a 100644 --- a/internal/hmyapi/types.go +++ b/internal/hmyapi/types.go @@ -389,14 +389,6 @@ func RPCMarshalBlock(b *types.Block, blockArgs BlockArgs) (map[string]interface{ return newRPCTransactionFromBlockHash(b, tx.Hash()), nil } } - formatStakingTx := func(tx *types2.StakingTransaction) (interface{}, error) { - return tx.Hash(), nil - } - if blockArgs.FullTx { - formatStakingTx = func(tx *types2.StakingTransaction) (interface{}, error) { - return newRPCStakingTransactionFromBlockHash(b, tx.Hash()), nil - } - } txs := b.Transactions() transactions := make([]interface{}, len(txs)) var err error @@ -407,14 +399,24 @@ func RPCMarshalBlock(b *types.Block, blockArgs BlockArgs) (map[string]interface{ } fields["transactions"] = transactions - stakingTxs := b.StakingTransactions() - stakingTransactions := make([]interface{}, len(stakingTxs)) - for i, tx := range stakingTxs { - if stakingTransactions[i], err = formatStakingTx(tx); err != nil { - return nil, err + if blockArgs.InclStaking { + formatStakingTx := func(tx *types2.StakingTransaction) (interface{}, error) { + return tx.Hash(), nil + } + if blockArgs.FullTx { + formatStakingTx = func(tx *types2.StakingTransaction) (interface{}, error) { + return newRPCStakingTransactionFromBlockHash(b, tx.Hash()), nil + } + } + stakingTxs := b.StakingTransactions() + stakingTransactions := make([]interface{}, len(stakingTxs)) + for i, tx := range stakingTxs { + if stakingTransactions[i], err = formatStakingTx(tx); err != nil { + return nil, err + } } + fields["stakingTransactions"] = stakingTransactions } - fields["stakingTransactions"] = stakingTransactions } uncles := b.Uncles()