-
Notifications
You must be signed in to change notification settings - Fork 12
/
server_accounts.go
53 lines (43 loc) · 2.13 KB
/
server_accounts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package inx
import (
"context"
"github.com/iotaledger/hive.go/ierrors"
inx "github.com/iotaledger/inx/go"
iotago "github.com/iotaledger/iota.go/v4"
)
func (s *Server) ReadIsValidatorAccount(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.GetAccountId())
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}
account, exists, err := deps.Protocol.Engines.Main.Get().Ledger.Account(accountID, slot)
if err != nil {
return nil, ierrors.Wrapf(err, "error when retrieving account data for %s", accountID)
}
return inx.WrapBoolResponse(exists && account.StakeEndEpoch() <= deps.Protocol.APIForSlot(slot).TimeProvider().EpochFromSlot(slot)), nil
}
func (s *Server) ReadIsCommitteeMember(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.GetAccountId())
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}
committee, exists := deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager().CommitteeInSlot(slot)
if !exists {
return nil, ierrors.Errorf("committee does not exist for slot %d", slot)
}
return inx.WrapBoolResponse(committee.HasAccount(accountID)), nil
}
func (s *Server) ReadIsCandidate(_ context.Context, accountInfoRequest *inx.AccountInfoRequest) (*inx.BoolResponse, error) {
slot := iotago.SlotIndex(accountInfoRequest.GetAccountSlot())
accountID, _, err := iotago.AccountIDFromBytes(accountInfoRequest.GetAccountId())
if err != nil {
return nil, ierrors.Wrap(err, "error when parsing account id")
}
isCandidateActive, err := deps.Protocol.Engines.Main.Get().SybilProtection.IsCandidateActive(accountID, deps.Protocol.APIForSlot(slot).TimeProvider().EpochFromSlot(slot))
if err != nil {
return nil, ierrors.Wrap(err, "error when checking if candidate is active")
}
return inx.WrapBoolResponse(isCandidateActive), nil
}