github.com/lino-network/lino@v0.6.11/x/account/manager/event.go (about) 1 package manager 2 3 import ( 4 sdk "github.com/cosmos/cosmos-sdk/types" 5 6 linotypes "github.com/lino-network/lino/types" 7 ) 8 9 // ReturnCoinEvent - return a certain amount of coin to an account 10 type ReturnCoinEvent struct { 11 Username linotypes.AccountKey `json:"username"` 12 Amount linotypes.Coin `json:"amount"` 13 ReturnType linotypes.TransferDetailType `json:"return_type"` 14 FromPool linotypes.PoolName `json:"from_pool"` 15 At int64 `json:"at"` 16 } 17 18 // Execute - execute coin return events 19 func (event ReturnCoinEvent) Execute(ctx sdk.Context, am AccountManager) sdk.Error { 20 return am.MoveFromPool( 21 ctx, event.FromPool, linotypes.NewAccOrAddrFromAcc(event.Username), event.Amount) 22 } 23 24 // CreateCoinReturnEvents - create coin return events 25 // The return interval list is expected to be executed at [start + interval, start + 2 * interval...] 26 // If [start, start + interval...] is expected, pass int (startAt - interval) as start at instead. 27 func CreateCoinReturnEvents(username linotypes.AccountKey, startAt, interval, times int64, coin linotypes.Coin, returnType linotypes.TransferDetailType, pool linotypes.PoolName) []ReturnCoinEvent { 28 events := []ReturnCoinEvent{} 29 for i := int64(0); i < times; i++ { 30 pieceDec := coin.ToDec().Quo(sdk.NewDec(times - i)) 31 piece := linotypes.DecToCoin(pieceDec) 32 coin = coin.Minus(piece) 33 34 event := ReturnCoinEvent{ 35 Username: username, 36 Amount: piece, 37 ReturnType: returnType, 38 FromPool: pool, 39 At: startAt + (i+1)*interval, 40 } 41 events = append(events, event) 42 } 43 return events 44 }