-
Notifications
You must be signed in to change notification settings - Fork 7
/
swap.go
40 lines (32 loc) · 1.06 KB
/
swap.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
package keeper
import (
"github.com/anathatech/project-anatha/x/treasury/internal/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k Keeper) HandleSwap(ctx sdk.Context, operator sdk.AccAddress, recipient sdk.AccAddress, amount sdk.Coins, reference string) error {
if ! k.IsOperator(ctx, operator) {
return types.ErrNotOperator
}
if k.IsDisbursementReferenceSet(ctx, reference) {
return types.ErrDuplicateReference
}
err := k.TransferFromSwapEscrow(ctx, recipient, amount)
if err != nil {
return err
}
k.SetDisbursementReferenceAmount(ctx, reference, sdk.ZeroInt())
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSwap,
sdk.NewAttribute(types.AttributeKeyRecipient, recipient.String()),
sdk.NewAttribute(types.AttributeKeyAmount, amount.String()),
sdk.NewAttribute(types.AttributeKeyReference, reference),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueModule),
sdk.NewAttribute(types.AttributeKeySender, operator.String()),
),
})
return nil
}