From 4037b09968ed161e480a5b73d00b1aaf41f9315a Mon Sep 17 00:00:00 2001 From: atvanguard <93arpit@gmail.com> Date: Mon, 17 Feb 2020 11:32:15 +0530 Subject: [PATCH 1/2] Add GetCurrentProposer API call :construction: --- consensus/bor/api.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/consensus/bor/api.go b/consensus/bor/api.go index cca115ebc041..a0806fa6698c 100644 --- a/consensus/bor/api.go +++ b/consensus/bor/api.go @@ -87,3 +87,13 @@ func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) { } return snap.signers(), nil } + +// GetSpan gets the current span details +func (api *API) GetCurrentProposer() (common.Address, error) { + header := api.chain.CurrentHeader() + snap, err := api.bor.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil) + if err != nil { + return common.BytesToAddress(make([]byte, 20)), err + } + return snap.ValidatorSet.GetProposer().Address, nil +} From 04f5abcc136811558f69cfda7f6d4ee99fe0d8a3 Mon Sep 17 00:00:00 2001 From: atvanguard <93arpit@gmail.com> Date: Mon, 17 Feb 2020 18:56:23 +0530 Subject: [PATCH 2/2] Expose API methods --- consensus/bor/api.go | 16 +++++++++---- internal/web3ext/web3ext.go | 45 +++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/consensus/bor/api.go b/consensus/bor/api.go index a0806fa6698c..98f7c46b6e61 100644 --- a/consensus/bor/api.go +++ b/consensus/bor/api.go @@ -88,12 +88,20 @@ func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) { return snap.signers(), nil } -// GetSpan gets the current span details +// GetCurrentProposer gets the current proposer func (api *API) GetCurrentProposer() (common.Address, error) { - header := api.chain.CurrentHeader() - snap, err := api.bor.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil) + snap, err := api.GetSnapshot(nil) if err != nil { - return common.BytesToAddress(make([]byte, 20)), err + return common.Address{}, err } return snap.ValidatorSet.GetProposer().Address, nil } + +// GetCurrentValidators gets the current validators +func (api *API) GetCurrentValidators() ([]*Validator, error) { + snap, err := api.GetSnapshot(nil) + if err != nil { + return make([]*Validator, 0), err + } + return snap.ValidatorSet.Validators, nil +} diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 0abcd5a8a5a0..d3fea7b50cc5 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -22,6 +22,7 @@ var Modules = map[string]string{ "admin": AdminJs, "chequebook": ChequebookJs, "clique": CliqueJs, + "bor": BorJs, "ethash": EthashJs, "debug": DebugJs, "eth": EthJs, @@ -112,6 +113,46 @@ web3._extend({ }); ` +const BorJs = ` +web3._extend({ + property: 'bor', + methods: [ + new web3._extend.Method({ + name: 'getSnapshot', + call: 'bor_getSnapshot', + params: 1, + inputFormatter: [null] + }), + new web3._extend.Method({ + name: 'getSnapshotAtHash', + call: 'bor_getSnapshotAtHash', + params: 1 + }), + new web3._extend.Method({ + name: 'getSigners', + call: 'bor_getSigners', + params: 1, + inputFormatter: [null] + }), + new web3._extend.Method({ + name: 'getSignersAtHash', + call: 'bor_getSignersAtHash', + params: 1 + }), + new web3._extend.Method({ + name: 'getCurrentProposer', + call: 'bor_getCurrentProposer', + params: 0 + }), + new web3._extend.Method({ + name: 'getCurrentValidators', + call: 'bor_getCurrentValidators', + params: 0 + }), + ] +}); +` + const EthashJs = ` web3._extend({ property: 'ethash', @@ -765,7 +806,7 @@ web3._extend({ const LESJs = ` web3._extend({ property: 'les', - methods: + methods: [ new web3._extend.Method({ name: 'getCheckpoint', @@ -773,7 +814,7 @@ web3._extend({ params: 1 }), ], - properties: + properties: [ new web3._extend.Property({ name: 'latestCheckpoint',