-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: common launch utilities * fix: create OutDir beforehand
- Loading branch information
Showing
24 changed files
with
2,424 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package launchtools | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func LaunchCmd( | ||
appCreator servertypes.AppCreator, | ||
defaultGenesisGetter func(denom string) map[string]json.RawMessage, | ||
steps []LauncherStepFuncFactory[Input], | ||
) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "launch [path to manifest]", | ||
Short: "Launch a new instance of the app", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
serverCtx := server.GetServerContextFromCmd(cmd) | ||
|
||
manifestPath := args[0] | ||
manifest, err := Input{}.FromFile(manifestPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
launcher := NewLauncher( | ||
cmd, | ||
&clientCtx, | ||
serverCtx, | ||
appCreator, | ||
defaultGenesisGetter(manifest.L2Config.Denom), | ||
) | ||
|
||
stepFns := make([]LauncherStepFunc, len(steps)) | ||
|
||
for stepI, step := range steps { | ||
stepFns[stepI] = step(*manifest) | ||
} | ||
|
||
for _, stepFn := range stepFns { | ||
if err := stepFn(launcher); err != nil { | ||
return errors.Wrapf(err, "failed to run launcher step") | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package launchtools | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/pkg/errors" | ||
"os" | ||
"time" | ||
) | ||
|
||
type Input struct { | ||
L2Config L2Config `json:"l2_config"` | ||
L1Config L1Config `json:"l1_config"` | ||
OpBridge OpBridge `json:"op_bridge"` | ||
SystemKeys SystemKeys `json:"system_keys"` | ||
UserKeys []UserKeys `json:"user_keys"` | ||
GenesisAccounts []AccountWithBalance `json:"genesis_accounts"` | ||
} | ||
|
||
func (input Input) FromFile(path string) (*Input, error) { | ||
bz, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, errors.Wrap(err, fmt.Sprintf("failed to read file: %s", path)) | ||
} | ||
|
||
ret := new(Input) | ||
if err := json.Unmarshal(bz, ret); err != nil { | ||
return nil, err | ||
} | ||
return ret, nil | ||
} | ||
|
||
type L2Config struct { | ||
ChainID string `json:"chain_id"` | ||
Denom string `json:"denom"` | ||
Moniker string `json:"moniker"` | ||
AccountPrefix string `json:"account_prefix"` | ||
GasPrices string `json:"gas_prices"` | ||
} | ||
|
||
type OpBridge struct { | ||
SubmissionStartTime time.Time `json:"submission_start_time"` | ||
SubmitTarget string `json:"submit_target"` | ||
SubmissionInterval string `json:"submission_interval"` | ||
FinalizationPeriod string `json:"finalization_period"` | ||
} | ||
|
||
type L1Config struct { | ||
ChainID string `json:"chain_id"` | ||
RPCURL string `json:"rpc_url"` | ||
Denom string `json:"denom"` | ||
RestURL string `json:"rest_url"` | ||
GrpcURL string `json:"grpc_url"` | ||
WsURL string `json:"ws_url"` | ||
AccountPrefix string `json:"account_prefix"` | ||
GasPrices string `json:"gas_prices"` | ||
} | ||
|
||
type Account struct { | ||
Address string `json:"address"` | ||
Mnemonic string `json:"mnemonic"` | ||
} | ||
|
||
type AccountWithBalance struct { | ||
Account | ||
Coins string `json:"coins"` | ||
} | ||
|
||
type SystemKeys struct { | ||
Validator Account `json:"validator"` | ||
Executor Account `json:"executor"` | ||
Output Account `json:"output"` | ||
Challenger Account `json:"challenger"` | ||
Submitter Account `json:"submitter"` | ||
Relayer Account `json:"relayer"` | ||
} | ||
|
||
type UserKeys struct { | ||
Name string `json:"name"` | ||
Address string `json:"address"` | ||
Mnemonic string `json:"mnemonic"` | ||
} | ||
|
||
func (i Input) Validate() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package steps | ||
|
||
import "github.com/initia-labs/OPinit/contrib/launchtools" | ||
|
||
// InitializeConfig sets the config for the server context. | ||
func InitializeConfig(manifest launchtools.Input) launchtools.LauncherStepFunc { | ||
return func(ctx launchtools.Launcher) error { | ||
// set config | ||
config := ctx.ServerContext().Config | ||
config.Moniker = manifest.L2Config.Moniker | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package steps | ||
|
||
import "time" | ||
|
||
const ( | ||
KeyringBackend = "test" | ||
RelayerPathName = "ibc" | ||
RelayerKeyName = "Relayer" | ||
RelayerPathTemp = ".relayer" | ||
|
||
CreateEmptyBlocksInterval = 3 * time.Second | ||
OpBridgeIDKey = "bridge_id" | ||
) |
Oops, something went wrong.