-
Notifications
You must be signed in to change notification settings - Fork 10
/
tgrade_distribution.go
46 lines (38 loc) · 1.38 KB
/
tgrade_distribution.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
package contract
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/confio/tgrade/x/poe/types"
)
type DistributionQuery struct {
WithdrawableRewards *WithdrawableRewardsQuery `json:"withdrawable_rewards,omitempty"`
}
type WithdrawableRewardsQuery struct {
Owner string `json:"owner"`
}
type RewardsResponse struct {
Rewards sdk.Coin
}
type DistributionContractAdapter struct {
contractAddr sdk.AccAddress
contractQuerier types.SmartQuerier
addressLookupErr error
}
// NewDistributionContractAdapter constructor
func NewDistributionContractAdapter(contractAddr sdk.AccAddress, contractQuerier types.SmartQuerier, addressLookupErr error) *DistributionContractAdapter {
return &DistributionContractAdapter{contractAddr: contractAddr, contractQuerier: contractQuerier, addressLookupErr: addressLookupErr}
}
func (d DistributionContractAdapter) ValidatorOutstandingReward(ctx sdk.Context, addr sdk.AccAddress) (sdk.Coin, error) {
if d.addressLookupErr != nil {
return sdk.Coin{}, d.addressLookupErr
}
query := DistributionQuery{WithdrawableRewards: &WithdrawableRewardsQuery{Owner: addr.String()}}
var resp RewardsResponse
err := doQuery(ctx, d.contractQuerier, d.contractAddr, query, &resp)
if err != nil {
return sdk.Coin{}, err
}
return resp.Rewards, err
}
func (d DistributionContractAdapter) Address() (sdk.AccAddress, error) {
return d.contractAddr, d.addressLookupErr
}