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

refactor: CUDOS nullable balance movement in config #388

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
8 changes: 4 additions & 4 deletions app/upgrade_cudos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
24 changes: 16 additions & 8 deletions app/upgrade_v_11_4_network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
Loading