Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement the genesis-time flag #363

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/fetchd/cmd/genesis-asi-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
ibccore "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
"regexp"
"strconv"
"strings"
"time"
)

const (
Expand All @@ -41,6 +43,8 @@ const (

NewAddrPrefix = "asi"
OldAddrPrefix = "fetch"

FlagGenesisTime = "genesis-time"
)

var (
Expand Down Expand Up @@ -185,6 +189,13 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

newGenesisTimeStr, err := cmd.Flags().GetString(FlagGenesisTime)
if err != nil {
return err
}

ASIGenesisUpgradeUpdateGenesisTime(genDoc, newGenesisTimeStr)

// fetch the network config using chain-id
var ok bool
var networkConfig NetworkConfig
Expand Down Expand Up @@ -257,6 +268,7 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
},
}

cmd.Flags().String(FlagGenesisTime, "", "The timestamp to replace 'genesis_time' in the genesis.json file, must be RFC3339 formatted")
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring backend (os|file|kwallet|pass|test)")
flags.AddQueryFlagsToCmd(cmd)
Expand Down Expand Up @@ -313,6 +325,16 @@ func replaceAddressInContractStateKey2(keyBytes []byte, prefix []byte) string {
return hex.EncodeToString(buffer.Bytes())
}

func ASIGenesisUpgradeUpdateGenesisTime(genDoc *types.GenesisDoc, newGenesisTimeStr string) {
if newGenesisTimeStr != "" {
genesisTime, err := time.Parse(time.RFC3339Nano, newGenesisTimeStr)
if err != nil {
panic(err)
}
genDoc.GenesisTime = tmtime.Canonical(genesisTime)
}
}

func ASIGenesisUpgradeUpdateFccCw20Contract(jsonData map[string]interface{}, networkInfo NetworkConfig) {
if networkInfo.Contracts == nil || networkInfo.Contracts.FccCw20 == nil {
return
Expand Down
Loading