From c249746bf36f4caf9dd782605c16473a2b8d4690 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Mon, 14 Sep 2020 16:18:21 -0400 Subject: [PATCH] [R4R] feat: payout liquid claims without creating vesting account (#651) * feat: payout liquid claims without creating vesting account --- x/incentive/keeper/payout.go | 8 +++++++- x/incentive/types/errors.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/x/incentive/keeper/payout.go b/x/incentive/keeper/payout.go index 65b5d11f..fa9a6f45 100644 --- a/x/incentive/keeper/payout.go +++ b/x/incentive/keeper/payout.go @@ -42,7 +42,7 @@ func (k Keeper) PayoutClaim(ctx sdk.Context, addr sdk.AccAddress, collateralType return nil } -// SendTimeLockedCoinsToAccount sends time-locked coins from the input module account to the recipient. If the recipients account is not a vesting account, it is converted to a periodic vesting account and the coins are added to the vesting balance as a vesting period with the input length. +// SendTimeLockedCoinsToAccount sends time-locked coins from the input module account to the recipient. If the recipients account is not a vesting account and the input length is greater than zero, the recipient account is converted to a periodic vesting account and the coins are added to the vesting balance as a vesting period with the input length. func (k Keeper) SendTimeLockedCoinsToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins, length int64) error { macc := k.supplyKeeper.GetModuleAccount(ctx, senderModule) if !macc.GetCoins().IsAllGTE(amt) { @@ -51,6 +51,12 @@ func (k Keeper) SendTimeLockedCoinsToAccount(ctx sdk.Context, senderModule strin // 0. Get the account from the account keeper and do a type switch, error if it's a validator vesting account or module account (can make this work for validator vesting later if necessary) acc := k.accountKeeper.GetAccount(ctx, recipientAddr) + if acc == nil { + return sdkerrors.Wrapf(types.ErrAccountNotFound, recipientAddr.String()) + } + if length == 0 { + return k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt) + } switch acc.(type) { case *validatorvesting.ValidatorVestingAccount, supplyExported.ModuleAccountI: diff --git a/x/incentive/types/errors.go b/x/incentive/types/errors.go index 51f54e78..04aa282c 100644 --- a/x/incentive/types/errors.go +++ b/x/incentive/types/errors.go @@ -12,4 +12,5 @@ var ( ErrInvalidAccountType = sdkerrors.Register(ModuleName, 3, "account type not supported") ErrNoClaimsFound = sdkerrors.Register(ModuleName, 4, "no claims with collateral type found for address") ErrInsufficientModAccountBalance = sdkerrors.Register(ModuleName, 5, "module account has insufficient balance to pay claim") + ErrAccountNotFound = sdkerrors.Register(ModuleName, 6, "account not found") )