-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package simulation | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/milkyway-labs/milkyway/v3/x/pools/types" | ||
) | ||
|
||
// GetGenesisState returns the pools genesis state from the SimulationState | ||
func GetGenesisState(simState *module.SimulationState) types.GenesisState { | ||
operatorsGenesisJSON, found := simState.GenState[types.ModuleName] | ||
var operatorsGenesis types.GenesisState | ||
if found { | ||
simState.Cdc.MustUnmarshalJSON(operatorsGenesisJSON, &operatorsGenesis) | ||
} else { | ||
operatorsGenesis = *types.DefaultGenesis() | ||
} | ||
|
||
return operatorsGenesis | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/milkyway-labs/milkyway/v3/utils" | ||
"github.com/milkyway-labs/milkyway/v3/x/pools/keeper" | ||
"github.com/milkyway-labs/milkyway/v3/x/pools/types" | ||
) | ||
|
||
// GetRandomExistingPool returns a random existing pool | ||
func GetRandomExistingPool(r *rand.Rand, ctx sdk.Context, k *keeper.Keeper, filter func(s types.Pool) bool) (types.Pool, bool) { | ||
pools, err := k.GetPools(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if filter != nil { | ||
pools = utils.Filter(pools, filter) | ||
} | ||
|
||
if len(pools) == 0 { | ||
return types.Pool{}, false | ||
} | ||
|
||
randomServiceIndex := r.Intn(len(pools)) | ||
return pools[randomServiceIndex], true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.