Skip to content

Commit f6f9920

Browse files
chore: add network parameters to manifest file (#367)
1 parent cac7411 commit f6f9920

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

cmd/fetchd/cmd/gen_asi_upgrade_manifest.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,20 @@ type ASIUpgradeSupply struct {
2525
ResultingSupplyTotal types.Coins `json:"resulting_supply_total"`
2626
}
2727

28+
type ValueUpdate struct {
29+
From string `json:"from"`
30+
To string `json:"to"`
31+
}
32+
33+
type MainParams struct {
34+
GenesisTime *ValueUpdate `json:"genesis_time,omitempty"`
35+
ChainID *ValueUpdate `json:"chain_id,omitempty"`
36+
AddressPrefix *ValueUpdate `json:"address_prefix,omitempty"`
37+
Supply *ASIUpgradeSupply `json:"supply,omitempty"`
38+
}
39+
2840
type ASIUpgradeManifest struct {
29-
Supply *ASIUpgradeSupply `json:"supply,omitempty"`
41+
Main *MainParams `json:"main,omitempty"`
3042
IBC *ASIUpgradeTransfers `json:"ibc,omitempty"`
3143
Reconciliation *ASIUpgradeTransfers `json:"reconciliation,omitempty"`
3244
}

cmd/fetchd/cmd/genesis-asi-upgrade.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
185185

186186
genFile := config.GenesisFile()
187187

188+
// create a new manifest
189+
manifest := ASIUpgradeManifest{
190+
Main: &MainParams{},
191+
}
192+
188193
_, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
189194
if err != nil {
190195
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
@@ -195,13 +200,13 @@ func ASIGenesisUpgradeCmd(defaultNodeHome string) *cobra.Command {
195200
return err
196201
}
197202

198-
ASIGenesisUpgradeUpdateGenesisTime(genDoc, newGenesisTimeStr)
203+
ASIGenesisUpgradeUpdateGenesisTime(genDoc, newGenesisTimeStr, &manifest)
199204

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

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

213-
// create a new manifest
214-
manifest := ASIUpgradeManifest{}
215-
216218
// replace chain-id
217-
ASIGenesisUpgradeReplaceChainID(genDoc, networkConfig)
219+
ASIGenesisUpgradeReplaceChainID(genDoc, networkConfig, &manifest)
218220

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

255257
// replace addresses across the genesis file
256-
ASIGenesisUpgradeReplaceAddresses(jsonData, networkConfig)
258+
ASIGenesisUpgradeReplaceAddresses(jsonData, networkConfig, &manifest)
257259

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

329-
func ASIGenesisUpgradeUpdateGenesisTime(genDoc *types.GenesisDoc, newGenesisTimeStr string) {
331+
func ASIGenesisUpgradeUpdateGenesisTime(genDoc *types.GenesisDoc, newGenesisTimeStr string, manifest *ASIUpgradeManifest) {
332+
oldGenesisTime := genDoc.GenesisTime
330333
if newGenesisTimeStr != "" {
331334
genesisTime, err := time.Parse(time.RFC3339Nano, newGenesisTimeStr)
332335
if err != nil {
333336
panic(err)
334337
}
335338
genDoc.GenesisTime = tmtime.Canonical(genesisTime)
339+
manifest.Main.GenesisTime = &ValueUpdate{
340+
From: oldGenesisTime.String(),
341+
To: genDoc.GenesisTime.String(),
342+
}
336343
}
337344
}
338345

@@ -607,8 +614,13 @@ func ASIGenesisUpgradeReplaceDenomMetadata(jsonData map[string]interface{}, netw
607614
}
608615
}
609616

610-
func ASIGenesisUpgradeReplaceChainID(genesisData *types.GenesisDoc, networkInfo NetworkConfig) {
617+
func ASIGenesisUpgradeReplaceChainID(genesisData *types.GenesisDoc, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
618+
oldChainID := genesisData.ChainID
611619
genesisData.ChainID = networkInfo.NewChainID
620+
manifest.Main.ChainID = &ValueUpdate{
621+
From: oldChainID,
622+
To: genesisData.ChainID,
623+
}
612624
}
613625

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

696-
func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkInfo NetworkConfig) {
708+
func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkInfo NetworkConfig, manifest *ASIUpgradeManifest) {
697709
// account addresses
698710
replaceAddresses(AccAddressPrefix, jsonData, AddrDataLength+AddrChecksumLength)
699711
// validator addresses
@@ -702,6 +714,11 @@ func ASIGenesisUpgradeReplaceAddresses(jsonData map[string]interface{}, networkI
702714
replaceAddresses(ConsAddressPrefix, jsonData, AddrDataLength+AddrChecksumLength)
703715
// contract addresses
704716
replaceAddresses(AccAddressPrefix, jsonData, WasmAddrDataLength+AddrChecksumLength)
717+
718+
manifest.Main.AddressPrefix = &ValueUpdate{
719+
From: OldAddrPrefix,
720+
To: NewAddrPrefix,
721+
}
705722
}
706723

707724
func replaceAddresses(addressTypePrefix string, jsonData map[string]interface{}, dataLength int) {
@@ -918,7 +935,7 @@ func ASIGenesisUpgradeASISupply(jsonData map[string]interface{}, networkInfo Net
918935
MintedAmount: sdk.NewCoins(additionalSupplyCoin),
919936
ResultingSupplyTotal: sdk.NewCoins(newSupplyCoins),
920937
}
921-
manifest.Supply = &supplyRecord
938+
manifest.Main.Supply = &supplyRecord
922939

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

0 commit comments

Comments
 (0)