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

chore: add network parameters to manifest file #367

Merged
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion cmd/fetchd/cmd/gen_asi_upgrade_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ type ASIUpgradeSupply struct {
ResultingSupplyTotal types.Coins `json:"resulting_supply_total"`
}

type ValueUpdate struct {
From string `json:"from"`
To string `json:"to"`
}

type MainParams struct {
GenesisTime *ValueUpdate `json:"genesis_time,omitempty"`
ChainID *ValueUpdate `json:"chain_id,omitempty"`
AddressPrefix *ValueUpdate `json:"address_prefix,omitempty"`
Supply *ASIUpgradeSupply `json:"supply,omitempty"`
}

type ASIUpgradeManifest struct {
Supply *ASIUpgradeSupply `json:"supply,omitempty"`
Main *MainParams `json:"main,omitempty"`
IBC *ASIUpgradeTransfers `json:"ibc,omitempty"`
Reconciliation *ASIUpgradeTransfers `json:"reconciliation,omitempty"`
}
Expand Down
39 changes: 28 additions & 11 deletions cmd/fetchd/cmd/genesis-asi-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {

genFile := config.GenesisFile()

// create a new manifest
manifest := ASIUpgradeManifest{
Main: &MainParams{},
}

_, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
Expand All @@ -195,13 +200,13 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
return err
}

ASIGenesisUpgradeUpdateGenesisTime(genDoc, newGenesisTimeStr)
ASIGenesisUpgradeUpdateGenesisTime(genDoc, newGenesisTimeStr, &manifest)

// fetch the network config using chain-id
var ok bool
var networkConfig NetworkConfig
if networkConfig, ok = networkInfos[genDoc.ChainID]; !ok {
return fmt.Errorf("network not found, no match for Chain-ID in genesis file")
return fmt.Errorf("network not found, no match for Chain-ID in genesis file: %s", genDoc.ChainID)
}

// unmarshal the app state
Expand All @@ -210,11 +215,8 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
return fmt.Errorf("failed to unmarshal app state: %w", err)
}

// create a new manifest
manifest := ASIUpgradeManifest{}

// replace chain-id
ASIGenesisUpgradeReplaceChainID(genDoc, networkConfig)
ASIGenesisUpgradeReplaceChainID(genDoc, networkConfig, &manifest)

// replace bridge contract admin
ASIGenesisUpgradeReplaceBridgeAdmin(jsonData, networkConfig)
Expand Down Expand Up @@ -253,7 +255,7 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
ASIGenesisUpgradeASISupply(jsonData, networkConfig, &manifest)

// replace addresses across the genesis file
ASIGenesisUpgradeReplaceAddresses(jsonData, networkConfig)
ASIGenesisUpgradeReplaceAddresses(jsonData, networkConfig, &manifest)

if err = SaveASIManifest(&manifest, config); err != nil {
return err
Expand Down Expand Up @@ -326,13 +328,18 @@ func replaceAddressInContractStateKey2(keyBytes []byte, prefix []byte) string {
return hex.EncodeToString(buffer.Bytes())
}

func ASIGenesisUpgradeUpdateGenesisTime(genDoc *types.GenesisDoc, newGenesisTimeStr string) {
func ASIGenesisUpgradeUpdateGenesisTime(genDoc *types.GenesisDoc, newGenesisTimeStr string, manifest *ASIUpgradeManifest) {
oldGenesisTime := genDoc.GenesisTime
if newGenesisTimeStr != "" {
genesisTime, err := time.Parse(time.RFC3339Nano, newGenesisTimeStr)
if err != nil {
panic(err)
}
genDoc.GenesisTime = tmtime.Canonical(genesisTime)
manifest.Main.GenesisTime = &ValueUpdate{
From: oldGenesisTime.String(),
To: genDoc.GenesisTime.String(),
}
}
}

Expand Down Expand Up @@ -607,8 +614,13 @@ func ASIGenesisUpgradeReplaceDenomMetadata(jsonData map[string]interface{}, netw
}
}

func ASIGenesisUpgradeReplaceChainID(genesisData *types.GenesisDoc, networkInfo NetworkConfig) {
func ASIGenesisUpgradeReplaceChainID(genesisData *types.GenesisDoc, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
oldChainID := genesisData.ChainID
genesisData.ChainID = networkInfo.NewChainID
manifest.Main.ChainID = &ValueUpdate{
From: oldChainID,
To: genesisData.ChainID,
}
}

func ASIGenesisUpgradeReplaceBridgeAdmin(jsonData map[string]interface{}, networkInfo NetworkConfig) {
Expand Down Expand Up @@ -693,7 +705,7 @@ func getContractFromAddr(addr string, jsonData map[string]interface{}) map[strin
panic("failed to find contract using provided address")
}

func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkInfo NetworkConfig) {
func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
// account addresses
replaceAddresses(AccAddressPrefix, jsonData, AddrDataLength+AddrChecksumLength)
// validator addresses
Expand All @@ -702,6 +714,11 @@ func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkI
replaceAddresses(ConsAddressPrefix, jsonData, AddrDataLength+AddrChecksumLength)
// contract addresses
replaceAddresses(AccAddressPrefix, jsonData, WasmAddrDataLength+AddrChecksumLength)

manifest.Main.AddressPrefix = &ValueUpdate{
From: OldAddrPrefix,
To: NewAddrPrefix,
}
}

func replaceAddresses(addressTypePrefix string, jsonData map[string]interface{}, dataLength int) {
Expand Down Expand Up @@ -918,7 +935,7 @@ func ASIGenesisUpgradeASISupply(jsonData map[string]interface{}, networkInfo Net
MintedAmount: sdk.NewCoins(additionalSupplyCoin),
ResultingSupplyTotal: sdk.NewCoins(newSupplyCoins),
}
manifest.Supply = &supplyRecord
manifest.Main.Supply = &supplyRecord

// update the supply in the bank module
supply[curSupplyIdx].(map[string]interface{})["amount"] = newSupplyCoins.Amount.String()
Expand Down
Loading