Skip to content

Commit

Permalink
Merge pull request ethereum#88 from maticnetwork/arpit/mat-2318
Browse files Browse the repository at this point in the history
mat-2318 (Create `bor.getAuthor()` api for bor module)
  • Loading branch information
jdkanani authored Sep 29, 2020
2 parents 21bbd17 + 0e4487d commit 93e2ac2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions consensus/bor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
return api.bor.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
}

// GetAuthor retrieves the author a block.
func (api *API) GetAuthor(number *rpc.BlockNumber) (*common.Address, error) {
// Retrieve the requested block number (or current if none requested)
var header *types.Header
if number == nil || *number == rpc.LatestBlockNumber {
header = api.chain.CurrentHeader()
} else {
header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
}
// Ensure we have an actually valid block and return its snapshot
if header == nil {
return nil, errUnknownBlock
}
author, err := api.bor.Author(header)
return &author, err
}

// GetSnapshotAtHash retrieves the state snapshot at a given block.
func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error) {
header := api.chain.GetHeaderByHash(hash)
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ web3._extend({
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'getAuthor',
call: 'bor_getAuthor',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'getSnapshotAtHash',
call: 'bor_getSnapshotAtHash',
Expand Down

0 comments on commit 93e2ac2

Please sign in to comment.