From 6c5f0fb39415ca9446f05f64c7ffe39e8e0ba304 Mon Sep 17 00:00:00 2001 From: Jiri Vestfal <45360788+MissingNO57@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:57:11 +0200 Subject: [PATCH] refactor: CUDOS nullable balance movement in config (#388) --- app/upgrade_cudos.go | 8 ++++---- app/upgrade_v_11_4_network_config.go | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/upgrade_cudos.go b/app/upgrade_cudos.go index 12f53d74..03cbe1b7 100644 --- a/app/upgrade_cudos.go +++ b/app/upgrade_cudos.go @@ -1997,10 +1997,10 @@ func DoGenesisAccountMovements(genesisData *GenesisData, cudosCfg *CudosMergeCon fromAccTokensAmount := fromAcc.balance.AmountOfNoDenomValidation(genesisData.bondDenom) // Move entire balance if balance to move is 0 or greater than available balance - if accountMovement.Amount.IsZero() || fromAccTokensAmount.LT(accountMovement.Amount) { - accountMovement.Amount = fromAccTokensAmount + if accountMovement.Amount == nil || fromAccTokensAmount.LT(*accountMovement.Amount) { + accountMovement.Amount = &fromAccTokensAmount } - balanceToMove := sdk.NewCoins(sdk.NewCoin(genesisData.bondDenom, accountMovement.Amount)) + balanceToMove := sdk.NewCoins(sdk.NewCoin(genesisData.bondDenom, *accountMovement.Amount)) // Handle balance movement err := moveGenesisBalance(genesisData, accountMovement.SourceAddress, accountMovement.DestinationAddress, balanceToMove, "balance_movement", manifest, cudosCfg) @@ -2009,7 +2009,7 @@ func DoGenesisAccountMovements(genesisData *GenesisData, cudosCfg *CudosMergeCon } // Handle delegations movement - remainingAmountToMove := accountMovement.Amount + remainingAmountToMove := sdk.NewIntFromBigInt(accountMovement.Amount.BigInt()) if sourceDelegations, exists := genesisData.delegations.Get(accountMovement.SourceAddress); exists { for i := range sourceDelegations.Iterate() { validatorAddr, delegatedAmount := i.Key, i.Value diff --git a/app/upgrade_v_11_4_network_config.go b/app/upgrade_v_11_4_network_config.go index ef89ad8b..4d90ede4 100644 --- a/app/upgrade_v_11_4_network_config.go +++ b/app/upgrade_v_11_4_network_config.go @@ -22,6 +22,14 @@ func newInt(val string) sdk.Int { return res } +func newIntRef(val string) *sdk.Int { + res, ok := sdk.NewIntFromString(val) + if !ok { + panic(fmt.Errorf("Failed to parse INT %s", val)) + } + return &res +} + func newDec(val string) sdk.Dec { res, err := sdk.NewDecFromStr(val) if err != nil { @@ -31,9 +39,9 @@ func newDec(val string) sdk.Dec { } type BalanceMovement struct { - SourceAddress string `json:"from"` - DestinationAddress string `json:"to"` - Amount sdk.Int `json:"amount"` + SourceAddress string `json:"from"` + DestinationAddress string `json:"to"` + Amount *sdk.Int `json:"amount,omitempty"` } var NetworkInfos = map[string]NetworkConfig{ @@ -96,8 +104,8 @@ var NetworkInfos = map[string]NetworkConfig{ }, MovedAccounts: []BalanceMovement{ - BalanceMovement{"cudos1h6r6g0pwq7kcys5jcvfm9r7gcj3n2753hvk2ym", "cudos1w63ph9e4l07vpx7xdnje43cr2tlnr4jsfm4mvq", newInt("0")}, - BalanceMovement{"cudos1jxyc7lny4q7te6sj5xyt9j86kyz82vlfdprl4a", "cudos1tfmkdzx9hm8g28vpgc3xhhxjjn460wzkwtayxr", newInt("0")}, + BalanceMovement{"cudos1h6r6g0pwq7kcys5jcvfm9r7gcj3n2753hvk2ym", "cudos1w63ph9e4l07vpx7xdnje43cr2tlnr4jsfm4mvq", nil}, + BalanceMovement{"cudos1jxyc7lny4q7te6sj5xyt9j86kyz82vlfdprl4a", "cudos1tfmkdzx9hm8g28vpgc3xhhxjjn460wzkwtayxr", nil}, }, BackupValidators: []string{"fetchvaloper14w6a4al72uc3fpfy4lqtg0a7xtkx3w7hda0vel"}, @@ -171,9 +179,9 @@ var NetworkInfos = map[string]NetworkConfig{ //cudos15jpukx39rtkt8w3u3gzwwvyptdeyejcjade6he MovedAccounts: []BalanceMovement{ - {"cudos196nrmandtwz67d8h4h0ux7amlcluecglx00wlw", "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5", newInt("10000")}, // Replace this - {"cudos1xcwjdw09cc9dyshr4gt5520sgsh582mjj03jge", "cudos1dslwarknhfsw3pfjzxxf5mn28q3ewfectw0gta", newInt("0")}, // Replace this - {"cudos1ejmf96efvjp6pmsaj8djv3gpmnsvmpnctger4v", "cudos15p3rl5aavw9rtu86tna5lgxfkz67zzr6tp4ltv", newInt("0")}, // Replace this + {"cudos196nrmandtwz67d8h4h0ux7amlcluecglx00wlw", "cudos1nj49l56x7sss5hqyvfmctxr3mq64whg273g3x5", newIntRef("10000")}, // Replace this + {"cudos1xcwjdw09cc9dyshr4gt5520sgsh582mjj03jge", "cudos1dslwarknhfsw3pfjzxxf5mn28q3ewfectw0gta", nil}, // Replace this + {"cudos1ejmf96efvjp6pmsaj8djv3gpmnsvmpnctger4v", "cudos15p3rl5aavw9rtu86tna5lgxfkz67zzr6tp4ltv", nil}, // Replace this }, BackupValidators: []string{"fetchvaloper1m9cjw6xgt04f9ddw25fff3cfe2exgwk07eu46u", "fetchvaloper122j02czdt5ca8cf576wy2hassyxyx67wdsecml"},