• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

razor-network / oracle-node / 11253055648

09 Oct 2024 10:24AM UTC coverage: 80.649% (+0.02%) from 80.63%
11253055648

push

github

web-flow
refactor: added context with timeout to retry mechanism (#1235)

* chore: updated config variable default and limits for 5 min epoch (#1232)

* feat: added timeout to retry mechanism using context

* refactor: called stateBuffer once and used in other functions

* refactor: added context to RPC calls used in vote function

* refactor: added context instance to all the dependent functions

* refactor: fixed tests for cmd package

* refactor: fixed tests for utils package

* refactor: fixed additional tests in cmd package

* refactor: fixed benchmarks in cmd package

* refactor: reduced number of retry attempts

* refactor: added tests for context deadline exceeded for retry case

* refactor: rebased retry params with current main branch v2.0.0 release

356 of 367 new or added lines in 37 files covered. (97.0%)

1 existing line in 1 file now uncovered.

6685 of 8289 relevant lines covered (80.65%)

504.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.41
/cmd/struct-utils.go
1
// Package cmd provides all functions related to command line
2
package cmd
3

4
import (
5
        "context"
6
        "crypto/ecdsa"
7
        "errors"
8
        "math/big"
9
        "os"
10
        "razor/core"
11
        "razor/core/types"
12
        "razor/path"
13
        "razor/pkg/bindings"
14
        "razor/utils"
15
        "strconv"
16
        "time"
17

18
        "github.com/avast/retry-go"
19
        ethAccounts "github.com/ethereum/go-ethereum/accounts"
20
        "github.com/ethereum/go-ethereum/accounts/abi"
21
        "github.com/ethereum/go-ethereum/accounts/abi/bind"
22
        "github.com/ethereum/go-ethereum/accounts/keystore"
23
        "github.com/ethereum/go-ethereum/common"
24
        Types "github.com/ethereum/go-ethereum/core/types"
25
        "github.com/ethereum/go-ethereum/crypto"
26
        "github.com/ethereum/go-ethereum/ethclient"
27
        "github.com/spf13/pflag"
28
        "github.com/spf13/viper"
29
)
30

31
var (
32
        razorUtils  = utils.UtilsInterface
33
        pathUtils   = path.PathUtilsInterface
34
        clientUtils = utils.ClientInterface
35
        fileUtils   = utils.FileInterface
36
        gasUtils    = utils.GasInterface
37
        merkleUtils = utils.MerkleInterface
38
)
39

40
//This function initializes the utils
41
func InitializeUtils() {
8✔
42
        razorUtils = &utils.UtilsStruct{}
8✔
43
        utils.UtilsInterface = &utils.UtilsStruct{}
8✔
44
        utils.EthClient = &utils.EthClientStruct{}
8✔
45
        utils.ClientInterface = &utils.ClientStruct{}
8✔
46
        utils.Time = &utils.TimeStruct{}
8✔
47
        utils.OS = &utils.OSStruct{}
8✔
48
        utils.CoinInterface = &utils.CoinStruct{}
8✔
49
        utils.MerkleInterface = &utils.MerkleTreeStruct{}
8✔
50
        utils.IOInterface = &utils.IOStruct{}
8✔
51
        utils.ABIInterface = &utils.ABIStruct{}
8✔
52
        utils.PathInterface = &utils.PathStruct{}
8✔
53
        utils.BindInterface = &utils.BindStruct{}
8✔
54
        utils.BlockManagerInterface = &utils.BlockManagerStruct{}
8✔
55
        utils.StakeManagerInterface = &utils.StakeManagerStruct{}
8✔
56
        utils.AssetManagerInterface = &utils.AssetManagerStruct{}
8✔
57
        utils.VoteManagerInterface = &utils.VoteManagerStruct{}
8✔
58
        utils.BindingsInterface = &utils.BindingsStruct{}
8✔
59
        utils.JsonInterface = &utils.JsonStruct{}
8✔
60
        utils.StakedTokenInterface = &utils.StakedTokenStruct{}
8✔
61
        utils.RetryInterface = &utils.RetryStruct{}
8✔
62
        utils.MerkleInterface = &utils.MerkleTreeStruct{}
8✔
63
        utils.FlagSetInterface = &utils.FlagSetStruct{}
8✔
64
        clientUtils = &utils.ClientStruct{}
8✔
65
        utils.ClientInterface = &utils.ClientStruct{}
8✔
66
        fileUtils = &utils.FileStruct{}
8✔
67
        utils.FileInterface = &utils.FileStruct{}
8✔
68
        gasUtils = &utils.GasStruct{}
8✔
69
        utils.GasInterface = &utils.GasStruct{}
8✔
70
        merkleUtils = &utils.MerkleTreeStruct{}
8✔
71
        utils.MerkleInterface = &utils.MerkleTreeStruct{}
8✔
72
}
8✔
73

74
func ExecuteTransaction(interfaceName interface{}, methodName string, args ...interface{}) (*Types.Transaction, error) {
×
75
        returnedValues := utils.InvokeFunctionWithTimeout(interfaceName, methodName, args...)
×
76
        returnedError := utils.CheckIfAnyError(returnedValues)
×
77
        if returnedError != nil {
×
78
                return nil, returnedError
×
79
        }
×
80
        return returnedValues[0].Interface().(*Types.Transaction), nil
×
81
}
82

83
// FetchFlagInput fetches input value of the flag with given data type and specified flag keyword
84
func (flagSetUtils FLagSetUtils) FetchFlagInput(flagSet *pflag.FlagSet, flagName string, dataType string) (interface{}, error) {
×
85
        switch dataType {
×
86
        case "string":
×
87
                return flagSet.GetString(flagName)
×
88
        case "float32":
×
89
                return flagSet.GetFloat32(flagName)
×
90
        case "int32":
×
91
                return flagSet.GetInt32(flagName)
×
92
        case "int64":
×
93
                return flagSet.GetInt64(flagName)
×
94
        case "uint64":
×
95
                return flagSet.GetUint64(flagName)
×
96
        case "int":
×
97
                return flagSet.GetInt(flagName)
×
98
        case "bool":
×
99
                return flagSet.GetBool(flagName)
×
100
        default:
×
101
                return nil, errors.New("unsupported data type for flag input")
×
102
        }
103
}
104

105
// FetchRootFlagInput fetches input value of the root flag with given data type and specified flag keyword
106
func (flagSetUtils FLagSetUtils) FetchRootFlagInput(flagName string, dataType string) (interface{}, error) {
×
107
        switch dataType {
×
108
        case "string":
×
109
                return rootCmd.PersistentFlags().GetString(flagName)
×
110
        case "float32":
×
111
                return rootCmd.PersistentFlags().GetFloat32(flagName)
×
112
        case "int32":
×
113
                return rootCmd.PersistentFlags().GetInt32(flagName)
×
114
        case "int64":
×
115
                return rootCmd.PersistentFlags().GetInt64(flagName)
×
116
        case "uint64":
×
117
                return rootCmd.PersistentFlags().GetUint64(flagName)
×
118
        case "int":
×
119
                return rootCmd.PersistentFlags().GetInt(flagName)
×
120
        case "bool":
×
121
                return rootCmd.PersistentFlags().GetBool(flagName)
×
122
        default:
×
123
                return nil, errors.New("unsupported data type for root flag input")
×
124
        }
125
}
126

127
// Changed returns true if flag was passed in the command else returns false
128
func (flagSetUtils FLagSetUtils) Changed(flagSet *pflag.FlagSet, flagName string) bool {
×
129
        return flagSet.Changed(flagName)
×
130
}
×
131

132
//This function returns the hash
133
func (transactionUtils TransactionUtils) Hash(txn *Types.Transaction) common.Hash {
×
134
        return txn.Hash()
×
135
}
×
136

137
//This function is of staking the razors
138
func (stakeManagerUtils StakeManagerUtils) Stake(client *ethclient.Client, txnOpts *bind.TransactOpts, epoch uint32, amount *big.Int) (*Types.Transaction, error) {
×
139
        stakeManager := razorUtils.GetStakeManager(client)
×
140
        return ExecuteTransaction(stakeManager, "Stake", txnOpts, epoch, amount)
×
141
}
×
142

143
//This function resets the unstake lock
144
func (stakeManagerUtils StakeManagerUtils) ResetUnstakeLock(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32) (*Types.Transaction, error) {
×
145
        stakeManager := razorUtils.GetStakeManager(client)
×
146
        return ExecuteTransaction(stakeManager, "ResetUnstakeLock", opts, stakerId)
×
147
}
×
148

149
//This function is for delegation
150
func (stakeManagerUtils StakeManagerUtils) Delegate(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32, amount *big.Int) (*Types.Transaction, error) {
×
151
        stakeManager := razorUtils.GetStakeManager(client)
×
152
        return ExecuteTransaction(stakeManager, "Delegate", opts, stakerId, amount)
×
153
}
×
154

155
//This function initiates the withdraw
156
func (stakeManagerUtils StakeManagerUtils) InitiateWithdraw(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32) (*Types.Transaction, error) {
×
157
        stakeManager := razorUtils.GetStakeManager(client)
×
158
        return ExecuteTransaction(stakeManager, "InitiateWithdraw", opts, stakerId)
×
159
}
×
160

161
//This function unlocks the withdraw amount
162
func (stakeManagerUtils StakeManagerUtils) UnlockWithdraw(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32) (*Types.Transaction, error) {
×
163
        stakeManager := razorUtils.GetStakeManager(client)
×
164
        return ExecuteTransaction(stakeManager, "UnlockWithdraw", opts, stakerId)
×
165
}
×
166

167
//This function sets the delegation acceptance or rejection
168
func (stakeManagerUtils StakeManagerUtils) SetDelegationAcceptance(client *ethclient.Client, opts *bind.TransactOpts, status bool) (*Types.Transaction, error) {
×
169
        stakeManager := razorUtils.GetStakeManager(client)
×
170
        return ExecuteTransaction(stakeManager, "SetDelegationAcceptance", opts, status)
×
171
}
×
172

173
//This function updates the commission
174
func (stakeManagerUtils StakeManagerUtils) UpdateCommission(client *ethclient.Client, opts *bind.TransactOpts, commission uint8) (*Types.Transaction, error) {
×
175
        stakeManager := razorUtils.GetStakeManager(client)
×
176
        return ExecuteTransaction(stakeManager, "UpdateCommission", opts, commission)
×
177
}
×
178

179
//This function allows to unstake the razors
180
func (stakeManagerUtils StakeManagerUtils) Unstake(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32, sAmount *big.Int) (*Types.Transaction, error) {
×
181
        stakeManager := razorUtils.GetStakeManager(client)
×
182
        return ExecuteTransaction(stakeManager, "Unstake", opts, stakerId, sAmount)
×
183
}
×
184

185
//This function approves the unstake your razor
186
func (stakeManagerUtils StakeManagerUtils) ApproveUnstake(client *ethclient.Client, opts *bind.TransactOpts, stakerTokenAddress common.Address, amount *big.Int) (*Types.Transaction, error) {
×
187
        stakedToken := razorUtils.GetStakedToken(client, stakerTokenAddress)
×
188
        log.Debugf("ApproveUnstake: Executing Approve transaction for stakedToken address: %s with arguments amount : %s", stakerTokenAddress, amount)
×
189
        return ExecuteTransaction(stakedToken, "Approve", opts, common.HexToAddress(core.StakeManagerAddress), amount)
×
190
}
×
191

192
//This function is used to redeem the bounty
193
func (stakeManagerUtils StakeManagerUtils) RedeemBounty(client *ethclient.Client, opts *bind.TransactOpts, bountyId uint32) (*Types.Transaction, error) {
×
194
        stakeManager := razorUtils.GetStakeManager(client)
×
195
        return ExecuteTransaction(stakeManager, "RedeemBounty", opts, bountyId)
×
196
}
×
197

198
//This function returns the staker Info
199
func (stakeManagerUtils StakeManagerUtils) StakerInfo(client *ethclient.Client, opts *bind.CallOpts, stakerId uint32) (types.Staker, error) {
×
200
        stakeManager := razorUtils.GetStakeManager(client)
×
201
        returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "Stakers", opts, stakerId)
×
202
        returnedError := utils.CheckIfAnyError(returnedValues)
×
203
        if returnedError != nil {
×
204
                return types.Staker{}, returnedError
×
205
        }
×
206
        staker := returnedValues[0].Interface().(struct {
×
207
                AcceptDelegation                bool
×
208
                IsSlashed                       bool
×
209
                Commission                      uint8
×
210
                Id                              uint32
×
211
                Age                             uint32
×
212
                Address                         common.Address
×
213
                TokenAddress                    common.Address
×
214
                EpochFirstStakedOrLastPenalized uint32
×
215
                EpochCommissionLastUpdated      uint32
×
216
                Stake                           *big.Int
×
217
                StakerReward                    *big.Int
×
218
        })
×
219
        return staker, nil
×
220
}
221

222
//This function returns the maturity
223
func (stakeManagerUtils StakeManagerUtils) GetMaturity(client *ethclient.Client, opts *bind.CallOpts, age uint32) (uint16, error) {
×
224
        stakeManager := razorUtils.GetStakeManager(client)
×
225
        index := age / 10000
×
226
        returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "Maturities", opts, big.NewInt(int64(index)))
×
227
        returnedError := utils.CheckIfAnyError(returnedValues)
×
228
        if returnedError != nil {
×
229
                return 0, returnedError
×
230
        }
×
231
        return returnedValues[0].Interface().(uint16), nil
×
232
}
233

234
//This function returns the bounty lock
235
func (stakeManagerUtils StakeManagerUtils) GetBountyLock(client *ethclient.Client, opts *bind.CallOpts, bountyId uint32) (types.BountyLock, error) {
×
236
        stakeManager := razorUtils.GetStakeManager(client)
×
237
        returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "BountyLocks", opts, bountyId)
×
238
        returnedError := utils.CheckIfAnyError(returnedValues)
×
239
        if returnedError != nil {
×
240
                return types.BountyLock{}, returnedError
×
241
        }
×
242
        bountyLock := returnedValues[0].Interface().(struct {
×
243
                RedeemAfter  uint32
×
244
                BountyHunter common.Address
×
245
                Amount       *big.Int
×
246
        })
×
247
        return bountyLock, nil
×
248
}
249

250
//This function is used to claim the staker reward
251
func (stakeManagerUtils StakeManagerUtils) ClaimStakerReward(client *ethclient.Client, opts *bind.TransactOpts) (*Types.Transaction, error) {
×
252
        stakeManager := razorUtils.GetStakeManager(client)
×
253
        return ExecuteTransaction(stakeManager, "ClaimStakerReward", opts)
×
254
}
×
255

256
//This function is used to claim the block reward
257
func (blockManagerUtils BlockManagerUtils) ClaimBlockReward(client *ethclient.Client, opts *bind.TransactOpts) (*Types.Transaction, error) {
×
258
        blockManager := razorUtils.GetBlockManager(client)
×
259
        return ExecuteTransaction(blockManager, "ClaimBlockReward", opts)
×
260
}
×
261

262
// Thid function is used to finalize the dispute
263
func (blockManagerUtils BlockManagerUtils) FinalizeDispute(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, positionOfCollectionInBlock *big.Int) (*Types.Transaction, error) {
×
264
        blockManager := razorUtils.GetBlockManager(client)
×
265
        var (
×
266
                txn *Types.Transaction
×
267
                err error
×
268
        )
×
269
        err = retry.Do(func() error {
×
270
                txn, err = ExecuteTransaction(blockManager, "FinalizeDispute", opts, epoch, blockIndex, positionOfCollectionInBlock)
×
271
                if err != nil {
×
272
                        log.Error("Error in finalizing dispute.. Retrying")
×
273
                        return err
×
274
                }
×
275
                return nil
×
276
        }, retry.Attempts(3))
277
        if err != nil {
×
278
                return nil, err
×
279
        }
×
280
        return txn, nil
×
281
}
282

283
//This function is used to dispute the biggest staker which is proposed
284
func (blockManagerUtils BlockManagerUtils) DisputeBiggestStakeProposed(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, correctBiggestStakerId uint32) (*Types.Transaction, error) {
×
285
        blockManager := razorUtils.GetBlockManager(client)
×
286
        var (
×
287
                txn *Types.Transaction
×
288
                err error
×
289
        )
×
290
        err = retry.Do(func() error {
×
291
                txn, err = ExecuteTransaction(blockManager, "DisputeBiggestStakeProposed", opts, epoch, blockIndex, correctBiggestStakerId)
×
292
                if err != nil {
×
293
                        log.Error("Error in disputing biggest influence proposed.. Retrying")
×
294
                        return err
×
295
                }
×
296
                return nil
×
297
        }, retry.Attempts(3))
298
        if err != nil {
×
299
                return nil, err
×
300
        }
×
301
        return txn, nil
×
302
}
303

304
//This function is used to check if dispute collection Id is absent or not
305
func (blockManagerUtils BlockManagerUtils) DisputeCollectionIdShouldBeAbsent(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, id uint16, positionOfCollectionInBlock *big.Int) (*Types.Transaction, error) {
×
306
        blockManager := razorUtils.GetBlockManager(client)
×
307
        var (
×
308
                txn *Types.Transaction
×
309
                err error
×
310
        )
×
311
        err = retry.Do(func() error {
×
312
                txn, err = ExecuteTransaction(blockManager, "DisputeCollectionIdShouldBeAbsent", opts, epoch, blockIndex, id, positionOfCollectionInBlock)
×
313

×
314
                if err != nil {
×
315
                        log.Error("Error in disputing collection id should be absent... Retrying")
×
316
                        return err
×
317
                }
×
318
                return nil
×
319
        }, retry.Attempts(3))
320
        if err != nil {
×
321
                return nil, err
×
322
        }
×
323
        return txn, nil
×
324
}
325

326
//This function is used to check if dispute collection Id is present or not
327
func (blockManagerUtils BlockManagerUtils) DisputeCollectionIdShouldBePresent(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, id uint16) (*Types.Transaction, error) {
×
328
        blockManager := razorUtils.GetBlockManager(client)
×
329
        var (
×
330
                txn *Types.Transaction
×
331
                err error
×
332
        )
×
333
        err = retry.Do(func() error {
×
334
                txn, err = ExecuteTransaction(blockManager, "DisputeCollectionIdShouldBePresent", opts, epoch, blockIndex, id)
×
335
                if err != nil {
×
336
                        log.Error("Error in disputing collection id should be present... Retrying")
×
337
                        return err
×
338
                }
×
339
                return nil
×
340
        }, retry.Attempts(3))
341
        if err != nil {
×
342
                return nil, err
×
343
        }
×
344
        return txn, nil
×
345
}
346

347
//This function is used to do dispute on order of Ids
348
func (blockManagerUtils BlockManagerUtils) DisputeOnOrderOfIds(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, index0 *big.Int, index1 *big.Int) (*Types.Transaction, error) {
×
349
        blockManager := razorUtils.GetBlockManager(client)
×
350
        var (
×
351
                txn *Types.Transaction
×
352
                err error
×
353
        )
×
354
        err = retry.Do(func() error {
×
355
                txn, err = ExecuteTransaction(blockManager, "DisputeOnOrderOfIds", opts, epoch, blockIndex, index0, index1)
×
356
                if err != nil {
×
357
                        log.Error("Error in disputing order of ids proposed... Retrying")
×
358
                        return err
×
359
                }
×
360
                return nil
×
361
        }, retry.Attempts(3))
362
        if err != nil {
×
363
                return nil, err
×
364
        }
×
365
        return txn, nil
×
366
}
367

368
//This function is used for proposing the block
369
func (blockManagerUtils BlockManagerUtils) Propose(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, ids []uint16, medians []*big.Int, iteration *big.Int, biggestInfluencerId uint32) (*Types.Transaction, error) {
×
370
        blockManager := razorUtils.GetBlockManager(client)
×
371
        var (
×
372
                txn *Types.Transaction
×
373
                err error
×
374
        )
×
375
        err = retry.Do(func() error {
×
376
                txn, err = ExecuteTransaction(blockManager, "Propose", opts, epoch, ids, medians, iteration, biggestInfluencerId)
×
377
                if err != nil {
×
378
                        log.Error("Error in proposing... Retrying")
×
379
                        return err
×
380
                }
×
381
                return nil
×
382
        }, retry.Attempts(3))
383
        if err != nil {
×
384
                return nil, err
×
385
        }
×
386
        return txn, nil
×
387
}
388

389
//This function returns the sorted Ids
390
func (blockManagerUtils BlockManagerUtils) GiveSorted(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*Types.Transaction, error) {
×
391
        return ExecuteTransaction(blockManager, "GiveSorted", opts, epoch, leafId, sortedValues)
×
392
}
×
393

394
//This function resets the dispute
395
func (blockManagerUtils BlockManagerUtils) ResetDispute(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32) (*Types.Transaction, error) {
×
396
        return ExecuteTransaction(blockManager, "ResetDispute", opts, epoch)
×
397
}
×
398

399
// This functiom gets Disputes mapping
400
func (blockManagerUtils BlockManagerUtils) Disputes(client *ethclient.Client, opts *bind.CallOpts, epoch uint32, address common.Address) (types.DisputesStruct, error) {
×
401
        blockManager := razorUtils.GetBlockManager(client)
×
402
        returnedValues := utils.InvokeFunctionWithTimeout(blockManager, "Disputes", opts, epoch, address)
×
403
        returnedError := utils.CheckIfAnyError(returnedValues)
×
404
        if returnedError != nil {
×
405
                return types.DisputesStruct{}, returnedError
×
406
        }
×
407
        disputesMapping := returnedValues[0].Interface().(struct {
×
408
                LeafId           uint16
×
409
                LastVisitedValue *big.Int
×
410
                AccWeight        *big.Int
×
411
                Median           *big.Int
×
412
        })
×
413
        return disputesMapping, nil
×
414
}
415

416
//This function is used to reveal the values
417
func (voteManagerUtils VoteManagerUtils) Reveal(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, tree bindings.StructsMerkleTree, signature []byte) (*Types.Transaction, error) {
×
418
        voteManager := razorUtils.GetVoteManager(client)
×
419
        var (
×
420
                txn *Types.Transaction
×
421
                err error
×
422
        )
×
423
        err = retry.Do(func() error {
×
424
                txn, err = ExecuteTransaction(voteManager, "Reveal", opts, epoch, tree, signature)
×
425
                if err != nil {
×
426
                        log.Error("Error in revealing... Retrying")
×
427
                        return err
×
428
                }
×
429
                return nil
×
430
        }, retry.Attempts(3))
431
        if err != nil {
×
432
                return nil, err
×
433
        }
×
434
        return txn, nil
×
435
}
436

437
//This function is used to commit the values
438
func (voteManagerUtils VoteManagerUtils) Commit(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, commitment [32]byte) (*Types.Transaction, error) {
×
439
        voteManager := razorUtils.GetVoteManager(client)
×
440
        var (
×
441
                txn *Types.Transaction
×
442
                err error
×
443
        )
×
444
        err = retry.Do(func() error {
×
445
                txn, err = ExecuteTransaction(voteManager, "Commit", opts, epoch, commitment)
×
446
                if err != nil {
×
447
                        log.Error("Error in committing... Retrying")
×
448
                        return err
×
449
                }
×
450
                return nil
×
451
        }, retry.Attempts(3))
452
        if err != nil {
×
453
                return nil, err
×
454
        }
×
455
        return txn, nil
×
456
}
457

458
//This function is used to check the allowance of staker
459
func (tokenManagerUtils TokenManagerUtils) Allowance(client *ethclient.Client, opts *bind.CallOpts, owner common.Address, spender common.Address) (*big.Int, error) {
×
460
        tokenManager := razorUtils.GetTokenManager(client)
×
461
        returnedValues := utils.InvokeFunctionWithTimeout(tokenManager, "Allowance", opts, owner, spender)
×
462
        returnedError := utils.CheckIfAnyError(returnedValues)
×
463
        if returnedError != nil {
×
464
                return nil, returnedError
×
465
        }
×
466
        return returnedValues[0].Interface().(*big.Int), nil
×
467
}
468

469
//This function is used to approve the transaction
470
func (tokenManagerUtils TokenManagerUtils) Approve(client *ethclient.Client, opts *bind.TransactOpts, spender common.Address, amount *big.Int) (*Types.Transaction, error) {
×
471
        tokenManager := razorUtils.GetTokenManager(client)
×
472
        return ExecuteTransaction(tokenManager, "Approve", opts, spender, amount)
×
473
}
×
474

475
//This function is used to transfer the tokens
476
func (tokenManagerUtils TokenManagerUtils) Transfer(client *ethclient.Client, opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*Types.Transaction, error) {
×
477
        tokenManager := razorUtils.GetTokenManager(client)
×
478
        return ExecuteTransaction(tokenManager, "Transfer", opts, recipient, amount)
×
479
}
×
480

481
//This function is used to create the job
482
func (assetManagerUtils AssetManagerUtils) CreateJob(client *ethclient.Client, opts *bind.TransactOpts, weight uint8, power int8, selectorType uint8, name string, selector string, url string) (*Types.Transaction, error) {
×
483
        assetManager := razorUtils.GetCollectionManager(client)
×
484
        return ExecuteTransaction(assetManager, "CreateJob", opts, weight, power, selectorType, name, selector, url)
×
485
}
×
486

487
//This function is used to set the collection status
488
func (assetManagerUtils AssetManagerUtils) SetCollectionStatus(client *ethclient.Client, opts *bind.TransactOpts, assetStatus bool, id uint16) (*Types.Transaction, error) {
×
489
        assetManager := razorUtils.GetCollectionManager(client)
×
490
        return ExecuteTransaction(assetManager, "SetCollectionStatus", opts, assetStatus, id)
×
491
}
×
492

493
//This function is used to get the active status
494
func (assetManagerUtils AssetManagerUtils) GetActiveStatus(client *ethclient.Client, opts *bind.CallOpts, id uint16) (bool, error) {
×
495
        assetMananger := razorUtils.GetCollectionManager(client)
×
496
        returnedValues := utils.InvokeFunctionWithTimeout(assetMananger, "GetCollectionStatus", opts, id)
×
497
        returnedError := utils.CheckIfAnyError(returnedValues)
×
498
        if returnedError != nil {
×
499
                return false, returnedError
×
500
        }
×
501
        return returnedValues[0].Interface().(bool), nil
×
502
}
503

504
//This function is used to update the job
505
func (assetManagerUtils AssetManagerUtils) UpdateJob(client *ethclient.Client, opts *bind.TransactOpts, jobId uint16, weight uint8, power int8, selectorType uint8, selector string, url string) (*Types.Transaction, error) {
×
506
        assetManager := razorUtils.GetCollectionManager(client)
×
507
        return ExecuteTransaction(assetManager, "UpdateJob", opts, jobId, weight, power, selectorType, selector, url)
×
508
}
×
509

510
//This function is used to create the collection
511
func (assetManagerUtils AssetManagerUtils) CreateCollection(client *ethclient.Client, opts *bind.TransactOpts, tolerance uint32, power int8, aggregationMethod uint32, jobIDs []uint16, name string) (*Types.Transaction, error) {
×
512
        assetManager := razorUtils.GetCollectionManager(client)
×
513
        return ExecuteTransaction(assetManager, "CreateCollection", opts, tolerance, power, aggregationMethod, jobIDs, name)
×
514
}
×
515

516
//This function is used to update the collection
517
func (assetManagerUtils AssetManagerUtils) UpdateCollection(client *ethclient.Client, opts *bind.TransactOpts, collectionId uint16, tolerance uint32, aggregationMethod uint32, power int8, jobIds []uint16) (*Types.Transaction, error) {
×
518
        assetManager := razorUtils.GetCollectionManager(client)
×
519
        return ExecuteTransaction(assetManager, "UpdateCollection", opts, collectionId, tolerance, aggregationMethod, power, jobIds)
×
520
}
×
521

522
//This function returns BountyId in Uint32
523
func (flagSetUtils FLagSetUtils) GetUint32BountyId(flagSet *pflag.FlagSet) (uint32, error) {
×
524
        return flagSet.GetUint32("bountyId")
×
525
}
×
526

527
//This function returns the from in string
528
func (flagSetUtils FLagSetUtils) GetStringFrom(flagSet *pflag.FlagSet) (string, error) {
×
529
        from, err := flagSet.GetString("from")
×
530
        if err != nil {
×
531
                return "", err
×
532
        }
×
533
        return utils.ValidateAddress(from)
×
534
}
535

536
//This function returns the to in string
537
func (flagSetUtils FLagSetUtils) GetStringTo(flagSet *pflag.FlagSet) (string, error) {
×
538
        to, err := flagSet.GetString("to")
×
539
        if err != nil {
×
540
                return "", err
×
541
        }
×
542
        return utils.ValidateAddress(to)
×
543
}
544

545
//This function returns the address in string
546
func (flagSetUtils FLagSetUtils) GetStringAddress(flagSet *pflag.FlagSet) (string, error) {
×
547
        address, err := flagSet.GetString("address")
×
548
        if err != nil {
×
549
                return "", err
×
550
        }
×
551
        return utils.ValidateAddress(address)
×
552
}
553

554
//This function returns the stakerId in Uint32
555
func (flagSetUtils FLagSetUtils) GetUint32StakerId(flagSet *pflag.FlagSet) (uint32, error) {
×
556
        return flagSet.GetUint32("stakerId")
×
557
}
×
558

559
//This function returns the name in string
560
func (flagSetUtils FLagSetUtils) GetStringName(flagSet *pflag.FlagSet) (string, error) {
×
561
        return flagSet.GetString("name")
×
562
}
×
563

564
//This function returns the Url in string
565
func (flagSetUtils FLagSetUtils) GetStringUrl(flagSet *pflag.FlagSet) (string, error) {
×
566
        return flagSet.GetString("url")
×
567
}
×
568

569
//This function returns the selector in string
570
func (flagSetUtils FLagSetUtils) GetStringSelector(flagSet *pflag.FlagSet) (string, error) {
×
571
        return flagSet.GetString("selector")
×
572
}
×
573

574
//This function returns the power in string
575
func (flagSetUtils FLagSetUtils) GetInt8Power(flagSet *pflag.FlagSet) (int8, error) {
×
576
        return flagSet.GetInt8("power")
×
577
}
×
578

579
//This function returns the weight in Uint8
580
func (flagSetUtils FLagSetUtils) GetUint8Weight(flagSet *pflag.FlagSet) (uint8, error) {
×
581
        return flagSet.GetUint8("weight")
×
582
}
×
583

584
//This function returns the selectorType in Uint8
585
func (flagSetUtils FLagSetUtils) GetUint8SelectorType(flagSet *pflag.FlagSet) (uint8, error) {
×
586
        return flagSet.GetUint8("selectorType")
×
587
}
×
588

589
//This function returns the status in string
590
func (flagSetUtils FLagSetUtils) GetStringStatus(flagSet *pflag.FlagSet) (string, error) {
×
591
        return flagSet.GetString("status")
×
592
}
×
593

594
//This function returns the commission in Uint8
595
func (flagSetUtils FLagSetUtils) GetUint8Commission(flagSet *pflag.FlagSet) (uint8, error) {
×
596
        return flagSet.GetUint8("commission")
×
597
}
×
598

599
//This function returns the jobIds in Uint
600
func (flagSetUtils FLagSetUtils) GetUintSliceJobIds(flagSet *pflag.FlagSet) ([]uint, error) {
×
601
        return flagSet.GetUintSlice("jobIds")
×
602
}
×
603

604
//This function returns the aggregation in Uint32
605
func (flagSetUtils FLagSetUtils) GetUint32Aggregation(flagSet *pflag.FlagSet) (uint32, error) {
×
606
        return flagSet.GetUint32("aggregation")
×
607
}
×
608

609
//This function returns the JobId in Uint16
610
func (flagSetUtils FLagSetUtils) GetUint16JobId(flagSet *pflag.FlagSet) (uint16, error) {
×
611
        return flagSet.GetUint16("jobId")
×
612
}
×
613

614
//This function returns the CollectionId in Uint16
615
func (flagSetUtils FLagSetUtils) GetUint16CollectionId(flagSet *pflag.FlagSet) (uint16, error) {
×
616
        return flagSet.GetUint16("collectionId")
×
617
}
×
618

619
//This function returns the value in string
620
func (flagSetUtils FLagSetUtils) GetStringValue(flagSet *pflag.FlagSet) (string, error) {
×
621
        return flagSet.GetString("value")
×
622
}
×
623

624
//This function is used to check if weiRazor is passed or not
625
func (flagSetUtils FLagSetUtils) GetBoolWeiRazor(flagSet *pflag.FlagSet) (bool, error) {
×
626
        return flagSet.GetBool("weiRazor")
×
627
}
×
628

629
//This function returns the tolerance in Uint32
630
func (flagSetUtils FLagSetUtils) GetUint32Tolerance(flagSet *pflag.FlagSet) (uint32, error) {
×
631
        return flagSet.GetUint32("tolerance")
×
632
}
×
633

634
//This function is used to check if rogue is passed or not
635
func (flagSetUtils FLagSetUtils) GetBoolRogue(flagSet *pflag.FlagSet) (bool, error) {
×
636
        return flagSet.GetBool("rogue")
×
637
}
×
638

639
//This function is used to check if rogueMode is passed or not
640
func (flagSetUtils FLagSetUtils) GetStringSliceRogueMode(flagSet *pflag.FlagSet) ([]string, error) {
×
641
        return flagSet.GetStringSlice("rogueMode")
×
642
}
×
643

644
//This function is used to check the inputs gor backupNode flag
645
func (flagSetUtils FLagSetUtils) GetStringSliceBackupNode(flagSet *pflag.FlagSet) ([]string, error) {
×
646
        return flagSet.GetStringSlice("backupNode")
×
647
}
×
648

649
//This function is used to check if exposeMetrics is passed or not
650
func (flagSetUtils FLagSetUtils) GetStringExposeMetrics(flagSet *pflag.FlagSet) (string, error) {
×
651
        return flagSet.GetString("exposeMetrics")
×
652
}
×
653

654
//This function is used to check if CertFile  is passed or not
655
func (flagSetUtils FLagSetUtils) GetStringCertFile(flagSet *pflag.FlagSet) (string, error) {
×
656
        return flagSet.GetString("certFile")
×
657
}
×
658

659
//This function is used to check if CertFile  is passed or not
660
func (flagSetUtils FLagSetUtils) GetStringCertKey(flagSet *pflag.FlagSet) (string, error) {
×
661
        return flagSet.GetString("certKey")
×
662
}
×
663

664
//This function returns the max size of log file in Int
665
func (flagSetUtils FLagSetUtils) GetIntLogFileMaxSize(flagSet *pflag.FlagSet) (int, error) {
×
666
        return flagSet.GetInt("logFileMaxSize")
×
667
}
×
668

669
//This function returns the max number of backups for logFile in Int
670
func (flagSetUtils FLagSetUtils) GetIntLogFileMaxBackups(flagSet *pflag.FlagSet) (int, error) {
×
671
        return flagSet.GetInt("logFileMaxBackups")
×
672
}
×
673

674
//This function returns the max nage for logFle in Int
675
func (flagSetUtils FLagSetUtils) GetIntLogFileMaxAge(flagSet *pflag.FlagSet) (int, error) {
×
676
        return flagSet.GetInt("logFileMaxAge")
×
677
}
×
678

679
//This function returns the accounts
680
func (keystoreUtils KeystoreUtils) Accounts(path string) []ethAccounts.Account {
×
681
        ks := keystore.NewKeyStore(path, keystore.StandardScryptN, keystore.StandardScryptP)
×
682
        return ks.Accounts()
×
683
}
×
684

685
//This function is used to import the ECDSA
686
func (keystoreUtils KeystoreUtils) ImportECDSA(path string, priv *ecdsa.PrivateKey, passphrase string) (ethAccounts.Account, error) {
×
687
        ks := keystore.NewKeyStore(path, keystore.StandardScryptN, keystore.StandardScryptP)
×
688
        return ks.ImportECDSA(priv, passphrase)
×
689
}
×
690

691
//This function is used to convert from Hex to ECDSA
692
func (c CryptoUtils) HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error) {
×
693
        return crypto.HexToECDSA(hexKey)
×
694
}
×
695

696
//This function is used to give the sorted Ids
NEW
697
func (*UtilsStruct) GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error {
×
NEW
698
        return GiveSorted(ctx, client, blockManager, txnArgs, epoch, assetId, sortedStakers)
×
UNCOV
699
}
×
700

701
//This function is used to write config as
702
func (v ViperUtils) ViperWriteConfigAs(path string) error {
×
703
        return viper.WriteConfigAs(path)
×
704
}
×
705

706
//This function is used for sleep
707
func (t TimeUtils) Sleep(duration time.Duration) {
×
708
        utils.Time.Sleep(duration)
×
709
}
×
710

711
//This function is used to parse the bool
712
func (s StringUtils) ParseBool(str string) (bool, error) {
×
713
        return strconv.ParseBool(str)
×
714
}
×
715

716
//This function is used for unpacking
717
func (a AbiUtils) Unpack(abi abi.ABI, name string, data []byte) ([]interface{}, error) {
×
718
        return abi.Unpack(name, data)
×
719
}
×
720

721
//This function is used for exiting the code
722
func (o OSUtils) Exit(code int) {
×
723
        os.Exit(code)
×
724
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc