/
msg_server_create_rollapp.go
66 lines (58 loc) · 1.88 KB
/
msg_server_create_rollapp.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gridfoundation/gridiron/x/rollapp/types"
)
func (k msgServer) CreateRollapp(goCtx context.Context, msg *types.MsgCreateRollapp) (*types.MsgCreateRollappResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// check to see if the RollappId has been registered before
if _, isFound := k.GetRollapp(ctx, msg.RollappId); isFound {
return nil, types.ErrRollappExists
}
// check to see if there is an active whitelist
if whitelist := k.DeployerWhitelist(ctx); len(whitelist) > 0 {
bInWhitelist := false
// check to see if the creator is in whitelist
var item types.DeployerParams
for _, item = range whitelist {
if item.Address == msg.Creator {
// Found!
bInWhitelist = true
break
}
}
if !bInWhitelist {
return nil, types.ErrUnauthorizedRollappCreator
}
if item.MaxRollapps > 0 {
// if MaxRollapps, it means there is a limit for this creator
// count how many rollapps he created
rollappsNumOfCreator := uint64(0)
for _, r := range k.GetAllRollapp(ctx) {
if r.Creator == msg.Creator {
rollappsNumOfCreator += 1
}
}
// check the creator didn't hit the maximum
if rollappsNumOfCreator >= item.MaxRollapps {
// check the deployer max rollapps limitation
return nil, types.ErrRollappCreatorExceedMaximumRollapps
}
}
}
// Create an updated rollapp record
rollapp := types.Rollapp{
RollappId: msg.RollappId,
Creator: msg.Creator,
Version: 0,
CodeStamp: msg.CodeStamp,
GenesisPath: msg.GenesisPath,
MaxWithholdingBlocks: msg.MaxWithholdingBlocks,
MaxSequencers: msg.MaxSequencers,
PermissionedAddresses: msg.PermissionedAddresses,
}
// Write rollapp information to the store
k.SetRollapp(ctx, rollapp)
return &types.MsgCreateRollappResponse{}, nil
}