-
Notifications
You must be signed in to change notification settings - Fork 20
/
policy.go
47 lines (41 loc) · 1.42 KB
/
policy.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
package utils
import (
sdkmath "cosmossdk.io/math"
"github.com/bnb-chain/greenfield-go-sdk/types"
"github.com/bnb-chain/greenfield/types/common"
permTypes "github.com/bnb-chain/greenfield/x/permission/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewStatement return the statement of permission module
func NewStatement(actions []permTypes.ActionType, effect permTypes.Effect,
resource []string, opts types.NewStatementOptions,
) permTypes.Statement {
statement := permTypes.Statement{
Actions: actions,
Effect: effect,
Resources: resource,
ExpirationTime: opts.StatementExpireTime,
}
if opts.LimitSize != 0 {
statement.LimitSize = &common.UInt64Value{Value: opts.LimitSize}
}
return statement
}
// NewPrincipalWithAccount return the marshaled Principal string which indicates the account
func NewPrincipalWithAccount(principalAddr sdk.AccAddress) (types.Principal, error) {
p := permTypes.NewPrincipalWithAccount(principalAddr)
principalBytes, err := p.Marshal()
if err != nil {
return "", err
}
return types.Principal(principalBytes), nil
}
// NewPrincipalWithGroupId return the marshaled Principal string which indicates the group
func NewPrincipalWithGroupId(groupId uint64) (types.Principal, error) {
p := permTypes.NewPrincipalWithGroupId(sdkmath.NewUint(groupId))
principalBytes, err := p.Marshal()
if err != nil {
return "", err
}
return types.Principal(principalBytes), nil
}