/
keeper.go
43 lines (34 loc) · 1.34 KB
/
keeper.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/axelarnetwork/axelar-core/x/bank/types"
)
// BankKeeper wraps the bankkeeper.BaseKeeper.
type BankKeeper struct {
types.BankKeeper
}
// NewBankKeeper returns a new BankKeeper.
func NewBankKeeper(bk types.BankKeeper) BankKeeper {
return BankKeeper{bk}
}
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure, or when the from/to address is blocked.
func (k BankKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
if k.BlockedAddr(fromAddr) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", fromAddr.String())
}
if k.BlockedAddr(toAddr) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", toAddr.String())
}
return k.BankKeeper.SendCoins(ctx, fromAddr, toAddr, amt)
}
// SpendableBalance returns the spendable balance of a specific denomination for a given account by address
func (k BankKeeper) SpendableBalance(ctx sdk.Context, address sdk.AccAddress, denom string) sdk.Coin {
for _, coin := range k.SpendableCoins(ctx, address) {
if coin.Denom == denom {
return coin
}
}
return sdk.NewCoin(denom, sdk.ZeroInt())
}