-
Notifications
You must be signed in to change notification settings - Fork 36
/
send_restrictions.go
48 lines (40 loc) · 1.48 KB
/
send_restrictions.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
44
45
46
47
48
package types
import sdk "github.com/cosmos/cosmos-sdk/types"
var (
bypassKey = "bypass-marker-restriction"
transferAgentKey = "marker-transfer-agent"
)
// WithBypass returns a new context that will cause the marker bank send restriction to be skipped.
func WithBypass(ctx sdk.Context) sdk.Context {
return ctx.WithValue(bypassKey, true)
}
// WithoutBypass returns a new context that will cause the marker bank send restriction to not be skipped.
func WithoutBypass(ctx sdk.Context) sdk.Context {
return ctx.WithValue(bypassKey, false)
}
// HasBypass checks the context to see if the marker bank send restriction should be skipped.
func HasBypass(ctx sdk.Context) bool {
bypassValue := ctx.Value(bypassKey)
if bypassValue == nil {
return false
}
bypass, isBool := bypassValue.(bool)
return isBool && bypass
}
// WithTransferAgent returns a new context that contains the provided marker transfer agent.
func WithTransferAgent(ctx sdk.Context, transferAgent sdk.AccAddress) sdk.Context {
return ctx.WithValue(transferAgentKey, transferAgent)
}
// WithoutTransferAgent returns a new context with a nil marker transfer agent.
func WithoutTransferAgent(ctx sdk.Context) sdk.Context {
return ctx.WithValue(transferAgentKey, sdk.AccAddress(nil))
}
// GetTransferAgent gets the marker transfer agent from the provided context.
func GetTransferAgent(ctx sdk.Context) sdk.AccAddress {
val := ctx.Value(transferAgentKey)
if val == nil {
return nil
}
rv, _ := val.(sdk.AccAddress)
return rv
}