mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #587 from maticnetwork/shivam/POS-991
add : statesync tx added to GetBlockTransactionCount rpc
This commit is contained in:
commit
aece5ca954
1 changed files with 24 additions and 2 deletions
|
|
@ -1615,6 +1615,26 @@ type PublicTransactionPoolAPI struct {
|
||||||
signer types.Signer
|
signer types.Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns block transactions along with state-sync transaction if present
|
||||||
|
// nolint: unparam
|
||||||
|
func (api *PublicTransactionPoolAPI) getAllBlockTransactions(ctx context.Context, block *types.Block) (types.Transactions, bool) {
|
||||||
|
txs := block.Transactions()
|
||||||
|
|
||||||
|
stateSyncPresent := false
|
||||||
|
|
||||||
|
borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64())
|
||||||
|
if borReceipt != nil {
|
||||||
|
txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
|
||||||
|
if txHash != (common.Hash{}) {
|
||||||
|
borTx, _, _, _, _ := api.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash())
|
||||||
|
txs = append(txs, borTx)
|
||||||
|
stateSyncPresent = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return txs, stateSyncPresent
|
||||||
|
}
|
||||||
|
|
||||||
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
|
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
|
||||||
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
|
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
|
||||||
// The signer used by the API should always be the 'latest' known one because we expect
|
// The signer used by the API should always be the 'latest' known one because we expect
|
||||||
|
|
@ -1626,7 +1646,8 @@ func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransa
|
||||||
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
|
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
|
||||||
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
|
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
|
||||||
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
|
||||||
n := hexutil.Uint(len(block.Transactions()))
|
txs, _ := s.getAllBlockTransactions(ctx, block)
|
||||||
|
n := hexutil.Uint(len(txs))
|
||||||
return &n
|
return &n
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1635,7 +1656,8 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.
|
||||||
// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
|
// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
|
||||||
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint {
|
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint {
|
||||||
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
|
||||||
n := hexutil.Uint(len(block.Transactions()))
|
txs, _ := s.getAllBlockTransactions(ctx, block)
|
||||||
|
n := hexutil.Uint(len(txs))
|
||||||
return &n
|
return &n
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue