/
msg_update_launch_information.go
58 lines (48 loc) · 1.4 KB
/
msg_update_launch_information.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
package keeper
import (
"context"
"fmt"
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/spn/x/launch/types"
profiletypes "github.com/tendermint/spn/x/profile/types"
)
func (k msgServer) UpdateLaunchInformation(
goCtx context.Context,
msg *types.MsgUpdateLaunchInformation,
) (*types.MsgUpdateLaunchInformationResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
chain, found := k.GetChain(ctx, msg.LaunchID)
if !found {
return nil, sdkerrors.Wrapf(types.ErrChainNotFound, "%d", msg.LaunchID)
}
if chain.LaunchTriggered {
return nil, sdkerrors.Wrapf(types.ErrTriggeredLaunch, "%d", msg.LaunchID)
}
// Get the coordinator ID associated to the sender address
coordID, err := k.profileKeeper.CoordinatorIDFromAddress(ctx, msg.Coordinator)
if err != nil {
return nil, err
}
if chain.CoordinatorID != coordID {
return nil, sdkerrors.Wrap(profiletypes.ErrCoordInvalid, fmt.Sprintf(
"coordinator of the chain is %d",
chain.CoordinatorID,
))
}
// Modify from provided values
if msg.GenesisChainID != "" {
chain.GenesisChainID = msg.GenesisChainID
}
if msg.SourceURL != "" {
chain.SourceURL = msg.SourceURL
}
if msg.SourceHash != "" {
chain.SourceHash = msg.SourceHash
}
if msg.InitialGenesis != nil {
chain.InitialGenesis = *msg.InitialGenesis
}
k.SetChain(ctx, chain)
return &types.MsgUpdateLaunchInformationResponse{}, nil
}