-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
common.go
32 lines (26 loc) · 917 Bytes
/
common.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
package common
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
// QueryDelegationRewards queries a delegation rewards between a delegator and a
// validator.
func QueryDelegationRewards(clientCtx client.Context, delAddr, valAddr string) ([]byte, int64, error) {
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
if err != nil {
return nil, 0, err
}
validatorAddr, err := sdk.ValAddressFromBech32(valAddr)
if err != nil {
return nil, 0, err
}
params := types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)
bz, err := clientCtx.LegacyAmino.MarshalJSON(params)
if err != nil {
return nil, 0, fmt.Errorf("failed to marshal params: %w", err)
}
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryDelegationRewards)
return clientCtx.QueryWithData(route, bz)
}