forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_stakers_query.go
66 lines (52 loc) · 2.42 KB
/
account_stakers_query.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
54
55
56
57
58
59
60
61
62
63
64
65
66
package hedera
import "github.com/hashgraph/hedera-sdk-go/proto"
// AccountStakersQuery gets all of the accounts that are proxy staking to this account. For each of them, the amount
// currently staked will be given. This is not yet implemented, but will be in a future version of the API.
type AccountStakersQuery struct {
QueryBuilder
pb *proto.CryptoGetStakersQuery
}
// NewAccountStakersQuery creates an AccountStakersQuery builder which can be used to construct and execute
// an AccountStakersQuery.
//
// It is recommended that you use this for creating new instances of an AccountStakersQuery
// instead of manually creating an instance of the struct.
func NewAccountStakersQuery() *AccountStakersQuery {
pb := &proto.CryptoGetStakersQuery{Header: &proto.QueryHeader{}}
inner := newQueryBuilder(pb.Header)
inner.pb.Query = &proto.Query_CryptoGetProxyStakers{CryptoGetProxyStakers: pb}
return &AccountStakersQuery{inner, pb}
}
// SetAccountID sets the Account ID for which the stakers should be retrieved
func (builder *AccountStakersQuery) SetAccountID(id AccountID) *AccountStakersQuery {
builder.pb.AccountID = id.toProto()
return builder
}
// Execute executes the AccountStakersQuery using the provided client.
func (builder *AccountStakersQuery) Execute(client *Client) ([]Transfer, error) {
resp, err := builder.execute(client)
if err != nil {
return []Transfer{}, err
}
var stakers = make([]Transfer, len(resp.GetCryptoGetProxyStakers().Stakers.ProxyStaker))
for i, element := range resp.GetCryptoGetProxyStakers().Stakers.ProxyStaker {
stakers[i] = Transfer{
AccountID: accountIDFromProto(element.AccountID),
Amount: HbarFromTinybar(element.Amount),
}
}
return stakers, nil
}
//
// The following _3_ must be copy-pasted at the bottom of **every** _query.go file
// We override the embedded fluent setter methods to return the outer type
//
func (builder *AccountStakersQuery) SetMaxQueryPayment(maxPayment Hbar) *AccountStakersQuery {
return &AccountStakersQuery{*builder.QueryBuilder.SetMaxQueryPayment(maxPayment), builder.pb}
}
func (builder *AccountStakersQuery) SetQueryPayment(paymentAmount Hbar) *AccountStakersQuery {
return &AccountStakersQuery{*builder.QueryBuilder.SetQueryPayment(paymentAmount), builder.pb}
}
func (builder *AccountStakersQuery) SetQueryPaymentTransaction(tx Transaction) *AccountStakersQuery {
return &AccountStakersQuery{*builder.QueryBuilder.SetQueryPaymentTransaction(tx), builder.pb}
}