Merge branch 'develop' of https://github.com/maticnetwork/bor into upstream_merge_v1.15.7

This commit is contained in:
Pratik Patil 2025-05-28 08:53:55 +05:30
commit a5745028a9
No known key found for this signature in database
GPG key ID: AFDCA496554874B3
5 changed files with 43 additions and 0 deletions

View file

@ -284,6 +284,13 @@ func (b *EthAPIBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int {
return nil return nil
} }
func (b *EthAPIBackend) GetTdByNumber(ctx context.Context, blockNr rpc.BlockNumber) *big.Int {
if header, err := b.HeaderByNumber(ctx, blockNr); header != nil && err == nil {
return b.eth.blockchain.GetTd(header.Hash(), uint64(blockNr.Int64()))
}
return nil
}
func (b *EthAPIBackend) GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM { func (b *EthAPIBackend) GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM {
if vmConfig == nil { if vmConfig == nil {
vmConfig = b.eth.blockchain.GetVMConfig() vmConfig = b.eth.blockchain.GetVMConfig()

View file

@ -767,6 +767,32 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp
return result, nil return result, nil
} }
// GetTdByHash returns a map containing the total difficulty (hex-encoded) for the given block hash.
func (api *BlockChainAPI) GetTdByHash(ctx context.Context, hash common.Hash) map[string]interface{} {
td := api.b.GetTd(ctx, hash)
if td == nil {
return nil
}
resp := make(map[string]interface{}, 2)
resp["blockHash"] = hash.Hex()
resp["totalDifficulty"] = hexutil.EncodeBig(td)
return resp
}
// GetTdByNumber returns a map containing the total difficulty (hex-encoded) for the given block number.
func (api *BlockChainAPI) GetTdByNumber(ctx context.Context, blockNr rpc.BlockNumber) map[string]interface{} {
td := api.b.GetTdByNumber(ctx, blockNr)
if td == nil {
return nil
}
resp := make(map[string]interface{}, 2)
resp["blockNumber"] = hexutil.EncodeUint64(uint64(blockNr.Int64()))
resp["totalDifficulty"] = hexutil.EncodeBig(td)
return resp
}
// ChainContextBackend provides methods required to implement ChainContext. // ChainContextBackend provides methods required to implement ChainContext.
type ChainContextBackend interface { type ChainContextBackend interface {
Engine() consensus.Engine Engine() consensus.Engine

View file

@ -570,6 +570,10 @@ func (b testBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int {
} }
return big.NewInt(1) return big.NewInt(1)
} }
func (b testBackend) GetTdByNumber(ctx context.Context, blockNr rpc.BlockNumber) *big.Int {
panic("not implemented")
}
func (b testBackend) GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockContext *vm.BlockContext) *vm.EVM { func (b testBackend) GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockContext *vm.BlockContext) *vm.EVM {
if vmConfig == nil { if vmConfig == nil {
vmConfig = b.chain.GetVMConfig() vmConfig = b.chain.GetVMConfig()

View file

@ -70,6 +70,8 @@ type Backend interface {
Pending() (*types.Block, types.Receipts, *state.StateDB) Pending() (*types.Block, types.Receipts, *state.StateDB)
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM GetEVM(ctx context.Context, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
GetTd(ctx context.Context, hash common.Hash) *big.Int
GetTdByNumber(ctx context.Context, blockNr rpc.BlockNumber) *big.Int
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

View file

@ -477,3 +477,7 @@ func (b backendMock) NewMatcherBackend() filtermaps.MatcherBackend {
func (b backendMock) SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription { func (b backendMock) SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription {
panic("implement me") panic("implement me")
} }
func (b backendMock) GetTdByNumber(ctx context.Context, blockNr rpc.BlockNumber) *big.Int {
panic("not implemented")
}