diff --git a/consensus/bor/api.go b/consensus/bor/api.go index cca115ebc0..98f7c46b6e 100644 --- a/consensus/bor/api.go +++ b/consensus/bor/api.go @@ -87,3 +87,21 @@ func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error) { } return snap.signers(), nil } + +// GetCurrentProposer gets the current proposer +func (api *API) GetCurrentProposer() (common.Address, error) { + snap, err := api.GetSnapshot(nil) + if err != nil { + 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 0abcd5a8a5..d3fea7b50c 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',