mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
Added GetSnapshotProposerSequence
This commit is contained in:
parent
98b71173df
commit
4e6d323382
2 changed files with 62 additions and 0 deletions
|
|
@ -46,6 +46,56 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
|
|||
return api.bor.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
|
||||
}
|
||||
|
||||
type BlockSigners struct {
|
||||
Signers map[common.Address]uint64
|
||||
Diff int
|
||||
Author common.Address
|
||||
}
|
||||
|
||||
// GetSnapshotProposerSequence retrieves the in-turn signers of all sprints in a span
|
||||
func (api *API) GetSnapshotProposerSequence(number *rpc.BlockNumber) (BlockSigners, error) {
|
||||
|
||||
var difficulties = make(map[common.Address]uint64)
|
||||
snap, err := api.GetSnapshot(number)
|
||||
if err != nil {
|
||||
return BlockSigners{}, err
|
||||
}
|
||||
proposer := snap.ValidatorSet.GetProposer().Address
|
||||
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
||||
|
||||
signers := snap.signers()
|
||||
for i := 0; i < len(signers); i++ {
|
||||
tempIndex := i
|
||||
if tempIndex < proposerIndex {
|
||||
tempIndex = tempIndex + len(signers)
|
||||
}
|
||||
difficulties[signers[i]] = uint64(len(signers) - (tempIndex - proposerIndex))
|
||||
}
|
||||
|
||||
author, err := api.GetAuthor(number)
|
||||
if err != nil {
|
||||
return BlockSigners{}, err
|
||||
}
|
||||
diff := int(difficulties[*author])
|
||||
blockSigners := &BlockSigners{
|
||||
Signers: difficulties,
|
||||
Diff: diff,
|
||||
Author: *author,
|
||||
}
|
||||
|
||||
return *blockSigners, nil
|
||||
}
|
||||
|
||||
// GetSnapshotProposer retrieves the in-turn signer at a given block.
|
||||
func (api *API) GetSnapshotProposer(number *rpc.BlockNumber) (common.Address, error) {
|
||||
*number -= 1
|
||||
snap, err := api.GetSnapshot(number)
|
||||
if err != nil {
|
||||
return common.Address{}, err
|
||||
}
|
||||
return snap.ValidatorSet.GetProposer().Address, 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)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,18 @@ web3._extend({
|
|||
params: 1,
|
||||
inputFormatter: [null]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'getSnapshotProposer',
|
||||
call: 'bor_getSnapshotProposer',
|
||||
params: 1,
|
||||
inputFormatter: [null]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'getSnapshotProposerSequence',
|
||||
call: 'bor_getSnapshotProposerSequence',
|
||||
params: 1,
|
||||
inputFormatter: [null]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'getSnapshotAtHash',
|
||||
call: 'bor_getSnapshotAtHash',
|
||||
|
|
|
|||
Loading…
Reference in a new issue