Skip to content

Commit

Permalink
feat: Cudos partial balance and delegations movement (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 authored Oct 9, 2024
1 parent c91059e commit 8872709
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 201 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
return subspace
}

func getNetworkInfo(app *App, ctx *sdk.Context, manifest *UpgradeManifest, expectedChainIdOfMergeSourceGenesis string) (*NetworkConfig, error) {
func getNetworkInfo(app *App, ctx sdk.Context, manifest *UpgradeManifest, expectedChainIdOfMergeSourceGenesis string) (*NetworkConfig, error) {
// Load network config from file if given
var networkInfo *NetworkConfig
var err error
Expand Down Expand Up @@ -761,7 +761,7 @@ func getNetworkInfo(app *App, ctx *sdk.Context, manifest *UpgradeManifest, expec
return networkInfo, nil
}

func LoadAndParseMergeSourceInputFiles(app *App, ctx *sdk.Context, manifest *UpgradeManifest) (*GenesisData, *NetworkConfig, error) {
func LoadAndParseMergeSourceInputFiles(app *App, ctx sdk.Context, manifest *UpgradeManifest) (*GenesisData, *NetworkConfig, error) {

cudosJsonData, cudosGenDoc, err := LoadCudosGenesis(app, manifest)

Expand All @@ -776,7 +776,7 @@ func LoadAndParseMergeSourceInputFiles(app *App, ctx *sdk.Context, manifest *Upg

cudosConfig := NewCudosMergeConfig(networkInfo.CudosMerge)

genesisData, err := parseGenesisData(*cudosJsonData, cudosGenDoc, cudosConfig, manifest)
genesisData, err := parseGenesisData(app, ctx, *cudosJsonData, cudosGenDoc, cudosConfig, manifest)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse genesis data: %w", err)
}
Expand All @@ -793,7 +793,7 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {

manifest := NewUpgradeManifest()

cudosGenesisData, networkInfo, err := LoadAndParseMergeSourceInputFiles(app, &ctx, manifest)
cudosGenesisData, networkInfo, err := LoadAndParseMergeSourceInputFiles(app, ctx, manifest)
if err != nil {
return nil, fmt.Errorf("cudos merge: %w", err)
}
Expand Down
21 changes: 21 additions & 0 deletions app/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ func (om *OrderedMap[K, V]) MustGet(key K) V {
return value
}

func (om *OrderedMap[K, V]) GetOrSetDefault(key K, defaultValue V) (V, bool) {
if value, exists := om.Get(key); exists {
return value, false
} else {
om.Set(key, defaultValue)
return om.MustGet(key), true
}
}

// Iterate returns a channel that yields key-value pairs in insertion order
func (om *OrderedMap[K, V]) Iterate() <-chan Pair[K, V] {
ch := make(chan Pair[K, V])
go func() {
for _, key := range om.keys {
ch <- Pair[K, V]{Key: key, Value: om.MustGet(key)}
}
close(ch)
}()
return ch
}

func (om *OrderedMap[K, V]) Has(key K) bool {
_, exists := om.Get(key)
return exists
Expand Down
Loading

0 comments on commit 8872709

Please sign in to comment.