-
Notifications
You must be signed in to change notification settings - Fork 0
/
simapp.go
47 lines (41 loc) · 1.38 KB
/
simapp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package typed
import (
"fmt"
"github.com/spellshape/cli/spellshape/pkg/multiformatname"
"github.com/spellshape/cli/spellshape/pkg/placeholder"
)
func ModuleSimulationMsgModify(
replacer placeholder.Replacer,
content,
moduleName string,
typeName multiformatname.Name,
msgs ...string,
) string {
if len(msgs) == 0 {
msgs = append(msgs, "")
}
for _, msg := range msgs {
// simulation constants
templateConst := `opWeightMsg%[2]v%[3]v = "op_weight_msg_%[4]v"
// TODO: Determine the simulation weight value
defaultWeightMsg%[2]v%[3]v int = 100
%[1]v`
replacementConst := fmt.Sprintf(templateConst, PlaceholderSimappConst, msg, typeName.UpperCamel, typeName.Snake)
content = replacer.Replace(content, PlaceholderSimappConst, replacementConst)
// simulation operations
templateOp := `var weightMsg%[2]v%[3]v int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsg%[2]v%[3]v, &weightMsg%[2]v%[3]v, nil,
func(_ *rand.Rand) {
weightMsg%[2]v%[3]v = defaultWeightMsg%[2]v%[3]v
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsg%[2]v%[3]v,
%[4]vsimulation.SimulateMsg%[2]v%[3]v(am.accountKeeper, am.bankKeeper, am.keeper),
))
%[1]v`
replacementOp := fmt.Sprintf(templateOp, PlaceholderSimappOperation, msg, typeName.UpperCamel, moduleName)
content = replacer.Replace(content, PlaceholderSimappOperation, replacementOp)
}
return content
}