completed auction-creation escrow
parent
69f2fa82de
commit
5c41dc7fef
|
@ -33,12 +33,12 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
|
||||||
Ceiling: msg.Ceiling,
|
Ceiling: msg.Ceiling,
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := sdk.AccAddressFromBech32(msg.Creator)
|
senderAddr, err := sdk.AccAddressFromBech32(msg.Creator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator)
|
return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator)
|
||||||
}
|
}
|
||||||
|
|
||||||
spendable := k.bank.SpendableCoins(ctx, addr)
|
spendable := k.bank.SpendableCoins(ctx, senderAddr)
|
||||||
// if balance does not exceed or equal proposed auction ceiling...
|
// if balance does not exceed or equal proposed auction ceiling...
|
||||||
ceiling := new(big.Int)
|
ceiling := new(big.Int)
|
||||||
ceiling.SetString(auction.Ceiling, 10)
|
ceiling.SetString(auction.Ceiling, 10)
|
||||||
|
@ -46,6 +46,15 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
|
||||||
return nil, fmt.Errorf("not enough balance to set ceiling %s%s", msg.Ceiling, auction.Denom)
|
return nil, fmt.Errorf("not enough balance to set ceiling %s%s", msg.Ceiling, auction.Denom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coins := sdk.NewCoins(sdk.Coin{
|
||||||
|
Amount: spendable.AmountOf(auction.Ceiling),
|
||||||
|
Denom: auction.Denom,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := k.bank.SendCoinsFromAccountToModule(ctx, senderAddr, "cosmostest", coins); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to transfer %s%s", auction.Ceiling, auction.Denom)
|
||||||
|
}
|
||||||
|
|
||||||
k.Keeper.SetAuction(ctx, auction)
|
k.Keeper.SetAuction(ctx, auction)
|
||||||
next.AuctionId++
|
next.AuctionId++
|
||||||
|
|
||||||
|
|
|
@ -14,5 +14,7 @@ type AccountKeeper interface {
|
||||||
// BankKeeper defines the expected interface needed to retrieve account balances.
|
// BankKeeper defines the expected interface needed to retrieve account balances.
|
||||||
type BankKeeper interface {
|
type BankKeeper interface {
|
||||||
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
||||||
|
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
|
||||||
|
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
|
||||||
// Methods imported from bank should be defined here
|
// Methods imported from bank should be defined here
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue