File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,56 @@ app.MintKeeper = mintkeeper.NewKeeper(
74
74
)
75
75
```
76
76
77
+ #### Custom Minter DI Example
78
+
79
+ Below is a simple approach to creating a custom mint function with extra dependencies in DI configurations.
80
+ For this basic example, we will make the minter simply double the supply of ` foo ` coin.
81
+
82
+ First, we will define a function that takes our required dependencies, and returns a ` MintFn ` .
83
+
84
+ ``` go
85
+ // MyCustomMintFunction is a custom mint function that doubles the supply of `foo` coin.
86
+ func MyCustomMintFunction (bank bankkeeper .BaseKeeper ) mintkeeper .MintFn {
87
+ return func (ctx sdk.Context , k *mintkeeper.Keeper ) error {
88
+ supply := bank.GetSupply (ctx, " foo" )
89
+ err := k.MintCoins (ctx, sdk.NewCoins (supply.Add (supply)))
90
+ if err != nil {
91
+ return err
92
+ }
93
+ return nil
94
+ }
95
+ }
96
+ ```
97
+
98
+ Then, pass the function defined above into the ` depinject.Supply ` function with the required dependencies.
99
+
100
+ ``` go
101
+ // NewSimApp returns a reference to an initialized SimApp.
102
+ func NewSimApp (
103
+ logger log.Logger ,
104
+ db dbm.DB ,
105
+ traceStore io.Writer ,
106
+ loadLatest bool ,
107
+ appOpts servertypes.AppOptions ,
108
+ baseAppOptions ...func (*baseapp.BaseApp ),
109
+ ) *SimApp {
110
+ var (
111
+ app = &SimApp{}
112
+ appBuilder *runtime.AppBuilder
113
+ appConfig = depinject.Configs (
114
+ AppConfig ,
115
+ depinject.Supply (
116
+ appOpts,
117
+ logger,
118
+ // our custom mint function with the necessary dependency passed in.
119
+ MyCustomMintFunction (app.BankKeeper ),
120
+ ),
121
+ )
122
+ )
123
+ // ...
124
+ }
125
+ ```
126
+
77
127
## State
78
128
79
129
### Minter
You can’t perform that action at this time.
0 commit comments