mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-09-13 20:00:10 +00:00

* added DER module * scaffold type --module der DER zigbeeID dirigeraID dirigeraMAC plmntAddress liquidAddress * ./ignite scaffold message registerDER der:DER --module der * changed URL * storing DER * added query * added liquid der asset type * added der asset notarization logic * added nft notarization for DER * added nft query * added query and fixed linter aspects * added store testcases to the der module * added test cases adjusted to the linter requirements * addd ignite generate code changes * added metadata json instead of specific data Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
111 lines
3.8 KiB
Go
111 lines
3.8 KiB
Go
package der
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
|
"github.com/cosmos/cosmos-sdk/x/simulation"
|
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
|
dersimulation "github.com/planetmint/planetmint-go/x/der/simulation"
|
|
"github.com/planetmint/planetmint-go/x/der/types"
|
|
)
|
|
|
|
// avoid unused import issue
|
|
var (
|
|
_ = sample.AccAddress
|
|
_ = dersimulation.FindAccount
|
|
_ = simulation.MsgEntryKind
|
|
_ = baseapp.Paramspace
|
|
_ = rand.Rand{}
|
|
)
|
|
|
|
const (
|
|
opWeightMsgRegisterDER = "op_weight_msg_register_der"
|
|
// TODO: Determine the simulation weight value
|
|
defaultWeightMsgRegisterDER int = 100
|
|
|
|
opWeightMsgNotarizeLiquidDerAsset = "op_weight_msg_notarize_liquid_der_asset"
|
|
// TODO: Determine the simulation weight value
|
|
defaultWeightMsgNotarizeLiquidDerAsset int = 100
|
|
|
|
// this line is used by starport scaffolding # simapp/module/const
|
|
)
|
|
|
|
// GenerateGenesisState creates a randomized GenState of the module.
|
|
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
|
accs := make([]string, len(simState.Accounts))
|
|
for i, acc := range simState.Accounts {
|
|
accs[i] = acc.Address.String()
|
|
}
|
|
derGenesis := types.GenesisState{
|
|
Params: types.DefaultParams(),
|
|
// this line is used by starport scaffolding # simapp/module/genesisState
|
|
}
|
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&derGenesis)
|
|
}
|
|
|
|
// RegisterStoreDecoder registers a decoder.
|
|
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
|
|
|
|
// ProposalContents doesn't return any content functions for governance proposals.
|
|
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
|
|
return nil
|
|
}
|
|
|
|
// WeightedOperations returns the all the gov module operations with their respective weights.
|
|
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
|
|
operations := make([]simtypes.WeightedOperation, 0)
|
|
|
|
var weightMsgRegisterDER int
|
|
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegisterDER, &weightMsgRegisterDER, nil,
|
|
func(_ *rand.Rand) {
|
|
weightMsgRegisterDER = defaultWeightMsgRegisterDER
|
|
},
|
|
)
|
|
operations = append(operations, simulation.NewWeightedOperation(
|
|
weightMsgRegisterDER,
|
|
dersimulation.SimulateMsgRegisterDER(am.accountKeeper, am.bankKeeper, am.keeper),
|
|
))
|
|
|
|
var weightMsgNotarizeLiquidDerAsset int
|
|
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgNotarizeLiquidDerAsset, &weightMsgNotarizeLiquidDerAsset, nil,
|
|
func(_ *rand.Rand) {
|
|
weightMsgNotarizeLiquidDerAsset = defaultWeightMsgNotarizeLiquidDerAsset
|
|
},
|
|
)
|
|
operations = append(operations, simulation.NewWeightedOperation(
|
|
weightMsgNotarizeLiquidDerAsset,
|
|
dersimulation.SimulateMsgNotarizeLiquidDerAsset(am.accountKeeper, am.bankKeeper, am.keeper),
|
|
))
|
|
|
|
// this line is used by starport scaffolding # simapp/module/operation
|
|
|
|
return operations
|
|
}
|
|
|
|
// ProposalMsgs returns msgs used for governance proposals for simulations.
|
|
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
|
|
return []simtypes.WeightedProposalMsg{
|
|
simulation.NewWeightedProposalMsg(
|
|
opWeightMsgRegisterDER,
|
|
defaultWeightMsgRegisterDER,
|
|
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
|
|
dersimulation.SimulateMsgRegisterDER(am.accountKeeper, am.bankKeeper, am.keeper)
|
|
return nil
|
|
},
|
|
),
|
|
simulation.NewWeightedProposalMsg(
|
|
opWeightMsgNotarizeLiquidDerAsset,
|
|
defaultWeightMsgNotarizeLiquidDerAsset,
|
|
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
|
|
dersimulation.SimulateMsgNotarizeLiquidDerAsset(am.accountKeeper, am.bankKeeper, am.keeper)
|
|
return nil
|
|
},
|
|
),
|
|
// this line is used by starport scaffolding # simapp/module/OpMsg
|
|
}
|
|
}
|