Skip to content

Commit

Permalink
Expose API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Feb 17, 2020
1 parent 4037b09 commit 04f5abc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
16 changes: 12 additions & 4 deletions consensus/bor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 43 additions & 2 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Modules = map[string]string{
"admin": AdminJs,
"chequebook": ChequebookJs,
"clique": CliqueJs,
"bor": BorJs,
"ethash": EthashJs,
"debug": DebugJs,
"eth": EthJs,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -765,15 +806,15 @@ web3._extend({
const LESJs = `
web3._extend({
property: 'les',
methods:
methods:
[
new web3._extend.Method({
name: 'getCheckpoint',
call: 'les_getCheckpoint',
params: 1
}),
],
properties:
properties:
[
new web3._extend.Property({
name: 'latestCheckpoint',
Expand Down

0 comments on commit 04f5abc

Please sign in to comment.