@@ -172,6 +172,67 @@ OuterSyncLoop:
172172 }
173173}
174174
175+ func (d * Pegnetd ) MintTokensForBalance (ctx context.Context , tx * sql.Tx , height uint32 ) error {
176+ fLog := log .WithFields (log.Fields {"height" : height })
177+
178+ FAGlobalMintAddress , err := factom .NewFAAddress (GlobalMintAddress )
179+ if err != nil {
180+ log .WithFields (log.Fields {
181+ "error" : err ,
182+ }).Info ("error getting mint address" )
183+ return err
184+ }
185+
186+ for _ , tokenSupply := range MintTotalSupplyMap {
187+ _ , err := d .Pegnet .AddToBalance (tx , & FAGlobalMintAddress , tokenSupply .Ticker , tokenSupply .Amount * 1e8 )
188+ if err != nil {
189+ fLog .WithFields (log.Fields {
190+ "token" : tokenSupply .Ticker ,
191+ "amount" : tokenSupply .Amount ,
192+ "error" : err ,
193+ }).Info ("error minting token is failed" )
194+ return err
195+ }
196+ }
197+
198+ return nil
199+ }
200+
201+ func (d * Pegnetd ) NullifyMintedTokens (ctx context.Context , tx * sql.Tx , height uint32 ) error {
202+ fLog := log .WithFields (log.Fields {"height" : height })
203+
204+ FAGlobalMintAddress , err := factom .NewFAAddress (GlobalMintAddress )
205+ if err != nil {
206+ log .WithFields (log.Fields {
207+ "error" : err ,
208+ }).Info ("error getting mint address" )
209+ return err
210+ }
211+
212+ // Get all balances for the address
213+ balances , err := d .Pegnet .SelectBalances (& FAGlobalMintAddress )
214+ if err != nil {
215+ fLog .WithFields (log.Fields {
216+ "err" : err ,
217+ }).Info ("zeroing burn | balances retrieval failed" )
218+ }
219+
220+ for _ , tokenSupply := range MintTotalSupplyMap {
221+ // Substract from every issuance
222+ ticker := tokenSupply .Ticker
223+ value , _ := balances [ticker ]
224+ _ , _ , err := d .Pegnet .SubFromBalance (tx , & FAGlobalMintAddress , ticker , value ) // lastInd, txErr, err
225+ if err != nil {
226+ fLog .WithFields (log.Fields {
227+ "ticker" : ticker ,
228+ "balance" : value ,
229+ }).Info ("zeroing burn | substract from balance failed" )
230+ return err
231+ }
232+ }
233+ return nil
234+ }
235+
175236func (d * Pegnetd ) NullifyBurnAddress (ctx context.Context , tx * sql.Tx , height uint32 ) error {
176237 fLog := log .WithFields (log.Fields {"height" : height })
177238
@@ -215,7 +276,7 @@ func (d *Pegnetd) NullifyBurnAddress(ctx context.Context, tx *sql.Tx, height uin
215276 }).Info ("zeroing burn | balances retrieval failed" )
216277 }
217278
218- i := 0 // value to keep witin 0-9 range for mock tx
279+ i := 0 // value to keep witin 0-9 range for mock tx
219280 j := 0 // value for uniqueness
220281 if height >= V202EnhanceActivation {
221282 j = 50
@@ -278,6 +339,18 @@ func (d *Pegnetd) SyncBlock(ctx context.Context, tx *sql.Tx, height uint32) erro
278339 return context .Canceled
279340 }
280341
342+ if height == V204EnhanceActivation {
343+ if err := d .MintTokensForBalance (ctx , tx , d .Sync .Synced + 1 ); err != nil {
344+ return err
345+ }
346+ }
347+
348+ if height == V204BurnMintedTokenActivation {
349+ if err := d .NullifyMintedTokens (ctx , tx , d .Sync .Synced + 1 ); err != nil {
350+ return err
351+ }
352+ }
353+
281354 dblock := new (factom.DBlock )
282355 dblock .Height = height
283356 if err := dblock .Get (nil , d .FactomClient ); err != nil {
@@ -1404,4 +1477,4 @@ func (d *Pegnetd) GetAssetRatesV0(oprWinners []opr.AssetUint, sprWinners []opr.A
14041477 return filteredRates , nil
14051478 }
14061479 return nil , fmt .Errorf ("no winners" )
1407- }
1480+ }
0 commit comments