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

razor-network / oracle-node / 10882594019

16 Sep 2024 05:47AM UTC coverage: 80.604% (+0.1%) from 80.5%
10882594019

push

github

web-flow
Releases/v1.2.0 (#1236)

* chore: merge develop to releases/v1.2.0 (#1227)

* feat: Github Migration  (#1146)

* feat: migrate to github actions

* chore: migrate from circle ci

* Update develop.yml (#1148)

* Update develop.yml (#1149)

* Update develop.yml

* Update develop.yml

* Update develop.yml

* Fix go mod tidy

* Replaced curve instance elliptic.P256() with crypto.S256() (#1150)

* fix: Update Dockerfile with version bumps (#1152)

* chore: hotfix missing workflow

* chore: fix dockerfile versions

* Feature/v1.1.0 (#1154)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Merged `v1.3.0-alpha` into `v1.0.5` (#973)

* Merged `v1` into `v1.3.0-aplha` with hotfixes (#966)

* Hotfix-proposed data (#913)

* Updated propose data global variables correctly

* Fixed tests

* Returned correct waitForBlockCompletion error

* coverage increase

* GetLocalData returns type types.ProposeFileData

* fixed benchmark

* Fetched Last proposed from contracts (#917)

* fetched getLastProposedEpoch from contracts and tests for it

* typo fix

* V1 propose hotfix (#918)

* Change propose.go to get sorted proposed block ids.
* Fix sorted proposed block issue.

Signed-off-by: Ashish Kumar Mishra <ashish10677@gmail.com>

* allow stakers to addStake < minSafeRazor (#928)

* Call claimStakerReward only if there reward to claim (#926)

* Make contract call only if there is commission to claim

* Add tests for claimCommission file

* update check

* Hotfix-giveSorted (#921)

* ResetDi... (continued)

887 of 1091 new or added lines in 40 files covered. (81.3%)

22 existing lines in 6 files now uncovered.

6641 of 8239 relevant lines covered (80.6%)

2524.53 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
        "crypto/ecdsa"
6
        "errors"
7
        "math/big"
8
        "os"
9
        "razor/core"
10
        "razor/core/types"
11
        "razor/path"
12
        "razor/pkg/bindings"
13
        "razor/utils"
14
        "strconv"
15
        "time"
16

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

367
//This function is used for proposing the block
368
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) {
×
369
        blockManager := razorUtils.GetBlockManager(client)
×
370
        var (
×
371
                txn *Types.Transaction
×
372
                err error
×
373
        )
×
374
        err = retry.Do(func() error {
×
375
                txn, err = ExecuteTransaction(blockManager, "Propose", opts, epoch, ids, medians, iteration, biggestInfluencerId)
×
376
                if err != nil {
×
377
                        log.Error("Error in proposing... Retrying")
×
378
                        return err
×
379
                }
×
380
                return nil
×
381
        }, retry.Attempts(3))
382
        if err != nil {
×
383
                return nil, err
×
384
        }
×
385
        return txn, nil
×
386
}
387

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

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

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

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

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

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

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

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

480
//This function is used to create the job
481
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) {
×
482
        assetManager := razorUtils.GetCollectionManager(client)
×
483
        return ExecuteTransaction(assetManager, "CreateJob", opts, weight, power, selectorType, name, selector, url)
×
484
}
×
485

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

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

503
//This function is used to update the job
504
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) {
×
505
        assetManager := razorUtils.GetCollectionManager(client)
×
506
        return ExecuteTransaction(assetManager, "UpdateJob", opts, jobId, weight, power, selectorType, selector, url)
×
507
}
×
508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

720
//This function is used for exiting the code
721
func (o OSUtils) Exit(code int) {
×
722
        os.Exit(code)
×
723
}
×
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