forked from tendermint/spn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_server_revert_launch.go
53 lines (43 loc) · 1.64 KB
/
msg_server_revert_launch.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
spnerrors "github.com/tendermint/spn/pkg/errors"
"github.com/tendermint/spn/x/launch/types"
profiletypes "github.com/tendermint/spn/x/profile/types"
)
func (k msgServer) RevertLaunch(goCtx context.Context, msg *types.MsgRevertLaunch) (*types.MsgRevertLaunchResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
chain, found := k.GetChain(ctx, msg.ChainID)
if !found {
return nil, sdkerrors.Wrap(types.ErrChainNotFound, msg.ChainID)
}
// Check sender is the coordinator of the chain
coordinatorID, found := k.profileKeeper.CoordinatorIDFromAddress(ctx, msg.Coordinator)
if !found {
return nil, sdkerrors.Wrap(profiletypes.ErrCoordAddressNotFound, msg.Coordinator)
}
if chain.CoordinatorID != coordinatorID {
return nil, sdkerrors.Wrapf(
profiletypes.ErrCoordInvalid,
"coordinator of the chain is %v",
chain.CoordinatorID,
)
}
if !chain.LaunchTriggered {
return nil, sdkerrors.Wrap(types.ErrNotTriggeredLaunch, msg.ChainID)
}
// The LaunchTimestamp must always be a non-zero value if LaunchTriggered is set
if chain.LaunchTimestamp == 0 {
return nil, spnerrors.Critical("LaunchTimestamp is not set while LaunchTriggered is set")
}
// We must wait for a specific delay once the chain is launched before being able to revert it
if ctx.BlockTime().Unix() < chain.LaunchTimestamp+types.RevertDelay {
return nil, sdkerrors.Wrap(types.ErrRevertDelayNotReached, msg.ChainID)
}
chain.LaunchTriggered = false
chain.LaunchTimestamp = 0
k.SetChain(ctx, chain)
return &types.MsgRevertLaunchResponse{}, nil
}