forked from irisnet/irishub
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26ffd79
commit b34b5f1
Showing
10 changed files
with
983 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"alliance/x/alliance/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdQueryRewards() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rewards delegator_addr validator_addr denom", | ||
Short: "Query module parameters", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
delegatorAddr := args[0] | ||
validatorAddr := args[1] | ||
denom := args[2] | ||
ctx := client.GetClientContextFromCmd(cmd) | ||
query := types.NewQueryClient(ctx) | ||
params := &types.AllianceDelegationRewardsRequest{ | ||
DelegatorAddr: delegatorAddr, | ||
ValidatorAddr: validatorAddr, | ||
Denom: denom, | ||
} | ||
|
||
res, err := query.AllianceDelegationRewards(context.Background(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ctx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package keeper | ||
|
||
import ( | ||
"alliance/x/alliance/types" | ||
"context" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
func (k Keeper) AllianceDelegationRewards(context context.Context, request *types.AllianceDelegationRewardsRequest) (*types.AllianceDelegationRewardsResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(context) | ||
delAddr, err := sdk.AccAddressFromBech32(request.DelegatorAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
valAddr, err := sdk.ValAddressFromBech32(request.ValidatorAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, found := k.GetAssetByDenom(ctx, request.Denom) | ||
if !found { | ||
return nil, types.ErrUnknownAsset | ||
} | ||
|
||
val, found := k.stakingKeeper.GetValidator(ctx, valAddr) | ||
if !found { | ||
return nil, stakingtypes.ErrNoValidatorFound | ||
} | ||
|
||
_, found = k.GetDelegation(ctx, delAddr, val, request.Denom) | ||
if !found { | ||
return nil, stakingtypes.ErrNoDelegation | ||
} | ||
|
||
rewards, err := k.ClaimDelegationRewards(ctx, delAddr, val, request.Denom) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &types.AllianceDelegationRewardsResponse{ | ||
Rewards: rewards, | ||
}, nil | ||
} |
Oops, something went wrong.