OSDN Git Service

Add the implementation for dppos
[bytom/vapor.git] / api / dpos.go
1 package api
2
3 import (
4         "context"
5
6         dpos "github.com/vapor/consensus/consensus/dpos"
7 )
8
9 func (a *API) listDelegates(ctx context.Context) Response {
10         return NewSuccessResponse(dpos.GDpos.ListDelegates())
11 }
12
13 func (a *API) getDelegateVotes(ctx context.Context, ins struct {
14         DelegateAddress string `json:"delegate_address"`
15 }) Response {
16         votes := map[string]uint64{"votes": dpos.GDpos.GetDelegateVotes(ins.DelegateAddress)}
17         return NewSuccessResponse(votes)
18 }
19
20 func (a *API) listVotedDelegates(ctx context.Context, ins struct {
21         Voter string `json:"voter"`
22 }) Response {
23         delegates := make(map[string]string)
24         for _, delegate := range dpos.GDpos.GetVotedDelegates(ins.Voter) {
25                 delegates[dpos.GDpos.GetDelegateName(delegate)] = delegate
26         }
27         return NewSuccessResponse(delegates)
28 }
29
30 func (a *API) listReceivedVotes(ctx context.Context, ins struct {
31         DelegateAddress string `json:"delegate_address"`
32 }) Response {
33         return NewSuccessResponse(dpos.GDpos.GetDelegateVoters(ins.DelegateAddress))
34 }
35
36 func (a *API) getAddressBalance(ctx context.Context, ins struct {
37         Address string `json:"address"`
38 }) Response {
39         return NewSuccessResponse(dpos.GDpos.GetAddressBalance(ins.Address))
40 }