diff --git a/RPC/rpc.go b/RPC/rpc.go new file mode 100644 index 00000000..ce1afc33 --- /dev/null +++ b/RPC/rpc.go @@ -0,0 +1,185 @@ +package RPC + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "github.com/ethereum/go-ethereum/ethclient" + "os" + "path/filepath" + "razor/logger" + "sort" + "strings" + "sync" + "time" +) + +var log = logger.NewLogger() + +func (m *RPCManager) calculateMetrics(endpoint *RPCEndpoint) error { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + client, err := ethclient.DialContext(ctx, endpoint.URL) + if err != nil { + return fmt.Errorf("failed to connect to RPC: %w", err) + } + + start := time.Now() + blockNumber, err := client.BlockNumber(ctx) + if err != nil { + if errors.Is(err, context.DeadlineExceeded) { + return fmt.Errorf("RPC call timed out: %w", err) + } + return fmt.Errorf("RPC call failed: %w", err) + } + latency := time.Since(start).Seconds() + + endpoint.BlockNumber = blockNumber + endpoint.Latency = latency + endpoint.Client = client // Store the client for future use + + return nil +} + +// updateAndSortEndpoints calculates metrics and sorts the endpoints +func (m *RPCManager) updateAndSortEndpoints() error { + if len(m.Endpoints) == 0 { + return fmt.Errorf("no endpoints available to update") + } + + var wg sync.WaitGroup + log.Debug("Starting concurrent metrics calculation for all endpoints...") + + for _, endpoint := range m.Endpoints { + wg.Add(1) + go func(ep *RPCEndpoint) { + defer wg.Done() + if err := m.calculateMetrics(ep); err != nil { + log.Printf("Error calculating metrics for endpoint %s: %v", ep.URL, err) + } + }(endpoint) + } + wg.Wait() + + log.Debug("Concurrent metrics calculation complete. Sorting endpoints...") + + m.mutex.Lock() + defer m.mutex.Unlock() + + sort.Slice(m.Endpoints, func(i, j int) bool { + if m.Endpoints[i].BlockNumber == m.Endpoints[j].BlockNumber { + return m.Endpoints[i].Latency < m.Endpoints[j].Latency + } + return m.Endpoints[i].BlockNumber > m.Endpoints[j].BlockNumber + }) + + // Update the best RPC client after sorting + m.BestRPCClient = m.Endpoints[0].Client + + return nil +} + +// RefreshEndpoints will update and sort the endpoints. +func (m *RPCManager) RefreshEndpoints() error { + if err := m.updateAndSortEndpoints(); err != nil { + return fmt.Errorf("failed to refresh endpoints: %w", err) + } + log.Infof("Endpoints refreshed successfully") + return nil +} + +func InitializeRPCManager(provider string) (*RPCManager, error) { + // Fetch the absolute path to the PROJECT directory and locate endpoints.json file + projectDir := filepath.Join("..", "..") // Relative path from build output + endpointsFile := filepath.Join(projectDir, "endpoints.json") + + fileData, err := os.ReadFile(endpointsFile) + if err != nil { + return nil, fmt.Errorf("failed to read endpoints.json: %w", err) + } + + // Unmarshal the JSON file into a list of RPC endpoints + var rpcEndpointsList []string + err = json.Unmarshal(fileData, &rpcEndpointsList) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal endpoints.json: %w", err) + } + + // Normalize provider input and check if it's already in the list + provider = strings.TrimSpace(provider) // Trim whitespace from the input + providerFound := false + for _, endpoint := range rpcEndpointsList { + if endpoint == provider { + providerFound = true + break + } + } + + // If the provider is not found, add it to the list + if !providerFound && provider != "" { + log.Infof("Adding user-provided endpoint: %s", provider) + rpcEndpointsList = append(rpcEndpointsList, provider) + } + + // Initialize the RPC endpoints + rpcEndpoints := make([]*RPCEndpoint, len(rpcEndpointsList)) + for i, url := range rpcEndpointsList { + rpcEndpoints[i] = &RPCEndpoint{URL: url} + } + + rpcManager := &RPCManager{ + Endpoints: rpcEndpoints, + } + + // Pre-calculate metrics and set the best client on initialization + if err := rpcManager.updateAndSortEndpoints(); err != nil { + return nil, fmt.Errorf("failed to initialize RPC Manager: %w", err) + } + + return rpcManager, nil +} + +func (m *RPCManager) GetBestRPCClient() (*ethclient.Client, error) { + m.mutex.RLock() + defer m.mutex.RUnlock() + + if m.BestRPCClient == nil { + return nil, fmt.Errorf("no best RPC client available") + } + return m.BestRPCClient, nil +} + +// SwitchToNextBestRPCClient switches to the next best available client after the current best client. +func (m *RPCManager) SwitchToNextBestRPCClient() error { + m.mutex.Lock() + defer m.mutex.Unlock() + + // If there are fewer than 2 endpoints, there are no alternate clients to switch to. + if len(m.Endpoints) < 2 { + return fmt.Errorf("no other RPC clients to switch to") + } + + // Find the index of the current best client + var currentIndex = -1 + for i, endpoint := range m.Endpoints { + if endpoint.Client == m.BestRPCClient { + currentIndex = i + break + } + } + + // If current client is not found (which is rare), return an error + if currentIndex == -1 { + return fmt.Errorf("current best client not found in the list of endpoints") + } + + // Calculate the next index by wrapping around if necessary + nextIndex := (currentIndex + 1) % len(m.Endpoints) + + // Switch to the next client in the list + m.BestRPCClient = m.Endpoints[nextIndex].Client + log.Infof("Switched to the next best RPC client: %s", m.Endpoints[nextIndex].URL) + return nil +} diff --git a/RPC/rpc_struct.go b/RPC/rpc_struct.go new file mode 100644 index 00000000..8da51beb --- /dev/null +++ b/RPC/rpc_struct.go @@ -0,0 +1,25 @@ +package RPC + +import ( + "context" + "github.com/ethereum/go-ethereum/ethclient" + "sync" +) + +type RPCEndpoint struct { + URL string + BlockNumber uint64 + Latency float64 + Client *ethclient.Client +} + +type RPCManager struct { + Endpoints []*RPCEndpoint + mutex sync.RWMutex + BestRPCClient *ethclient.Client // Holds the current best RPC client +} + +type RPCParameters struct { + Ctx context.Context // Context with timeout for handling unresponsive RPC calls + RPCManager *RPCManager // RPC manager for client selection and contract calls +} diff --git a/cmd/addStake.go b/cmd/addStake.go index 7092b329..44ed0c90 100644 --- a/cmd/addStake.go +++ b/cmd/addStake.go @@ -2,11 +2,9 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" @@ -34,33 +32,11 @@ func initialiseStake(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the StakeCoins function func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteStake: config: %+v", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteStake: Address: ", address) - - logger.SetLoggerParameters(client, address) - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - - balance, err := razorUtils.FetchBalance(client, address) - utils.CheckError("Error in fetching razor balance for account: "+address, err) + balance, err := razorUtils.FetchBalance(rpcParameters, account.Address) + utils.CheckError("Error in fetching razor balance for account: "+account.Address, err) log.Debug("Getting amount in wei...") valueInWei, err := cmdUtils.AssignAmountInWei(flagSet) utils.CheckError("Error in getting amount: ", err) @@ -70,13 +46,13 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) { razorUtils.CheckAmountAndBalance(valueInWei, balance) log.Debug("Checking whether sFUEL balance is not 0...") - razorUtils.CheckEthBalanceIsZero(context.Background(), client, address) + razorUtils.CheckEthBalanceIsZero(rpcParameters, account.Address) - minSafeRazor, err := razorUtils.GetMinSafeRazor(context.Background(), client) + minSafeRazor, err := razorUtils.GetMinSafeRazor(rpcParameters) utils.CheckError("Error in getting minimum safe razor amount: ", err) log.Debug("ExecuteStake: Minimum razor that you can stake for first time: ", minSafeRazor) - stakerId, err := razorUtils.GetStakerId(context.Background(), client, address) + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) utils.CheckError("Error in getting stakerId: ", err) log.Debug("ExecuteStake: Staker Id: ", stakerId) @@ -85,7 +61,7 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) { } if stakerId != 0 { - staker, err := razorUtils.GetStaker(context.Background(), client, stakerId) + staker, err := razorUtils.GetStaker(rpcParameters, stakerId) utils.CheckError("Error in getting staker: ", err) if staker.IsSlashed { @@ -94,7 +70,6 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) { } txnArgs := types.TransactionOptions{ - Client: client, Amount: valueInWei, ChainId: core.ChainId, Config: config, @@ -102,25 +77,25 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) { } log.Debug("ExecuteStake: Calling Approve() for amount: ", txnArgs.Amount) - approveTxnHash, err := cmdUtils.Approve(txnArgs) + approveTxnHash, err := cmdUtils.Approve(rpcParameters, txnArgs) utils.CheckError("Approve error: ", err) if approveTxnHash != core.NilHash { - err = razorUtils.WaitForBlockCompletion(txnArgs.Client, approveTxnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, approveTxnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for approve: ", err) } log.Debug("ExecuteStake: Calling StakeCoins() for amount: ", txnArgs.Amount) - stakeTxnHash, err := cmdUtils.StakeCoins(txnArgs) + stakeTxnHash, err := cmdUtils.StakeCoins(rpcParameters, txnArgs) utils.CheckError("Stake error: ", err) - err = razorUtils.WaitForBlockCompletion(txnArgs.Client, stakeTxnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, stakeTxnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for stake: ", err) } //This function allows the user to stake razors in the razor network and returns the hash -func (*UtilsStruct) StakeCoins(txnArgs types.TransactionOptions) (common.Hash, error) { - epoch, err := razorUtils.GetEpoch(context.Background(), txnArgs.Client) +func (*UtilsStruct) StakeCoins(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) { + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { return core.NilHash, err } @@ -130,9 +105,15 @@ func (*UtilsStruct) StakeCoins(txnArgs types.TransactionOptions) (common.Hash, e txnArgs.MethodName = "stake" txnArgs.Parameters = []interface{}{epoch, txnArgs.Amount} txnArgs.ABI = bindings.StakeManagerMetaData.ABI - txnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing Stake transaction with epoch = %d, amount = %d", epoch, txnArgs.Amount) - txn, err := stakeManagerUtils.Stake(txnArgs.Client, txnOpts, epoch, txnArgs.Amount) + txn, err := stakeManagerUtils.Stake(client, txnOpts, epoch, txnArgs.Amount) if err != nil { return core.NilHash, err } diff --git a/cmd/approve.go b/cmd/approve.go index 04872dfb..a74a3f4a 100644 --- a/cmd/approve.go +++ b/cmd/approve.go @@ -2,17 +2,16 @@ package cmd import ( - "context" "github.com/ethereum/go-ethereum/common" + "razor/RPC" "razor/core" "razor/core/types" "razor/pkg/bindings" ) //This function approves the transaction if the user has sufficient balance otherwise it fails the transaction -func (*UtilsStruct) Approve(txnArgs types.TransactionOptions) (common.Hash, error) { - opts := razorUtils.GetOptions() - allowance, err := tokenManagerUtils.Allowance(txnArgs.Client, &opts, common.HexToAddress(txnArgs.Account.Address), common.HexToAddress(core.StakeManagerAddress)) +func (*UtilsStruct) Approve(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) { + allowance, err := razorUtils.Allowance(rpcParameters, common.HexToAddress(txnArgs.Account.Address), common.HexToAddress(core.StakeManagerAddress)) if err != nil { return core.NilHash, err } @@ -26,9 +25,15 @@ func (*UtilsStruct) Approve(txnArgs types.TransactionOptions) (common.Hash, erro txnArgs.MethodName = "approve" txnArgs.ABI = bindings.RAZORMetaData.ABI txnArgs.Parameters = []interface{}{common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount} - txnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debug("Executing Approve transaction with amount: ", txnArgs.Amount) - txn, err := tokenManagerUtils.Approve(txnArgs.Client, txnOpts, common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount) + txn, err := tokenManagerUtils.Approve(client, txnOpts, common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount) if err != nil { return core.NilHash, err } diff --git a/cmd/claimBounty.go b/cmd/claimBounty.go index d7f8bde8..9880b145 100644 --- a/cmd/claimBounty.go +++ b/cmd/claimBounty.go @@ -2,20 +2,17 @@ package cmd import ( - "context" "errors" "math/big" "os" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/path" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -37,31 +34,8 @@ func initialiseClaimBounty(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the ClaimBounty function func (*UtilsStruct) ExecuteClaimBounty(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteClaimBounty: config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteClaimBounty: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) if razorUtils.IsFlagPassed("bountyId") { bountyId, err := flagSetUtils.GetUint32BountyId(flagSet) @@ -73,23 +47,23 @@ func (*UtilsStruct) ExecuteClaimBounty(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.ClaimBounty(config, client, redeemBountyInput) + txn, err := cmdUtils.ClaimBounty(rpcParameters, config, redeemBountyInput) utils.CheckError("ClaimBounty error: ", err) if txn != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for claimBounty: ", err) } } else { log.Debug("ExecuteClaimBounty: Calling HandleClaimBounty()") - err := cmdUtils.HandleClaimBounty(client, config, account) + err := cmdUtils.HandleClaimBounty(rpcParameters, config, account) utils.CheckError("HandleClaimBounty error: ", err) } } //This function handles claimBounty by picking bountyid's from disputeData file and if there is any error it returns the error -func (*UtilsStruct) HandleClaimBounty(client *ethclient.Client, config types.Configurations, account types.Account) error { +func (*UtilsStruct) HandleClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account) error { disputeFilePath, err := pathUtils.GetDisputeDataFileName(account.Address) if err != nil { return err @@ -119,12 +93,12 @@ func (*UtilsStruct) HandleClaimBounty(client *ethclient.Client, config types.Con Account: account, } log.Debugf("HandleClaimBounty: Calling ClaimBounty() with arguments redeemBountyInput: %+v", redeemBountyInput) - claimBountyTxn, err := cmdUtils.ClaimBounty(config, client, redeemBountyInput) + claimBountyTxn, err := cmdUtils.ClaimBounty(rpcParameters, config, redeemBountyInput) if err != nil { return err } if claimBountyTxn != core.NilHash { - claimBountyErr := razorUtils.WaitForBlockCompletion(client, claimBountyTxn.Hex()) + claimBountyErr := razorUtils.WaitForBlockCompletion(rpcParameters, claimBountyTxn.Hex()) if claimBountyErr == nil { if len(disputeData.BountyIdQueue) > 1 { //Removing the bountyId from the queue as the bounty is being claimed @@ -145,9 +119,8 @@ func (*UtilsStruct) HandleClaimBounty(client *ethclient.Client, config types.Con } //This function allows the users who are bountyHunter to redeem their bounty in razor network -func (*UtilsStruct) ClaimBounty(config types.Configurations, client *ethclient.Client, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) { +func (*UtilsStruct) ClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) { txnArgs := types.TransactionOptions{ - Client: client, Account: redeemBountyInput.Account, ChainId: core.ChainId, Config: config, @@ -156,15 +129,14 @@ func (*UtilsStruct) ClaimBounty(config types.Configurations, client *ethclient.C MethodName: "redeemBounty", Parameters: []interface{}{redeemBountyInput.BountyId}, } - epoch, err := razorUtils.GetEpoch(context.Background(), txnArgs.Client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { log.Error("Error in getting epoch: ", err) return core.NilHash, err } log.Debug("ClaimBounty: Epoch: ", epoch) - callOpts := razorUtils.GetOptions() - bountyLock, err := stakeManagerUtils.GetBountyLock(txnArgs.Client, &callOpts, redeemBountyInput.BountyId) + bountyLock, err := razorUtils.GetBountyLock(rpcParameters, redeemBountyInput.BountyId) if err != nil { log.Error("Error in getting bounty lock: ", err) return core.NilHash, err @@ -191,10 +163,14 @@ func (*UtilsStruct) ClaimBounty(config types.Configurations, client *ethclient.C return core.NilHash, nil } - txnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } log.Debug("Executing RedeemBounty transaction with bountyId: ", redeemBountyInput.BountyId) - tx, err := stakeManagerUtils.RedeemBounty(txnArgs.Client, txnOpts, redeemBountyInput.BountyId) + tx, err := stakeManagerUtils.RedeemBounty(client, txnOpts, redeemBountyInput.BountyId) if err != nil { return core.NilHash, err } diff --git a/cmd/claimCommission.go b/cmd/claimCommission.go index e16aafdb..90e28122 100644 --- a/cmd/claimCommission.go +++ b/cmd/claimCommission.go @@ -2,12 +2,9 @@ package cmd import ( - "context" "math/big" - "razor/accounts" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" @@ -29,44 +26,19 @@ Example: //This function allows the staker to claim the rewards earned from delegator's pool share as commission func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ClaimCommission: Config: %+v", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ClaimCommission: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - - stakerId, err := razorUtils.GetStakerId(context.Background(), client, address) + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) utils.CheckError("Error in getting stakerId: ", err) log.Debug("ClaimCommission: Staker Id: ", stakerId) - callOpts := razorUtils.GetOptions() - stakerInfo, err := stakeManagerUtils.StakerInfo(client, &callOpts, stakerId) + stakerInfo, err := razorUtils.StakerInfo(rpcParameters, stakerId) utils.CheckError("Error in getting stakerInfo: ", err) log.Debugf("ClaimCommission: Staker Info: %+v", stakerInfo) if stakerInfo.StakerReward.Cmp(big.NewInt(0)) > 0 { - txnOpts := razorUtils.GetTxnOpts(context.Background(), types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -78,13 +50,16 @@ func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) { log.Info("Claiming commission...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + utils.CheckError("Error in getting best RPC client: ", err) + log.Debug("Executing ClaimStakeReward transaction...") txn, err := stakeManagerUtils.ClaimStakerReward(client, txnOpts) utils.CheckError("Error in claiming stake reward: ", err) txnHash := transactionUtils.Hash(txn) log.Info("Txn Hash: ", txnHash.Hex()) - err = razorUtils.WaitForBlockCompletion(client, txnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for claimCommission: ", err) } else { log.Error("no commission to claim") diff --git a/cmd/cmd-utils.go b/cmd/cmd-utils.go index d034b9ba..9514c007 100644 --- a/cmd/cmd-utils.go +++ b/cmd/cmd-utils.go @@ -5,18 +5,20 @@ import ( "context" "errors" "math/big" + "razor/RPC" + "razor/accounts" + "razor/core/types" + "razor/logger" "razor/utils" "strconv" "time" "github.com/spf13/pflag" - - "github.com/ethereum/go-ethereum/ethclient" ) //This function takes client as a parameter and returns the epoch and state -func (*UtilsStruct) GetEpochAndState(ctx context.Context, client *ethclient.Client) (uint32, int64, error) { - epoch, err := razorUtils.GetEpoch(ctx, client) +func (*UtilsStruct) GetEpochAndState(rpcParameter RPC.RPCParameters) (uint32, int64, error) { + epoch, err := razorUtils.GetEpoch(rpcParameter) if err != nil { return 0, 0, err } @@ -24,16 +26,16 @@ func (*UtilsStruct) GetEpochAndState(ctx context.Context, client *ethclient.Clie if err != nil { return 0, 0, err } - err = ValidateBufferPercentLimit(ctx, client, bufferPercent) + err = ValidateBufferPercentLimit(rpcParameter, bufferPercent) if err != nil { return 0, 0, err } - latestHeader, err := clientUtils.GetLatestBlockWithRetry(ctx, client) + latestHeader, err := clientUtils.GetLatestBlockWithRetry(rpcParameter) if err != nil { log.Error("Error in fetching block: ", err) return 0, 0, err } - stateBuffer, err := razorUtils.GetStateBuffer(ctx, client) + stateBuffer, err := razorUtils.GetStateBuffer(rpcParameter) if err != nil { log.Error("Error in getting state buffer: ", err) return 0, 0, err @@ -48,10 +50,10 @@ func (*UtilsStruct) GetEpochAndState(ctx context.Context, client *ethclient.Clie } //This function waits for the appropriate states which are required -func (*UtilsStruct) WaitForAppropriateState(ctx context.Context, client *ethclient.Client, action string, states ...int) (uint32, error) { +func (*UtilsStruct) WaitForAppropriateState(rpcParameter RPC.RPCParameters, action string, states ...int) (uint32, error) { statesAllowed := GetFormattedStateNames(states) for { - epoch, state, err := cmdUtils.GetEpochAndState(ctx, client) + epoch, state, err := cmdUtils.GetEpochAndState(rpcParameter) if err != nil { log.Error("Error in fetching epoch and state: ", err) return epoch, err @@ -66,9 +68,9 @@ func (*UtilsStruct) WaitForAppropriateState(ctx context.Context, client *ethclie } //This function wait if the state is commit state -func (*UtilsStruct) WaitIfCommitState(ctx context.Context, client *ethclient.Client, action string) (uint32, error) { +func (*UtilsStruct) WaitIfCommitState(rpcParameter RPC.RPCParameters, action string) (uint32, error) { for { - epoch, state, err := cmdUtils.GetEpochAndState(ctx, client) + epoch, state, err := cmdUtils.GetEpochAndState(rpcParameter) if err != nil { log.Error("Error in fetching epoch and state: ", err) return epoch, err @@ -124,3 +126,60 @@ func GetFormattedStateNames(states []int) string { } return statesAllowed } + +func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations, RPC.RPCParameters, types.Account, error) { + config, err := cmdUtils.GetConfigData() + if err != nil { + log.Error("Error in getting config: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + log.Debugf("Config: %+v", config) + + address, err := flagSetUtils.GetStringAddress(flagSet) + if err != nil { + log.Error("Error in getting address: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + log.Debug("Address: %v", address) + + log.Debug("Checking to assign log file...") + fileUtils.AssignLogFile(flagSet, config) + + log.Debug("Getting password...") + password := razorUtils.AssignPassword(flagSet) + + accountManager, err := razorUtils.AccountManagerForKeystore() + if err != nil { + log.Error("Error in getting accounts manager for keystore: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + + account := accounts.InitAccountStruct(address, password, accountManager) + + err = razorUtils.CheckPassword(account) + if err != nil { + log.Error("Error in fetching private key from given password: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + + rpcManager, err := RPC.InitializeRPCManager(config.Provider) + if err != nil { + log.Error("Error in initializing RPC Manager: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + + rpcParameters := RPC.RPCParameters{ + RPCManager: rpcManager, + Ctx: context.Background(), + } + + client, err := rpcManager.GetBestRPCClient() + if err != nil { + log.Error("Error in getting best RPC client: ", err) + return types.Configurations{}, RPC.RPCParameters{}, types.Account{}, err + } + + logger.SetLoggerParameters(client, address) + + return config, rpcParameters, account, nil +} diff --git a/cmd/collectionList.go b/cmd/collectionList.go index f6700f86..1b4ab7f4 100644 --- a/cmd/collectionList.go +++ b/cmd/collectionList.go @@ -5,12 +5,12 @@ import ( "context" "encoding/json" "os" + "razor/RPC" "razor/logger" "razor/utils" "strconv" "strings" - "github.com/ethereum/go-ethereum/ethclient" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -40,14 +40,22 @@ func (*UtilsStruct) ExecuteCollectionList(flagSet *pflag.FlagSet) { client := razorUtils.ConnectToClient(config.Provider) logger.SetLoggerParameters(client, "") + rpcManager, err := RPC.InitializeRPCManager(config.Provider) + utils.CheckError("Error in initializing RPC Manager: ", err) + + rpcParameters := RPC.RPCParameters{ + RPCManager: rpcManager, + Ctx: context.Background(), + } + log.Debug("Calling GetCollectionList()") - err = cmdUtils.GetCollectionList(client) + err = cmdUtils.GetCollectionList(rpcParameters) utils.CheckError("Error in getting collection list: ", err) } //This function provides the list of all collections with their name, power, ID etc. -func (*UtilsStruct) GetCollectionList(client *ethclient.Client) error { - collections, err := razorUtils.GetAllCollections(context.Background(), client) +func (*UtilsStruct) GetCollectionList(rpcParameters RPC.RPCParameters) error { + collections, err := razorUtils.GetAllCollections(rpcParameters) log.Debugf("GetCollectionList: Collections: %+v", collections) if err != nil { diff --git a/cmd/commit.go b/cmd/commit.go index 6927c992..f2bc354e 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -2,11 +2,11 @@ package cmd import ( - "context" "encoding/hex" "errors" Types "github.com/ethereum/go-ethereum/core/types" "math/big" + "razor/RPC" "razor/core" "razor/core/types" "razor/pkg/bindings" @@ -14,7 +14,6 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" solsha3 "github.com/miguelmota/go-solidity-sha3" ) @@ -22,28 +21,28 @@ import ( GetSalt calculates the salt on the basis of previous epoch and the medians of the previous epoch. If the previous epoch doesn't contain any medians, then the value is fetched from the smart contract. */ -func (*UtilsStruct) GetSalt(ctx context.Context, client *ethclient.Client, epoch uint32) ([32]byte, error) { +func (*UtilsStruct) GetSalt(rpcParameters RPC.RPCParameters, epoch uint32) ([32]byte, error) { previousEpoch := epoch - 1 log.Debug("GetSalt: Previous epoch: ", previousEpoch) - numProposedBlock, err := razorUtils.GetNumberOfProposedBlocks(ctx, client, previousEpoch) + numProposedBlock, err := razorUtils.GetNumberOfProposedBlocks(rpcParameters, previousEpoch) if err != nil { return [32]byte{}, err } log.Debug("GetSalt: Number of proposed blocks: ", numProposedBlock) - blockIndexToBeConfirmed, err := razorUtils.GetBlockIndexToBeConfirmed(ctx, client) + blockIndexToBeConfirmed, err := razorUtils.GetBlockIndexToBeConfirmed(rpcParameters) if err != nil { return [32]byte{}, err } log.Debug("GetSalt: Block Index to be confirmed: ", blockIndexToBeConfirmed) if numProposedBlock == 0 || (numProposedBlock > 0 && blockIndexToBeConfirmed < 0) { - return utils.VoteManagerInterface.GetSaltFromBlockchain(client) + return razorUtils.GetSaltFromBlockchain(rpcParameters) } - blockId, err := razorUtils.GetSortedProposedBlockId(ctx, client, previousEpoch, big.NewInt(int64(blockIndexToBeConfirmed))) + blockId, err := razorUtils.GetSortedProposedBlockId(rpcParameters, previousEpoch, big.NewInt(int64(blockIndexToBeConfirmed))) if err != nil { return [32]byte{}, errors.New("Error in getting blockId: " + err.Error()) } log.Debug("GetSalt: Block Id: ", blockId) - previousBlock, err := razorUtils.GetProposedBlock(ctx, client, previousEpoch, blockId) + previousBlock, err := razorUtils.GetProposedBlock(rpcParameters, previousEpoch, blockId) if err != nil { return [32]byte{}, errors.New("Error in getting previous block: " + err.Error()) } @@ -56,14 +55,14 @@ func (*UtilsStruct) GetSalt(ctx context.Context, client *ethclient.Client, epoch HandleCommitState fetches the collections assigned to the staker and creates the leaves required for the merkle tree generation. Values for only the collections assigned to the staker is fetched for others, 0 is added to the leaves of tree. */ -func (*UtilsStruct) HandleCommitState(ctx context.Context, client *ethclient.Client, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) { - numActiveCollections, err := razorUtils.GetNumActiveCollections(ctx, client) +func (*UtilsStruct) HandleCommitState(rpcParameters RPC.RPCParameters, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) { + numActiveCollections, err := razorUtils.GetNumActiveCollections(rpcParameters) if err != nil { return types.CommitData{}, err } log.Debug("HandleCommitState: Number of active collections: ", numActiveCollections) log.Debugf("HandleCommitState: Calling GetAssignedCollections() with arguments number of active collections = %d", numActiveCollections) - assignedCollections, seqAllottedCollections, err := razorUtils.GetAssignedCollections(ctx, client, numActiveCollections, seed) + assignedCollections, seqAllottedCollections, err := razorUtils.GetAssignedCollections(rpcParameters, numActiveCollections, seed) if err != nil { return types.CommitData{}, err } @@ -89,13 +88,13 @@ func (*UtilsStruct) HandleCommitState(ctx context.Context, client *ethclient.Cli log.Debugf("HandleCommitState: Is the collection at iterating index %v assigned: %v ", i, assignedCollections[i]) if assignedCollections[i] { - collectionId, err := razorUtils.GetCollectionIdFromIndex(ctx, client, uint16(i)) + collectionId, err := razorUtils.GetCollectionIdFromIndex(rpcParameters, uint16(i)) if err != nil { log.Error("Error in getting collection ID: ", err) errChan <- err return } - collectionData, err := razorUtils.GetAggregatedDataOfCollection(ctx, client, collectionId, epoch, commitParams) + collectionData, err := razorUtils.GetAggregatedDataOfCollection(rpcParameters, collectionId, epoch, commitParams) if err != nil { log.Error("Error in getting aggregated data of collection: ", err) errChan <- err @@ -146,14 +145,13 @@ func (*UtilsStruct) HandleCommitState(ctx context.Context, client *ethclient.Cli /* Commit finally commits the data to the smart contract. It calculates the commitment to send using the merkle tree root and the seed. */ -func (*UtilsStruct) Commit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitmentToSend [32]byte) (common.Hash, error) { +func (*UtilsStruct) Commit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitmentToSend [32]byte) (common.Hash, error) { if state, err := razorUtils.GetBufferedState(latestHeader, stateBuffer, config.BufferPercent); err != nil || state != 0 { log.Error("Not commit state") return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.VoteManagerAddress, @@ -164,6 +162,12 @@ func (*UtilsStruct) Commit(ctx context.Context, client *ethclient.Client, config }) log.Info("Commitment sent...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + log.Error(err) + return core.NilHash, err + } + log.Debugf("Executing Commit transaction with epoch = %d, commitmentToSend = %v", epoch, commitmentToSend) txn, err := voteManagerUtils.Commit(client, txnOpts, epoch, commitmentToSend) if err != nil { @@ -174,14 +178,14 @@ func (*UtilsStruct) Commit(ctx context.Context, client *ethclient.Client, config return txnHash, nil } -func CalculateSeed(ctx context.Context, client *ethclient.Client, account types.Account, keystorePath string, epoch uint32) ([]byte, error) { +func CalculateSeed(rpcParameters RPC.RPCParameters, account types.Account, keystorePath string, epoch uint32) ([]byte, error) { log.Debugf("CalculateSeed: Calling CalculateSecret() with arguments epoch = %d, keystorePath = %s, chainId = %s", epoch, keystorePath, core.ChainId) _, secret, err := cmdUtils.CalculateSecret(account, epoch, keystorePath, core.ChainId) if err != nil { return nil, err } log.Debugf("CalculateSeed: Getting Salt for current epoch %d...", epoch) - salt, err := cmdUtils.GetSalt(ctx, client, epoch) + salt, err := cmdUtils.GetSalt(rpcParameters, epoch) if err != nil { log.Error("Error in getting salt: ", err) return nil, err @@ -209,8 +213,8 @@ func CalculateCommitment(seed []byte, values []*big.Int) ([32]byte, error) { return commitmentToSend, nil } -func VerifyCommitment(ctx context.Context, client *ethclient.Client, account types.Account, commitmentFetched [32]byte) (bool, error) { - commitmentStruct, err := razorUtils.GetCommitment(ctx, client, account.Address) +func VerifyCommitment(rpcParameters RPC.RPCParameters, account types.Account, commitmentFetched [32]byte) (bool, error) { + commitmentStruct, err := razorUtils.GetCommitment(rpcParameters, account.Address) if err != nil { log.Error("Error in getting commitments: ", err) return false, err @@ -225,7 +229,7 @@ func VerifyCommitment(ctx context.Context, client *ethclient.Client, account typ return false, nil } -func GetCommittedDataForEpoch(ctx context.Context, client *ethclient.Client, account types.Account, epoch uint32, rogueData types.Rogue) (types.CommitFileData, error) { +func GetCommittedDataForEpoch(rpcParameters RPC.RPCParameters, account types.Account, epoch uint32, rogueData types.Rogue) (types.CommitFileData, error) { // Attempt to fetch global commit data from memory if epoch matches if globalCommitDataStruct.Epoch == epoch { log.Debugf("Epoch in global commit data is equal to current epoch %v. Fetching commit data from memory!", epoch) @@ -260,7 +264,7 @@ func GetCommittedDataForEpoch(ctx context.Context, client *ethclient.Client, acc // Verify the final selected commit data log.Debugf("Verifying commit data for epoch %v...", epoch) - isValid, err := VerifyCommitment(ctx, client, account, globalCommitDataStruct.Commitment) + isValid, err := VerifyCommitment(rpcParameters, account, globalCommitDataStruct.Commitment) if err != nil { return types.CommitFileData{}, err } diff --git a/cmd/config-utils.go b/cmd/config-utils.go index e9d9bf6b..634301ab 100644 --- a/cmd/config-utils.go +++ b/cmd/config-utils.go @@ -2,15 +2,14 @@ package cmd import ( - "context" "errors" + "razor/RPC" "razor/client" "razor/core" "razor/core/types" "razor/utils" "strings" - "github.com/ethereum/go-ethereum/ethclient" "github.com/sirupsen/logrus" "github.com/spf13/viper" @@ -406,8 +405,8 @@ func setLogLevel(config types.Configurations) { } } -func ValidateBufferPercentLimit(ctx context.Context, client *ethclient.Client, bufferPercent int32) error { - stateBuffer, err := razorUtils.GetStateBuffer(ctx, client) +func ValidateBufferPercentLimit(rpcParameters RPC.RPCParameters, bufferPercent int32) error { + stateBuffer, err := razorUtils.GetStateBuffer(rpcParameters) if err != nil { return err } diff --git a/cmd/confirm.go b/cmd/confirm.go index 620c6740..e4cc7d9e 100644 --- a/cmd/confirm.go +++ b/cmd/confirm.go @@ -2,7 +2,7 @@ package cmd import ( - "context" + "razor/RPC" "razor/core" "razor/core/types" @@ -10,15 +10,15 @@ import ( ) //This function allows the user to claim the block reward and returns the hash -func (*UtilsStruct) ClaimBlockReward(ctx context.Context, options types.TransactionOptions) (common.Hash, error) { - epoch, err := razorUtils.GetEpoch(ctx, options.Client) +func (*UtilsStruct) ClaimBlockReward(rpcParameters RPC.RPCParameters, options types.TransactionOptions) (common.Hash, error) { + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { log.Error("Error in getting epoch: ", err) return core.NilHash, err } log.Debug("ClaimBlockReward: Epoch: ", epoch) - sortedProposedBlockIds, err := razorUtils.GetSortedProposedBlockIds(ctx, options.Client, epoch) + sortedProposedBlockIds, err := razorUtils.GetSortedProposedBlockIds(rpcParameters, epoch) if err != nil { log.Error("Error in getting sortedProposedBlockIds: ", err) return core.NilHash, err @@ -30,14 +30,14 @@ func (*UtilsStruct) ClaimBlockReward(ctx context.Context, options types.Transact return core.NilHash, nil } - stakerID, err := razorUtils.GetStakerId(ctx, options.Client, options.Account.Address) + stakerID, err := razorUtils.GetStakerId(rpcParameters, options.Account.Address) if err != nil { log.Error("Error in getting stakerId: ", err) return core.NilHash, err } log.Debug("ClaimBlockReward: Staker Id: ", stakerID) - selectedProposedBlock, err := razorUtils.GetProposedBlock(ctx, options.Client, epoch, sortedProposedBlockIds[0]) + selectedProposedBlock, err := razorUtils.GetProposedBlock(rpcParameters, epoch, sortedProposedBlockIds[0]) if err != nil { log.Error("Error in getting selectedProposedBlock: ", err) return core.NilHash, err @@ -46,9 +46,15 @@ func (*UtilsStruct) ClaimBlockReward(ctx context.Context, options types.Transact if selectedProposedBlock.ProposerId == stakerID { log.Info("Claiming block reward...") - txnOpts := razorUtils.GetTxnOpts(ctx, options) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, options) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debug("Executing ClaimBlockReward transaction...") - txn, err := blockManagerUtils.ClaimBlockReward(options.Client, txnOpts) + txn, err := blockManagerUtils.ClaimBlockReward(client, txnOpts) if err != nil { log.Error("Error in claiming block reward: ", err) return core.NilHash, err diff --git a/cmd/createCollection.go b/cmd/createCollection.go index ecbcdffd..e690e639 100644 --- a/cmd/createCollection.go +++ b/cmd/createCollection.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -37,29 +34,8 @@ func initialiseCreateCollection(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the CreateCollection function func (*UtilsStruct) ExecuteCreateCollection(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteCreateCollection: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) name, err := flagSetUtils.GetStringName(flagSet) utils.CheckError("Error in getting name: ", err) @@ -85,23 +61,22 @@ func (*UtilsStruct) ExecuteCreateCollection(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.CreateCollection(client, config, collectionInput) + txn, err := cmdUtils.CreateCollection(rpcParameters, config, collectionInput) utils.CheckError("CreateCollection error: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for createCollection: ", err) } //This function allows the admin to create collction if existing jobs are present -func (*UtilsStruct) CreateCollection(client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) { +func (*UtilsStruct) CreateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) { jobIds := utils.ConvertUintArrayToUint16Array(collectionInput.JobIds) log.Debug("CreateCollection: Uint16 jobIds: ", jobIds) - _, err := cmdUtils.WaitForAppropriateState(context.Background(), client, "create collection", 4) + _, err := cmdUtils.WaitForAppropriateState(rpcParameters, "create collection", 4) if err != nil { log.Error("Error in fetching state") return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(context.Background(), types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -110,6 +85,12 @@ func (*UtilsStruct) CreateCollection(client *ethclient.Client, config types.Conf ABI: bindings.CollectionManagerMetaData.ABI, Account: collectionInput.Account, }) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing CreateCollection transaction with tolerance: %d, power = %d , aggregation = %d, jobIds = %v, name = %s", collectionInput.Tolerance, collectionInput.Power, collectionInput.Aggregation, jobIds, collectionInput.Name) txn, err := assetManagerUtils.CreateCollection(client, txnOpts, collectionInput.Tolerance, collectionInput.Power, collectionInput.Aggregation, jobIds, collectionInput.Name) if err != nil { diff --git a/cmd/createJob.go b/cmd/createJob.go index 1d7959a5..d0e9e5fd 100644 --- a/cmd/createJob.go +++ b/cmd/createJob.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/pflag" "github.com/spf13/cobra" @@ -38,29 +35,8 @@ func initialiseCreateJob(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the CreateJob function func (*UtilsStruct) ExecuteCreateJob(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteCreateJob: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) name, err := flagSetUtils.GetStringName(flagSet) utils.CheckError("Error in getting name: ", err) @@ -90,16 +66,15 @@ func (*UtilsStruct) ExecuteCreateJob(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.CreateJob(client, config, jobInput) + txn, err := cmdUtils.CreateJob(rpcParameters, config, jobInput) utils.CheckError("CreateJob error: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for createJob: ", err) } //This function allows the admin to create the job -func (*UtilsStruct) CreateJob(client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) { +func (*UtilsStruct) CreateJob(rpcParameters RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) { txnArgs := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -109,10 +84,16 @@ func (*UtilsStruct) CreateJob(client *ethclient.Client, config types.Configurati Account: jobInput.Account, } - txnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Info("Creating Job...") + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("CreateJob: Executing CreateJob transaction with weight = %d, power = %d, selector type = %d, name = %s, selector = %s, URl = %s", jobInput.Weight, jobInput.Power, jobInput.SelectorType, jobInput.Name, jobInput.Selector, jobInput.Url) - txn, err := assetManagerUtils.CreateJob(txnArgs.Client, txnOpts, jobInput.Weight, jobInput.Power, jobInput.SelectorType, jobInput.Name, jobInput.Selector, jobInput.Url) + txn, err := assetManagerUtils.CreateJob(client, txnOpts, jobInput.Weight, jobInput.Power, jobInput.SelectorType, jobInput.Name, jobInput.Selector, jobInput.Url) if err != nil { return core.NilHash, err } diff --git a/cmd/delegate.go b/cmd/delegate.go index 8ebbaff6..8e8b5e8f 100644 --- a/cmd/delegate.go +++ b/cmd/delegate.go @@ -2,11 +2,9 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" @@ -34,36 +32,14 @@ func initialiseDelegate(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the Delegate function func (*UtilsStruct) ExecuteDelegate(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteDelegate: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteDelegate: Address: ", address) - - logger.SetLoggerParameters(client, address) - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) stakerId, err := flagSetUtils.GetUint32StakerId(flagSet) utils.CheckError("Error in getting stakerId: ", err) log.Debug("ExecuteDelegate: Staker Id: ", stakerId) - balance, err := razorUtils.FetchBalance(client, address) - utils.CheckError("Error in fetching razor balance for account "+address+": ", err) + balance, err := razorUtils.FetchBalance(rpcParameters, account.Address) + utils.CheckError("Error in fetching razor balance for account "+account.Address+": ", err) log.Debug("ExecuteDelegate: Balance: ", balance) log.Debug("Getting amount in wei...") @@ -74,42 +50,47 @@ func (*UtilsStruct) ExecuteDelegate(flagSet *pflag.FlagSet) { razorUtils.CheckAmountAndBalance(valueInWei, balance) log.Debug("Checking whether sFUEL balance is not 0...") - razorUtils.CheckEthBalanceIsZero(context.Background(), client, address) + razorUtils.CheckEthBalanceIsZero(rpcParameters, account.Address) txnArgs := types.TransactionOptions{ - Client: client, Amount: valueInWei, ChainId: core.ChainId, Config: config, Account: account, } - approveTxnHash, err := cmdUtils.Approve(txnArgs) + approveTxnHash, err := cmdUtils.Approve(rpcParameters, txnArgs) utils.CheckError("Approve error: ", err) if approveTxnHash != core.NilHash { - err = razorUtils.WaitForBlockCompletion(txnArgs.Client, approveTxnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, approveTxnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for approve: ", err) } log.Debug("ExecuteDelegate:Calling Delegate() with stakerId: ", stakerId) - delegateTxnHash, err := cmdUtils.Delegate(txnArgs, stakerId) + delegateTxnHash, err := cmdUtils.Delegate(rpcParameters, txnArgs, stakerId) utils.CheckError("Delegate error: ", err) - err = razorUtils.WaitForBlockCompletion(client, delegateTxnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, delegateTxnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for delegate: ", err) } //This function allows the delegator to stake coins without setting up a node -func (*UtilsStruct) Delegate(txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) { +func (*UtilsStruct) Delegate(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) { log.Infof("Delegating %g razors to Staker %d", utils.GetAmountInDecimal(txnArgs.Amount), stakerId) txnArgs.ContractAddress = core.StakeManagerAddress txnArgs.MethodName = "delegate" txnArgs.ABI = bindings.StakeManagerMetaData.ABI txnArgs.Parameters = []interface{}{stakerId, txnArgs.Amount} - delegationTxnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) + delegationTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Info("Sending Delegate transaction...") + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing Delegate transaction with stakerId = %d, amount = %s", stakerId, txnArgs.Amount) - txn, err := stakeManagerUtils.Delegate(txnArgs.Client, delegationTxnOpts, stakerId, txnArgs.Amount) + txn, err := stakeManagerUtils.Delegate(client, delegationTxnOpts, stakerId, txnArgs.Amount) if err != nil { return core.NilHash, err } diff --git a/cmd/dispute.go b/cmd/dispute.go index 4f18c794..147bb94b 100644 --- a/cmd/dispute.go +++ b/cmd/dispute.go @@ -2,10 +2,10 @@ package cmd import ( - "context" "errors" "math/big" "os" + "razor/RPC" "razor/core" "razor/core/types" "razor/path" @@ -17,7 +17,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" Types "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" solsha3 "github.com/miguelmota/go-solidity-sha3" ) @@ -28,23 +27,23 @@ var ( //blockId is id of the block //This function handles the dispute and if there is any error it returns the error -func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { +func (*UtilsStruct) HandleDispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { - sortedProposedBlockIds, err := razorUtils.GetSortedProposedBlockIds(ctx, client, epoch) + sortedProposedBlockIds, err := razorUtils.GetSortedProposedBlockIds(rpcParameters, epoch) if err != nil { log.Error("Error in fetching sorted proposed block id: ", err) return err } log.Debug("HandleDispute: SortedProposedBlockIds: ", sortedProposedBlockIds) - biggestStake, biggestStakerId, err := cmdUtils.GetBiggestStakeAndId(ctx, client, epoch) + biggestStake, biggestStakerId, err := cmdUtils.GetBiggestStakeAndId(rpcParameters, epoch) if err != nil { return err } log.Debugf("HandleDispute: Biggest stake: %s, Biggest staker Id: %d", biggestStake, biggestStakerId) log.Debugf("HandleDispute: Calling GetLocalMediansData() with arguments epoch = %d, blockNumber = %d, rogueData = %+v", epoch, blockNumber, rogueData) - locallyCalculatedData, err := cmdUtils.GetLocalMediansData(ctx, client, account, epoch, blockNumber, rogueData) + locallyCalculatedData, err := cmdUtils.GetLocalMediansData(rpcParameters, account, epoch, blockNumber, rogueData) if err != nil { return err } @@ -58,7 +57,6 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, randomSortedProposedBlockIds := utils.Shuffle(sortedProposedBlockIds) //shuffles the sortedProposedBlockIds array transactionOptions := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, Account: account, @@ -67,7 +65,7 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, log.Debug("Iterating over random sorted proposed blocks to check dispute...") for _, blockId := range randomSortedProposedBlockIds { - proposedBlock, err := razorUtils.GetProposedBlock(ctx, client, epoch, blockId) + proposedBlock, err := razorUtils.GetProposedBlock(rpcParameters, epoch, blockId) if err != nil { log.Error(err) continue @@ -87,12 +85,18 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, log.Debug("Biggest Stake in proposed block: ", proposedBlock.BiggestStake) log.Warn("PROPOSED BIGGEST STAKE DOES NOT MATCH WITH ACTUAL BIGGEST STAKE") log.Info("Disputing BiggestStakeProposed...") - txnOpts := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, Account: account, }) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + log.Error(err) + continue + } + log.Debugf("Executing DisputeBiggestStakeProposed transaction with arguments epoch = %d, blockIndex = %d, biggest staker Id = %d", epoch, blockIndex, biggestStakerId) disputeBiggestStakeProposedTxn, err := blockManagerUtils.DisputeBiggestStakeProposed(client, txnOpts, epoch, uint8(blockIndex), biggestStakerId) if err != nil { @@ -101,12 +105,12 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, } disputeBiggestStakeProposedTxnHash := transactionUtils.Hash(disputeBiggestStakeProposedTxn) log.Info("Txn Hash: ", disputeBiggestStakeProposedTxnHash.Hex()) - WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(client, disputeBiggestStakeProposedTxnHash.Hex()) + WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(rpcParameters, disputeBiggestStakeProposedTxnHash.Hex()) //If dispute happens, then storing the bountyId into disputeData file if WaitForBlockCompletionErr == nil { log.Debug("Storing bounty Id in dispute data file....") - err = cmdUtils.StoreBountyId(ctx, client, account) + err = cmdUtils.StoreBountyId(rpcParameters, account) if err != nil { log.Error(err) } @@ -119,7 +123,7 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, log.Debug("HandleDispute: Revealed collection ids in the block ", proposedBlock.Ids) log.Debugf("HandleDispute: Calling CheckDisputeForIds() with arguments epoch = %d, blockIndex = %d, proposed revealed Ids = %v, locally calculated revealed Ids = %v", epoch, blockIndex, proposedBlock.Ids, revealedCollectionIds) - idDisputeTxn, err := cmdUtils.CheckDisputeForIds(ctx, client, transactionOptions, epoch, uint8(blockIndex), proposedBlock.Ids, revealedCollectionIds) + idDisputeTxn, err := cmdUtils.CheckDisputeForIds(rpcParameters, transactionOptions, epoch, uint8(blockIndex), proposedBlock.Ids, revealedCollectionIds) if err != nil { log.Error("Error in disputing: ", err) continue @@ -127,12 +131,12 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, if idDisputeTxn != nil { idDisputeTxnHash := transactionUtils.Hash(idDisputeTxn) log.Debugf("Txn Hash: %s", idDisputeTxnHash.Hex()) - WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(client, idDisputeTxnHash.Hex()) + WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(rpcParameters, idDisputeTxnHash.Hex()) //If dispute happens, then storing the bountyId into disputeData file if WaitForBlockCompletionErr == nil { log.Debug("Storing bounty Id in dispute data file...") - err = cmdUtils.StoreBountyId(ctx, client, account) + err = cmdUtils.StoreBountyId(rpcParameters, account) if err != nil { log.Error(err) } @@ -165,14 +169,14 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, sortedValues := revealedDataMaps.SortedRevealedValues[collectionIdOfWrongMedian-1] log.Debug("HandleDispute: Sorted values: ", sortedValues) - leafId, err := razorUtils.GetLeafIdOfACollection(ctx, client, collectionIdOfWrongMedian) + leafId, err := razorUtils.GetLeafIdOfACollection(rpcParameters, collectionIdOfWrongMedian) if err != nil { log.Error("Error in leaf id: ", err) continue } log.Debug("HandleDispute: Leaf Id: ", leafId) log.Debugf("Calling Dispute() with arguments epoch = %d, blockIndex = %d, proposed block = %+v, leafId = %d, sortedValues = %s", epoch, uint8(blockIndex), proposedBlock, leafId, sortedValues) - disputeErr := cmdUtils.Dispute(ctx, client, config, account, epoch, uint8(blockIndex), proposedBlock, leafId, sortedValues) + disputeErr := cmdUtils.Dispute(rpcParameters, config, account, epoch, uint8(blockIndex), proposedBlock, leafId, sortedValues) if disputeErr != nil { log.Error("Error in disputing...", disputeErr) continue @@ -192,11 +196,11 @@ func (*UtilsStruct) HandleDispute(ctx context.Context, client *ethclient.Client, } //This function returns the local median data -func (*UtilsStruct) GetLocalMediansData(ctx context.Context, client *ethclient.Client, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) { +func (*UtilsStruct) GetLocalMediansData(rpcParameters RPC.RPCParameters, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) { if rogueData.IsRogue { // As the staker has proposed with incorrect medians in rogue mode so those values needs to be compared with the correct calculated medians log.Debug("Staker proposed in rogue mode, now calculating medians correctly...") - return calculateMedian(ctx, client, account, epoch, blockNumber) + return calculateMedian(rpcParameters, account, epoch, blockNumber) } // Fetching the data from file only if the node is not in rogue mode and @@ -207,18 +211,18 @@ func (*UtilsStruct) GetLocalMediansData(ctx context.Context, client *ethclient.C fileName, err := pathUtils.GetProposeDataFileName(account.Address) if err != nil { log.Error("Error in getting file name to read median data: ", err) - return calculateMedian(ctx, client, account, epoch, blockNumber) + return calculateMedian(rpcParameters, account, epoch, blockNumber) } log.Debug("GetLocalMediansData: Propose data file path: ", fileName) proposedData, err := fileUtils.ReadFromProposeJsonFile(fileName) if err != nil { log.Errorf("Error in getting propose data from file %s: %v", fileName, err) - return calculateMedian(ctx, client, account, epoch, blockNumber) + return calculateMedian(rpcParameters, account, epoch, blockNumber) } log.Debugf("GetLocalMediansData: Proposed data from file: %+v", proposedData) if proposedData.Epoch != epoch { log.Errorf("File %s doesn't contain latest median data", fileName) - return calculateMedian(ctx, client, account, epoch, blockNumber) + return calculateMedian(rpcParameters, account, epoch, blockNumber) } return proposedData, err } @@ -226,8 +230,8 @@ func (*UtilsStruct) GetLocalMediansData(ctx context.Context, client *ethclient.C return globalProposedDataStruct, nil } -func calculateMedian(ctx context.Context, client *ethclient.Client, account types.Account, epoch uint32, blockNumber *big.Int) (types.ProposeFileData, error) { - stakerId, err := razorUtils.GetStakerId(ctx, client, account.Address) +func calculateMedian(rpcParameters RPC.RPCParameters, account types.Account, epoch uint32, blockNumber *big.Int) (types.ProposeFileData, error) { + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) if err != nil { log.Error("Error in getting stakerId: ", err) return types.ProposeFileData{}, err @@ -236,7 +240,7 @@ func calculateMedian(ctx context.Context, client *ethclient.Client, account type log.Debug("Calculating the medians data again...") log.Debugf("GetLocalMediansData: Calling MakeBlock() with arguments blockNumber = %s, epoch = %d, rogueData = %+v", blockNumber, epoch, types.Rogue{IsRogue: false}) - medians, revealedCollectionIds, revealedDataMaps, err := cmdUtils.MakeBlock(ctx, client, blockNumber, epoch, types.Rogue{IsRogue: false}) + medians, revealedCollectionIds, revealedDataMaps, err := cmdUtils.MakeBlock(rpcParameters, blockNumber, epoch, types.Rogue{IsRogue: false}) if err != nil { log.Error("Error in calculating block medians: ", err) return types.ProposeFileData{}, err @@ -253,7 +257,7 @@ func calculateMedian(ctx context.Context, client *ethclient.Client, account type } //This function check for the dispute in different type of Id's -func (*UtilsStruct) CheckDisputeForIds(ctx context.Context, client *ethclient.Client, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*Types.Transaction, error) { +func (*UtilsStruct) CheckDisputeForIds(rpcParameters RPC.RPCParameters, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*Types.Transaction, error) { //checking for hashing whether there is any dispute or not hashIdsInProposedBlock := solsha3.SoliditySHA3([]string{"uint16[]"}, []interface{}{idsInProposedBlock}) log.Debug("CheckDisputeForIds: Hash of reveal Ids in proposed block: ", hashIdsInProposedBlock) @@ -273,7 +277,13 @@ func (*UtilsStruct) CheckDisputeForIds(ctx context.Context, client *ethclient.Cl transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeOnOrderOfIds" transactionOpts.Parameters = []interface{}{epoch, blockIndex, index0, index1} - txnOpts := razorUtils.GetTxnOpts(ctx, transactionOpts) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return nil, err + } + log.Debug("Disputing sorted order of ids!") log.Debugf("CheckDisputeForIds: Executing DisputeOnOrderOfIds transaction with arguments epoch: %d, blockIndex: %d, index0: %d, index1: %d", epoch, blockIndex, index0, index1) return blockManagerUtils.DisputeOnOrderOfIds(client, txnOpts, epoch, blockIndex, big.NewInt(int64(index0)), big.NewInt(int64(index1))) @@ -285,13 +295,19 @@ func (*UtilsStruct) CheckDisputeForIds(ctx context.Context, client *ethclient.Cl transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeCollectionIdShouldBePresent" transactionOpts.Parameters = []interface{}{epoch, blockIndex, missingCollectionId} - txnOpts := razorUtils.GetTxnOpts(ctx, transactionOpts) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) gasLimit := txnOpts.GasLimit - incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(ctx, client, gasLimit, core.DisputeGasMultiplier) + incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(rpcParameters, gasLimit, core.DisputeGasMultiplier) if err != nil { return nil, err } txnOpts.GasLimit = incrementedGasLimit + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return nil, err + } + log.Debug("Disputing collection id should be present!") log.Debugf("CheckDisputeForIds: Executing DisputeCollectionIdShouldBePresent transaction with arguments epoch: %d, blockIndex: %d, missingCollectionId: %d", epoch, blockIndex, missingCollectionId) return blockManagerUtils.DisputeCollectionIdShouldBePresent(client, txnOpts, epoch, blockIndex, missingCollectionId) @@ -303,13 +319,19 @@ func (*UtilsStruct) CheckDisputeForIds(ctx context.Context, client *ethclient.Cl transactionOpts.ABI = bindings.BlockManagerMetaData.ABI transactionOpts.MethodName = "disputeCollectionIdShouldBeAbsent" transactionOpts.Parameters = []interface{}{epoch, blockIndex, presentCollectionId, big.NewInt(int64(positionOfPresentValue))} - txnOpts := razorUtils.GetTxnOpts(ctx, transactionOpts) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, transactionOpts) gasLimit := txnOpts.GasLimit - incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(ctx, client, gasLimit, core.DisputeGasMultiplier) + incrementedGasLimit, err := gasUtils.IncreaseGasLimitValue(rpcParameters, gasLimit, core.DisputeGasMultiplier) if err != nil { return nil, err } txnOpts.GasLimit = incrementedGasLimit + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return nil, err + } + log.Debug("Disputing collection id should be absent!") log.Debugf("CheckDisputeForIds: Executing DisputeCollectionIdShouldBeAbsent transaction with arguments epoch: %d, blockIndex: %d, presentCollectionId: %d, positionOfPresentValue: %d", epoch, blockIndex, presentCollectionId, positionOfPresentValue) return blockManagerUtils.DisputeCollectionIdShouldBeAbsent(client, txnOpts, epoch, blockIndex, presentCollectionId, big.NewInt(int64(positionOfPresentValue))) @@ -319,11 +341,8 @@ func (*UtilsStruct) CheckDisputeForIds(ctx context.Context, client *ethclient.Cl } //This function finalizes the dispute and return the error if there is any -func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error { - blockManager := razorUtils.GetBlockManager(client) - +func (*UtilsStruct) Dispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error { txnArgs := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, Account: account, @@ -343,15 +362,15 @@ func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, confi end = lenOfSortedValues } log.Debugf("Dispute: Calling GiveSorted with arguments epoch = %d, leafId = %d, sortedValues = %s", epoch, leafId, sortedValues[start:end]) - err := cmdUtils.GiveSorted(ctx, client, blockManager, txnArgs, epoch, leafId, sortedValues[start:end]) + err := cmdUtils.GiveSorted(rpcParameters, txnArgs, epoch, leafId, sortedValues[start:end]) if err != nil { if err.Error() == errors.New("gas limit reached").Error() { end = end / 2 } else { log.Error("Error in GiveSorted: ", err) - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Debugf("Dispute: Calling CheckToDoResetDispute with arguments epoch = %d, sortedValues = %s", epoch, sortedValues) - cmdUtils.CheckToDoResetDispute(client, blockManager, txnOpts, epoch, sortedValues) + cmdUtils.CheckToDoResetDispute(rpcParameters, txnOpts, epoch, sortedValues) return err } } else { @@ -369,7 +388,7 @@ func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, confi giveSortedLeafIds = append(giveSortedLeafIds, int(leafId)) } log.Debugf("Dispute: Calling GetCollectionIdPositionInBlock with arguments leafId = %d, proposed block = %+v", leafId, proposedBlock) - positionOfCollectionInBlock := cmdUtils.GetCollectionIdPositionInBlock(ctx, client, leafId, proposedBlock) + positionOfCollectionInBlock := cmdUtils.GetCollectionIdPositionInBlock(rpcParameters, leafId, proposedBlock) log.Debug("Dispute: Position of collection id in block: ", positionOfCollectionInBlock) log.Info("Finalizing dispute...") @@ -378,7 +397,12 @@ func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, confi finalizeDisputeTxnArgs.MethodName = "finalizeDispute" finalizeDisputeTxnArgs.ABI = bindings.BlockManagerMetaData.ABI finalizeDisputeTxnArgs.Parameters = []interface{}{epoch, blockIndex, positionOfCollectionInBlock} - finalizeDisputeTxnOpts := razorUtils.GetTxnOpts(ctx, finalizeDisputeTxnArgs) + finalizeDisputeTxnOpts := razorUtils.GetTxnOpts(rpcParameters, finalizeDisputeTxnArgs) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return err + } log.Debugf("Executing FinalizeDispute transaction with arguments epoch = %d, blockIndex = %d, positionOfCollectionInBlock = %d", epoch, blockIndex, positionOfCollectionInBlock) finalizeTxn, err := blockManagerUtils.FinalizeDispute(client, finalizeDisputeTxnOpts, epoch, blockIndex, positionOfCollectionInBlock) @@ -392,11 +416,11 @@ func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, confi finalizeTxnHash := transactionUtils.Hash(finalizeTxn) log.Info("Txn Hash: ", finalizeTxnHash.Hex()) log.Debug("Dispute: Checking mining status of FinalizeDispute transaction...") - WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(client, finalizeTxnHash.Hex()) + WaitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(rpcParameters, finalizeTxnHash.Hex()) //If dispute happens, then storing the bountyId into disputeData file if WaitForBlockCompletionErr == nil { log.Debug("Storing bounty Id in dispute data file...") - err = cmdUtils.StoreBountyId(ctx, client, account) + err = cmdUtils.StoreBountyId(rpcParameters, account) if err != nil { return err } @@ -413,21 +437,20 @@ func (*UtilsStruct) Dispute(ctx context.Context, client *ethclient.Client, confi resetDisputeTxnArgs.MethodName = "resetDispute" resetDisputeTxnArgs.ABI = bindings.BlockManagerMetaData.ABI resetDisputeTxnArgs.Parameters = []interface{}{epoch} - resetDisputeTxnOpts := razorUtils.GetTxnOpts(ctx, resetDisputeTxnArgs) + resetDisputeTxnOpts := razorUtils.GetTxnOpts(rpcParameters, resetDisputeTxnArgs) - cmdUtils.ResetDispute(client, blockManager, resetDisputeTxnOpts, epoch) + cmdUtils.ResetDispute(rpcParameters, resetDisputeTxnOpts, epoch) return nil } //This function sorts the Id's recursively -func GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, leafId uint16, sortedValues []*big.Int) error { +func GiveSorted(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, epoch uint32, leafId uint16, sortedValues []*big.Int) error { if len(sortedValues) == 0 { return errors.New("length of sortedValues is 0") } - callOpts := razorUtils.GetOptions() - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) - disputesMapping, err := blockManagerUtils.Disputes(client, &callOpts, epoch, common.HexToAddress(txnArgs.Account.Address)) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + disputesMapping, err := razorUtils.Disputes(rpcParameters, epoch, common.HexToAddress(txnArgs.Account.Address)) if err != nil { log.Error("Error in getting disputes mapping: ", disputesMapping) return err @@ -446,8 +469,14 @@ func GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bin log.Debug("GiveSorted: Is give sorted initiated: ", isGiveSortedInitiated) log.Info("Calling GiveSorted...") + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return err + } + log.Debugf("Executing GiveSorted transaction with arguments epoch = %d, leafId = %d , sortedValues = %s", epoch, leafId, sortedValues) - txn, err := blockManagerUtils.GiveSorted(blockManager, txnOpts, epoch, leafId, sortedValues) + txn, err := blockManagerUtils.GiveSorted(client, txnOpts, epoch, leafId, sortedValues) if err != nil { return err } @@ -455,7 +484,7 @@ func GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bin txnHash := transactionUtils.Hash(txn) log.Info("Txn Hash: ", txnHash.Hex()) giveSortedLeafIds = append(giveSortedLeafIds, int(leafId)) - err = razorUtils.WaitForBlockCompletion(client, txnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txnHash.Hex()) if err != nil { log.Error("Error in WaitForBlockCompletion for giveSorted: ", err) return err @@ -464,9 +493,9 @@ func GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bin } //This function returns the collection Id position in block -func (*UtilsStruct) GetCollectionIdPositionInBlock(ctx context.Context, client *ethclient.Client, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int { +func (*UtilsStruct) GetCollectionIdPositionInBlock(rpcParameters RPC.RPCParameters, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int { ids := proposedBlock.Ids - idToBeDisputed, err := razorUtils.GetCollectionIdFromLeafId(ctx, client, leafId) + idToBeDisputed, err := razorUtils.GetCollectionIdFromLeafId(rpcParameters, leafId) if err != nil { log.Error("Error in fetching collection id from leaf id") return nil @@ -482,7 +511,7 @@ func (*UtilsStruct) GetCollectionIdPositionInBlock(ctx context.Context, client * } //This function saves the bountyId in disputeData file and return the error if there is any -func (*UtilsStruct) StoreBountyId(ctx context.Context, client *ethclient.Client, account types.Account) error { +func (*UtilsStruct) StoreBountyId(rpcParameters RPC.RPCParameters, account types.Account) error { disputeFilePath, err := pathUtils.GetDisputeDataFileName(account.Address) if err != nil { return err @@ -491,7 +520,7 @@ func (*UtilsStruct) StoreBountyId(ctx context.Context, client *ethclient.Client, var latestBountyId uint32 - latestHeader, err := clientUtils.GetLatestBlockWithRetry(ctx, client) + latestHeader, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in fetching block: ", err) return err @@ -499,7 +528,7 @@ func (*UtilsStruct) StoreBountyId(ctx context.Context, client *ethclient.Client, log.Debug("StoreBountyId: Latest header: ", latestHeader) log.Debugf("StoreBountyId: Calling GetBountyIdFromEvents with arguments blockNumber = %d, address = %s", latestHeader.Number, account.Address) - latestBountyId, err = cmdUtils.GetBountyIdFromEvents(ctx, client, latestHeader.Number, account.Address) + latestBountyId, err = cmdUtils.GetBountyIdFromEvents(rpcParameters, latestHeader.Number, account.Address) if err != nil { return err } @@ -528,16 +557,20 @@ func (*UtilsStruct) StoreBountyId(ctx context.Context, client *ethclient.Client, } //This function resets the dispute -func (*UtilsStruct) ResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32) { +func (*UtilsStruct) ResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32) { + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return + } log.Debug("Executing ResetDispute transaction with arguments epoch = ", epoch) - txn, err := blockManagerUtils.ResetDispute(blockManager, txnOpts, epoch) + txn, err := blockManagerUtils.ResetDispute(client, txnOpts, epoch) if err != nil { log.Error("error in resetting dispute", err) return } txnHash := transactionUtils.Hash(txn) log.Info("Txn Hash: ", txnHash.Hex()) - err = razorUtils.WaitForBlockCompletion(client, txnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txnHash.Hex()) if err != nil { log.Error("Error in WaitForBlockCompletion for resetDispute: ", err) return @@ -546,8 +579,8 @@ func (*UtilsStruct) ResetDispute(client *ethclient.Client, blockManager *binding } //This function returns the bountyId from events -func (*UtilsStruct) GetBountyIdFromEvents(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, bountyHunter string) (uint32, error) { - fromBlock, err := razorUtils.EstimateBlockNumberAtEpochBeginning(client, blockNumber) +func (*UtilsStruct) GetBountyIdFromEvents(rpcParameters RPC.RPCParameters, blockNumber *big.Int, bountyHunter string) (uint32, error) { + fromBlock, err := razorUtils.EstimateBlockNumberAtEpochBeginning(rpcParameters, blockNumber) if err != nil { log.Error(err) return 0, err @@ -561,7 +594,7 @@ func (*UtilsStruct) GetBountyIdFromEvents(ctx context.Context, client *ethclient }, } log.Debugf("GetBountyIdFromEvents: Query to send in filter logs: %+v", query) - logs, err := clientUtils.FilterLogsWithRetry(ctx, client, query) + logs, err := clientUtils.FilterLogsWithRetry(rpcParameters, query) if err != nil { return 0, err } @@ -589,10 +622,9 @@ func (*UtilsStruct) GetBountyIdFromEvents(ctx context.Context, client *ethclient return bountyId, nil } -func (*UtilsStruct) CheckToDoResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) { +func (*UtilsStruct) CheckToDoResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) { // Fetch updated dispute mapping - callOpts := razorUtils.GetOptions() - disputesMapping, err := blockManagerUtils.Disputes(client, &callOpts, epoch, txnOpts.From) + disputesMapping, err := razorUtils.Disputes(rpcParameters, epoch, txnOpts.From) if err != nil { log.Error("Error in getting disputes mapping: ", disputesMapping) return @@ -602,6 +634,6 @@ func (*UtilsStruct) CheckToDoResetDispute(client *ethclient.Client, blockManager //Checking whether LVV is equal to maximum value in sortedValues, if not equal resetting dispute if disputesMapping.LastVisitedValue.Cmp(big.NewInt(0)) != 0 && disputesMapping.LastVisitedValue.Cmp(sortedValues[len(sortedValues)-1]) != 0 { log.Debug("CheckToDoResetDispute: Calling Reset Dispute with arguments epoch = ", epoch) - cmdUtils.ResetDispute(client, blockManager, txnOpts, epoch) + cmdUtils.ResetDispute(rpcParameters, txnOpts, epoch) } } diff --git a/cmd/eventListeners.go b/cmd/eventListeners.go index 268e0316..f83842d3 100644 --- a/cmd/eventListeners.go +++ b/cmd/eventListeners.go @@ -1,13 +1,12 @@ package cmd import ( - "context" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" Types "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" "math/big" + "razor/RPC" "razor/cache" "razor/core" "razor/core/types" @@ -16,8 +15,8 @@ import ( "strings" ) -func (*UtilsStruct) InitJobAndCollectionCache(ctx context.Context, client *ethclient.Client) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) { - initAssetCacheBlock, err := clientUtils.GetLatestBlockWithRetry(ctx, client) +func (*UtilsStruct) InitJobAndCollectionCache(rpcParameters RPC.RPCParameters) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) { + initAssetCacheBlock, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in fetching block: ", err) return nil, nil, nil, err @@ -31,11 +30,11 @@ func (*UtilsStruct) InitJobAndCollectionCache(ctx context.Context, client *ethcl collectionsCache := cache.NewCollectionsCache() // Initialize caches - if err := utils.InitJobsCache(ctx, client, jobsCache); err != nil { + if err := utils.InitJobsCache(rpcParameters, jobsCache); err != nil { log.Error("Error in initializing jobs cache: ", err) return nil, nil, nil, err } - if err := utils.InitCollectionsCache(client, collectionsCache); err != nil { + if err := utils.InitCollectionsCache(rpcParameters, collectionsCache); err != nil { log.Error("Error in initializing collections cache: ", err) return nil, nil, nil, err } @@ -44,7 +43,7 @@ func (*UtilsStruct) InitJobAndCollectionCache(ctx context.Context, client *ethcl } // CheckForJobAndCollectionEvents checks for specific job and collections event that were emitted. -func CheckForJobAndCollectionEvents(ctx context.Context, client *ethclient.Client, commitParams *types.CommitParams) error { +func CheckForJobAndCollectionEvents(rpcParameters RPC.RPCParameters, commitParams *types.CommitParams) error { collectionManagerContractABI, err := abi.JSON(strings.NewReader(bindings.CollectionManagerMetaData.ABI)) if err != nil { log.Errorf("Error in parsing collection manager contract ABI: %v", err) @@ -54,14 +53,14 @@ func CheckForJobAndCollectionEvents(ctx context.Context, client *ethclient.Clien eventNames := []string{core.JobUpdatedEvent, core.CollectionUpdatedEvent, core.CollectionActivityStatusEvent, core.JobCreatedEvent, core.CollectionCreatedEvent} log.Debug("Checking for Job/Collection update events...") - toBlock, err := clientUtils.GetLatestBlockWithRetry(ctx, client) + toBlock, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in getting latest block to start event listener: ", err) return err } // Process events and update the fromBlock for the next iteration - newFromBlock, err := processEvents(ctx, client, collectionManagerContractABI, commitParams.FromBlockToCheckForEvents, toBlock.Number, eventNames, commitParams.JobsCache, commitParams.CollectionsCache) + newFromBlock, err := processEvents(rpcParameters, collectionManagerContractABI, commitParams.FromBlockToCheckForEvents, toBlock.Number, eventNames, commitParams.JobsCache, commitParams.CollectionsCache) if err != nil { return err } @@ -73,8 +72,8 @@ func CheckForJobAndCollectionEvents(ctx context.Context, client *ethclient.Clien } // processEvents fetches and processes logs for multiple event types. -func processEvents(ctx context.Context, client *ethclient.Client, contractABI abi.ABI, fromBlock, toBlock *big.Int, eventNames []string, jobsCache *cache.JobsCache, collectionsCache *cache.CollectionsCache) (*big.Int, error) { - logs, err := getEventLogs(ctx, client, fromBlock, toBlock) +func processEvents(rpcParameters RPC.RPCParameters, contractABI abi.ABI, fromBlock, toBlock *big.Int, eventNames []string, jobsCache *cache.JobsCache, collectionsCache *cache.CollectionsCache) (*big.Int, error) { + logs, err := getEventLogs(rpcParameters, fromBlock, toBlock) if err != nil { log.Errorf("Failed to fetch logs: %v", err) return nil, err @@ -87,7 +86,7 @@ func processEvents(ctx context.Context, client *ethclient.Client, contractABI ab switch eventName { case core.JobUpdatedEvent, core.JobCreatedEvent: jobId := utils.ConvertHashToUint16(vLog.Topics[1]) - updatedJob, err := utils.UtilsInterface.GetActiveJob(ctx, client, jobId) + updatedJob, err := razorUtils.GetActiveJob(rpcParameters, jobId) if err != nil { log.Errorf("Error in getting job with job Id %v: %v", jobId, err) continue @@ -96,7 +95,7 @@ func processEvents(ctx context.Context, client *ethclient.Client, contractABI ab jobsCache.UpdateJob(jobId, updatedJob) case core.CollectionUpdatedEvent, core.CollectionCreatedEvent, core.CollectionActivityStatusEvent: collectionId := utils.ConvertHashToUint16(vLog.Topics[1]) - newCollection, err := utils.UtilsInterface.GetCollection(ctx, client, collectionId) + newCollection, err := razorUtils.GetCollection(rpcParameters, collectionId) if err != nil { log.Errorf("Error in getting collection with collection Id %v: %v", collectionId, err) continue @@ -113,7 +112,7 @@ func processEvents(ctx context.Context, client *ethclient.Client, contractABI ab } // getEventLogs is a utility function to fetch the event logs -func getEventLogs(ctx context.Context, client *ethclient.Client, fromBlock *big.Int, toBlock *big.Int) ([]Types.Log, error) { +func getEventLogs(rpcParameters RPC.RPCParameters, fromBlock *big.Int, toBlock *big.Int) ([]Types.Log, error) { log.Debugf("Checking for events from block %v to block %v...", fromBlock, toBlock) // Set up the query for filtering logs @@ -126,7 +125,7 @@ func getEventLogs(ctx context.Context, client *ethclient.Client, fromBlock *big. } // Retrieve the logs - logs, err := clientUtils.FilterLogsWithRetry(ctx, client, query) + logs, err := clientUtils.FilterLogsWithRetry(rpcParameters, query) if err != nil { log.Errorf("Error in filter logs: %v", err) return []Types.Log{}, err diff --git a/cmd/initiateWithdraw.go b/cmd/initiateWithdraw.go index 30a42649..d01bb8da 100644 --- a/cmd/initiateWithdraw.go +++ b/cmd/initiateWithdraw.go @@ -2,19 +2,16 @@ package cmd import ( - "context" "errors" "math/big" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -34,49 +31,26 @@ Example: //This function sets the flags appropriately and executes the InitiateWithdraw function func (*UtilsStruct) ExecuteInitiateWithdraw(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteInitiateWithdraw: Config: %+v: ", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteInitiateWithdraw: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - - stakerId, err := razorUtils.AssignStakerId(context.Background(), flagSet, client, address) + stakerId, err := razorUtils.AssignStakerId(rpcParameters, flagSet, account.Address) utils.CheckError("Error in fetching stakerId: ", err) log.Debug("ExecuteInitiateWithdraw: Staker Id: ", stakerId) - log.Debugf("ExecuteInitiateWithdraw: Calling HandleUnstakeLock() with arguments account address: %s, stakerId: %d", address, stakerId) - txn, err := cmdUtils.HandleUnstakeLock(context.Background(), client, account, config, stakerId) + log.Debugf("ExecuteInitiateWithdraw: Calling HandleUnstakeLock() with arguments account address: %s, stakerId: %d", account.Address, stakerId) + txn, err := cmdUtils.HandleUnstakeLock(rpcParameters, account, config, stakerId) utils.CheckError("InitiateWithdraw error: ", err) if txn != core.NilHash { - err := razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err := razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for initiateWithdraw: ", err) } } //This function handles the unstake lock -func (*UtilsStruct) HandleUnstakeLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { - unstakeLock, err := razorUtils.GetLock(ctx, client, account.Address, stakerId, 0) +func (*UtilsStruct) HandleUnstakeLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { + unstakeLock, err := razorUtils.GetLock(rpcParameters, account.Address, stakerId, 0) if err != nil { log.Error("Error in fetching unstakeLock") return core.NilHash, err @@ -88,7 +62,7 @@ func (*UtilsStruct) HandleUnstakeLock(ctx context.Context, client *ethclient.Cli return core.NilHash, errors.New("unstake Razors before withdrawing") } - withdrawInitiationPeriod, err := razorUtils.GetWithdrawInitiationPeriod(ctx, client) + withdrawInitiationPeriod, err := razorUtils.GetWithdrawInitiationPeriod(rpcParameters) if err != nil { log.Error("Error in fetching withdraw release period") return core.NilHash, err @@ -97,7 +71,7 @@ func (*UtilsStruct) HandleUnstakeLock(ctx context.Context, client *ethclient.Cli withdrawBefore := big.NewInt(0).Add(unstakeLock.UnlockAfter, big.NewInt(int64(withdrawInitiationPeriod))) log.Debug("HandleUnstakeLock: Withdraw before epoch: ", withdrawBefore) - epoch, err := razorUtils.GetEpoch(ctx, client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { log.Error("Error in fetching epoch") return core.NilHash, err @@ -117,14 +91,13 @@ func (*UtilsStruct) HandleUnstakeLock(ctx context.Context, client *ethclient.Cli } log.Debug("Waiting for appropriate state to initiate withdraw...") - _, err = cmdUtils.WaitForAppropriateState(ctx, client, "initiateWithdraw", 0, 1, 4) + _, err = cmdUtils.WaitForAppropriateState(rpcParameters, "initiateWithdraw", 0, 1, 4) if err != nil { log.Error("Error in fetching state: ", err) return core.NilHash, err } txnArgs := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: configurations, ContractAddress: core.StakeManagerAddress, @@ -133,18 +106,24 @@ func (*UtilsStruct) HandleUnstakeLock(ctx context.Context, client *ethclient.Cli Parameters: []interface{}{stakerId}, Account: account, } - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) if big.NewInt(int64(epoch)).Cmp(unstakeLock.UnlockAfter) >= 0 && big.NewInt(int64(epoch)).Cmp(withdrawBefore) <= 0 { log.Debug("Calling InitiateWithdraw() with arguments stakerId: ", stakerId) - return cmdUtils.InitiateWithdraw(client, txnOpts, stakerId) + return cmdUtils.InitiateWithdraw(rpcParameters, txnOpts, stakerId) } return core.NilHash, errors.New("unstakeLock period not over yet! Please try after some time") } //This function initiate withdraw for your razors once you've unstaked -func (*UtilsStruct) InitiateWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { +func (*UtilsStruct) InitiateWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { log.Info("Initiating withdrawal of funds...") + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debug("Executing InitiateWithdraw transaction for stakerId = ", stakerId) txn, err := stakeManagerUtils.InitiateWithdraw(client, txnOpts, stakerId) if err != nil { diff --git a/cmd/interface.go b/cmd/interface.go index 3905c9ee..ddf7c983 100644 --- a/cmd/interface.go +++ b/cmd/interface.go @@ -2,9 +2,9 @@ package cmd import ( - "context" "crypto/ecdsa" "math/big" + "razor/RPC" "razor/cache" "razor/core/types" "razor/path" @@ -64,11 +64,6 @@ type StakeManagerInterface interface { UpdateCommission(client *ethclient.Client, opts *bind.TransactOpts, commission uint8) (*Types.Transaction, error) ApproveUnstake(client *ethclient.Client, opts *bind.TransactOpts, stakerTokenAddress common.Address, amount *big.Int) (*Types.Transaction, error) ClaimStakerReward(client *ethclient.Client, opts *bind.TransactOpts) (*Types.Transaction, error) - - //Getter methods - StakerInfo(client *ethclient.Client, opts *bind.CallOpts, stakerId uint32) (types.Staker, error) - GetMaturity(client *ethclient.Client, opts *bind.CallOpts, age uint32) (uint16, error) - GetBountyLock(client *ethclient.Client, opts *bind.CallOpts, bountyId uint32) (types.BountyLock, error) } type KeystoreInterface interface { @@ -84,9 +79,8 @@ type BlockManagerInterface interface { DisputeOnOrderOfIds(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, index0 *big.Int, index1 *big.Int) (*Types.Transaction, error) DisputeCollectionIdShouldBeAbsent(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, id uint16, positionOfCollectionInBlock *big.Int) (*Types.Transaction, error) DisputeCollectionIdShouldBePresent(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, id uint16) (*Types.Transaction, error) - GiveSorted(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*Types.Transaction, error) - ResetDispute(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32) (*Types.Transaction, error) - Disputes(client *ethclient.Client, opts *bind.CallOpts, epoch uint32, address common.Address) (types.DisputesStruct, error) + GiveSorted(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*Types.Transaction, error) + ResetDispute(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32) (*Types.Transaction, error) } type VoteManagerInterface interface { @@ -95,7 +89,6 @@ type VoteManagerInterface interface { } type TokenManagerInterface interface { - Allowance(client *ethclient.Client, opts *bind.CallOpts, owner common.Address, spender common.Address) (*big.Int, error) Approve(client *ethclient.Client, opts *bind.TransactOpts, spender common.Address, amount *big.Int) (*Types.Transaction, error) Transfer(client *ethclient.Client, opts *bind.TransactOpts, recipient common.Address, amount *big.Int) (*Types.Transaction, error) } @@ -162,95 +155,94 @@ type UtilsCmdInterface interface { GetLogFileMaxAge() (int, error) GetConfigData() (types.Configurations, error) ExecuteClaimBounty(flagSet *pflag.FlagSet) - ClaimBounty(config types.Configurations, client *ethclient.Client, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) - ClaimBlockReward(ctx context.Context, options types.TransactionOptions) (common.Hash, error) - GetSalt(ctx context.Context, client *ethclient.Client, epoch uint32) ([32]byte, error) - HandleCommitState(ctx context.Context, client *ethclient.Client, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) - Commit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitment [32]byte) (common.Hash, error) + ClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) + ClaimBlockReward(rpcParameters RPC.RPCParameters, options types.TransactionOptions) (common.Hash, error) + GetSalt(rpcParameters RPC.RPCParameters, epoch uint32) ([32]byte, error) + HandleCommitState(rpcParameters RPC.RPCParameters, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) + Commit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitment [32]byte) (common.Hash, error) ListAccounts() ([]accounts.Account, error) AssignAmountInWei(flagSet *pflag.FlagSet) (*big.Int, error) ExecuteTransfer(flagSet *pflag.FlagSet) - Transfer(client *ethclient.Client, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) - CheckForLastCommitted(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker, epoch uint32) error - Reveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) + Transfer(rpcParameters RPC.RPCParameters, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) + CheckForLastCommitted(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker, epoch uint32) error + Reveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) GenerateTreeRevealData(merkleTree [][][]byte, commitData types.CommitData) bindings.StructsMerkleTree - IndexRevealEventsOfCurrentEpoch(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) + IndexRevealEventsOfCurrentEpoch(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) ExecuteCreateJob(flagSet *pflag.FlagSet) - CreateJob(client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) + CreateJob(rpcParameter RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) ExecuteCreateCollection(flagSet *pflag.FlagSet) - CreateCollection(client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) - GetEpochAndState(ctx context.Context, client *ethclient.Client) (uint32, int64, error) - WaitForAppropriateState(ctx context.Context, client *ethclient.Client, action string, states ...int) (uint32, error) + CreateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) + GetEpochAndState(rpcParameter RPC.RPCParameters) (uint32, int64, error) + WaitForAppropriateState(rpcParameter RPC.RPCParameters, action string, states ...int) (uint32, error) ExecuteJobList(flagSet *pflag.FlagSet) - GetJobList(client *ethclient.Client) error + GetJobList(rpcParameters RPC.RPCParameters) error ExecuteUnstake(flagSet *pflag.FlagSet) - Unstake(ctx context.Context, config types.Configurations, client *ethclient.Client, input types.UnstakeInput) (common.Hash, error) - ApproveUnstake(client *ethclient.Client, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) + Unstake(rpcParameters RPC.RPCParameters, config types.Configurations, input types.UnstakeInput) (common.Hash, error) + ApproveUnstake(rpcParameters RPC.RPCParameters, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) ExecuteInitiateWithdraw(flagSet *pflag.FlagSet) ExecuteUnlockWithdraw(flagSet *pflag.FlagSet) - InitiateWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) - UnlockWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) - HandleUnstakeLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) - HandleWithdrawLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) + InitiateWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) + UnlockWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) + HandleUnstakeLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) + HandleWithdrawLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) ExecuteUpdateJob(flagSet *pflag.FlagSet) - UpdateJob(ctx context.Context, client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) - WaitIfCommitState(ctx context.Context, client *ethclient.Client, action string) (uint32, error) + UpdateJob(rpcParameters RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) + WaitIfCommitState(rpcParameter RPC.RPCParameters, action string) (uint32, error) ExecuteCollectionList(flagSet *pflag.FlagSet) - GetCollectionList(client *ethclient.Client) error + GetCollectionList(rpcParameters RPC.RPCParameters) error ExecuteStakerinfo(flagSet *pflag.FlagSet) ExecuteSetDelegation(flagSet *pflag.FlagSet) - SetDelegation(ctx context.Context, client *ethclient.Client, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) - GetStakerInfo(ctx context.Context, client *ethclient.Client, stakerId uint32) error + SetDelegation(rpcParameters RPC.RPCParameters, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) + GetStakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) error ExecuteUpdateCollection(flagSet *pflag.FlagSet) - UpdateCollection(ctx context.Context, client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) - MakeBlock(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) + UpdateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) + MakeBlock(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) IsElectedProposer(proposer types.ElectedProposer, currentStakerStake *big.Int) bool - GetSortedRevealedValues(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) - GetIteration(ctx context.Context, client *ethclient.Client, proposer types.ElectedProposer, bufferPercent int32) int - Propose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error - GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error - GetLocalMediansData(ctx context.Context, client *ethclient.Client, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) - CheckDisputeForIds(ctx context.Context, client *ethclient.Client, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*Types.Transaction, error) - Dispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error - GetCollectionIdPositionInBlock(ctx context.Context, client *ethclient.Client, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int - HandleDispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error + GetSortedRevealedValues(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) + GetIteration(rpcParameters RPC.RPCParameters, proposer types.ElectedProposer, bufferPercent int32) int + Propose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error + GiveSorted(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error + GetLocalMediansData(rpcParameters RPC.RPCParameters, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) + CheckDisputeForIds(rpcParameters RPC.RPCParameters, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*Types.Transaction, error) + Dispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error + GetCollectionIdPositionInBlock(rpcParameters RPC.RPCParameters, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int + HandleDispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error ExecuteExtendLock(flagSet *pflag.FlagSet) - ResetUnstakeLock(client *ethclient.Client, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) - CheckCurrentStatus(client *ethclient.Client, collectionId uint16) (bool, error) + ResetUnstakeLock(rpcParameters RPC.RPCParameters, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) ExecuteModifyCollectionStatus(flagSet *pflag.FlagSet) - ModifyCollectionStatus(ctx context.Context, client *ethclient.Client, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) - Approve(txnArgs types.TransactionOptions) (common.Hash, error) + ModifyCollectionStatus(rpcParameters RPC.RPCParameters, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) + Approve(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) ExecuteDelegate(flagSet *pflag.FlagSet) - Delegate(txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) + Delegate(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) ExecuteCreate(flagSet *pflag.FlagSet) Create(password string) (accounts.Account, error) ExecuteImport(flagSet *pflag.FlagSet) ImportAccount() (accounts.Account, error) ExecuteUpdateCommission(flagSet *pflag.FlagSet) - UpdateCommission(ctx context.Context, config types.Configurations, client *ethclient.Client, updateCommissionInput types.UpdateCommissionInput) error - GetBiggestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) - GetSmallestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) - StakeCoins(txnArgs types.TransactionOptions) (common.Hash, error) + UpdateCommission(rpcParameters RPC.RPCParameters, config types.Configurations, updateCommissionInput types.UpdateCommissionInput) error + GetBiggestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) + GetSmallestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) + StakeCoins(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) CalculateSecret(account types.Account, epoch uint32, keystorePath string, chainId *big.Int) ([]byte, []byte, error) - HandleBlock(client *ethclient.Client, account types.Account, stakerId uint32, header *Types.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) + HandleBlock(rpcParameters RPC.RPCParameters, account types.Account, stakerId uint32, header *Types.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) ExecuteVote(flagSet *pflag.FlagSet) - Vote(ctx context.Context, config types.Configurations, client *ethclient.Client, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error + Vote(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error HandleExit() ExecuteListAccounts(flagSet *pflag.FlagSet) ClaimCommission(flagSet *pflag.FlagSet) ExecuteStake(flagSet *pflag.FlagSet) - InitiateCommit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *Types.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error - InitiateReveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error - InitiatePropose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error - GetBountyIdFromEvents(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, bountyHunter string) (uint32, error) - HandleClaimBounty(client *ethclient.Client, config types.Configurations, account types.Account) error + InitiateCommit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *Types.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error + InitiateReveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error + InitiatePropose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error + GetBountyIdFromEvents(rpcParameters RPC.RPCParameters, blockNumber *big.Int, bountyHunter string) (uint32, error) + HandleClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account) error ExecuteContractAddresses(flagSet *pflag.FlagSet) ContractAddresses() - ResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32) - StoreBountyId(ctx context.Context, client *ethclient.Client, account types.Account) error - CheckToDoResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) - InitJobAndCollectionCache(ctx context.Context, client *ethclient.Client) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) - BatchGetStakeSnapshotCalls(client *ethclient.Client, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) + ResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32) + StoreBountyId(rpcParameters RPC.RPCParameters, account types.Account) error + CheckToDoResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) + InitJobAndCollectionCache(rpcParameters RPC.RPCParameters) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) + BatchGetStakeSnapshotCalls(rpcParameters RPC.RPCParameters, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) } type TransactionInterface interface { diff --git a/cmd/jobList.go b/cmd/jobList.go index c670dfe9..aa92367e 100644 --- a/cmd/jobList.go +++ b/cmd/jobList.go @@ -3,11 +3,11 @@ package cmd import ( "context" - "github.com/ethereum/go-ethereum/ethclient" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "github.com/spf13/pflag" "os" + "razor/RPC" "razor/logger" "razor/utils" "strconv" @@ -38,14 +38,22 @@ func (*UtilsStruct) ExecuteJobList(flagSet *pflag.FlagSet) { client := razorUtils.ConnectToClient(config.Provider) logger.SetLoggerParameters(client, "") + rpcManager, err := RPC.InitializeRPCManager(config.Provider) + utils.CheckError("Error in initializing RPC Manager: ", err) + + rpcParameters := RPC.RPCParameters{ + RPCManager: rpcManager, + Ctx: context.Background(), + } + log.Debug("ExecuteJobList: Calling JobList()...") - err = cmdUtils.GetJobList(client) + err = cmdUtils.GetJobList(rpcParameters) utils.CheckError("Error in getting job list: ", err) } //This function provides the list of all jobs -func (*UtilsStruct) GetJobList(client *ethclient.Client) error { - jobs, err := razorUtils.GetJobs(context.Background(), client) +func (*UtilsStruct) GetJobList(rpcParameters RPC.RPCParameters) error { + jobs, err := razorUtils.GetJobs(rpcParameters) log.Debugf("JobList: Jobs: %+v", jobs) if err != nil { return err diff --git a/cmd/mocks/abi_interface.go b/cmd/mocks/abi_interface.go index 5545d651..9f888d8d 100644 --- a/cmd/mocks/abi_interface.go +++ b/cmd/mocks/abi_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ func (_m *AbiInterface) Unpack(_a0 abi.ABI, name string, data []byte) ([]interfa ret := _m.Called(_a0, name, data) var r0 []interface{} + var r1 error + if rf, ok := ret.Get(0).(func(abi.ABI, string, []byte) ([]interface{}, error)); ok { + return rf(_a0, name, data) + } if rf, ok := ret.Get(0).(func(abi.ABI, string, []byte) []interface{}); ok { r0 = rf(_a0, name, data) } else { @@ -26,7 +30,6 @@ func (_m *AbiInterface) Unpack(_a0 abi.ABI, name string, data []byte) ([]interfa } } - var r1 error if rf, ok := ret.Get(1).(func(abi.ABI, string, []byte) error); ok { r1 = rf(_a0, name, data) } else { @@ -36,13 +39,12 @@ func (_m *AbiInterface) Unpack(_a0 abi.ABI, name string, data []byte) ([]interfa return r0, r1 } -type mockConstructorTestingTNewAbiInterface interface { +// NewAbiInterface creates a new instance of AbiInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAbiInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewAbiInterface creates a new instance of AbiInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAbiInterface(t mockConstructorTestingTNewAbiInterface) *AbiInterface { +}) *AbiInterface { mock := &AbiInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/asset_manager_interface.go b/cmd/mocks/asset_manager_interface.go index d4f3304f..ea2dc603 100644 --- a/cmd/mocks/asset_manager_interface.go +++ b/cmd/mocks/asset_manager_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -22,6 +22,10 @@ func (_m *AssetManagerInterface) CreateCollection(client *ethclient.Client, opts ret := _m.Called(client, opts, tolerance, power, aggregationMethod, jobIDs, name) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, int8, uint32, []uint16, string) (*types.Transaction, error)); ok { + return rf(client, opts, tolerance, power, aggregationMethod, jobIDs, name) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, int8, uint32, []uint16, string) *types.Transaction); ok { r0 = rf(client, opts, tolerance, power, aggregationMethod, jobIDs, name) } else { @@ -30,7 +34,6 @@ func (_m *AssetManagerInterface) CreateCollection(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, int8, uint32, []uint16, string) error); ok { r1 = rf(client, opts, tolerance, power, aggregationMethod, jobIDs, name) } else { @@ -45,6 +48,10 @@ func (_m *AssetManagerInterface) CreateJob(client *ethclient.Client, opts *bind. ret := _m.Called(client, opts, weight, power, selectorType, name, selector, url) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint8, int8, uint8, string, string, string) (*types.Transaction, error)); ok { + return rf(client, opts, weight, power, selectorType, name, selector, url) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint8, int8, uint8, string, string, string) *types.Transaction); ok { r0 = rf(client, opts, weight, power, selectorType, name, selector, url) } else { @@ -53,7 +60,6 @@ func (_m *AssetManagerInterface) CreateJob(client *ethclient.Client, opts *bind. } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint8, int8, uint8, string, string, string) error); ok { r1 = rf(client, opts, weight, power, selectorType, name, selector, url) } else { @@ -68,13 +74,16 @@ func (_m *AssetManagerInterface) GetActiveStatus(client *ethclient.Client, opts ret := _m.Called(client, opts, id) var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint16) (bool, error)); ok { + return rf(client, opts, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint16) bool); ok { r0 = rf(client, opts, id) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, uint16) error); ok { r1 = rf(client, opts, id) } else { @@ -89,6 +98,10 @@ func (_m *AssetManagerInterface) SetCollectionStatus(client *ethclient.Client, o ret := _m.Called(client, opts, assetStatus, id) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, bool, uint16) (*types.Transaction, error)); ok { + return rf(client, opts, assetStatus, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, bool, uint16) *types.Transaction); ok { r0 = rf(client, opts, assetStatus, id) } else { @@ -97,7 +110,6 @@ func (_m *AssetManagerInterface) SetCollectionStatus(client *ethclient.Client, o } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, bool, uint16) error); ok { r1 = rf(client, opts, assetStatus, id) } else { @@ -112,6 +124,10 @@ func (_m *AssetManagerInterface) UpdateCollection(client *ethclient.Client, opts ret := _m.Called(client, opts, collectionId, tolerance, aggregationMethod, power, jobIds) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint32, uint32, int8, []uint16) (*types.Transaction, error)); ok { + return rf(client, opts, collectionId, tolerance, aggregationMethod, power, jobIds) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint32, uint32, int8, []uint16) *types.Transaction); ok { r0 = rf(client, opts, collectionId, tolerance, aggregationMethod, power, jobIds) } else { @@ -120,7 +136,6 @@ func (_m *AssetManagerInterface) UpdateCollection(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint32, uint32, int8, []uint16) error); ok { r1 = rf(client, opts, collectionId, tolerance, aggregationMethod, power, jobIds) } else { @@ -135,6 +150,10 @@ func (_m *AssetManagerInterface) UpdateJob(client *ethclient.Client, opts *bind. ret := _m.Called(client, opts, jobId, weight, power, selectorType, selector, url) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint8, int8, uint8, string, string) (*types.Transaction, error)); ok { + return rf(client, opts, jobId, weight, power, selectorType, selector, url) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint8, int8, uint8, string, string) *types.Transaction); ok { r0 = rf(client, opts, jobId, weight, power, selectorType, selector, url) } else { @@ -143,7 +162,6 @@ func (_m *AssetManagerInterface) UpdateJob(client *ethclient.Client, opts *bind. } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint16, uint8, int8, uint8, string, string) error); ok { r1 = rf(client, opts, jobId, weight, power, selectorType, selector, url) } else { @@ -153,13 +171,12 @@ func (_m *AssetManagerInterface) UpdateJob(client *ethclient.Client, opts *bind. return r0, r1 } -type mockConstructorTestingTNewAssetManagerInterface interface { +// NewAssetManagerInterface creates a new instance of AssetManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAssetManagerInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewAssetManagerInterface creates a new instance of AssetManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAssetManagerInterface(t mockConstructorTestingTNewAssetManagerInterface) *AssetManagerInterface { +}) *AssetManagerInterface { mock := &AssetManagerInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/block_manager_interface.go b/cmd/mocks/block_manager_interface.go index 37fc600a..cc630d8b 100644 --- a/cmd/mocks/block_manager_interface.go +++ b/cmd/mocks/block_manager_interface.go @@ -1,17 +1,12 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks import ( big "math/big" - bindings "razor/pkg/bindings" bind "github.com/ethereum/go-ethereum/accounts/abi/bind" - common "github.com/ethereum/go-ethereum/common" - - coretypes "razor/core/types" - ethclient "github.com/ethereum/go-ethereum/ethclient" mock "github.com/stretchr/testify/mock" @@ -29,6 +24,10 @@ func (_m *BlockManagerInterface) ClaimBlockReward(client *ethclient.Client, opts ret := _m.Called(client, opts) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts) (*types.Transaction, error)); ok { + return rf(client, opts) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts) *types.Transaction); ok { r0 = rf(client, opts) } else { @@ -37,7 +36,6 @@ func (_m *BlockManagerInterface) ClaimBlockReward(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts) error); ok { r1 = rf(client, opts) } else { @@ -52,6 +50,10 @@ func (_m *BlockManagerInterface) DisputeBiggestStakeProposed(client *ethclient.C ret := _m.Called(client, opts, epoch, blockIndex, correctBiggestStakerId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, blockIndex, correctBiggestStakerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint32) *types.Transaction); ok { r0 = rf(client, opts, epoch, blockIndex, correctBiggestStakerId) } else { @@ -60,7 +62,6 @@ func (_m *BlockManagerInterface) DisputeBiggestStakeProposed(client *ethclient.C } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint32) error); ok { r1 = rf(client, opts, epoch, blockIndex, correctBiggestStakerId) } else { @@ -75,6 +76,10 @@ func (_m *BlockManagerInterface) DisputeCollectionIdShouldBeAbsent(client *ethcl ret := _m.Called(client, opts, epoch, blockIndex, id, positionOfCollectionInBlock) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, blockIndex, id, positionOfCollectionInBlock) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, epoch, blockIndex, id, positionOfCollectionInBlock) } else { @@ -83,7 +88,6 @@ func (_m *BlockManagerInterface) DisputeCollectionIdShouldBeAbsent(client *ethcl } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16, *big.Int) error); ok { r1 = rf(client, opts, epoch, blockIndex, id, positionOfCollectionInBlock) } else { @@ -98,6 +102,10 @@ func (_m *BlockManagerInterface) DisputeCollectionIdShouldBePresent(client *ethc ret := _m.Called(client, opts, epoch, blockIndex, id) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, blockIndex, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16) *types.Transaction); ok { r0 = rf(client, opts, epoch, blockIndex, id) } else { @@ -106,7 +114,6 @@ func (_m *BlockManagerInterface) DisputeCollectionIdShouldBePresent(client *ethc } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, uint16) error); ok { r1 = rf(client, opts, epoch, blockIndex, id) } else { @@ -121,6 +128,10 @@ func (_m *BlockManagerInterface) DisputeOnOrderOfIds(client *ethclient.Client, o ret := _m.Called(client, opts, epoch, blockIndex, index0, index1) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, blockIndex, index0, index1) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, epoch, blockIndex, index0, index1) } else { @@ -129,7 +140,6 @@ func (_m *BlockManagerInterface) DisputeOnOrderOfIds(client *ethclient.Client, o } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int, *big.Int) error); ok { r1 = rf(client, opts, epoch, blockIndex, index0, index1) } else { @@ -139,32 +149,15 @@ func (_m *BlockManagerInterface) DisputeOnOrderOfIds(client *ethclient.Client, o return r0, r1 } -// Disputes provides a mock function with given fields: client, opts, epoch, address -func (_m *BlockManagerInterface) Disputes(client *ethclient.Client, opts *bind.CallOpts, epoch uint32, address common.Address) (coretypes.DisputesStruct, error) { - ret := _m.Called(client, opts, epoch, address) - - var r0 coretypes.DisputesStruct - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint32, common.Address) coretypes.DisputesStruct); ok { - r0 = rf(client, opts, epoch, address) - } else { - r0 = ret.Get(0).(coretypes.DisputesStruct) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, uint32, common.Address) error); ok { - r1 = rf(client, opts, epoch, address) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // FinalizeDispute provides a mock function with given fields: client, opts, epoch, blockIndex, positionOfCollectionInBlock func (_m *BlockManagerInterface) FinalizeDispute(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, blockIndex uint8, positionOfCollectionInBlock *big.Int) (*types.Transaction, error) { ret := _m.Called(client, opts, epoch, blockIndex, positionOfCollectionInBlock) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, blockIndex, positionOfCollectionInBlock) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, epoch, blockIndex, positionOfCollectionInBlock) } else { @@ -173,7 +166,6 @@ func (_m *BlockManagerInterface) FinalizeDispute(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint8, *big.Int) error); ok { r1 = rf(client, opts, epoch, blockIndex, positionOfCollectionInBlock) } else { @@ -183,22 +175,25 @@ func (_m *BlockManagerInterface) FinalizeDispute(client *ethclient.Client, opts return r0, r1 } -// GiveSorted provides a mock function with given fields: blockManager, opts, epoch, leafId, sortedValues -func (_m *BlockManagerInterface) GiveSorted(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*types.Transaction, error) { - ret := _m.Called(blockManager, opts, epoch, leafId, sortedValues) +// GiveSorted provides a mock function with given fields: client, opts, epoch, leafId, sortedValues +func (_m *BlockManagerInterface) GiveSorted(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*types.Transaction, error) { + ret := _m.Called(client, opts, epoch, leafId, sortedValues) var r0 *types.Transaction - if rf, ok := ret.Get(0).(func(*bindings.BlockManager, *bind.TransactOpts, uint32, uint16, []*big.Int) *types.Transaction); ok { - r0 = rf(blockManager, opts, epoch, leafId, sortedValues) + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint16, []*big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, leafId, sortedValues) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint16, []*big.Int) *types.Transaction); ok { + r0 = rf(client, opts, epoch, leafId, sortedValues) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.Transaction) } } - var r1 error - if rf, ok := ret.Get(1).(func(*bindings.BlockManager, *bind.TransactOpts, uint32, uint16, []*big.Int) error); ok { - r1 = rf(blockManager, opts, epoch, leafId, sortedValues) + if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, uint16, []*big.Int) error); ok { + r1 = rf(client, opts, epoch, leafId, sortedValues) } else { r1 = ret.Error(1) } @@ -211,6 +206,10 @@ func (_m *BlockManagerInterface) Propose(client *ethclient.Client, opts *bind.Tr ret := _m.Called(client, opts, epoch, ids, medians, iteration, biggestInfluencerId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, []uint16, []*big.Int, *big.Int, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, epoch, ids, medians, iteration, biggestInfluencerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, []uint16, []*big.Int, *big.Int, uint32) *types.Transaction); ok { r0 = rf(client, opts, epoch, ids, medians, iteration, biggestInfluencerId) } else { @@ -219,7 +218,6 @@ func (_m *BlockManagerInterface) Propose(client *ethclient.Client, opts *bind.Tr } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, []uint16, []*big.Int, *big.Int, uint32) error); ok { r1 = rf(client, opts, epoch, ids, medians, iteration, biggestInfluencerId) } else { @@ -229,22 +227,25 @@ func (_m *BlockManagerInterface) Propose(client *ethclient.Client, opts *bind.Tr return r0, r1 } -// ResetDispute provides a mock function with given fields: blockManager, opts, epoch -func (_m *BlockManagerInterface) ResetDispute(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32) (*types.Transaction, error) { - ret := _m.Called(blockManager, opts, epoch) +// ResetDispute provides a mock function with given fields: client, opts, epoch +func (_m *BlockManagerInterface) ResetDispute(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32) (*types.Transaction, error) { + ret := _m.Called(client, opts, epoch) var r0 *types.Transaction - if rf, ok := ret.Get(0).(func(*bindings.BlockManager, *bind.TransactOpts, uint32) *types.Transaction); ok { - r0 = rf(blockManager, opts, epoch) + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, epoch) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) *types.Transaction); ok { + r0 = rf(client, opts, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.Transaction) } } - var r1 error - if rf, ok := ret.Get(1).(func(*bindings.BlockManager, *bind.TransactOpts, uint32) error); ok { - r1 = rf(blockManager, opts, epoch) + if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { + r1 = rf(client, opts, epoch) } else { r1 = ret.Error(1) } @@ -252,13 +253,12 @@ func (_m *BlockManagerInterface) ResetDispute(blockManager *bindings.BlockManage return r0, r1 } -type mockConstructorTestingTNewBlockManagerInterface interface { +// NewBlockManagerInterface creates a new instance of BlockManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBlockManagerInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewBlockManagerInterface creates a new instance of BlockManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBlockManagerInterface(t mockConstructorTestingTNewBlockManagerInterface) *BlockManagerInterface { +}) *BlockManagerInterface { mock := &BlockManagerInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/crypto_interface.go b/cmd/mocks/crypto_interface.go index 386334ac..f842d91c 100644 --- a/cmd/mocks/crypto_interface.go +++ b/cmd/mocks/crypto_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ func (_m *CryptoInterface) HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error) ret := _m.Called(hexKey) var r0 *ecdsa.PrivateKey + var r1 error + if rf, ok := ret.Get(0).(func(string) (*ecdsa.PrivateKey, error)); ok { + return rf(hexKey) + } if rf, ok := ret.Get(0).(func(string) *ecdsa.PrivateKey); ok { r0 = rf(hexKey) } else { @@ -26,7 +30,6 @@ func (_m *CryptoInterface) HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error) } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(hexKey) } else { @@ -36,13 +39,12 @@ func (_m *CryptoInterface) HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error) return r0, r1 } -type mockConstructorTestingTNewCryptoInterface interface { +// NewCryptoInterface creates a new instance of CryptoInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewCryptoInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewCryptoInterface creates a new instance of CryptoInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewCryptoInterface(t mockConstructorTestingTNewCryptoInterface) *CryptoInterface { +}) *CryptoInterface { mock := &CryptoInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/flag_set_interface.go b/cmd/mocks/flag_set_interface.go index e8615962..3fd59dad 100644 --- a/cmd/mocks/flag_set_interface.go +++ b/cmd/mocks/flag_set_interface.go @@ -792,4 +792,4 @@ func NewFlagSetInterface(t interface { t.Cleanup(func() { mock.AssertExpectations(t) }) return mock -} \ No newline at end of file +} diff --git a/cmd/mocks/keystore_interface.go b/cmd/mocks/keystore_interface.go index b987385a..8261cead 100644 --- a/cmd/mocks/keystore_interface.go +++ b/cmd/mocks/keystore_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -36,13 +36,16 @@ func (_m *KeystoreInterface) ImportECDSA(path string, priv *ecdsa.PrivateKey, pa ret := _m.Called(path, priv, passphrase) var r0 accounts.Account + var r1 error + if rf, ok := ret.Get(0).(func(string, *ecdsa.PrivateKey, string) (accounts.Account, error)); ok { + return rf(path, priv, passphrase) + } if rf, ok := ret.Get(0).(func(string, *ecdsa.PrivateKey, string) accounts.Account); ok { r0 = rf(path, priv, passphrase) } else { r0 = ret.Get(0).(accounts.Account) } - var r1 error if rf, ok := ret.Get(1).(func(string, *ecdsa.PrivateKey, string) error); ok { r1 = rf(path, priv, passphrase) } else { @@ -52,13 +55,12 @@ func (_m *KeystoreInterface) ImportECDSA(path string, priv *ecdsa.PrivateKey, pa return r0, r1 } -type mockConstructorTestingTNewKeystoreInterface interface { +// NewKeystoreInterface creates a new instance of KeystoreInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewKeystoreInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewKeystoreInterface creates a new instance of KeystoreInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewKeystoreInterface(t mockConstructorTestingTNewKeystoreInterface) *KeystoreInterface { +}) *KeystoreInterface { mock := &KeystoreInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/os_interface.go b/cmd/mocks/os_interface.go index 84b7d091..9a013ca0 100644 --- a/cmd/mocks/os_interface.go +++ b/cmd/mocks/os_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -14,13 +14,12 @@ func (_m *OSInterface) Exit(code int) { _m.Called(code) } -type mockConstructorTestingTNewOSInterface interface { +// NewOSInterface creates a new instance of OSInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewOSInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewOSInterface creates a new instance of OSInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewOSInterface(t mockConstructorTestingTNewOSInterface) *OSInterface { +}) *OSInterface { mock := &OSInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/stake_manager_interface.go b/cmd/mocks/stake_manager_interface.go index f0661906..aaf25e31 100644 --- a/cmd/mocks/stake_manager_interface.go +++ b/cmd/mocks/stake_manager_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -9,8 +9,6 @@ import ( common "github.com/ethereum/go-ethereum/common" - coretypes "razor/core/types" - ethclient "github.com/ethereum/go-ethereum/ethclient" mock "github.com/stretchr/testify/mock" @@ -28,6 +26,10 @@ func (_m *StakeManagerInterface) ApproveUnstake(client *ethclient.Client, opts * ret := _m.Called(client, opts, stakerTokenAddress, amount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, stakerTokenAddress, amount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, stakerTokenAddress, amount) } else { @@ -36,7 +38,6 @@ func (_m *StakeManagerInterface) ApproveUnstake(client *ethclient.Client, opts * } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) error); ok { r1 = rf(client, opts, stakerTokenAddress, amount) } else { @@ -51,6 +52,10 @@ func (_m *StakeManagerInterface) ClaimStakerReward(client *ethclient.Client, opt ret := _m.Called(client, opts) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts) (*types.Transaction, error)); ok { + return rf(client, opts) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts) *types.Transaction); ok { r0 = rf(client, opts) } else { @@ -59,7 +64,6 @@ func (_m *StakeManagerInterface) ClaimStakerReward(client *ethclient.Client, opt } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts) error); ok { r1 = rf(client, opts) } else { @@ -74,6 +78,10 @@ func (_m *StakeManagerInterface) Delegate(client *ethclient.Client, opts *bind.T ret := _m.Called(client, opts, stakerId, amount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, stakerId, amount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, stakerId, amount) } else { @@ -82,7 +90,6 @@ func (_m *StakeManagerInterface) Delegate(client *ethclient.Client, opts *bind.T } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) error); ok { r1 = rf(client, opts, stakerId, amount) } else { @@ -92,53 +99,15 @@ func (_m *StakeManagerInterface) Delegate(client *ethclient.Client, opts *bind.T return r0, r1 } -// GetBountyLock provides a mock function with given fields: client, opts, bountyId -func (_m *StakeManagerInterface) GetBountyLock(client *ethclient.Client, opts *bind.CallOpts, bountyId uint32) (coretypes.BountyLock, error) { - ret := _m.Called(client, opts, bountyId) - - var r0 coretypes.BountyLock - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint32) coretypes.BountyLock); ok { - r0 = rf(client, opts, bountyId) - } else { - r0 = ret.Get(0).(coretypes.BountyLock) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, uint32) error); ok { - r1 = rf(client, opts, bountyId) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// GetMaturity provides a mock function with given fields: client, opts, age -func (_m *StakeManagerInterface) GetMaturity(client *ethclient.Client, opts *bind.CallOpts, age uint32) (uint16, error) { - ret := _m.Called(client, opts, age) - - var r0 uint16 - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint32) uint16); ok { - r0 = rf(client, opts, age) - } else { - r0 = ret.Get(0).(uint16) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, uint32) error); ok { - r1 = rf(client, opts, age) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // InitiateWithdraw provides a mock function with given fields: client, opts, stakerId func (_m *StakeManagerInterface) InitiateWithdraw(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32) (*types.Transaction, error) { ret := _m.Called(client, opts, stakerId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, stakerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) *types.Transaction); ok { r0 = rf(client, opts, stakerId) } else { @@ -147,7 +116,6 @@ func (_m *StakeManagerInterface) InitiateWithdraw(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { r1 = rf(client, opts, stakerId) } else { @@ -162,6 +130,10 @@ func (_m *StakeManagerInterface) RedeemBounty(client *ethclient.Client, opts *bi ret := _m.Called(client, opts, bountyId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, bountyId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) *types.Transaction); ok { r0 = rf(client, opts, bountyId) } else { @@ -170,7 +142,6 @@ func (_m *StakeManagerInterface) RedeemBounty(client *ethclient.Client, opts *bi } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { r1 = rf(client, opts, bountyId) } else { @@ -185,6 +156,10 @@ func (_m *StakeManagerInterface) ResetUnstakeLock(client *ethclient.Client, opts ret := _m.Called(client, opts, stakerId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, stakerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) *types.Transaction); ok { r0 = rf(client, opts, stakerId) } else { @@ -193,7 +168,6 @@ func (_m *StakeManagerInterface) ResetUnstakeLock(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { r1 = rf(client, opts, stakerId) } else { @@ -208,6 +182,10 @@ func (_m *StakeManagerInterface) SetDelegationAcceptance(client *ethclient.Clien ret := _m.Called(client, opts, status) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, bool) (*types.Transaction, error)); ok { + return rf(client, opts, status) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, bool) *types.Transaction); ok { r0 = rf(client, opts, status) } else { @@ -216,7 +194,6 @@ func (_m *StakeManagerInterface) SetDelegationAcceptance(client *ethclient.Clien } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, bool) error); ok { r1 = rf(client, opts, status) } else { @@ -231,6 +208,10 @@ func (_m *StakeManagerInterface) Stake(client *ethclient.Client, txnOpts *bind.T ret := _m.Called(client, txnOpts, epoch, amount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) (*types.Transaction, error)); ok { + return rf(client, txnOpts, epoch, amount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) *types.Transaction); ok { r0 = rf(client, txnOpts, epoch, amount) } else { @@ -239,7 +220,6 @@ func (_m *StakeManagerInterface) Stake(client *ethclient.Client, txnOpts *bind.T } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) error); ok { r1 = rf(client, txnOpts, epoch, amount) } else { @@ -249,32 +229,15 @@ func (_m *StakeManagerInterface) Stake(client *ethclient.Client, txnOpts *bind.T return r0, r1 } -// StakerInfo provides a mock function with given fields: client, opts, stakerId -func (_m *StakeManagerInterface) StakerInfo(client *ethclient.Client, opts *bind.CallOpts, stakerId uint32) (coretypes.Staker, error) { - ret := _m.Called(client, opts, stakerId) - - var r0 coretypes.Staker - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, uint32) coretypes.Staker); ok { - r0 = rf(client, opts, stakerId) - } else { - r0 = ret.Get(0).(coretypes.Staker) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, uint32) error); ok { - r1 = rf(client, opts, stakerId) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // UnlockWithdraw provides a mock function with given fields: client, opts, stakerId func (_m *StakeManagerInterface) UnlockWithdraw(client *ethclient.Client, opts *bind.TransactOpts, stakerId uint32) (*types.Transaction, error) { ret := _m.Called(client, opts, stakerId) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (*types.Transaction, error)); ok { + return rf(client, opts, stakerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) *types.Transaction); ok { r0 = rf(client, opts, stakerId) } else { @@ -283,7 +246,6 @@ func (_m *StakeManagerInterface) UnlockWithdraw(client *ethclient.Client, opts * } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { r1 = rf(client, opts, stakerId) } else { @@ -298,6 +260,10 @@ func (_m *StakeManagerInterface) Unstake(client *ethclient.Client, opts *bind.Tr ret := _m.Called(client, opts, stakerId, sAmount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, stakerId, sAmount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, stakerId, sAmount) } else { @@ -306,7 +272,6 @@ func (_m *StakeManagerInterface) Unstake(client *ethclient.Client, opts *bind.Tr } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, *big.Int) error); ok { r1 = rf(client, opts, stakerId, sAmount) } else { @@ -321,6 +286,10 @@ func (_m *StakeManagerInterface) UpdateCommission(client *ethclient.Client, opts ret := _m.Called(client, opts, commission) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint8) (*types.Transaction, error)); ok { + return rf(client, opts, commission) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint8) *types.Transaction); ok { r0 = rf(client, opts, commission) } else { @@ -329,7 +298,6 @@ func (_m *StakeManagerInterface) UpdateCommission(client *ethclient.Client, opts } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint8) error); ok { r1 = rf(client, opts, commission) } else { @@ -339,13 +307,12 @@ func (_m *StakeManagerInterface) UpdateCommission(client *ethclient.Client, opts return r0, r1 } -type mockConstructorTestingTNewStakeManagerInterface interface { +// NewStakeManagerInterface creates a new instance of StakeManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStakeManagerInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewStakeManagerInterface creates a new instance of StakeManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStakeManagerInterface(t mockConstructorTestingTNewStakeManagerInterface) *StakeManagerInterface { +}) *StakeManagerInterface { mock := &StakeManagerInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/string_interface.go b/cmd/mocks/string_interface.go index de733d7a..2eb16556 100644 --- a/cmd/mocks/string_interface.go +++ b/cmd/mocks/string_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -14,13 +14,16 @@ func (_m *StringInterface) ParseBool(str string) (bool, error) { ret := _m.Called(str) var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { + return rf(str) + } if rf, ok := ret.Get(0).(func(string) bool); ok { r0 = rf(str) } else { r0 = ret.Get(0).(bool) } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(str) } else { @@ -30,13 +33,12 @@ func (_m *StringInterface) ParseBool(str string) (bool, error) { return r0, r1 } -type mockConstructorTestingTNewStringInterface interface { +// NewStringInterface creates a new instance of StringInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStringInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewStringInterface creates a new instance of StringInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStringInterface(t mockConstructorTestingTNewStringInterface) *StringInterface { +}) *StringInterface { mock := &StringInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/time_interface.go b/cmd/mocks/time_interface.go index 7e3a8ca9..d1b6858a 100644 --- a/cmd/mocks/time_interface.go +++ b/cmd/mocks/time_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,13 +18,12 @@ func (_m *TimeInterface) Sleep(duration time.Duration) { _m.Called(duration) } -type mockConstructorTestingTNewTimeInterface interface { +// NewTimeInterface creates a new instance of TimeInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTimeInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewTimeInterface creates a new instance of TimeInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTimeInterface(t mockConstructorTestingTNewTimeInterface) *TimeInterface { +}) *TimeInterface { mock := &TimeInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/token_manager_interface.go b/cmd/mocks/token_manager_interface.go index c5f94686..7bbc2ba6 100644 --- a/cmd/mocks/token_manager_interface.go +++ b/cmd/mocks/token_manager_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -21,34 +21,15 @@ type TokenManagerInterface struct { mock.Mock } -// Allowance provides a mock function with given fields: client, opts, owner, spender -func (_m *TokenManagerInterface) Allowance(client *ethclient.Client, opts *bind.CallOpts, owner common.Address, spender common.Address) (*big.Int, error) { - ret := _m.Called(client, opts, owner, spender) - - var r0 *big.Int - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.CallOpts, common.Address, common.Address) *big.Int); ok { - r0 = rf(client, opts, owner, spender) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.CallOpts, common.Address, common.Address) error); ok { - r1 = rf(client, opts, owner, spender) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // Approve provides a mock function with given fields: client, opts, spender, amount func (_m *TokenManagerInterface) Approve(client *ethclient.Client, opts *bind.TransactOpts, spender common.Address, amount *big.Int) (*types.Transaction, error) { ret := _m.Called(client, opts, spender, amount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, spender, amount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, spender, amount) } else { @@ -57,7 +38,6 @@ func (_m *TokenManagerInterface) Approve(client *ethclient.Client, opts *bind.Tr } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) error); ok { r1 = rf(client, opts, spender, amount) } else { @@ -72,6 +52,10 @@ func (_m *TokenManagerInterface) Transfer(client *ethclient.Client, opts *bind.T ret := _m.Called(client, opts, recipient, amount) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) (*types.Transaction, error)); ok { + return rf(client, opts, recipient, amount) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) *types.Transaction); ok { r0 = rf(client, opts, recipient, amount) } else { @@ -80,7 +64,6 @@ func (_m *TokenManagerInterface) Transfer(client *ethclient.Client, opts *bind.T } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, common.Address, *big.Int) error); ok { r1 = rf(client, opts, recipient, amount) } else { @@ -90,13 +73,12 @@ func (_m *TokenManagerInterface) Transfer(client *ethclient.Client, opts *bind.T return r0, r1 } -type mockConstructorTestingTNewTokenManagerInterface interface { +// NewTokenManagerInterface creates a new instance of TokenManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTokenManagerInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewTokenManagerInterface creates a new instance of TokenManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTokenManagerInterface(t mockConstructorTestingTNewTokenManagerInterface) *TokenManagerInterface { +}) *TokenManagerInterface { mock := &TokenManagerInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/transaction_interface.go b/cmd/mocks/transaction_interface.go index 9255cd7b..c3bd72ea 100644 --- a/cmd/mocks/transaction_interface.go +++ b/cmd/mocks/transaction_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -30,13 +30,12 @@ func (_m *TransactionInterface) Hash(txn *types.Transaction) common.Hash { return r0 } -type mockConstructorTestingTNewTransactionInterface interface { +// NewTransactionInterface creates a new instance of TransactionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTransactionInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewTransactionInterface creates a new instance of TransactionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTransactionInterface(t mockConstructorTestingTNewTransactionInterface) *TransactionInterface { +}) *TransactionInterface { mock := &TransactionInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/utils_cmd_interface.go b/cmd/mocks/utils_cmd_interface.go index 5827ad67..4ff44071 100644 --- a/cmd/mocks/utils_cmd_interface.go +++ b/cmd/mocks/utils_cmd_interface.go @@ -4,6 +4,7 @@ package mocks import ( big "math/big" + RPC "razor/RPC" accounts "github.com/ethereum/go-ethereum/accounts" @@ -15,12 +16,8 @@ import ( common "github.com/ethereum/go-ethereum/common" - context "context" - coretypes "github.com/ethereum/go-ethereum/core/types" - ethclient "github.com/ethereum/go-ethereum/ethclient" - mock "github.com/stretchr/testify/mock" pflag "github.com/spf13/pflag" @@ -33,25 +30,25 @@ type UtilsCmdInterface struct { mock.Mock } -// Approve provides a mock function with given fields: txnArgs -func (_m *UtilsCmdInterface) Approve(txnArgs types.TransactionOptions) (common.Hash, error) { - ret := _m.Called(txnArgs) +// Approve provides a mock function with given fields: rpcParameters, txnArgs +func (_m *UtilsCmdInterface) Approve(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) { + ret := _m.Called(rpcParameters, txnArgs) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(types.TransactionOptions) (common.Hash, error)); ok { - return rf(txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) (common.Hash, error)); ok { + return rf(rpcParameters, txnArgs) } - if rf, ok := ret.Get(0).(func(types.TransactionOptions) common.Hash); ok { - r0 = rf(txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) common.Hash); ok { + r0 = rf(rpcParameters, txnArgs) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(types.TransactionOptions) error); ok { - r1 = rf(txnArgs) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions) error); ok { + r1 = rf(rpcParameters, txnArgs) } else { r1 = ret.Error(1) } @@ -59,25 +56,25 @@ func (_m *UtilsCmdInterface) Approve(txnArgs types.TransactionOptions) (common.H return r0, r1 } -// ApproveUnstake provides a mock function with given fields: client, stakerTokenAddress, txnArgs -func (_m *UtilsCmdInterface) ApproveUnstake(client *ethclient.Client, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) { - ret := _m.Called(client, stakerTokenAddress, txnArgs) +// ApproveUnstake provides a mock function with given fields: rpcParameters, stakerTokenAddress, txnArgs +func (_m *UtilsCmdInterface) ApproveUnstake(rpcParameters RPC.RPCParameters, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) { + ret := _m.Called(rpcParameters, stakerTokenAddress, txnArgs) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, types.TransactionOptions) (common.Hash, error)); ok { - return rf(client, stakerTokenAddress, txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address, types.TransactionOptions) (common.Hash, error)); ok { + return rf(rpcParameters, stakerTokenAddress, txnArgs) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, types.TransactionOptions) common.Hash); ok { - r0 = rf(client, stakerTokenAddress, txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address, types.TransactionOptions) common.Hash); ok { + r0 = rf(rpcParameters, stakerTokenAddress, txnArgs) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address, types.TransactionOptions) error); ok { - r1 = rf(client, stakerTokenAddress, txnArgs) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, common.Address, types.TransactionOptions) error); ok { + r1 = rf(rpcParameters, stakerTokenAddress, txnArgs) } else { r1 = ret.Error(1) } @@ -111,25 +108,25 @@ func (_m *UtilsCmdInterface) AssignAmountInWei(flagSet *pflag.FlagSet) (*big.Int return r0, r1 } -// BatchGetStakeSnapshotCalls provides a mock function with given fields: client, epoch, numberOfStakers -func (_m *UtilsCmdInterface) BatchGetStakeSnapshotCalls(client *ethclient.Client, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) { - ret := _m.Called(client, epoch, numberOfStakers) +// BatchGetStakeSnapshotCalls provides a mock function with given fields: rpcParameters, epoch, numberOfStakers +func (_m *UtilsCmdInterface) BatchGetStakeSnapshotCalls(rpcParameters RPC.RPCParameters, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) { + ret := _m.Called(rpcParameters, epoch, numberOfStakers) var r0 []*big.Int var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32, uint32) ([]*big.Int, error)); ok { - return rf(client, epoch, numberOfStakers) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) ([]*big.Int, error)); ok { + return rf(rpcParameters, epoch, numberOfStakers) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32, uint32) []*big.Int); ok { - r0 = rf(client, epoch, numberOfStakers) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) []*big.Int); ok { + r0 = rf(rpcParameters, epoch, numberOfStakers) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*big.Int) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, uint32, uint32) error); ok { - r1 = rf(client, epoch, numberOfStakers) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint32) error); ok { + r1 = rf(rpcParameters, epoch, numberOfStakers) } else { r1 = ret.Error(1) } @@ -172,49 +169,25 @@ func (_m *UtilsCmdInterface) CalculateSecret(account types.Account, epoch uint32 return r0, r1, r2 } -// CheckCurrentStatus provides a mock function with given fields: client, collectionId -func (_m *UtilsCmdInterface) CheckCurrentStatus(client *ethclient.Client, collectionId uint16) (bool, error) { - ret := _m.Called(client, collectionId) - - var r0 bool - var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (bool, error)); ok { - return rf(client, collectionId) - } - if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) bool); ok { - r0 = rf(client, collectionId) - } else { - r0 = ret.Get(0).(bool) - } - - if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { - r1 = rf(client, collectionId) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// CheckDisputeForIds provides a mock function with given fields: ctx, client, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds -func (_m *UtilsCmdInterface) CheckDisputeForIds(ctx context.Context, client *ethclient.Client, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*coretypes.Transaction, error) { - ret := _m.Called(ctx, client, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) +// CheckDisputeForIds provides a mock function with given fields: rpcParameters, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds +func (_m *UtilsCmdInterface) CheckDisputeForIds(rpcParameters RPC.RPCParameters, transactionOpts types.TransactionOptions, epoch uint32, blockIndex uint8, idsInProposedBlock []uint16, revealedCollectionIds []uint16) (*coretypes.Transaction, error) { + ret := _m.Called(rpcParameters, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) var r0 *coretypes.Transaction var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.TransactionOptions, uint32, uint8, []uint16, []uint16) (*coretypes.Transaction, error)); ok { - return rf(ctx, client, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, uint32, uint8, []uint16, []uint16) (*coretypes.Transaction, error)); ok { + return rf(rpcParameters, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.TransactionOptions, uint32, uint8, []uint16, []uint16) *coretypes.Transaction); ok { - r0 = rf(ctx, client, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, uint32, uint8, []uint16, []uint16) *coretypes.Transaction); ok { + r0 = rf(rpcParameters, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*coretypes.Transaction) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.TransactionOptions, uint32, uint8, []uint16, []uint16) error); ok { - r1 = rf(ctx, client, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions, uint32, uint8, []uint16, []uint16) error); ok { + r1 = rf(rpcParameters, transactionOpts, epoch, blockIndex, idsInProposedBlock, revealedCollectionIds) } else { r1 = ret.Error(1) } @@ -222,13 +195,13 @@ func (_m *UtilsCmdInterface) CheckDisputeForIds(ctx context.Context, client *eth return r0, r1 } -// CheckForLastCommitted provides a mock function with given fields: ctx, client, staker, epoch -func (_m *UtilsCmdInterface) CheckForLastCommitted(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker, epoch uint32) error { - ret := _m.Called(ctx, client, staker, epoch) +// CheckForLastCommitted provides a mock function with given fields: rpcParameters, staker, epoch +func (_m *UtilsCmdInterface) CheckForLastCommitted(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker, epoch uint32) error { + ret := _m.Called(rpcParameters, staker, epoch) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, bindings.StructsStaker, uint32) error); ok { - r0 = rf(ctx, client, staker, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, bindings.StructsStaker, uint32) error); ok { + r0 = rf(rpcParameters, staker, epoch) } else { r0 = ret.Error(0) } @@ -236,30 +209,30 @@ func (_m *UtilsCmdInterface) CheckForLastCommitted(ctx context.Context, client * return r0 } -// CheckToDoResetDispute provides a mock function with given fields: client, blockManager, txnOpts, epoch, sortedValues -func (_m *UtilsCmdInterface) CheckToDoResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) { - _m.Called(client, blockManager, txnOpts, epoch, sortedValues) +// CheckToDoResetDispute provides a mock function with given fields: rpcParameters, txnOpts, epoch, sortedValues +func (_m *UtilsCmdInterface) CheckToDoResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32, sortedValues []*big.Int) { + _m.Called(rpcParameters, txnOpts, epoch, sortedValues) } -// ClaimBlockReward provides a mock function with given fields: ctx, options -func (_m *UtilsCmdInterface) ClaimBlockReward(ctx context.Context, options types.TransactionOptions) (common.Hash, error) { - ret := _m.Called(ctx, options) +// ClaimBlockReward provides a mock function with given fields: rpcParameters, options +func (_m *UtilsCmdInterface) ClaimBlockReward(rpcParameters RPC.RPCParameters, options types.TransactionOptions) (common.Hash, error) { + ret := _m.Called(rpcParameters, options) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.TransactionOptions) (common.Hash, error)); ok { - return rf(ctx, options) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) (common.Hash, error)); ok { + return rf(rpcParameters, options) } - if rf, ok := ret.Get(0).(func(context.Context, types.TransactionOptions) common.Hash); ok { - r0 = rf(ctx, options) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) common.Hash); ok { + r0 = rf(rpcParameters, options) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, types.TransactionOptions) error); ok { - r1 = rf(ctx, options) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions) error); ok { + r1 = rf(rpcParameters, options) } else { r1 = ret.Error(1) } @@ -267,25 +240,25 @@ func (_m *UtilsCmdInterface) ClaimBlockReward(ctx context.Context, options types return r0, r1 } -// ClaimBounty provides a mock function with given fields: config, client, redeemBountyInput -func (_m *UtilsCmdInterface) ClaimBounty(config types.Configurations, client *ethclient.Client, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) { - ret := _m.Called(config, client, redeemBountyInput) +// ClaimBounty provides a mock function with given fields: rpcParameters, config, redeemBountyInput +func (_m *UtilsCmdInterface) ClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, redeemBountyInput types.RedeemBountyInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, redeemBountyInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(types.Configurations, *ethclient.Client, types.RedeemBountyInput) (common.Hash, error)); ok { - return rf(config, client, redeemBountyInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.RedeemBountyInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, redeemBountyInput) } - if rf, ok := ret.Get(0).(func(types.Configurations, *ethclient.Client, types.RedeemBountyInput) common.Hash); ok { - r0 = rf(config, client, redeemBountyInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.RedeemBountyInput) common.Hash); ok { + r0 = rf(rpcParameters, config, redeemBountyInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(types.Configurations, *ethclient.Client, types.RedeemBountyInput) error); ok { - r1 = rf(config, client, redeemBountyInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.RedeemBountyInput) error); ok { + r1 = rf(rpcParameters, config, redeemBountyInput) } else { r1 = ret.Error(1) } @@ -298,25 +271,25 @@ func (_m *UtilsCmdInterface) ClaimCommission(flagSet *pflag.FlagSet) { _m.Called(flagSet) } -// Commit provides a mock function with given fields: ctx, client, config, account, epoch, latestHeader, stateBuffer, commitment -func (_m *UtilsCmdInterface) Commit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, commitment [32]byte) (common.Hash, error) { - ret := _m.Called(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitment) +// Commit provides a mock function with given fields: rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitment +func (_m *UtilsCmdInterface) Commit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, commitment [32]byte) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitment) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) (common.Hash, error)); ok { - return rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitment) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) (common.Hash, error)); ok { + return rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitment) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) common.Hash); ok { - r0 = rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitment) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) common.Hash); ok { + r0 = rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitment) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) error); ok { - r1 = rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitment) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, [32]byte) error); ok { + r1 = rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitment) } else { r1 = ret.Error(1) } @@ -353,25 +326,25 @@ func (_m *UtilsCmdInterface) Create(password string) (accounts.Account, error) { return r0, r1 } -// CreateCollection provides a mock function with given fields: client, config, collectionInput -func (_m *UtilsCmdInterface) CreateCollection(client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) { - ret := _m.Called(client, config, collectionInput) +// CreateCollection provides a mock function with given fields: rpcParameters, config, collectionInput +func (_m *UtilsCmdInterface) CreateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, collectionInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.CreateCollectionInput) (common.Hash, error)); ok { - return rf(client, config, collectionInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, collectionInput) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.CreateCollectionInput) common.Hash); ok { - r0 = rf(client, config, collectionInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput) common.Hash); ok { + r0 = rf(rpcParameters, config, collectionInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, types.Configurations, types.CreateCollectionInput) error); ok { - r1 = rf(client, config, collectionInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput) error); ok { + r1 = rf(rpcParameters, config, collectionInput) } else { r1 = ret.Error(1) } @@ -379,25 +352,25 @@ func (_m *UtilsCmdInterface) CreateCollection(client *ethclient.Client, config t return r0, r1 } -// CreateJob provides a mock function with given fields: client, config, jobInput -func (_m *UtilsCmdInterface) CreateJob(client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) { - ret := _m.Called(client, config, jobInput) +// CreateJob provides a mock function with given fields: rpcParameter, config, jobInput +func (_m *UtilsCmdInterface) CreateJob(rpcParameter RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput) (common.Hash, error) { + ret := _m.Called(rpcParameter, config, jobInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.CreateJobInput) (common.Hash, error)); ok { - return rf(client, config, jobInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput) (common.Hash, error)); ok { + return rf(rpcParameter, config, jobInput) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.CreateJobInput) common.Hash); ok { - r0 = rf(client, config, jobInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput) common.Hash); ok { + r0 = rf(rpcParameter, config, jobInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, types.Configurations, types.CreateJobInput) error); ok { - r1 = rf(client, config, jobInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput) error); ok { + r1 = rf(rpcParameter, config, jobInput) } else { r1 = ret.Error(1) } @@ -405,25 +378,25 @@ func (_m *UtilsCmdInterface) CreateJob(client *ethclient.Client, config types.Co return r0, r1 } -// Delegate provides a mock function with given fields: txnArgs, stakerId -func (_m *UtilsCmdInterface) Delegate(txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) { - ret := _m.Called(txnArgs, stakerId) +// Delegate provides a mock function with given fields: rpcParameters, txnArgs, stakerId +func (_m *UtilsCmdInterface) Delegate(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, stakerId uint32) (common.Hash, error) { + ret := _m.Called(rpcParameters, txnArgs, stakerId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(types.TransactionOptions, uint32) (common.Hash, error)); ok { - return rf(txnArgs, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, uint32) (common.Hash, error)); ok { + return rf(rpcParameters, txnArgs, stakerId) } - if rf, ok := ret.Get(0).(func(types.TransactionOptions, uint32) common.Hash); ok { - r0 = rf(txnArgs, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, uint32) common.Hash); ok { + r0 = rf(rpcParameters, txnArgs, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(types.TransactionOptions, uint32) error); ok { - r1 = rf(txnArgs, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions, uint32) error); ok { + r1 = rf(rpcParameters, txnArgs, stakerId) } else { r1 = ret.Error(1) } @@ -431,13 +404,13 @@ func (_m *UtilsCmdInterface) Delegate(txnArgs types.TransactionOptions, stakerId return r0, r1 } -// Dispute provides a mock function with given fields: ctx, client, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues -func (_m *UtilsCmdInterface) Dispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error { - ret := _m.Called(ctx, client, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues) +// Dispute provides a mock function with given fields: rpcParameters, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues +func (_m *UtilsCmdInterface) Dispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockIndex uint8, proposedBlock bindings.StructsBlock, leafId uint16, sortedValues []*big.Int) error { + ret := _m.Called(rpcParameters, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, uint8, bindings.StructsBlock, uint16, []*big.Int) error); ok { - r0 = rf(ctx, client, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, uint8, bindings.StructsBlock, uint16, []*big.Int) error); ok { + r0 = rf(rpcParameters, config, account, epoch, blockIndex, proposedBlock, leafId, sortedValues) } else { r0 = ret.Error(0) } @@ -598,32 +571,32 @@ func (_m *UtilsCmdInterface) GetAlternateProvider() (string, error) { return r0, r1 } -// GetBiggestStakeAndId provides a mock function with given fields: ctx, client, epoch -func (_m *UtilsCmdInterface) GetBiggestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) { - ret := _m.Called(ctx, client, epoch) +// GetBiggestStakeAndId provides a mock function with given fields: rpcParameters, epoch +func (_m *UtilsCmdInterface) GetBiggestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) { + ret := _m.Called(rpcParameters, epoch) var r0 *big.Int var r1 uint32 var r2 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (*big.Int, uint32, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (*big.Int, uint32, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) *big.Int); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) *big.Int); ok { + r0 = rf(rpcParameters, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) uint32); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) uint32); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Get(1).(uint32) } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client, uint32) error); ok { - r2 = rf(ctx, client, epoch) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters, uint32) error); ok { + r2 = rf(rpcParameters, epoch) } else { r2 = ret.Error(2) } @@ -631,23 +604,23 @@ func (_m *UtilsCmdInterface) GetBiggestStakeAndId(ctx context.Context, client *e return r0, r1, r2 } -// GetBountyIdFromEvents provides a mock function with given fields: ctx, client, blockNumber, bountyHunter -func (_m *UtilsCmdInterface) GetBountyIdFromEvents(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, bountyHunter string) (uint32, error) { - ret := _m.Called(ctx, client, blockNumber, bountyHunter) +// GetBountyIdFromEvents provides a mock function with given fields: rpcParameters, blockNumber, bountyHunter +func (_m *UtilsCmdInterface) GetBountyIdFromEvents(rpcParameters RPC.RPCParameters, blockNumber *big.Int, bountyHunter string) (uint32, error) { + ret := _m.Called(rpcParameters, blockNumber, bountyHunter) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, string) (uint32, error)); ok { - return rf(ctx, client, blockNumber, bountyHunter) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, string) (uint32, error)); ok { + return rf(rpcParameters, blockNumber, bountyHunter) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, string) uint32); ok { - r0 = rf(ctx, client, blockNumber, bountyHunter) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, string) uint32); ok { + r0 = rf(rpcParameters, blockNumber, bountyHunter) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, *big.Int, string) error); ok { - r1 = rf(ctx, client, blockNumber, bountyHunter) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int, string) error); ok { + r1 = rf(rpcParameters, blockNumber, bountyHunter) } else { r1 = ret.Error(1) } @@ -679,13 +652,13 @@ func (_m *UtilsCmdInterface) GetBufferPercent() (int32, error) { return r0, r1 } -// GetCollectionIdPositionInBlock provides a mock function with given fields: ctx, client, leafId, proposedBlock -func (_m *UtilsCmdInterface) GetCollectionIdPositionInBlock(ctx context.Context, client *ethclient.Client, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int { - ret := _m.Called(ctx, client, leafId, proposedBlock) +// GetCollectionIdPositionInBlock provides a mock function with given fields: rpcParameters, leafId, proposedBlock +func (_m *UtilsCmdInterface) GetCollectionIdPositionInBlock(rpcParameters RPC.RPCParameters, leafId uint16, proposedBlock bindings.StructsBlock) *big.Int { + ret := _m.Called(rpcParameters, leafId, proposedBlock) var r0 *big.Int - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16, bindings.StructsBlock) *big.Int); ok { - r0 = rf(ctx, client, leafId, proposedBlock) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16, bindings.StructsBlock) *big.Int); ok { + r0 = rf(rpcParameters, leafId, proposedBlock) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) @@ -695,13 +668,13 @@ func (_m *UtilsCmdInterface) GetCollectionIdPositionInBlock(ctx context.Context, return r0 } -// GetCollectionList provides a mock function with given fields: client -func (_m *UtilsCmdInterface) GetCollectionList(client *ethclient.Client) error { - ret := _m.Called(client) +// GetCollectionList provides a mock function with given fields: rpcParameters +func (_m *UtilsCmdInterface) GetCollectionList(rpcParameters RPC.RPCParameters) error { + ret := _m.Called(rpcParameters) var r0 error - if rf, ok := ret.Get(0).(func(*ethclient.Client) error); ok { - r0 = rf(client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) error); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Error(0) } @@ -733,30 +706,30 @@ func (_m *UtilsCmdInterface) GetConfigData() (types.Configurations, error) { return r0, r1 } -// GetEpochAndState provides a mock function with given fields: ctx, client -func (_m *UtilsCmdInterface) GetEpochAndState(ctx context.Context, client *ethclient.Client) (uint32, int64, error) { - ret := _m.Called(ctx, client) +// GetEpochAndState provides a mock function with given fields: rpcParameter +func (_m *UtilsCmdInterface) GetEpochAndState(rpcParameter RPC.RPCParameters) (uint32, int64, error) { + ret := _m.Called(rpcParameter) var r0 uint32 var r1 int64 var r2 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint32, int64, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint32, int64, error)); ok { + return rf(rpcParameter) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint32); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint32); ok { + r0 = rf(rpcParameter) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) int64); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) int64); ok { + r1 = rf(rpcParameter) } else { r1 = ret.Get(1).(int64) } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client) error); ok { - r2 = rf(ctx, client) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters) error); ok { + r2 = rf(rpcParameter) } else { r2 = ret.Error(2) } @@ -860,13 +833,13 @@ func (_m *UtilsCmdInterface) GetHTTPTimeout() (int64, error) { return r0, r1 } -// GetIteration provides a mock function with given fields: ctx, client, proposer, bufferPercent -func (_m *UtilsCmdInterface) GetIteration(ctx context.Context, client *ethclient.Client, proposer types.ElectedProposer, bufferPercent int32) int { - ret := _m.Called(ctx, client, proposer, bufferPercent) +// GetIteration provides a mock function with given fields: rpcParameters, proposer, bufferPercent +func (_m *UtilsCmdInterface) GetIteration(rpcParameters RPC.RPCParameters, proposer types.ElectedProposer, bufferPercent int32) int { + ret := _m.Called(rpcParameters, proposer, bufferPercent) var r0 int - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.ElectedProposer, int32) int); ok { - r0 = rf(ctx, client, proposer, bufferPercent) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.ElectedProposer, int32) int); ok { + r0 = rf(rpcParameters, proposer, bufferPercent) } else { r0 = ret.Get(0).(int) } @@ -874,13 +847,13 @@ func (_m *UtilsCmdInterface) GetIteration(ctx context.Context, client *ethclient return r0 } -// GetJobList provides a mock function with given fields: client -func (_m *UtilsCmdInterface) GetJobList(client *ethclient.Client) error { - ret := _m.Called(client) +// GetJobList provides a mock function with given fields: rpcParameters +func (_m *UtilsCmdInterface) GetJobList(rpcParameters RPC.RPCParameters) error { + ret := _m.Called(rpcParameters) var r0 error - if rf, ok := ret.Get(0).(func(*ethclient.Client) error); ok { - r0 = rf(client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) error); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Error(0) } @@ -888,23 +861,23 @@ func (_m *UtilsCmdInterface) GetJobList(client *ethclient.Client) error { return r0 } -// GetLocalMediansData provides a mock function with given fields: ctx, client, account, epoch, blockNumber, rogueData -func (_m *UtilsCmdInterface) GetLocalMediansData(ctx context.Context, client *ethclient.Client, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) { - ret := _m.Called(ctx, client, account, epoch, blockNumber, rogueData) +// GetLocalMediansData provides a mock function with given fields: rpcParameters, account, epoch, blockNumber, rogueData +func (_m *UtilsCmdInterface) GetLocalMediansData(rpcParameters RPC.RPCParameters, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue) (types.ProposeFileData, error) { + ret := _m.Called(rpcParameters, account, epoch, blockNumber, rogueData) var r0 types.ProposeFileData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, uint32, *big.Int, types.Rogue) (types.ProposeFileData, error)); ok { - return rf(ctx, client, account, epoch, blockNumber, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, uint32, *big.Int, types.Rogue) (types.ProposeFileData, error)); ok { + return rf(rpcParameters, account, epoch, blockNumber, rogueData) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, uint32, *big.Int, types.Rogue) types.ProposeFileData); ok { - r0 = rf(ctx, client, account, epoch, blockNumber, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, uint32, *big.Int, types.Rogue) types.ProposeFileData); ok { + r0 = rf(rpcParameters, account, epoch, blockNumber, rogueData) } else { r0 = ret.Get(0).(types.ProposeFileData) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Account, uint32, *big.Int, types.Rogue) error); ok { - r1 = rf(ctx, client, account, epoch, blockNumber, rogueData) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Account, uint32, *big.Int, types.Rogue) error); ok { + r1 = rf(rpcParameters, account, epoch, blockNumber, rogueData) } else { r1 = ret.Error(1) } @@ -1080,25 +1053,25 @@ func (_m *UtilsCmdInterface) GetRPCTimeout() (int64, error) { return r0, r1 } -// GetSalt provides a mock function with given fields: ctx, client, epoch -func (_m *UtilsCmdInterface) GetSalt(ctx context.Context, client *ethclient.Client, epoch uint32) ([32]byte, error) { - ret := _m.Called(ctx, client, epoch) +// GetSalt provides a mock function with given fields: rpcParameters, epoch +func (_m *UtilsCmdInterface) GetSalt(rpcParameters RPC.RPCParameters, epoch uint32) ([32]byte, error) { + ret := _m.Called(rpcParameters, epoch) var r0 [32]byte var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) ([32]byte, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) ([32]byte, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) [32]byte); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) [32]byte); ok { + r0 = rf(rpcParameters, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([32]byte) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Error(1) } @@ -1106,32 +1079,32 @@ func (_m *UtilsCmdInterface) GetSalt(ctx context.Context, client *ethclient.Clie return r0, r1 } -// GetSmallestStakeAndId provides a mock function with given fields: ctx, client, epoch -func (_m *UtilsCmdInterface) GetSmallestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) { - ret := _m.Called(ctx, client, epoch) +// GetSmallestStakeAndId provides a mock function with given fields: rpcParameters, epoch +func (_m *UtilsCmdInterface) GetSmallestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) { + ret := _m.Called(rpcParameters, epoch) var r0 *big.Int var r1 uint32 var r2 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (*big.Int, uint32, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (*big.Int, uint32, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) *big.Int); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) *big.Int); ok { + r0 = rf(rpcParameters, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) uint32); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) uint32); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Get(1).(uint32) } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client, uint32) error); ok { - r2 = rf(ctx, client, epoch) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters, uint32) error); ok { + r2 = rf(rpcParameters, epoch) } else { r2 = ret.Error(2) } @@ -1139,25 +1112,25 @@ func (_m *UtilsCmdInterface) GetSmallestStakeAndId(ctx context.Context, client * return r0, r1, r2 } -// GetSortedRevealedValues provides a mock function with given fields: ctx, client, blockNumber, epoch -func (_m *UtilsCmdInterface) GetSortedRevealedValues(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) { - ret := _m.Called(ctx, client, blockNumber, epoch) +// GetSortedRevealedValues provides a mock function with given fields: rpcParameters, blockNumber, epoch +func (_m *UtilsCmdInterface) GetSortedRevealedValues(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) { + ret := _m.Called(rpcParameters, blockNumber, epoch) var r0 *types.RevealedDataMaps var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32) (*types.RevealedDataMaps, error)); ok { - return rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32) (*types.RevealedDataMaps, error)); ok { + return rf(rpcParameters, blockNumber, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32) *types.RevealedDataMaps); ok { - r0 = rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32) *types.RevealedDataMaps); ok { + r0 = rf(rpcParameters, blockNumber, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.RevealedDataMaps) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, *big.Int, uint32) error); ok { - r1 = rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int, uint32) error); ok { + r1 = rf(rpcParameters, blockNumber, epoch) } else { r1 = ret.Error(1) } @@ -1165,13 +1138,13 @@ func (_m *UtilsCmdInterface) GetSortedRevealedValues(ctx context.Context, client return r0, r1 } -// GetStakerInfo provides a mock function with given fields: ctx, client, stakerId -func (_m *UtilsCmdInterface) GetStakerInfo(ctx context.Context, client *ethclient.Client, stakerId uint32) error { - ret := _m.Called(ctx, client, stakerId) +// GetStakerInfo provides a mock function with given fields: rpcParameters, stakerId +func (_m *UtilsCmdInterface) GetStakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) error { + ret := _m.Called(rpcParameters, stakerId) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) error); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) error); ok { + r0 = rf(rpcParameters, stakerId) } else { r0 = ret.Error(0) } @@ -1203,13 +1176,13 @@ func (_m *UtilsCmdInterface) GetWaitTime() (int32, error) { return r0, r1 } -// GiveSorted provides a mock function with given fields: ctx, client, blockManager, txnArgs, epoch, assetId, sortedStakers -func (_m *UtilsCmdInterface) GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error { - ret := _m.Called(ctx, client, blockManager, txnArgs, epoch, assetId, sortedStakers) +// GiveSorted provides a mock function with given fields: rpcParameters, txnArgs, epoch, assetId, sortedStakers +func (_m *UtilsCmdInterface) GiveSorted(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error { + ret := _m.Called(rpcParameters, txnArgs, epoch, assetId, sortedStakers) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *bindings.BlockManager, types.TransactionOptions, uint32, uint16, []*big.Int) error); ok { - r0 = rf(ctx, client, blockManager, txnArgs, epoch, assetId, sortedStakers) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, uint32, uint16, []*big.Int) error); ok { + r0 = rf(rpcParameters, txnArgs, epoch, assetId, sortedStakers) } else { r0 = ret.Error(0) } @@ -1217,18 +1190,18 @@ func (_m *UtilsCmdInterface) GiveSorted(ctx context.Context, client *ethclient.C return r0 } -// HandleBlock provides a mock function with given fields: client, account, stakerId, header, config, commitParams, rogueData, backupNodeActionsToIgnore -func (_m *UtilsCmdInterface) HandleBlock(client *ethclient.Client, account types.Account, stakerId uint32, header *coretypes.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) { - _m.Called(client, account, stakerId, header, config, commitParams, rogueData, backupNodeActionsToIgnore) +// HandleBlock provides a mock function with given fields: rpcParameters, account, stakerId, header, config, commitParams, rogueData, backupNodeActionsToIgnore +func (_m *UtilsCmdInterface) HandleBlock(rpcParameters RPC.RPCParameters, account types.Account, stakerId uint32, header *coretypes.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) { + _m.Called(rpcParameters, account, stakerId, header, config, commitParams, rogueData, backupNodeActionsToIgnore) } -// HandleClaimBounty provides a mock function with given fields: client, config, account -func (_m *UtilsCmdInterface) HandleClaimBounty(client *ethclient.Client, config types.Configurations, account types.Account) error { - ret := _m.Called(client, config, account) +// HandleClaimBounty provides a mock function with given fields: rpcParameters, config, account +func (_m *UtilsCmdInterface) HandleClaimBounty(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account) error { + ret := _m.Called(rpcParameters, config, account) var r0 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.Account) error); ok { - r0 = rf(client, config, account) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account) error); ok { + r0 = rf(rpcParameters, config, account) } else { r0 = ret.Error(0) } @@ -1236,23 +1209,23 @@ func (_m *UtilsCmdInterface) HandleClaimBounty(client *ethclient.Client, config return r0 } -// HandleCommitState provides a mock function with given fields: ctx, client, epoch, seed, commitParams, rogueData -func (_m *UtilsCmdInterface) HandleCommitState(ctx context.Context, client *ethclient.Client, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) { - ret := _m.Called(ctx, client, epoch, seed, commitParams, rogueData) +// HandleCommitState provides a mock function with given fields: rpcParameters, epoch, seed, commitParams, rogueData +func (_m *UtilsCmdInterface) HandleCommitState(rpcParameters RPC.RPCParameters, epoch uint32, seed []byte, commitParams *types.CommitParams, rogueData types.Rogue) (types.CommitData, error) { + ret := _m.Called(rpcParameters, epoch, seed, commitParams, rogueData) var r0 types.CommitData var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, []byte, *types.CommitParams, types.Rogue) (types.CommitData, error)); ok { - return rf(ctx, client, epoch, seed, commitParams, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, []byte, *types.CommitParams, types.Rogue) (types.CommitData, error)); ok { + return rf(rpcParameters, epoch, seed, commitParams, rogueData) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, []byte, *types.CommitParams, types.Rogue) types.CommitData); ok { - r0 = rf(ctx, client, epoch, seed, commitParams, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, []byte, *types.CommitParams, types.Rogue) types.CommitData); ok { + r0 = rf(rpcParameters, epoch, seed, commitParams, rogueData) } else { r0 = ret.Get(0).(types.CommitData) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, []byte, *types.CommitParams, types.Rogue) error); ok { - r1 = rf(ctx, client, epoch, seed, commitParams, rogueData) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, []byte, *types.CommitParams, types.Rogue) error); ok { + r1 = rf(rpcParameters, epoch, seed, commitParams, rogueData) } else { r1 = ret.Error(1) } @@ -1260,13 +1233,13 @@ func (_m *UtilsCmdInterface) HandleCommitState(ctx context.Context, client *ethc return r0, r1 } -// HandleDispute provides a mock function with given fields: ctx, client, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore -func (_m *UtilsCmdInterface) HandleDispute(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { - ret := _m.Called(ctx, client, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore) +// HandleDispute provides a mock function with given fields: rpcParameters, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore +func (_m *UtilsCmdInterface) HandleDispute(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, blockNumber *big.Int, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { + ret := _m.Called(rpcParameters, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *big.Int, types.Rogue, []string) error); ok { - r0 = rf(ctx, client, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *big.Int, types.Rogue, []string) error); ok { + r0 = rf(rpcParameters, config, account, epoch, blockNumber, rogueData, backupNodeActionsToIgnore) } else { r0 = ret.Error(0) } @@ -1279,25 +1252,25 @@ func (_m *UtilsCmdInterface) HandleExit() { _m.Called() } -// HandleUnstakeLock provides a mock function with given fields: ctx, client, account, configurations, stakerId -func (_m *UtilsCmdInterface) HandleUnstakeLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { - ret := _m.Called(ctx, client, account, configurations, stakerId) +// HandleUnstakeLock provides a mock function with given fields: rpcParameters, account, configurations, stakerId +func (_m *UtilsCmdInterface) HandleUnstakeLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { + ret := _m.Called(rpcParameters, account, configurations, stakerId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) (common.Hash, error)); ok { - return rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) (common.Hash, error)); ok { + return rf(rpcParameters, account, configurations, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) common.Hash); ok { - r0 = rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) common.Hash); ok { + r0 = rf(rpcParameters, account, configurations, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) error); ok { - r1 = rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) error); ok { + r1 = rf(rpcParameters, account, configurations, stakerId) } else { r1 = ret.Error(1) } @@ -1305,25 +1278,25 @@ func (_m *UtilsCmdInterface) HandleUnstakeLock(ctx context.Context, client *ethc return r0, r1 } -// HandleWithdrawLock provides a mock function with given fields: ctx, client, account, configurations, stakerId -func (_m *UtilsCmdInterface) HandleWithdrawLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { - ret := _m.Called(ctx, client, account, configurations, stakerId) +// HandleWithdrawLock provides a mock function with given fields: rpcParameters, account, configurations, stakerId +func (_m *UtilsCmdInterface) HandleWithdrawLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { + ret := _m.Called(rpcParameters, account, configurations, stakerId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) (common.Hash, error)); ok { - return rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) (common.Hash, error)); ok { + return rf(rpcParameters, account, configurations, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) common.Hash); ok { - r0 = rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) common.Hash); ok { + r0 = rf(rpcParameters, account, configurations, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Account, types.Configurations, uint32) error); ok { - r1 = rf(ctx, client, account, configurations, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Account, types.Configurations, uint32) error); ok { + r1 = rf(rpcParameters, account, configurations, stakerId) } else { r1 = ret.Error(1) } @@ -1355,25 +1328,25 @@ func (_m *UtilsCmdInterface) ImportAccount() (accounts.Account, error) { return r0, r1 } -// IndexRevealEventsOfCurrentEpoch provides a mock function with given fields: ctx, client, blockNumber, epoch -func (_m *UtilsCmdInterface) IndexRevealEventsOfCurrentEpoch(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) { - ret := _m.Called(ctx, client, blockNumber, epoch) +// IndexRevealEventsOfCurrentEpoch provides a mock function with given fields: rpcParameters, blockNumber, epoch +func (_m *UtilsCmdInterface) IndexRevealEventsOfCurrentEpoch(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) { + ret := _m.Called(rpcParameters, blockNumber, epoch) var r0 []types.RevealedStruct var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32) ([]types.RevealedStruct, error)); ok { - return rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32) ([]types.RevealedStruct, error)); ok { + return rf(rpcParameters, blockNumber, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32) []types.RevealedStruct); ok { - r0 = rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32) []types.RevealedStruct); ok { + r0 = rf(rpcParameters, blockNumber, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]types.RevealedStruct) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, *big.Int, uint32) error); ok { - r1 = rf(ctx, client, blockNumber, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int, uint32) error); ok { + r1 = rf(rpcParameters, blockNumber, epoch) } else { r1 = ret.Error(1) } @@ -1381,43 +1354,43 @@ func (_m *UtilsCmdInterface) IndexRevealEventsOfCurrentEpoch(ctx context.Context return r0, r1 } -// InitJobAndCollectionCache provides a mock function with given fields: ctx, client -func (_m *UtilsCmdInterface) InitJobAndCollectionCache(ctx context.Context, client *ethclient.Client) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) { - ret := _m.Called(ctx, client) +// InitJobAndCollectionCache provides a mock function with given fields: rpcParameters +func (_m *UtilsCmdInterface) InitJobAndCollectionCache(rpcParameters RPC.RPCParameters) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error) { + ret := _m.Called(rpcParameters) var r0 *cache.JobsCache var r1 *cache.CollectionsCache var r2 *big.Int var r3 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (*cache.JobsCache, *cache.CollectionsCache, *big.Int, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) *cache.JobsCache); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) *cache.JobsCache); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*cache.JobsCache) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) *cache.CollectionsCache); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) *cache.CollectionsCache); ok { + r1 = rf(rpcParameters) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*cache.CollectionsCache) } } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client) *big.Int); ok { - r2 = rf(ctx, client) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters) *big.Int); ok { + r2 = rf(rpcParameters) } else { if ret.Get(2) != nil { r2 = ret.Get(2).(*big.Int) } } - if rf, ok := ret.Get(3).(func(context.Context, *ethclient.Client) error); ok { - r3 = rf(ctx, client) + if rf, ok := ret.Get(3).(func(RPC.RPCParameters) error); ok { + r3 = rf(rpcParameters) } else { r3 = ret.Error(3) } @@ -1425,13 +1398,13 @@ func (_m *UtilsCmdInterface) InitJobAndCollectionCache(ctx context.Context, clie return r0, r1, r2, r3 } -// InitiateCommit provides a mock function with given fields: ctx, client, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData -func (_m *UtilsCmdInterface) InitiateCommit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *coretypes.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error { - ret := _m.Called(ctx, client, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) +// InitiateCommit provides a mock function with given fields: rpcParameters, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData +func (_m *UtilsCmdInterface) InitiateCommit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *coretypes.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error { + ret := _m.Called(rpcParameters, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, uint32, *coretypes.Header, *types.CommitParams, uint64, types.Rogue) error); ok { - r0 = rf(ctx, client, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, uint32, *coretypes.Header, *types.CommitParams, uint64, types.Rogue) error); ok { + r0 = rf(rpcParameters, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) } else { r0 = ret.Error(0) } @@ -1439,13 +1412,13 @@ func (_m *UtilsCmdInterface) InitiateCommit(ctx context.Context, client *ethclie return r0 } -// InitiatePropose provides a mock function with given fields: ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData -func (_m *UtilsCmdInterface) InitiatePropose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { - ret := _m.Called(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) +// InitiatePropose provides a mock function with given fields: rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData +func (_m *UtilsCmdInterface) InitiatePropose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { + ret := _m.Called(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, bindings.StructsStaker, *coretypes.Header, uint64, types.Rogue) error); ok { - r0 = rf(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, bindings.StructsStaker, *coretypes.Header, uint64, types.Rogue) error); ok { + r0 = rf(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) } else { r0 = ret.Error(0) } @@ -1453,13 +1426,13 @@ func (_m *UtilsCmdInterface) InitiatePropose(ctx context.Context, client *ethcli return r0 } -// InitiateReveal provides a mock function with given fields: ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData -func (_m *UtilsCmdInterface) InitiateReveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { - ret := _m.Called(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) +// InitiateReveal provides a mock function with given fields: rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData +func (_m *UtilsCmdInterface) InitiateReveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { + ret := _m.Called(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, bindings.StructsStaker, *coretypes.Header, uint64, types.Rogue) error); ok { - r0 = rf(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, bindings.StructsStaker, *coretypes.Header, uint64, types.Rogue) error); ok { + r0 = rf(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) } else { r0 = ret.Error(0) } @@ -1467,25 +1440,25 @@ func (_m *UtilsCmdInterface) InitiateReveal(ctx context.Context, client *ethclie return r0 } -// InitiateWithdraw provides a mock function with given fields: client, txnOpts, stakerId -func (_m *UtilsCmdInterface) InitiateWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { - ret := _m.Called(client, txnOpts, stakerId) +// InitiateWithdraw provides a mock function with given fields: rpcParameters, txnOpts, stakerId +func (_m *UtilsCmdInterface) InitiateWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { + ret := _m.Called(rpcParameters, txnOpts, stakerId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (common.Hash, error)); ok { - return rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) (common.Hash, error)); ok { + return rf(rpcParameters, txnOpts, stakerId) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) common.Hash); ok { - r0 = rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) common.Hash); ok { + r0 = rf(rpcParameters, txnOpts, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { - r1 = rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) error); ok { + r1 = rf(rpcParameters, txnOpts, stakerId) } else { r1 = ret.Error(1) } @@ -1533,43 +1506,43 @@ func (_m *UtilsCmdInterface) ListAccounts() ([]accounts.Account, error) { return r0, r1 } -// MakeBlock provides a mock function with given fields: ctx, client, blockNumber, epoch, rogueData -func (_m *UtilsCmdInterface) MakeBlock(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) { - ret := _m.Called(ctx, client, blockNumber, epoch, rogueData) +// MakeBlock provides a mock function with given fields: rpcParameters, blockNumber, epoch, rogueData +func (_m *UtilsCmdInterface) MakeBlock(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) { + ret := _m.Called(rpcParameters, blockNumber, epoch, rogueData) var r0 []*big.Int var r1 []uint16 var r2 *types.RevealedDataMaps var r3 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32, types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error)); ok { - return rf(ctx, client, blockNumber, epoch, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32, types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error)); ok { + return rf(rpcParameters, blockNumber, epoch, rogueData) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, *big.Int, uint32, types.Rogue) []*big.Int); ok { - r0 = rf(ctx, client, blockNumber, epoch, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int, uint32, types.Rogue) []*big.Int); ok { + r0 = rf(rpcParameters, blockNumber, epoch, rogueData) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, *big.Int, uint32, types.Rogue) []uint16); ok { - r1 = rf(ctx, client, blockNumber, epoch, rogueData) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int, uint32, types.Rogue) []uint16); ok { + r1 = rf(rpcParameters, blockNumber, epoch, rogueData) } else { if ret.Get(1) != nil { r1 = ret.Get(1).([]uint16) } } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client, *big.Int, uint32, types.Rogue) *types.RevealedDataMaps); ok { - r2 = rf(ctx, client, blockNumber, epoch, rogueData) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters, *big.Int, uint32, types.Rogue) *types.RevealedDataMaps); ok { + r2 = rf(rpcParameters, blockNumber, epoch, rogueData) } else { if ret.Get(2) != nil { r2 = ret.Get(2).(*types.RevealedDataMaps) } } - if rf, ok := ret.Get(3).(func(context.Context, *ethclient.Client, *big.Int, uint32, types.Rogue) error); ok { - r3 = rf(ctx, client, blockNumber, epoch, rogueData) + if rf, ok := ret.Get(3).(func(RPC.RPCParameters, *big.Int, uint32, types.Rogue) error); ok { + r3 = rf(rpcParameters, blockNumber, epoch, rogueData) } else { r3 = ret.Error(3) } @@ -1577,25 +1550,25 @@ func (_m *UtilsCmdInterface) MakeBlock(ctx context.Context, client *ethclient.Cl return r0, r1, r2, r3 } -// ModifyCollectionStatus provides a mock function with given fields: ctx, client, config, modifyCollectionInput -func (_m *UtilsCmdInterface) ModifyCollectionStatus(ctx context.Context, client *ethclient.Client, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) { - ret := _m.Called(ctx, client, config, modifyCollectionInput) +// ModifyCollectionStatus provides a mock function with given fields: rpcParameters, config, modifyCollectionInput +func (_m *UtilsCmdInterface) ModifyCollectionStatus(rpcParameters RPC.RPCParameters, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, modifyCollectionInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.ModifyCollectionInput) (common.Hash, error)); ok { - return rf(ctx, client, config, modifyCollectionInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.ModifyCollectionInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, modifyCollectionInput) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.ModifyCollectionInput) common.Hash); ok { - r0 = rf(ctx, client, config, modifyCollectionInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.ModifyCollectionInput) common.Hash); ok { + r0 = rf(rpcParameters, config, modifyCollectionInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.ModifyCollectionInput) error); ok { - r1 = rf(ctx, client, config, modifyCollectionInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.ModifyCollectionInput) error); ok { + r1 = rf(rpcParameters, config, modifyCollectionInput) } else { r1 = ret.Error(1) } @@ -1603,13 +1576,13 @@ func (_m *UtilsCmdInterface) ModifyCollectionStatus(ctx context.Context, client return r0, r1 } -// Propose provides a mock function with given fields: ctx, client, config, account, staker, epoch, latestHeader, stateBuffer, rogueData -func (_m *UtilsCmdInterface) Propose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { - ret := _m.Called(ctx, client, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) +// Propose provides a mock function with given fields: rpcParameters, config, account, staker, epoch, latestHeader, stateBuffer, rogueData +func (_m *UtilsCmdInterface) Propose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, rogueData types.Rogue) error { + ret := _m.Called(rpcParameters, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, bindings.StructsStaker, uint32, *coretypes.Header, uint64, types.Rogue) error); ok { - r0 = rf(ctx, client, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, bindings.StructsStaker, uint32, *coretypes.Header, uint64, types.Rogue) error); ok { + r0 = rf(rpcParameters, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) } else { r0 = ret.Error(0) } @@ -1617,30 +1590,30 @@ func (_m *UtilsCmdInterface) Propose(ctx context.Context, client *ethclient.Clie return r0 } -// ResetDispute provides a mock function with given fields: client, blockManager, txnOpts, epoch -func (_m *UtilsCmdInterface) ResetDispute(client *ethclient.Client, blockManager *bindings.BlockManager, txnOpts *bind.TransactOpts, epoch uint32) { - _m.Called(client, blockManager, txnOpts, epoch) +// ResetDispute provides a mock function with given fields: rpcParameters, txnOpts, epoch +func (_m *UtilsCmdInterface) ResetDispute(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, epoch uint32) { + _m.Called(rpcParameters, txnOpts, epoch) } -// ResetUnstakeLock provides a mock function with given fields: client, config, extendLockInput -func (_m *UtilsCmdInterface) ResetUnstakeLock(client *ethclient.Client, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) { - ret := _m.Called(client, config, extendLockInput) +// ResetUnstakeLock provides a mock function with given fields: rpcParameters, config, extendLockInput +func (_m *UtilsCmdInterface) ResetUnstakeLock(rpcParameters RPC.RPCParameters, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, extendLockInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.ExtendLockInput) (common.Hash, error)); ok { - return rf(client, config, extendLockInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.ExtendLockInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, extendLockInput) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.ExtendLockInput) common.Hash); ok { - r0 = rf(client, config, extendLockInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.ExtendLockInput) common.Hash); ok { + r0 = rf(rpcParameters, config, extendLockInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, types.Configurations, types.ExtendLockInput) error); ok { - r1 = rf(client, config, extendLockInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.ExtendLockInput) error); ok { + r1 = rf(rpcParameters, config, extendLockInput) } else { r1 = ret.Error(1) } @@ -1648,25 +1621,25 @@ func (_m *UtilsCmdInterface) ResetUnstakeLock(client *ethclient.Client, config t return r0, r1 } -// Reveal provides a mock function with given fields: ctx, client, config, account, epoch, latestHeader, stateBuffer, commitData, signature -func (_m *UtilsCmdInterface) Reveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) { - ret := _m.Called(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitData, signature) +// Reveal provides a mock function with given fields: rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitData, signature +func (_m *UtilsCmdInterface) Reveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *coretypes.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitData, signature) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) (common.Hash, error)); ok { - return rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitData, signature) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) (common.Hash, error)); ok { + return rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitData, signature) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) common.Hash); ok { - r0 = rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitData, signature) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) common.Hash); ok { + r0 = rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitData, signature) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) error); ok { - r1 = rf(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitData, signature) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *coretypes.Header, uint64, types.CommitData, []byte) error); ok { + r1 = rf(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitData, signature) } else { r1 = ret.Error(1) } @@ -1688,25 +1661,25 @@ func (_m *UtilsCmdInterface) SetConfig(flagSet *pflag.FlagSet) error { return r0 } -// SetDelegation provides a mock function with given fields: ctx, client, config, delegationInput -func (_m *UtilsCmdInterface) SetDelegation(ctx context.Context, client *ethclient.Client, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) { - ret := _m.Called(ctx, client, config, delegationInput) +// SetDelegation provides a mock function with given fields: rpcParameters, config, delegationInput +func (_m *UtilsCmdInterface) SetDelegation(rpcParameters RPC.RPCParameters, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, delegationInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.SetDelegationInput) (common.Hash, error)); ok { - return rf(ctx, client, config, delegationInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.SetDelegationInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, delegationInput) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.SetDelegationInput) common.Hash); ok { - r0 = rf(ctx, client, config, delegationInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.SetDelegationInput) common.Hash); ok { + r0 = rf(rpcParameters, config, delegationInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.SetDelegationInput) error); ok { - r1 = rf(ctx, client, config, delegationInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.SetDelegationInput) error); ok { + r1 = rf(rpcParameters, config, delegationInput) } else { r1 = ret.Error(1) } @@ -1714,25 +1687,25 @@ func (_m *UtilsCmdInterface) SetDelegation(ctx context.Context, client *ethclien return r0, r1 } -// StakeCoins provides a mock function with given fields: txnArgs -func (_m *UtilsCmdInterface) StakeCoins(txnArgs types.TransactionOptions) (common.Hash, error) { - ret := _m.Called(txnArgs) +// StakeCoins provides a mock function with given fields: rpcParameters, txnArgs +func (_m *UtilsCmdInterface) StakeCoins(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions) (common.Hash, error) { + ret := _m.Called(rpcParameters, txnArgs) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(types.TransactionOptions) (common.Hash, error)); ok { - return rf(txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) (common.Hash, error)); ok { + return rf(rpcParameters, txnArgs) } - if rf, ok := ret.Get(0).(func(types.TransactionOptions) common.Hash); ok { - r0 = rf(txnArgs) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) common.Hash); ok { + r0 = rf(rpcParameters, txnArgs) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(types.TransactionOptions) error); ok { - r1 = rf(txnArgs) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions) error); ok { + r1 = rf(rpcParameters, txnArgs) } else { r1 = ret.Error(1) } @@ -1740,13 +1713,13 @@ func (_m *UtilsCmdInterface) StakeCoins(txnArgs types.TransactionOptions) (commo return r0, r1 } -// StoreBountyId provides a mock function with given fields: ctx, client, account -func (_m *UtilsCmdInterface) StoreBountyId(ctx context.Context, client *ethclient.Client, account types.Account) error { - ret := _m.Called(ctx, client, account) +// StoreBountyId provides a mock function with given fields: rpcParameters, account +func (_m *UtilsCmdInterface) StoreBountyId(rpcParameters RPC.RPCParameters, account types.Account) error { + ret := _m.Called(rpcParameters, account) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Account) error); ok { - r0 = rf(ctx, client, account) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Account) error); ok { + r0 = rf(rpcParameters, account) } else { r0 = ret.Error(0) } @@ -1754,25 +1727,25 @@ func (_m *UtilsCmdInterface) StoreBountyId(ctx context.Context, client *ethclien return r0 } -// Transfer provides a mock function with given fields: client, config, transferInput -func (_m *UtilsCmdInterface) Transfer(client *ethclient.Client, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) { - ret := _m.Called(client, config, transferInput) +// Transfer provides a mock function with given fields: rpcParameters, config, transferInput +func (_m *UtilsCmdInterface) Transfer(rpcParameters RPC.RPCParameters, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, transferInput) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.TransferInput) (common.Hash, error)); ok { - return rf(client, config, transferInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.TransferInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, transferInput) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, types.Configurations, types.TransferInput) common.Hash); ok { - r0 = rf(client, config, transferInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.TransferInput) common.Hash); ok { + r0 = rf(rpcParameters, config, transferInput) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, types.Configurations, types.TransferInput) error); ok { - r1 = rf(client, config, transferInput) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.TransferInput) error); ok { + r1 = rf(rpcParameters, config, transferInput) } else { r1 = ret.Error(1) } @@ -1780,25 +1753,25 @@ func (_m *UtilsCmdInterface) Transfer(client *ethclient.Client, config types.Con return r0, r1 } -// UnlockWithdraw provides a mock function with given fields: client, txnOpts, stakerId -func (_m *UtilsCmdInterface) UnlockWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { - ret := _m.Called(client, txnOpts, stakerId) +// UnlockWithdraw provides a mock function with given fields: rpcParameters, txnOpts, stakerId +func (_m *UtilsCmdInterface) UnlockWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { + ret := _m.Called(rpcParameters, txnOpts, stakerId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) (common.Hash, error)); ok { - return rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) (common.Hash, error)); ok { + return rf(rpcParameters, txnOpts, stakerId) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32) common.Hash); ok { - r0 = rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) common.Hash); ok { + r0 = rf(rpcParameters, txnOpts, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32) error); ok { - r1 = rf(client, txnOpts, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *bind.TransactOpts, uint32) error); ok { + r1 = rf(rpcParameters, txnOpts, stakerId) } else { r1 = ret.Error(1) } @@ -1806,25 +1779,25 @@ func (_m *UtilsCmdInterface) UnlockWithdraw(client *ethclient.Client, txnOpts *b return r0, r1 } -// Unstake provides a mock function with given fields: ctx, config, client, input -func (_m *UtilsCmdInterface) Unstake(ctx context.Context, config types.Configurations, client *ethclient.Client, input types.UnstakeInput) (common.Hash, error) { - ret := _m.Called(ctx, config, client, input) +// Unstake provides a mock function with given fields: rpcParameters, config, input +func (_m *UtilsCmdInterface) Unstake(rpcParameters RPC.RPCParameters, config types.Configurations, input types.UnstakeInput) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, input) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.Configurations, *ethclient.Client, types.UnstakeInput) (common.Hash, error)); ok { - return rf(ctx, config, client, input) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.UnstakeInput) (common.Hash, error)); ok { + return rf(rpcParameters, config, input) } - if rf, ok := ret.Get(0).(func(context.Context, types.Configurations, *ethclient.Client, types.UnstakeInput) common.Hash); ok { - r0 = rf(ctx, config, client, input) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.UnstakeInput) common.Hash); ok { + r0 = rf(rpcParameters, config, input) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, types.Configurations, *ethclient.Client, types.UnstakeInput) error); ok { - r1 = rf(ctx, config, client, input) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.UnstakeInput) error); ok { + r1 = rf(rpcParameters, config, input) } else { r1 = ret.Error(1) } @@ -1832,25 +1805,25 @@ func (_m *UtilsCmdInterface) Unstake(ctx context.Context, config types.Configura return r0, r1 } -// UpdateCollection provides a mock function with given fields: ctx, client, config, collectionInput, collectionId -func (_m *UtilsCmdInterface) UpdateCollection(ctx context.Context, client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) { - ret := _m.Called(ctx, client, config, collectionInput, collectionId) +// UpdateCollection provides a mock function with given fields: rpcParameters, config, collectionInput, collectionId +func (_m *UtilsCmdInterface) UpdateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, collectionInput, collectionId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateCollectionInput, uint16) (common.Hash, error)); ok { - return rf(ctx, client, config, collectionInput, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput, uint16) (common.Hash, error)); ok { + return rf(rpcParameters, config, collectionInput, collectionId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateCollectionInput, uint16) common.Hash); ok { - r0 = rf(ctx, client, config, collectionInput, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput, uint16) common.Hash); ok { + r0 = rf(rpcParameters, config, collectionInput, collectionId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateCollectionInput, uint16) error); ok { - r1 = rf(ctx, client, config, collectionInput, collectionId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.CreateCollectionInput, uint16) error); ok { + r1 = rf(rpcParameters, config, collectionInput, collectionId) } else { r1 = ret.Error(1) } @@ -1858,13 +1831,13 @@ func (_m *UtilsCmdInterface) UpdateCollection(ctx context.Context, client *ethcl return r0, r1 } -// UpdateCommission provides a mock function with given fields: ctx, config, client, updateCommissionInput -func (_m *UtilsCmdInterface) UpdateCommission(ctx context.Context, config types.Configurations, client *ethclient.Client, updateCommissionInput types.UpdateCommissionInput) error { - ret := _m.Called(ctx, config, client, updateCommissionInput) +// UpdateCommission provides a mock function with given fields: rpcParameters, config, updateCommissionInput +func (_m *UtilsCmdInterface) UpdateCommission(rpcParameters RPC.RPCParameters, config types.Configurations, updateCommissionInput types.UpdateCommissionInput) error { + ret := _m.Called(rpcParameters, config, updateCommissionInput) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.Configurations, *ethclient.Client, types.UpdateCommissionInput) error); ok { - r0 = rf(ctx, config, client, updateCommissionInput) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.UpdateCommissionInput) error); ok { + r0 = rf(rpcParameters, config, updateCommissionInput) } else { r0 = ret.Error(0) } @@ -1872,25 +1845,25 @@ func (_m *UtilsCmdInterface) UpdateCommission(ctx context.Context, config types. return r0 } -// UpdateJob provides a mock function with given fields: ctx, client, config, jobInput, jobId -func (_m *UtilsCmdInterface) UpdateJob(ctx context.Context, client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) { - ret := _m.Called(ctx, client, config, jobInput, jobId) +// UpdateJob provides a mock function with given fields: rpcParameters, config, jobInput, jobId +func (_m *UtilsCmdInterface) UpdateJob(rpcParameters RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) { + ret := _m.Called(rpcParameters, config, jobInput, jobId) var r0 common.Hash var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateJobInput, uint16) (common.Hash, error)); ok { - return rf(ctx, client, config, jobInput, jobId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput, uint16) (common.Hash, error)); ok { + return rf(rpcParameters, config, jobInput, jobId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateJobInput, uint16) common.Hash); ok { - r0 = rf(ctx, client, config, jobInput, jobId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput, uint16) common.Hash); ok { + r0 = rf(rpcParameters, config, jobInput, jobId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(common.Hash) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, types.Configurations, types.CreateJobInput, uint16) error); ok { - r1 = rf(ctx, client, config, jobInput, jobId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.Configurations, types.CreateJobInput, uint16) error); ok { + r1 = rf(rpcParameters, config, jobInput, jobId) } else { r1 = ret.Error(1) } @@ -1898,13 +1871,13 @@ func (_m *UtilsCmdInterface) UpdateJob(ctx context.Context, client *ethclient.Cl return r0, r1 } -// Vote provides a mock function with given fields: ctx, config, client, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore -func (_m *UtilsCmdInterface) Vote(ctx context.Context, config types.Configurations, client *ethclient.Client, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { - ret := _m.Called(ctx, config, client, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore) +// Vote provides a mock function with given fields: rpcParameters, config, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore +func (_m *UtilsCmdInterface) Vote(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { + ret := _m.Called(rpcParameters, config, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, types.Configurations, *ethclient.Client, types.Account, uint32, *types.CommitParams, types.Rogue, []string) error); ok { - r0 = rf(ctx, config, client, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations, types.Account, uint32, *types.CommitParams, types.Rogue, []string) error); ok { + r0 = rf(rpcParameters, config, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore) } else { r0 = ret.Error(0) } @@ -1912,30 +1885,30 @@ func (_m *UtilsCmdInterface) Vote(ctx context.Context, config types.Configuratio return r0 } -// WaitForAppropriateState provides a mock function with given fields: ctx, client, action, states -func (_m *UtilsCmdInterface) WaitForAppropriateState(ctx context.Context, client *ethclient.Client, action string, states ...int) (uint32, error) { +// WaitForAppropriateState provides a mock function with given fields: rpcParameter, action, states +func (_m *UtilsCmdInterface) WaitForAppropriateState(rpcParameter RPC.RPCParameters, action string, states ...int) (uint32, error) { _va := make([]interface{}, len(states)) for _i := range states { _va[_i] = states[_i] } var _ca []interface{} - _ca = append(_ca, ctx, client, action) + _ca = append(_ca, rpcParameter, action) _ca = append(_ca, _va...) ret := _m.Called(_ca...) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string, ...int) (uint32, error)); ok { - return rf(ctx, client, action, states...) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string, ...int) (uint32, error)); ok { + return rf(rpcParameter, action, states...) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string, ...int) uint32); ok { - r0 = rf(ctx, client, action, states...) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string, ...int) uint32); ok { + r0 = rf(rpcParameter, action, states...) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, string, ...int) error); ok { - r1 = rf(ctx, client, action, states...) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string, ...int) error); ok { + r1 = rf(rpcParameter, action, states...) } else { r1 = ret.Error(1) } @@ -1943,23 +1916,23 @@ func (_m *UtilsCmdInterface) WaitForAppropriateState(ctx context.Context, client return r0, r1 } -// WaitIfCommitState provides a mock function with given fields: ctx, client, action -func (_m *UtilsCmdInterface) WaitIfCommitState(ctx context.Context, client *ethclient.Client, action string) (uint32, error) { - ret := _m.Called(ctx, client, action) +// WaitIfCommitState provides a mock function with given fields: rpcParameter, action +func (_m *UtilsCmdInterface) WaitIfCommitState(rpcParameter RPC.RPCParameters, action string) (uint32, error) { + ret := _m.Called(rpcParameter, action) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) (uint32, error)); ok { - return rf(ctx, client, action) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) (uint32, error)); ok { + return rf(rpcParameter, action) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) uint32); ok { - r0 = rf(ctx, client, action) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) uint32); ok { + r0 = rf(rpcParameter, action) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, string) error); ok { - r1 = rf(ctx, client, action) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string) error); ok { + r1 = rf(rpcParameter, action) } else { r1 = ret.Error(1) } diff --git a/cmd/mocks/viper_interface.go b/cmd/mocks/viper_interface.go index f664ff79..ddbb6674 100644 --- a/cmd/mocks/viper_interface.go +++ b/cmd/mocks/viper_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -23,13 +23,12 @@ func (_m *ViperInterface) ViperWriteConfigAs(path string) error { return r0 } -type mockConstructorTestingTNewViperInterface interface { +// NewViperInterface creates a new instance of ViperInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewViperInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewViperInterface creates a new instance of ViperInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewViperInterface(t mockConstructorTestingTNewViperInterface) *ViperInterface { +}) *ViperInterface { mock := &ViperInterface{} mock.Mock.Test(t) diff --git a/cmd/mocks/vote_manager_interface.go b/cmd/mocks/vote_manager_interface.go index f9e96332..8a602d25 100644 --- a/cmd/mocks/vote_manager_interface.go +++ b/cmd/mocks/vote_manager_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -24,6 +24,10 @@ func (_m *VoteManagerInterface) Commit(client *ethclient.Client, txnOpts *bind.T ret := _m.Called(client, txnOpts, epoch, commitment) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, [32]byte) (*types.Transaction, error)); ok { + return rf(client, txnOpts, epoch, commitment) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, [32]byte) *types.Transaction); ok { r0 = rf(client, txnOpts, epoch, commitment) } else { @@ -32,7 +36,6 @@ func (_m *VoteManagerInterface) Commit(client *ethclient.Client, txnOpts *bind.T } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, [32]byte) error); ok { r1 = rf(client, txnOpts, epoch, commitment) } else { @@ -47,6 +50,10 @@ func (_m *VoteManagerInterface) Reveal(client *ethclient.Client, txnOpts *bind.T ret := _m.Called(client, txnOpts, epoch, tree, signature) var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, bindings.StructsMerkleTree, []byte) (*types.Transaction, error)); ok { + return rf(client, txnOpts, epoch, tree, signature) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, *bind.TransactOpts, uint32, bindings.StructsMerkleTree, []byte) *types.Transaction); ok { r0 = rf(client, txnOpts, epoch, tree, signature) } else { @@ -55,7 +62,6 @@ func (_m *VoteManagerInterface) Reveal(client *ethclient.Client, txnOpts *bind.T } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, *bind.TransactOpts, uint32, bindings.StructsMerkleTree, []byte) error); ok { r1 = rf(client, txnOpts, epoch, tree, signature) } else { @@ -65,13 +71,12 @@ func (_m *VoteManagerInterface) Reveal(client *ethclient.Client, txnOpts *bind.T return r0, r1 } -type mockConstructorTestingTNewVoteManagerInterface interface { +// NewVoteManagerInterface creates a new instance of VoteManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewVoteManagerInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewVoteManagerInterface creates a new instance of VoteManagerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewVoteManagerInterface(t mockConstructorTestingTNewVoteManagerInterface) *VoteManagerInterface { +}) *VoteManagerInterface { mock := &VoteManagerInterface{} mock.Mock.Test(t) diff --git a/cmd/modifyCollectionStatus.go b/cmd/modifyCollectionStatus.go index 65a928a5..19ed8fbe 100644 --- a/cmd/modifyCollectionStatus.go +++ b/cmd/modifyCollectionStatus.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -32,31 +29,8 @@ func initialiseModifyCollectionStatus(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the ModifyCollectionStatus function func (*UtilsStruct) ExecuteModifyCollectionStatus(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteModifyCollectionStatus: Config: %+v: ", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteModifyCollectionStatus: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) collectionId, err := flagSetUtils.GetUint16CollectionId(flagSet) utils.CheckError("Error in getting collectionId: ", err) @@ -73,23 +47,17 @@ func (*UtilsStruct) ExecuteModifyCollectionStatus(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.ModifyCollectionStatus(context.Background(), client, config, modifyCollectionInput) + txn, err := cmdUtils.ModifyCollectionStatus(rpcParameters, config, modifyCollectionInput) utils.CheckError("Error in changing collection active status: ", err) if txn != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for modifyCollectionStatus: ", err) } } -//This function checks the current status of particular collectionId -func (*UtilsStruct) CheckCurrentStatus(client *ethclient.Client, collectionId uint16) (bool, error) { - callOpts := razorUtils.GetOptions() - return assetManagerUtils.GetActiveStatus(client, &callOpts, collectionId) -} - //This function allows the admin to modify the active status of collection -func (*UtilsStruct) ModifyCollectionStatus(ctx context.Context, client *ethclient.Client, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) { - currentStatus, err := cmdUtils.CheckCurrentStatus(client, modifyCollectionInput.CollectionId) +func (*UtilsStruct) ModifyCollectionStatus(rpcParameters RPC.RPCParameters, config types.Configurations, modifyCollectionInput types.ModifyCollectionInput) (common.Hash, error) { + currentStatus, err := razorUtils.GetActiveStatus(rpcParameters, modifyCollectionInput.CollectionId) if err != nil { log.Error("Error in fetching active status") return core.NilHash, err @@ -99,13 +67,12 @@ func (*UtilsStruct) ModifyCollectionStatus(ctx context.Context, client *ethclien log.Errorf("Collection %d has the active status already set to %t", modifyCollectionInput.CollectionId, modifyCollectionInput.Status) return core.NilHash, nil } - _, err = cmdUtils.WaitForAppropriateState(ctx, client, "modify collection status", 4) + _, err = cmdUtils.WaitForAppropriateState(rpcParameters, "modify collection status", 4) if err != nil { return core.NilHash, err } txnArgs := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -115,8 +82,13 @@ func (*UtilsStruct) ModifyCollectionStatus(ctx context.Context, client *ethclien Account: modifyCollectionInput.Account, } - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Infof("Changing active status of collection: %d from %t to %t", modifyCollectionInput.CollectionId, !modifyCollectionInput.Status, modifyCollectionInput.Status) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing SetCollectionStatus transaction with status = %v, collectionId = %d", modifyCollectionInput.Status, modifyCollectionInput.CollectionId) txn, err := assetManagerUtils.SetCollectionStatus(client, txnOpts, modifyCollectionInput.Status, modifyCollectionInput.CollectionId) if err != nil { diff --git a/cmd/propose.go b/cmd/propose.go index 6bf71267..36da127a 100644 --- a/cmd/propose.go +++ b/cmd/propose.go @@ -2,11 +2,11 @@ package cmd import ( - "context" "encoding/hex" "errors" "math" "math/big" + "razor/RPC" "razor/core" "razor/core/types" "razor/pkg/bindings" @@ -17,7 +17,6 @@ import ( "time" Types "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" solsha3 "github.com/miguelmota/go-solidity-sha3" ) @@ -32,12 +31,12 @@ var globalProposedDataStruct types.ProposeFileData // Find iteration using salt as seed //This functions handles the propose state -func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { +func (*UtilsStruct) Propose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, staker bindings.StructsStaker, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { if state, err := razorUtils.GetBufferedState(latestHeader, stateBuffer, config.BufferPercent); err != nil || state != 2 { log.Error("Not propose state") return err } - numStakers, err := razorUtils.GetNumberOfStakers(ctx, client) + numStakers, err := razorUtils.GetNumberOfStakers(rpcParameters) if err != nil { log.Error("Error in fetching number of stakers: ", err) return err @@ -54,7 +53,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi if rogueData.IsRogue && utils.Contains(rogueData.RogueMode, "biggestStakerId") { log.Warn("YOU ARE PROPOSING IN ROGUE MODE, THIS CAN INCUR PENALTIES!") // If staker is going rogue with biggestStakerId than we do biggestStakerId = smallestStakerId - smallestStake, smallestStakerId, smallestStakerErr := cmdUtils.GetSmallestStakeAndId(ctx, client, epoch) + smallestStake, smallestStakerId, smallestStakerErr := cmdUtils.GetSmallestStakeAndId(rpcParameters, epoch) if smallestStakerErr != nil { log.Error("Error in calculating smallest staker: ", smallestStakerErr) return smallestStakerErr @@ -63,7 +62,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi biggestStakerId = smallestStakerId log.Debugf("Propose: In rogue mode, Biggest Stake: %s, Biggest Staker Id: %d", biggestStake, biggestStakerId) } else { - biggestStake, biggestStakerId, biggestStakerErr = cmdUtils.GetBiggestStakeAndId(ctx, client, epoch) + biggestStake, biggestStakerId, biggestStakerErr = cmdUtils.GetBiggestStakeAndId(rpcParameters, epoch) if biggestStakerErr != nil { log.Error("Error in calculating biggest staker: ", biggestStakerErr) return biggestStakerErr @@ -71,7 +70,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi } log.Debugf("Getting Salt for current epoch %d...", epoch) - salt, err := cmdUtils.GetSalt(ctx, client, epoch) + salt, err := cmdUtils.GetSalt(rpcParameters, epoch) if err != nil { return err } @@ -86,20 +85,20 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi Epoch: epoch, } log.Debugf("Propose: Calling GetIteration with arguments proposer = %+v, buffer percent = %d", proposer, config.BufferPercent) - iteration := cmdUtils.GetIteration(ctx, client, proposer, config.BufferPercent) + iteration := cmdUtils.GetIteration(rpcParameters, proposer, config.BufferPercent) log.Debug("Iteration: ", iteration) if iteration == -1 { return nil } - numOfProposedBlocks, err := razorUtils.GetNumberOfProposedBlocks(ctx, client, epoch) + numOfProposedBlocks, err := razorUtils.GetNumberOfProposedBlocks(rpcParameters, epoch) if err != nil { log.Error(err) return err } log.Debug("Propose: Number of proposed blocks: ", numOfProposedBlocks) - maxAltBlocks, err := razorUtils.GetMaxAltBlocks(ctx, client) + maxAltBlocks, err := razorUtils.GetMaxAltBlocks(rpcParameters) if err != nil { log.Error(err) return err @@ -108,7 +107,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi if numOfProposedBlocks >= maxAltBlocks { log.Debugf("Number of blocks proposed: %d, which is equal or greater than maximum alternative blocks allowed", numOfProposedBlocks) log.Debug("Comparing iterations...") - sortedProposedBlocks, err := razorUtils.GetSortedProposedBlockIds(ctx, client, epoch) + sortedProposedBlocks, err := razorUtils.GetSortedProposedBlockIds(rpcParameters, epoch) if err != nil { log.Error("Error in fetching sorted proposed block ids") return err @@ -116,7 +115,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi log.Debug("Propose: Sorted proposed blocks: ", sortedProposedBlocks) lastBlockIndex := sortedProposedBlocks[numOfProposedBlocks-1] log.Debug("Propose: Last block index: ", lastBlockIndex) - lastProposedBlockStruct, err := razorUtils.GetProposedBlock(ctx, client, epoch, lastBlockIndex) + lastProposedBlockStruct, err := razorUtils.GetProposedBlock(rpcParameters, epoch, lastBlockIndex) if err != nil { log.Error(err) return err @@ -131,7 +130,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi log.Info("Current iteration is less than iteration of last proposed block, can propose") } log.Debugf("Propose: Calling MakeBlock() with arguments blockNumber = %s, epoch = %d, rogueData = %+v", latestHeader.Number, epoch, rogueData) - medians, ids, revealedDataMaps, err := cmdUtils.MakeBlock(ctx, client, latestHeader.Number, epoch, rogueData) + medians, ids, revealedDataMaps, err := cmdUtils.MakeBlock(rpcParameters, latestHeader.Number, epoch, rogueData) if err != nil { log.Error(err) return err @@ -141,8 +140,7 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi log.Debugf("Propose: Iteration: %d Biggest Staker Id: %d", iteration, biggestStakerId) log.Info("Proposing block...") - txnOpts := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.BlockManagerAddress, @@ -152,6 +150,12 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi Account: account, }) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + log.Error(err) + return err + } + log.Debugf("Executing Propose transaction with epoch = %d, Ids = %v, medians = %s, iteration = %s, biggestStakerId = %d", epoch, ids, medians, big.NewInt(int64(iteration)), biggestStakerId) txn, err := blockManagerUtils.Propose(client, txnOpts, epoch, ids, medians, big.NewInt(int64(iteration)), biggestStakerId) if err != nil { @@ -190,8 +194,8 @@ func (*UtilsStruct) Propose(ctx context.Context, client *ethclient.Client, confi } //This function returns the biggest stake and Id of it -func (*UtilsStruct) GetBiggestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) { - numberOfStakers, err := razorUtils.GetNumberOfStakers(ctx, client) +func (*UtilsStruct) GetBiggestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) { + numberOfStakers, err := razorUtils.GetNumberOfStakers(rpcParameters) if err != nil { return nil, 0, err } @@ -202,7 +206,7 @@ func (*UtilsStruct) GetBiggestStakeAndId(ctx context.Context, client *ethclient. var biggestStakerId uint32 biggestStake := big.NewInt(0) - stakeSnapshotArray, err := cmdUtils.BatchGetStakeSnapshotCalls(client, epoch, numberOfStakers) + stakeSnapshotArray, err := cmdUtils.BatchGetStakeSnapshotCalls(rpcParameters, epoch, numberOfStakers) if err != nil { return nil, 0, err } @@ -225,20 +229,20 @@ func (*UtilsStruct) GetBiggestStakeAndId(ctx context.Context, client *ethclient. return biggestStake, biggestStakerId, nil } -func (*UtilsStruct) GetIteration(ctx context.Context, client *ethclient.Client, proposer types.ElectedProposer, bufferPercent int32) int { - stake, err := razorUtils.GetStakeSnapshot(ctx, client, proposer.StakerId, proposer.Epoch) +func (*UtilsStruct) GetIteration(rpcParameters RPC.RPCParameters, proposer types.ElectedProposer, bufferPercent int32) int { + stake, err := razorUtils.GetStakeSnapshot(rpcParameters, proposer.StakerId, proposer.Epoch) if err != nil { log.Error("Error in fetching influence of staker: ", err) return -1 } log.Debug("GetIteration: Stake: ", stake) currentStakerStake := big.NewInt(1).Mul(stake, big.NewInt(int64(math.Exp2(32)))) - stateBuffer, err := razorUtils.GetStateBuffer(ctx, client) + stateBuffer, err := razorUtils.GetStateBuffer(rpcParameters) if err != nil { log.Error("Error in getting state buffer: ", err) return -1 } - latestHeader, err := clientUtils.GetLatestBlockWithRetry(ctx, client) + latestHeader, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in getting latest block: ", err) return -1 @@ -345,9 +349,9 @@ func pseudoRandomNumberGenerator(seed []byte, max uint32, blockHashes []byte) *b } //This function returns the sorted revealed values -func (*UtilsStruct) GetSortedRevealedValues(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) { +func (*UtilsStruct) GetSortedRevealedValues(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) (*types.RevealedDataMaps, error) { log.Debugf("GetSortedRevealedValues: Calling IndexRevealEventsOfCurrentEpoch with arguments blockNumber = %s, epoch = %d", blockNumber, epoch) - assignedAsset, err := cmdUtils.IndexRevealEventsOfCurrentEpoch(ctx, client, blockNumber, epoch) + assignedAsset, err := cmdUtils.IndexRevealEventsOfCurrentEpoch(rpcParameters, blockNumber, epoch) if err != nil { return nil, err } @@ -392,15 +396,15 @@ func (*UtilsStruct) GetSortedRevealedValues(ctx context.Context, client *ethclie } //This function returns the medians, idsRevealedInThisEpoch and revealedDataMaps -func (*UtilsStruct) MakeBlock(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) { +func (*UtilsStruct) MakeBlock(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32, rogueData types.Rogue) ([]*big.Int, []uint16, *types.RevealedDataMaps, error) { log.Debugf("MakeBlock: Calling GetSortedRevealedValues with arguments blockNumber = %s, epoch = %d", blockNumber, epoch) - revealedDataMaps, err := cmdUtils.GetSortedRevealedValues(ctx, client, blockNumber, epoch) + revealedDataMaps, err := cmdUtils.GetSortedRevealedValues(rpcParameters, blockNumber, epoch) if err != nil { return nil, nil, nil, err } log.Debugf("MakeBlock: Revealed data map: %+v", revealedDataMaps) - activeCollections, err := razorUtils.GetActiveCollectionIds(ctx, client) + activeCollections, err := razorUtils.GetActiveCollectionIds(rpcParameters) if err != nil { return nil, nil, nil, err } @@ -452,8 +456,8 @@ func (*UtilsStruct) MakeBlock(ctx context.Context, client *ethclient.Client, blo return medians, idsRevealedInThisEpoch, revealedDataMaps, nil } -func (*UtilsStruct) GetSmallestStakeAndId(ctx context.Context, client *ethclient.Client, epoch uint32) (*big.Int, uint32, error) { - numberOfStakers, err := razorUtils.GetNumberOfStakers(ctx, client) +func (*UtilsStruct) GetSmallestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) { + numberOfStakers, err := razorUtils.GetNumberOfStakers(rpcParameters) if err != nil { return nil, 0, err } @@ -464,7 +468,7 @@ func (*UtilsStruct) GetSmallestStakeAndId(ctx context.Context, client *ethclient smallestStake := big.NewInt(1).Mul(big.NewInt(1e18), big.NewInt(1e18)) for i := 1; i <= int(numberOfStakers); i++ { - stake, err := razorUtils.GetStakeSnapshot(ctx, client, uint32(i), epoch) + stake, err := razorUtils.GetStakeSnapshot(rpcParameters, uint32(i), epoch) if err != nil { return nil, 0, err } @@ -476,7 +480,7 @@ func (*UtilsStruct) GetSmallestStakeAndId(ctx context.Context, client *ethclient return smallestStake, smallestStakerId, nil } -func (*UtilsStruct) BatchGetStakeSnapshotCalls(client *ethclient.Client, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) { +func (*UtilsStruct) BatchGetStakeSnapshotCalls(rpcParameters RPC.RPCParameters, epoch uint32, numberOfStakers uint32) ([]*big.Int, error) { voteManagerABI, err := utils.ABIInterface.Parse(strings.NewReader(bindings.VoteManagerMetaData.ABI)) if err != nil { log.Errorf("Error in parsed voteManager ABI: %v", err) @@ -488,7 +492,7 @@ func (*UtilsStruct) BatchGetStakeSnapshotCalls(client *ethclient.Client, epoch u args[i-1] = []interface{}{epoch, i} } - results, err := clientUtils.BatchCall(client, &voteManagerABI, core.VoteManagerAddress, core.GetStakeSnapshotMethod, args) + results, err := clientUtils.BatchCall(rpcParameters, &voteManagerABI, core.VoteManagerAddress, core.GetStakeSnapshotMethod, args) if err != nil { log.Error("Error in performing getStakeSnapshot batch calls: ", err) return nil, err diff --git a/cmd/resetUnstakeLock.go b/cmd/resetUnstakeLock.go index 13efd91d..9eb6c1d3 100644 --- a/cmd/resetUnstakeLock.go +++ b/cmd/resetUnstakeLock.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/pflag" "github.com/spf13/cobra" @@ -35,32 +32,10 @@ func initialiseExtendLock(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the ResetUnstakeLock function func (*UtilsStruct) ExecuteExtendLock(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteExtendLock: Config: %+v", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - - stakerId, err := razorUtils.AssignStakerId(context.Background(), flagSet, client, address) + stakerId, err := razorUtils.AssignStakerId(rpcParameters, flagSet, account.Address) utils.CheckError("Error in getting stakerId: ", err) extendLockInput := types.ExtendLockInput{ @@ -68,16 +43,15 @@ func (*UtilsStruct) ExecuteExtendLock(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.ResetUnstakeLock(client, config, extendLockInput) + txn, err := cmdUtils.ResetUnstakeLock(rpcParameters, config, extendLockInput) utils.CheckError("Error in extending lock: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for resetUnstakeLock: ", err) } //This function is used to reset the lock once the withdraw lock period is over -func (*UtilsStruct) ResetUnstakeLock(client *ethclient.Client, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) { - txnOpts := razorUtils.GetTxnOpts(context.Background(), types.TransactionOptions{ - Client: client, +func (*UtilsStruct) ResetUnstakeLock(rpcParameters RPC.RPCParameters, config types.Configurations, extendLockInput types.ExtendLockInput) (common.Hash, error) { + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -88,6 +62,11 @@ func (*UtilsStruct) ResetUnstakeLock(client *ethclient.Client, config types.Conf }) log.Info("Extending lock...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debug("Executing ResetUnstakeLock transaction with stakerId = ", extendLockInput.StakerId) txn, err := stakeManagerUtils.ResetUnstakeLock(client, txnOpts, extendLockInput.StakerId) if err != nil { diff --git a/cmd/reveal.go b/cmd/reveal.go index 637f77a3..7a761ef8 100644 --- a/cmd/reveal.go +++ b/cmd/reveal.go @@ -2,9 +2,9 @@ package cmd import ( - "context" "errors" "math/big" + "razor/RPC" "razor/core" "razor/core/types" "razor/pkg/bindings" @@ -14,12 +14,11 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" Types "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" ) //This function checks for epoch last committed -func (*UtilsStruct) CheckForLastCommitted(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker, epoch uint32) error { - epochLastCommitted, err := razorUtils.GetEpochLastCommitted(ctx, client, staker.Id) +func (*UtilsStruct) CheckForLastCommitted(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker, epoch uint32) error { + epochLastCommitted, err := razorUtils.GetEpochLastCommitted(rpcParameters, staker.Id) if err != nil { return err } @@ -31,7 +30,7 @@ func (*UtilsStruct) CheckForLastCommitted(ctx context.Context, client *ethclient } //This function checks if the state is reveal or not and then reveals the votes -func (*UtilsStruct) Reveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) { +func (*UtilsStruct) Reveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, latestHeader *Types.Header, stateBuffer uint64, commitData types.CommitData, signature []byte) (common.Hash, error) { if state, err := razorUtils.GetBufferedState(latestHeader, stateBuffer, config.BufferPercent); err != nil || state != 1 { log.Error("Not reveal state") return core.NilHash, err @@ -56,8 +55,7 @@ func (*UtilsStruct) Reveal(ctx context.Context, client *ethclient.Client, config log.Info("Revealing votes...") - txnOpts := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.VoteManagerAddress, @@ -66,6 +64,13 @@ func (*UtilsStruct) Reveal(ctx context.Context, client *ethclient.Client, config Parameters: []interface{}{epoch, treeRevealData, signature}, Account: account, }) + + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + log.Error(err) + return core.NilHash, err + } + log.Debugf("Executing Reveal transaction wih epoch = %d, treeRevealData = %v, signature = %v", epoch, treeRevealData, signature) txn, err := voteManagerUtils.Reveal(client, txnOpts, epoch, treeRevealData, signature) if err != nil { @@ -113,9 +118,9 @@ func (*UtilsStruct) GenerateTreeRevealData(merkleTree [][][]byte, commitData typ } //This function indexes the reveal events of current epoch -func (*UtilsStruct) IndexRevealEventsOfCurrentEpoch(ctx context.Context, client *ethclient.Client, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) { +func (*UtilsStruct) IndexRevealEventsOfCurrentEpoch(rpcParameters RPC.RPCParameters, blockNumber *big.Int, epoch uint32) ([]types.RevealedStruct, error) { log.Debug("Fetching reveal events of current epoch...") - fromBlock, err := razorUtils.EstimateBlockNumberAtEpochBeginning(client, blockNumber) + fromBlock, err := razorUtils.EstimateBlockNumberAtEpochBeginning(rpcParameters, blockNumber) if err != nil { return nil, errors.New("Not able to Fetch Block: " + err.Error()) } @@ -128,7 +133,7 @@ func (*UtilsStruct) IndexRevealEventsOfCurrentEpoch(ctx context.Context, client }, } log.Debugf("IndexRevealEventsOfCurrentEpoch: Query to send in filter logs: %+v", query) - logs, err := clientUtils.FilterLogsWithRetry(ctx, client, query) + logs, err := clientUtils.FilterLogsWithRetry(rpcParameters, query) if err != nil { return nil, err } diff --git a/cmd/setDelegation.go b/cmd/setDelegation.go index 4de0d08f..1f78439a 100644 --- a/cmd/setDelegation.go +++ b/cmd/setDelegation.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/pflag" "github.com/spf13/cobra" @@ -35,30 +32,8 @@ func initialiseSetDelegation(cmd *cobra.Command, args []string) { //This function sets the flags appropriately and executes the SetDelegation function func (*UtilsStruct) ExecuteSetDelegation(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteSetDelegation: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) statusString, err := flagSetUtils.GetStringStatus(flagSet) utils.CheckError("Error in getting status: ", err) @@ -66,7 +41,7 @@ func (*UtilsStruct) ExecuteSetDelegation(flagSet *pflag.FlagSet) { status, err := stringUtils.ParseBool(statusString) utils.CheckError("Error in parsing status to boolean: ", err) - stakerId, err := razorUtils.GetStakerId(context.Background(), client, address) + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) utils.CheckError("StakerId error: ", err) commission, err := flagSetUtils.GetUint8Commission(flagSet) @@ -80,17 +55,17 @@ func (*UtilsStruct) ExecuteSetDelegation(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.SetDelegation(context.Background(), client, config, delegationInput) + txn, err := cmdUtils.SetDelegation(rpcParameters, config, delegationInput) utils.CheckError("SetDelegation error: ", err) if txn != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for setDelegation: ", err) } } //This function allows the staker to start accepting/rejecting delegation requests -func (*UtilsStruct) SetDelegation(ctx context.Context, client *ethclient.Client, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) { - stakerInfo, err := razorUtils.GetStaker(ctx, client, delegationInput.StakerId) +func (*UtilsStruct) SetDelegation(rpcParameters RPC.RPCParameters, config types.Configurations, delegationInput types.SetDelegationInput) (common.Hash, error) { + stakerInfo, err := razorUtils.GetStaker(rpcParameters, delegationInput.StakerId) if err != nil { return core.NilHash, err } @@ -101,14 +76,13 @@ func (*UtilsStruct) SetDelegation(ctx context.Context, client *ethclient.Client, Commission: delegationInput.Commission, Account: delegationInput.Account, } - err = cmdUtils.UpdateCommission(ctx, config, client, updateCommissionInput) + err = cmdUtils.UpdateCommission(rpcParameters, config, updateCommissionInput) if err != nil { return core.NilHash, err } } txnOpts := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -123,7 +97,12 @@ func (*UtilsStruct) SetDelegation(ctx context.Context, client *ethclient.Client, return core.NilHash, nil } log.Infof("Setting delegation acceptance of Staker %d to %t", delegationInput.StakerId, delegationInput.Status) - setDelegationAcceptanceTxnOpts := razorUtils.GetTxnOpts(ctx, txnOpts) + setDelegationAcceptanceTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnOpts) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debug("Executing SetDelegationAcceptance transaction with status ", delegationInput.Status) delegationAcceptanceTxn, err := stakeManagerUtils.SetDelegationAcceptance(client, setDelegationAcceptanceTxnOpts, delegationInput.Status) if err != nil { diff --git a/cmd/stakerInfo.go b/cmd/stakerInfo.go index 5dc5a663..7b761f01 100644 --- a/cmd/stakerInfo.go +++ b/cmd/stakerInfo.go @@ -3,11 +3,11 @@ package cmd import ( "context" - "github.com/ethereum/go-ethereum/ethclient" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "github.com/spf13/pflag" "os" + "razor/RPC" "razor/logger" "razor/utils" "strconv" @@ -41,28 +41,35 @@ func (*UtilsStruct) ExecuteStakerinfo(flagSet *pflag.FlagSet) { utils.CheckError("Error in getting stakerId: ", err) log.Debug("ExecuteStakerinfo: StakerId: ", stakerId) + rpcManager, err := RPC.InitializeRPCManager(config.Provider) + utils.CheckError("Error in initializing RPC Manager: ", err) + + rpcParameters := RPC.RPCParameters{ + RPCManager: rpcManager, + Ctx: context.Background(), + } + log.Debug("ExecuteStakerinfo: Calling GetStakerInfo() with argument stakerId = ", stakerId) - err = cmdUtils.GetStakerInfo(context.Background(), client, stakerId) + err = cmdUtils.GetStakerInfo(rpcParameters, stakerId) utils.CheckError("Error in getting staker info: ", err) } //This function provides the staker details like age, stake, maturity etc. -func (*UtilsStruct) GetStakerInfo(ctx context.Context, client *ethclient.Client, stakerId uint32) error { - callOpts := razorUtils.GetOptions() - stakerInfo, err := stakeManagerUtils.StakerInfo(client, &callOpts, stakerId) +func (*UtilsStruct) GetStakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) error { + stakerInfo, err := razorUtils.StakerInfo(rpcParameters, stakerId) if err != nil { return err } - maturity, err := stakeManagerUtils.GetMaturity(client, &callOpts, stakerInfo.Age) + maturity, err := razorUtils.GetMaturity(rpcParameters, stakerInfo.Age) if err != nil { return err } - epoch, err := razorUtils.GetEpoch(ctx, client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { return err } - influence, err := razorUtils.GetInfluenceSnapshot(ctx, client, stakerId, epoch) + influence, err := razorUtils.GetInfluenceSnapshot(rpcParameters, stakerId, epoch) if err != nil { return err } diff --git a/cmd/struct-utils.go b/cmd/struct-utils.go index 0c22a71d..27b11459 100644 --- a/cmd/struct-utils.go +++ b/cmd/struct-utils.go @@ -2,11 +2,11 @@ package cmd import ( - "context" "crypto/ecdsa" "errors" "math/big" "os" + "razor/RPC" "razor/core" "razor/core/types" "razor/path" @@ -195,58 +195,6 @@ func (stakeManagerUtils StakeManagerUtils) RedeemBounty(client *ethclient.Client return ExecuteTransaction(stakeManager, "RedeemBounty", opts, bountyId) } -//This function returns the staker Info -func (stakeManagerUtils StakeManagerUtils) StakerInfo(client *ethclient.Client, opts *bind.CallOpts, stakerId uint32) (types.Staker, error) { - stakeManager := razorUtils.GetStakeManager(client) - returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "Stakers", opts, stakerId) - returnedError := utils.CheckIfAnyError(returnedValues) - if returnedError != nil { - return types.Staker{}, returnedError - } - staker := returnedValues[0].Interface().(struct { - AcceptDelegation bool - IsSlashed bool - Commission uint8 - Id uint32 - Age uint32 - Address common.Address - TokenAddress common.Address - EpochFirstStakedOrLastPenalized uint32 - EpochCommissionLastUpdated uint32 - Stake *big.Int - StakerReward *big.Int - }) - return staker, nil -} - -//This function returns the maturity -func (stakeManagerUtils StakeManagerUtils) GetMaturity(client *ethclient.Client, opts *bind.CallOpts, age uint32) (uint16, error) { - stakeManager := razorUtils.GetStakeManager(client) - index := age / 10000 - returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "Maturities", opts, big.NewInt(int64(index))) - returnedError := utils.CheckIfAnyError(returnedValues) - if returnedError != nil { - return 0, returnedError - } - return returnedValues[0].Interface().(uint16), nil -} - -//This function returns the bounty lock -func (stakeManagerUtils StakeManagerUtils) GetBountyLock(client *ethclient.Client, opts *bind.CallOpts, bountyId uint32) (types.BountyLock, error) { - stakeManager := razorUtils.GetStakeManager(client) - returnedValues := utils.InvokeFunctionWithTimeout(stakeManager, "BountyLocks", opts, bountyId) - returnedError := utils.CheckIfAnyError(returnedValues) - if returnedError != nil { - return types.BountyLock{}, returnedError - } - bountyLock := returnedValues[0].Interface().(struct { - RedeemAfter uint32 - BountyHunter common.Address - Amount *big.Int - }) - return bountyLock, nil -} - //This function is used to claim the staker reward func (stakeManagerUtils StakeManagerUtils) ClaimStakerReward(client *ethclient.Client, opts *bind.TransactOpts) (*Types.Transaction, error) { stakeManager := razorUtils.GetStakeManager(client) @@ -387,30 +335,15 @@ func (blockManagerUtils BlockManagerUtils) Propose(client *ethclient.Client, opt } //This function returns the sorted Ids -func (blockManagerUtils BlockManagerUtils) GiveSorted(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*Types.Transaction, error) { +func (blockManagerUtils BlockManagerUtils) GiveSorted(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32, leafId uint16, sortedValues []*big.Int) (*Types.Transaction, error) { + blockManager := razorUtils.GetBlockManager(client) return ExecuteTransaction(blockManager, "GiveSorted", opts, epoch, leafId, sortedValues) } //This function resets the dispute -func (blockManagerUtils BlockManagerUtils) ResetDispute(blockManager *bindings.BlockManager, opts *bind.TransactOpts, epoch uint32) (*Types.Transaction, error) { - return ExecuteTransaction(blockManager, "ResetDispute", opts, epoch) -} - -// This functiom gets Disputes mapping -func (blockManagerUtils BlockManagerUtils) Disputes(client *ethclient.Client, opts *bind.CallOpts, epoch uint32, address common.Address) (types.DisputesStruct, error) { +func (blockManagerUtils BlockManagerUtils) ResetDispute(client *ethclient.Client, opts *bind.TransactOpts, epoch uint32) (*Types.Transaction, error) { blockManager := razorUtils.GetBlockManager(client) - returnedValues := utils.InvokeFunctionWithTimeout(blockManager, "Disputes", opts, epoch, address) - returnedError := utils.CheckIfAnyError(returnedValues) - if returnedError != nil { - return types.DisputesStruct{}, returnedError - } - disputesMapping := returnedValues[0].Interface().(struct { - LeafId uint16 - LastVisitedValue *big.Int - AccWeight *big.Int - Median *big.Int - }) - return disputesMapping, nil + return ExecuteTransaction(blockManager, "ResetDispute", opts, epoch) } //This function is used to reveal the values @@ -455,17 +388,6 @@ func (voteManagerUtils VoteManagerUtils) Commit(client *ethclient.Client, opts * return txn, nil } -//This function is used to check the allowance of staker -func (tokenManagerUtils TokenManagerUtils) Allowance(client *ethclient.Client, opts *bind.CallOpts, owner common.Address, spender common.Address) (*big.Int, error) { - tokenManager := razorUtils.GetTokenManager(client) - returnedValues := utils.InvokeFunctionWithTimeout(tokenManager, "Allowance", opts, owner, spender) - returnedError := utils.CheckIfAnyError(returnedValues) - if returnedError != nil { - return nil, returnedError - } - return returnedValues[0].Interface().(*big.Int), nil -} - //This function is used to approve the transaction func (tokenManagerUtils TokenManagerUtils) Approve(client *ethclient.Client, opts *bind.TransactOpts, spender common.Address, amount *big.Int) (*Types.Transaction, error) { tokenManager := razorUtils.GetTokenManager(client) @@ -694,8 +616,8 @@ func (c CryptoUtils) HexToECDSA(hexKey string) (*ecdsa.PrivateKey, error) { } //This function is used to give the sorted Ids -func (*UtilsStruct) GiveSorted(ctx context.Context, client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error { - return GiveSorted(ctx, client, blockManager, txnArgs, epoch, assetId, sortedStakers) +func (*UtilsStruct) GiveSorted(rpcParameters RPC.RPCParameters, txnArgs types.TransactionOptions, epoch uint32, assetId uint16, sortedStakers []*big.Int) error { + return GiveSorted(rpcParameters, txnArgs, epoch, assetId, sortedStakers) } //This function is used to write config as diff --git a/cmd/transfer.go b/cmd/transfer.go index 3a66b8f4..1b159ea7 100644 --- a/cmd/transfer.go +++ b/cmd/transfer.go @@ -3,6 +3,7 @@ package cmd import ( "context" + "razor/RPC" "razor/accounts" "razor/core" "razor/core/types" @@ -10,8 +11,6 @@ import ( "razor/pkg/bindings" "razor/utils" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/spf13/pflag" "github.com/ethereum/go-ethereum/common" @@ -63,7 +62,15 @@ func (*UtilsStruct) ExecuteTransfer(flagSet *pflag.FlagSet) { toAddress, err := flagSetUtils.GetStringTo(flagSet) utils.CheckError("Error in getting toAddress: ", err) - balance, err := razorUtils.FetchBalance(client, fromAddress) + rpcManager, err := RPC.InitializeRPCManager(config.Provider) + utils.CheckError("Error in initializing RPC Manager: ", err) + + rpcParameters := RPC.RPCParameters{ + RPCManager: rpcManager, + Ctx: context.Background(), + } + + balance, err := razorUtils.FetchBalance(rpcParameters, account.Address) utils.CheckError("Error in fetching razor balance: ", err) log.Debug("Getting amount in wei...") @@ -77,20 +84,19 @@ func (*UtilsStruct) ExecuteTransfer(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.Transfer(client, config, transferInput) + txn, err := cmdUtils.Transfer(rpcParameters, config, transferInput) utils.CheckError("Transfer error: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for transfer: ", err) } //This function transfers the razors from your account to others account -func (*UtilsStruct) Transfer(client *ethclient.Client, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) { +func (*UtilsStruct) Transfer(rpcParameters RPC.RPCParameters, config types.Configurations, transferInput types.TransferInput) (common.Hash, error) { log.Debug("Checking for sufficient balance...") razorUtils.CheckAmountAndBalance(transferInput.ValueInWei, transferInput.Balance) - txnOpts := razorUtils.GetTxnOpts(context.Background(), types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.RAZORAddress, @@ -100,6 +106,10 @@ func (*UtilsStruct) Transfer(client *ethclient.Client, config types.Configuratio Account: transferInput.Account, }) log.Infof("Transferring %g tokens from %s to %s", utils.GetAmountInDecimal(transferInput.ValueInWei), transferInput.Account.Address, transferInput.ToAddress) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } log.Debugf("Executing Transfer transaction with toAddress: %s, amount: %s", transferInput.ToAddress, transferInput.ValueInWei) txn, err := tokenManagerUtils.Transfer(client, txnOpts, common.HexToAddress(transferInput.ToAddress), transferInput.ValueInWei) diff --git a/cmd/unlockWithdraw.go b/cmd/unlockWithdraw.go index 187cd907..725b966c 100644 --- a/cmd/unlockWithdraw.go +++ b/cmd/unlockWithdraw.go @@ -2,19 +2,16 @@ package cmd import ( - "context" "errors" "math/big" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -34,48 +31,25 @@ func initializeUnlockWithdraw(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the UnlockWithdraw function func (*UtilsStruct) ExecuteUnlockWithdraw(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteUnlockWithdraw: Config: %+v", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteUnlockWithdraw: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - - stakerId, err := razorUtils.AssignStakerId(context.Background(), flagSet, client, address) + stakerId, err := razorUtils.AssignStakerId(rpcParameters, flagSet, account.Address) utils.CheckError("Error in fetching stakerId: ", err) log.Debug("ExecuteUnlockWithdraw: StakerId: ", stakerId) - txn, err := cmdUtils.HandleWithdrawLock(context.Background(), client, account, config, stakerId) + txn, err := cmdUtils.HandleWithdrawLock(rpcParameters, account, config, stakerId) utils.CheckError("HandleWithdrawLock error: ", err) if txn != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for unlockWithdraw: ", err) } } //This function handles the Withdraw lock -func (*UtilsStruct) HandleWithdrawLock(ctx context.Context, client *ethclient.Client, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { - withdrawLock, err := razorUtils.GetLock(ctx, client, account.Address, stakerId, 1) +func (*UtilsStruct) HandleWithdrawLock(rpcParameters RPC.RPCParameters, account types.Account, configurations types.Configurations, stakerId uint32) (common.Hash, error) { + withdrawLock, err := razorUtils.GetLock(rpcParameters, account.Address, stakerId, 1) if err != nil { return core.NilHash, err } @@ -86,7 +60,7 @@ func (*UtilsStruct) HandleWithdrawLock(ctx context.Context, client *ethclient.Cl return core.NilHash, errors.New("initiate withdrawal of Razors before unlocking withdraw") } - epoch, err := razorUtils.GetEpoch(ctx, client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { log.Error("Error in fetching epoch") return core.NilHash, err @@ -102,7 +76,6 @@ func (*UtilsStruct) HandleWithdrawLock(ctx context.Context, client *ethclient.Cl if big.NewInt(int64(epoch)).Cmp(withdrawLock.UnlockAfter) >= 0 { txnArgs := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: configurations, ContractAddress: core.StakeManagerAddress, @@ -111,16 +84,20 @@ func (*UtilsStruct) HandleWithdrawLock(ctx context.Context, client *ethclient.Cl Parameters: []interface{}{stakerId}, Account: account, } - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Debug("HandleWithdrawLock: Calling UnlockWithdraw() with arguments stakerId = ", stakerId) - return cmdUtils.UnlockWithdraw(client, txnOpts, stakerId) + return cmdUtils.UnlockWithdraw(rpcParameters, txnOpts, stakerId) } return core.NilHash, errors.New("withdrawLock period not over yet! Please try after some time") } //This function withdraws your razor once withdraw lock has passed -func (*UtilsStruct) UnlockWithdraw(client *ethclient.Client, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { +func (*UtilsStruct) UnlockWithdraw(rpcParameters RPC.RPCParameters, txnOpts *bind.TransactOpts, stakerId uint32) (common.Hash, error) { log.Info("Unlocking funds...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } log.Debug("Executing UnlockWithdraw transaction with stakerId = ", stakerId) txn, err := stakeManagerUtils.UnlockWithdraw(client, txnOpts, stakerId) diff --git a/cmd/unstake.go b/cmd/unstake.go index 8d0ec8f5..86698303 100644 --- a/cmd/unstake.go +++ b/cmd/unstake.go @@ -2,19 +2,16 @@ package cmd import ( - "context" "errors" "math/big" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/pflag" "github.com/spf13/cobra" @@ -38,36 +35,14 @@ func initialiseUnstake(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the Unstake function func (*UtilsStruct) ExecuteUnstake(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteUnstake: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) log.Debug("Getting amount in wei...") valueInWei, err := cmdUtils.AssignAmountInWei(flagSet) utils.CheckError("Error in getting amountInWei: ", err) - stakerId, err := razorUtils.AssignStakerId(context.Background(), flagSet, client, address) + stakerId, err := razorUtils.AssignStakerId(rpcParameters, flagSet, account.Address) utils.CheckError("StakerId error: ", err) unstakeInput := types.UnstakeInput{ @@ -76,25 +51,24 @@ func (*UtilsStruct) ExecuteUnstake(flagSet *pflag.FlagSet) { Account: account, } - txnHash, err := cmdUtils.Unstake(context.Background(), config, client, unstakeInput) + txnHash, err := cmdUtils.Unstake(rpcParameters, config, unstakeInput) utils.CheckError("Unstake Error: ", err) if txnHash != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, txnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txnHash.Hex()) utils.CheckError("Error in WaitForBlockCompletion for unstake: ", err) } } //This function allows user to unstake their sRZRs in the razor network -func (*UtilsStruct) Unstake(ctx context.Context, config types.Configurations, client *ethclient.Client, input types.UnstakeInput) (common.Hash, error) { +func (*UtilsStruct) Unstake(rpcParameters RPC.RPCParameters, config types.Configurations, input types.UnstakeInput) (common.Hash, error) { txnArgs := types.TransactionOptions{ - Client: client, Amount: input.ValueInWei, ChainId: core.ChainId, Config: config, Account: input.Account, } stakerId := input.StakerId - staker, err := razorUtils.GetStaker(ctx, client, stakerId) + staker, err := razorUtils.GetStaker(rpcParameters, stakerId) if err != nil { log.Error("Error in getting staker: ", err) return core.NilHash, err @@ -102,13 +76,13 @@ func (*UtilsStruct) Unstake(ctx context.Context, config types.Configurations, cl log.Debugf("Unstake: Staker info: %+v", staker) log.Debug("Unstake: Calling ApproveUnstake()...") - approveHash, err := cmdUtils.ApproveUnstake(client, staker.TokenAddress, txnArgs) + approveHash, err := cmdUtils.ApproveUnstake(rpcParameters, staker.TokenAddress, txnArgs) if err != nil { return core.NilHash, err } if approveHash != core.NilHash { - err = razorUtils.WaitForBlockCompletion(client, approveHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, approveHash.Hex()) if err != nil { return core.NilHash, err } @@ -120,7 +94,7 @@ func (*UtilsStruct) Unstake(ctx context.Context, config types.Configurations, cl txnArgs.MethodName = "unstake" txnArgs.ABI = bindings.StakeManagerMetaData.ABI - unstakeLock, err := razorUtils.GetLock(ctx, txnArgs.Client, txnArgs.Account.Address, stakerId, 0) + unstakeLock, err := razorUtils.GetLock(rpcParameters, txnArgs.Account.Address, stakerId, 0) if err != nil { log.Error("Error in getting unstakeLock: ", err) return core.NilHash, err @@ -134,10 +108,15 @@ func (*UtilsStruct) Unstake(ctx context.Context, config types.Configurations, cl } txnArgs.Parameters = []interface{}{stakerId, txnArgs.Amount} - txnOpts := razorUtils.GetTxnOpts(ctx, txnArgs) + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) log.Info("Unstaking coins") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing Unstake transaction with stakerId = %d, amount = %s", stakerId, txnArgs.Amount) - txn, err := stakeManagerUtils.Unstake(txnArgs.Client, txnOpts, stakerId, txnArgs.Amount) + txn, err := stakeManagerUtils.Unstake(client, txnOpts, stakerId, txnArgs.Amount) if err != nil { log.Error("Error in un-staking: ", err) return core.NilHash, err @@ -148,8 +127,13 @@ func (*UtilsStruct) Unstake(ctx context.Context, config types.Configurations, cl } //This function approves the unstake -func (*UtilsStruct) ApproveUnstake(client *ethclient.Client, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) { - txnOpts := razorUtils.GetTxnOpts(context.Background(), txnArgs) +func (*UtilsStruct) ApproveUnstake(rpcParameters RPC.RPCParameters, stakerTokenAddress common.Address, txnArgs types.TransactionOptions) (common.Hash, error) { + txnOpts := razorUtils.GetTxnOpts(rpcParameters, txnArgs) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Infof("Approving %d amount for unstake...", txnArgs.Amount) txn, err := stakeManagerUtils.ApproveUnstake(client, txnOpts, stakerTokenAddress, txnArgs.Amount) if err != nil { diff --git a/cmd/updateCollection.go b/cmd/updateCollection.go index 0d4efc63..1636702a 100644 --- a/cmd/updateCollection.go +++ b/cmd/updateCollection.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -37,30 +34,8 @@ func initialiseUpdateCollection(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the UpdateCollection function func (*UtilsStruct) ExecuteUpdateCollection(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteUpdateCollection: Config : %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) collectionId, err := flagSetUtils.GetUint16CollectionId(flagSet) utils.CheckError("Error in getting collectionID: ", err) @@ -84,23 +59,22 @@ func (*UtilsStruct) ExecuteUpdateCollection(flagSet *pflag.FlagSet) { Tolerance: tolerance, Account: account, } - txn, err := cmdUtils.UpdateCollection(context.Background(), client, config, collectionInput, collectionId) + txn, err := cmdUtils.UpdateCollection(rpcParameters, config, collectionInput, collectionId) utils.CheckError("Update Collection error: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for updateCollection: ", err) } //This function allows the admin to update an existing collection -func (*UtilsStruct) UpdateCollection(ctx context.Context, client *ethclient.Client, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) { +func (*UtilsStruct) UpdateCollection(rpcParameters RPC.RPCParameters, config types.Configurations, collectionInput types.CreateCollectionInput, collectionId uint16) (common.Hash, error) { jobIds := utils.ConvertUintArrayToUint16Array(collectionInput.JobIds) log.Debug("UpdateCollection: Uint16 jobIds: ", jobIds) - _, err := cmdUtils.WaitIfCommitState(ctx, client, "update collection") + _, err := cmdUtils.WaitIfCommitState(rpcParameters, "update collection") if err != nil { log.Error("Error in fetching state") return core.NilHash, err } - txnOpts := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnOpts := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -110,6 +84,11 @@ func (*UtilsStruct) UpdateCollection(ctx context.Context, client *ethclient.Clie Account: collectionInput.Account, }) log.Info("Updating collection...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing UpdateCollection transaction with collectionId = %d, tolerance = %d, aggregation method = %d, power = %d, jobIds = %v", collectionId, collectionInput.Tolerance, collectionInput.Aggregation, collectionInput.Power, jobIds) txn, err := assetManagerUtils.UpdateCollection(client, txnOpts, collectionId, collectionInput.Tolerance, collectionInput.Aggregation, collectionInput.Power, jobIds) if err != nil { diff --git a/cmd/updateCommission.go b/cmd/updateCommission.go index 5a79e17d..5a3b7c28 100644 --- a/cmd/updateCommission.go +++ b/cmd/updateCommission.go @@ -2,16 +2,13 @@ package cmd import ( - "context" "errors" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/pflag" "github.com/spf13/cobra" @@ -34,35 +31,13 @@ func initialiseUpdateCommission(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the UpdateCommission function func (*UtilsStruct) ExecuteUpdateCommission(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteUpdateCommission: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) commission, err := flagSetUtils.GetUint8Commission(flagSet) utils.CheckError("Error in getting commission", err) - stakerId, err := razorUtils.GetStakerId(context.Background(), client, address) + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) utils.CheckError("Error in getting stakerId", err) updateCommissionInput := types.UpdateCommissionInput{ @@ -71,20 +46,20 @@ func (*UtilsStruct) ExecuteUpdateCommission(flagSet *pflag.FlagSet) { Account: account, } - err = cmdUtils.UpdateCommission(context.Background(), config, client, updateCommissionInput) + err = cmdUtils.UpdateCommission(rpcParameters, config, updateCommissionInput) utils.CheckError("UpdateCommission error: ", err) } //This function allows a staker to add/update the commission value -func (*UtilsStruct) UpdateCommission(ctx context.Context, config types.Configurations, client *ethclient.Client, updateCommissionInput types.UpdateCommissionInput) error { - stakerInfo, err := razorUtils.GetStaker(ctx, client, updateCommissionInput.StakerId) +func (*UtilsStruct) UpdateCommission(rpcParameters RPC.RPCParameters, config types.Configurations, updateCommissionInput types.UpdateCommissionInput) error { + stakerInfo, err := razorUtils.GetStaker(rpcParameters, updateCommissionInput.StakerId) if err != nil { log.Error("Error in fetching staker info") return err } log.Debugf("UpdateCommission: Staker Info: %+v", stakerInfo) - maxCommission, err := razorUtils.GetMaxCommission(ctx, client) + maxCommission, err := razorUtils.GetMaxCommission(rpcParameters) if err != nil { return err } @@ -94,13 +69,13 @@ func (*UtilsStruct) UpdateCommission(ctx context.Context, config types.Configura return errors.New("commission out of range") } - epochLimitForUpdateCommission, err := razorUtils.GetEpochLimitForUpdateCommission(ctx, client) + epochLimitForUpdateCommission, err := razorUtils.GetEpochLimitForUpdateCommission(rpcParameters) if err != nil { return err } log.Debug("UpdateCommission: Epoch limit to update commission: ", epochLimitForUpdateCommission) - epoch, err := razorUtils.GetEpoch(ctx, client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { return err } @@ -118,7 +93,6 @@ func (*UtilsStruct) UpdateCommission(ctx context.Context, config types.Configura return errors.New("invalid epoch for update") } txnOpts := types.TransactionOptions{ - Client: client, ChainId: core.ChainId, Config: config, ContractAddress: core.StakeManagerAddress, @@ -127,8 +101,13 @@ func (*UtilsStruct) UpdateCommission(ctx context.Context, config types.Configura Parameters: []interface{}{updateCommissionInput.Commission}, Account: updateCommissionInput.Account, } - updateCommissionTxnOpts := razorUtils.GetTxnOpts(ctx, txnOpts) + updateCommissionTxnOpts := razorUtils.GetTxnOpts(rpcParameters, txnOpts) log.Infof("Setting the commission value of Staker %d to %d%%", updateCommissionInput.StakerId, updateCommissionInput.Commission) + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return err + } + log.Debug("Executing UpdateCommission transaction with commission = ", updateCommissionInput.Commission) txn, err := stakeManagerUtils.UpdateCommission(client, updateCommissionTxnOpts, updateCommissionInput.Commission) if err != nil { @@ -137,7 +116,7 @@ func (*UtilsStruct) UpdateCommission(ctx context.Context, config types.Configura } txnHash := transactionUtils.Hash(txn) log.Infof("Txn Hash: %s", txnHash.Hex()) - err = razorUtils.WaitForBlockCompletion(client, txnHash.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txnHash.Hex()) if err != nil { log.Error("Error in WaitForBlockCompletion for updateCommission: ", err) return err diff --git a/cmd/updateJob.go b/cmd/updateJob.go index b0828f2d..9cdec339 100644 --- a/cmd/updateJob.go +++ b/cmd/updateJob.go @@ -2,16 +2,13 @@ package cmd import ( - "context" - "razor/accounts" + "razor/RPC" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -37,30 +34,8 @@ func initialiseUpdateJob(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the UpdateJob function func (*UtilsStruct) ExecuteUpdateJob(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteUpdateJob: Config: %+v", config) - - client := razorUtils.ConnectToClient(config.Provider) - - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) jobId, err := flagSetUtils.GetUint16JobId(flagSet) utils.CheckError("Error in getting jobId: ", err) @@ -89,21 +64,20 @@ func (*UtilsStruct) ExecuteUpdateJob(flagSet *pflag.FlagSet) { Account: account, } - txn, err := cmdUtils.UpdateJob(context.Background(), client, config, jobInput, jobId) + txn, err := cmdUtils.UpdateJob(rpcParameters, config, jobInput, jobId) utils.CheckError("UpdateJob error: ", err) - err = razorUtils.WaitForBlockCompletion(client, txn.Hex()) + err = razorUtils.WaitForBlockCompletion(rpcParameters, txn.Hex()) utils.CheckError("Error in WaitForBlockCompletion for updateJob: ", err) } //This function allows the admin to update an existing job -func (*UtilsStruct) UpdateJob(ctx context.Context, client *ethclient.Client, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) { - _, err := cmdUtils.WaitIfCommitState(ctx, client, "update job") +func (*UtilsStruct) UpdateJob(rpcParameters RPC.RPCParameters, config types.Configurations, jobInput types.CreateJobInput, jobId uint16) (common.Hash, error) { + _, err := cmdUtils.WaitIfCommitState(rpcParameters, "update job") if err != nil { log.Error("Error in fetching state") return core.NilHash, err } - txnArgs := razorUtils.GetTxnOpts(ctx, types.TransactionOptions{ - Client: client, + txnArgs := razorUtils.GetTxnOpts(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.CollectionManagerAddress, @@ -113,6 +87,11 @@ func (*UtilsStruct) UpdateJob(ctx context.Context, client *ethclient.Client, con Account: jobInput.Account, }) log.Info("Updating Job...") + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return core.NilHash, err + } + log.Debugf("Executing UpdateJob transaction with arguments jobId = %d, weight = %d, power = %d, selector type = %d, selector = %s, URL = %s", jobId, jobInput.Weight, jobInput.Power, jobInput.SelectorType, jobInput.Selector, jobInput.Url) txn, err := assetManagerUtils.UpdateJob(client, txnArgs, jobId, jobInput.Weight, jobInput.Power, jobInput.SelectorType, jobInput.Selector, jobInput.Url) if err != nil { diff --git a/cmd/vote.go b/cmd/vote.go index 2f7b4110..729b5357 100644 --- a/cmd/vote.go +++ b/cmd/vote.go @@ -10,11 +10,10 @@ import ( "os" "os/signal" "path/filepath" - "razor/accounts" + "razor/RPC" "razor/cache" "razor/core" "razor/core/types" - "razor/logger" "razor/pkg/bindings" "razor/utils" "time" @@ -26,7 +25,6 @@ import ( "github.com/spf13/pflag" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" solsha3 "github.com/miguelmota/go-solidity-sha3" "github.com/spf13/cobra" ) @@ -48,35 +46,12 @@ func initializeVote(cmd *cobra.Command, args []string) { //This function sets the flag appropriately and executes the Vote function func (*UtilsStruct) ExecuteVote(flagSet *pflag.FlagSet) { - config, err := cmdUtils.GetConfigData() - utils.CheckError("Error in getting config: ", err) - log.Debugf("ExecuteVote: Config: %+v", config) + config, rpcParameters, account, err := InitializeCommandDependencies(flagSet) + utils.CheckError("Error in initialising command dependencies: ", err) - client := razorUtils.ConnectToClient(config.Provider) - - err = ValidateBufferPercentLimit(context.Background(), client, config.BufferPercent) + err = ValidateBufferPercentLimit(rpcParameters, config.BufferPercent) utils.CheckError("Error in validating buffer percent: ", err) - address, err := flagSetUtils.GetStringAddress(flagSet) - utils.CheckError("Error in getting address: ", err) - log.Debug("ExecuteVote: Address: ", address) - - logger.SetLoggerParameters(client, address) - - log.Debug("Checking to assign log file...") - fileUtils.AssignLogFile(flagSet, config) - - log.Debug("Getting password...") - password := razorUtils.AssignPassword(flagSet) - - accountManager, err := razorUtils.AccountManagerForKeystore() - utils.CheckError("Error in getting accounts manager for keystore: ", err) - - account := accounts.InitAccountStruct(address, password, accountManager) - - err = razorUtils.CheckPassword(account) - utils.CheckError("Error in fetching private key from given password: ", err) - isRogue, err := flagSetUtils.GetBoolRogue(flagSet) utils.CheckError("Error in getting rogue status: ", err) log.Debug("ExecuteVote: IsRogue: ", isRogue) @@ -106,7 +81,7 @@ func (*UtilsStruct) ExecuteVote(flagSet *pflag.FlagSet) { }, } - stakerId, err := razorUtils.GetStakerId(context.Background(), client, address) + stakerId, err := razorUtils.GetStakerId(rpcParameters, account.Address) utils.CheckError("Error in getting staker id: ", err) if stakerId == 0 { @@ -115,7 +90,7 @@ func (*UtilsStruct) ExecuteVote(flagSet *pflag.FlagSet) { cmdUtils.HandleExit() - jobsCache, collectionsCache, initCacheBlockNumber, err := cmdUtils.InitJobAndCollectionCache(context.Background(), client) + jobsCache, collectionsCache, initCacheBlockNumber, err := cmdUtils.InitJobAndCollectionCache(rpcParameters) utils.CheckError("Error in initializing asset cache: ", err) commitParams := &types.CommitParams{ @@ -127,7 +102,7 @@ func (*UtilsStruct) ExecuteVote(flagSet *pflag.FlagSet) { } log.Debugf("Calling Vote() with arguments rogueData = %+v, account address = %s, backup node actions to ignore = %s", rogueData, account.Address, backupNodeActionsToIgnore) - if err := cmdUtils.Vote(context.Background(), config, client, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore); err != nil { + if err := cmdUtils.Vote(rpcParameters, config, account, stakerId, commitParams, rogueData, backupNodeActionsToIgnore); err != nil { log.Errorf("%v\n", err) osUtils.Exit(1) } @@ -158,16 +133,16 @@ func (*UtilsStruct) HandleExit() { } //This function handles all the states of voting -func (*UtilsStruct) Vote(ctx context.Context, config types.Configurations, client *ethclient.Client, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { - header, err := clientUtils.GetLatestBlockWithRetry(context.Background(), client) +func (*UtilsStruct) Vote(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, stakerId uint32, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) error { + header, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) utils.CheckError("Error in getting block: ", err) for { select { - case <-ctx.Done(): + case <-rpcParameters.Ctx.Done(): return nil default: log.Debugf("Vote: Header value: %d", header.Number) - latestHeader, err := clientUtils.GetLatestBlockWithRetry(context.Background(), client) + latestHeader, err := clientUtils.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in fetching block: ", err) continue @@ -175,7 +150,7 @@ func (*UtilsStruct) Vote(ctx context.Context, config types.Configurations, clien log.Debugf("Vote: Latest header value: %d", latestHeader.Number) if latestHeader.Number.Cmp(header.Number) != 0 { header = latestHeader - cmdUtils.HandleBlock(client, account, stakerId, latestHeader, config, commitParams, rogueData, backupNodeActionsToIgnore) + cmdUtils.HandleBlock(rpcParameters, account, stakerId, latestHeader, config, commitParams, rogueData, backupNodeActionsToIgnore) } time.Sleep(time.Second * time.Duration(core.BlockNumberInterval)) } @@ -187,11 +162,12 @@ var ( lastVerification uint32 blockConfirmed uint32 disputeData types.DisputeFileData + lastRPCRefreshEpoch uint32 ) //This function handles the block -func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, stakerId uint32, latestHeader *Types.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) { - stateBuffer, err := razorUtils.GetStateBuffer(context.Background(), client) +func (*UtilsStruct) HandleBlock(rpcParameters RPC.RPCParameters, account types.Account, stakerId uint32, latestHeader *Types.Header, config types.Configurations, commitParams *types.CommitParams, rogueData types.Rogue, backupNodeActionsToIgnore []string) { + stateBuffer, err := razorUtils.GetStateBuffer(rpcParameters) if err != nil { log.Error("Error in getting state buffer: ", err) return @@ -207,25 +183,29 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, ctx, cancel := context.WithTimeout(context.Background(), time.Duration(remainingTimeOfTheCurrentState)*time.Second) defer cancel() + + // Replacing context with the context which timeouts after remainingTimeOfTheCurrentState seconds + rpcParameters.Ctx = ctx + state, err := razorUtils.GetBufferedState(latestHeader, stateBuffer, config.BufferPercent) if err != nil { log.Error("Error in getting state: ", err) return } - epoch, err := razorUtils.GetEpoch(ctx, client) + epoch, err := razorUtils.GetEpoch(rpcParameters) if err != nil { log.Error("Error in getting epoch: ", err) return } - staker, err := razorUtils.GetStaker(ctx, client, stakerId) + staker, err := razorUtils.GetStaker(rpcParameters, stakerId) if err != nil { log.Error(err) return } stakedAmount := staker.Stake - ethBalance, err := clientUtils.BalanceAtWithRetry(ctx, client, common.HexToAddress(account.Address)) + ethBalance, err := clientUtils.BalanceAtWithRetry(rpcParameters, common.HexToAddress(account.Address)) if err != nil { log.Errorf("Error in fetching balance of the account: %s\n%v", account.Address, err) return @@ -247,7 +227,7 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, return } - sRZRBalance, err := razorUtils.GetStakerSRZRBalance(ctx, client, staker) + sRZRBalance, err := razorUtils.GetStakerSRZRBalance(rpcParameters, staker) if err != nil { log.Error("Error in getting sRZR balance for staker: ", err) return @@ -274,21 +254,21 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, switch state { case 0: log.Debugf("Starting commit...") - err := cmdUtils.InitiateCommit(ctx, client, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) + err := cmdUtils.InitiateCommit(rpcParameters, config, account, epoch, stakerId, latestHeader, commitParams, stateBuffer, rogueData) if err != nil { log.Error(err) break } case 1: log.Debugf("Starting reveal...") - err := cmdUtils.InitiateReveal(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) + err := cmdUtils.InitiateReveal(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) if err != nil { log.Error(err) break } case 2: log.Debugf("Starting propose...") - err := cmdUtils.InitiatePropose(ctx, client, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) + err := cmdUtils.InitiatePropose(rpcParameters, config, account, epoch, staker, latestHeader, stateBuffer, rogueData) if err != nil { log.Error(err) break @@ -301,7 +281,7 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, break } - err := cmdUtils.HandleDispute(ctx, client, config, account, epoch, latestHeader.Number, rogueData, backupNodeActionsToIgnore) + err := cmdUtils.HandleDispute(rpcParameters, config, account, epoch, latestHeader.Number, rogueData, backupNodeActionsToIgnore) if err != nil { log.Error(err) break @@ -311,7 +291,7 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, if razorUtils.IsFlagPassed("autoClaimBounty") { log.Debugf("Automatically claiming bounty") - err = cmdUtils.HandleClaimBounty(client, config, account) + err = cmdUtils.HandleClaimBounty(rpcParameters, config, account) if err != nil { log.Error(err) break @@ -327,7 +307,7 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, break } - confirmedBlock, err := razorUtils.GetConfirmedBlocks(ctx, client, epoch) + confirmedBlock, err := razorUtils.GetConfirmedBlocks(rpcParameters, epoch) if err != nil { log.Error(err) break @@ -339,8 +319,7 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, break } if (lastVerification == epoch || lastVerification == 0) && blockConfirmed < epoch { - txn, err := cmdUtils.ClaimBlockReward(ctx, types.TransactionOptions{ - Client: client, + txn, err := cmdUtils.ClaimBlockReward(rpcParameters, types.TransactionOptions{ ChainId: core.ChainId, Config: config, ContractAddress: core.BlockManagerAddress, @@ -356,6 +335,15 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, if txn != core.NilHash { log.Info("Confirm Transaction Hash: ", txn) } + + if lastRPCRefreshEpoch < epoch { + err = rpcParameters.RPCManager.RefreshEndpoints() + if err != nil { + log.Error("Error in refreshing RPC endpoints: ", err) + break + } + lastRPCRefreshEpoch = epoch + } } case -1: if config.WaitTime >= core.BufferStateSleepTime { @@ -368,8 +356,8 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account, } //This function initiates the commit -func (*UtilsStruct) InitiateCommit(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *Types.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error { - lastCommit, err := razorUtils.GetEpochLastCommitted(ctx, client, stakerId) +func (*UtilsStruct) InitiateCommit(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, stakerId uint32, latestHeader *Types.Header, commitParams *types.CommitParams, stateBuffer uint64, rogueData types.Rogue) error { + lastCommit, err := razorUtils.GetEpochLastCommitted(rpcParameters, stakerId) if err != nil { return errors.New("Error in fetching last commit: " + err.Error()) } @@ -381,20 +369,20 @@ func (*UtilsStruct) InitiateCommit(ctx context.Context, client *ethclient.Client return nil } - err = CheckForJobAndCollectionEvents(ctx, client, commitParams) + err = CheckForJobAndCollectionEvents(rpcParameters, commitParams) if err != nil { log.Error("Error in checking for asset events: ", err) return err } - staker, err := razorUtils.GetStaker(ctx, client, stakerId) + staker, err := razorUtils.GetStaker(rpcParameters, stakerId) if err != nil { log.Error(err) return err } log.Debug("InitiateCommit: Staker:", staker) stakedAmount := staker.Stake - minStakeAmount, err := razorUtils.GetMinStakeAmount(ctx, client) + minStakeAmount, err := razorUtils.GetMinStakeAmount(rpcParameters) if err != nil { log.Error("Error in getting minimum stake amount: ", err) return err @@ -412,13 +400,13 @@ func (*UtilsStruct) InitiateCommit(ctx context.Context, client *ethclient.Client keystorePath := filepath.Join(razorPath, "keystore_files") log.Debugf("InitiateCommit: Keystore file path: %s", keystorePath) log.Debugf("InitiateCommit: Calling CalculateSeed() with arguments keystorePath = %s, epoch = %d", keystorePath, epoch) - seed, err := CalculateSeed(ctx, client, account, keystorePath, epoch) + seed, err := CalculateSeed(rpcParameters, account, keystorePath, epoch) if err != nil { return errors.New("Error in getting seed: " + err.Error()) } log.Debugf("InitiateCommit: Calling HandleCommitState with arguments epoch = %d, seed = %v, rogueData = %+v", epoch, seed, rogueData) - commitData, err := cmdUtils.HandleCommitState(ctx, client, epoch, seed, commitParams, rogueData) + commitData, err := cmdUtils.HandleCommitState(rpcParameters, epoch, seed, commitParams, rogueData) if err != nil { return errors.New("Error in getting active assets: " + err.Error()) } @@ -430,7 +418,7 @@ func (*UtilsStruct) InitiateCommit(ctx context.Context, client *ethclient.Client return err } - commitTxn, err := cmdUtils.Commit(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitmentToSend) + commitTxn, err := cmdUtils.Commit(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitmentToSend) if err != nil { return errors.New("Error in committing data: " + err.Error()) } @@ -457,10 +445,10 @@ func (*UtilsStruct) InitiateCommit(ctx context.Context, client *ethclient.Client } //This function initiates the reveal -func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { +func (*UtilsStruct) InitiateReveal(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { stakedAmount := staker.Stake log.Debug("InitiateReveal: Staked Amount: ", stakedAmount) - minStakeAmount, err := razorUtils.GetMinStakeAmount(ctx, client) + minStakeAmount, err := razorUtils.GetMinStakeAmount(rpcParameters) if err != nil { log.Error("Error in getting minimum stake amount: ", err) return err @@ -470,7 +458,7 @@ func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client log.Error("Stake is below minimum required. Kindly add stake to continue voting.") return nil } - lastReveal, err := razorUtils.GetEpochLastRevealed(ctx, client, staker.Id) + lastReveal, err := razorUtils.GetEpochLastRevealed(rpcParameters, staker.Id) if err != nil { return errors.New("Error in fetching last reveal: " + err.Error()) } @@ -482,7 +470,7 @@ func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client } log.Debugf("InitiateReveal: Calling CheckForLastCommitted with arguments staker = %+v, epoch = %d", staker, epoch) - if err := cmdUtils.CheckForLastCommitted(ctx, client, staker, epoch); err != nil { + if err := cmdUtils.CheckForLastCommitted(rpcParameters, staker, epoch); err != nil { log.Error(err) return err } @@ -496,7 +484,7 @@ func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client log.Debugf("InitiateReveal: Keystore file path: %s", keystorePath) // Consolidated commitment verification for commit data being fetched from memory or file - commitData, err := GetCommittedDataForEpoch(ctx, client, account, epoch, rogueData) + commitData, err := GetCommittedDataForEpoch(rpcParameters, account, epoch, rogueData) if err != nil { return err } @@ -517,7 +505,7 @@ func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client SeqAllottedCollections: commitData.SeqAllottedCollections, } log.Debugf("InitiateReveal: Calling Reveal() with arguments epoch = %d, commitDataToSend = %+v, signature = %v", epoch, commitDataToSend, signature) - revealTxn, err := cmdUtils.Reveal(ctx, client, config, account, epoch, latestHeader, stateBuffer, commitDataToSend, signature) + revealTxn, err := cmdUtils.Reveal(rpcParameters, config, account, epoch, latestHeader, stateBuffer, commitDataToSend, signature) if err != nil { return errors.New("Reveal error: " + err.Error()) } @@ -526,10 +514,10 @@ func (*UtilsStruct) InitiateReveal(ctx context.Context, client *ethclient.Client } //This function initiates the propose -func (*UtilsStruct) InitiatePropose(ctx context.Context, client *ethclient.Client, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { +func (*UtilsStruct) InitiatePropose(rpcParameters RPC.RPCParameters, config types.Configurations, account types.Account, epoch uint32, staker bindings.StructsStaker, latestHeader *Types.Header, stateBuffer uint64, rogueData types.Rogue) error { stakedAmount := staker.Stake log.Debug("InitiatePropose: Staked Amount: ", stakedAmount) - minStakeAmount, err := razorUtils.GetMinStakeAmount(ctx, client) + minStakeAmount, err := razorUtils.GetMinStakeAmount(rpcParameters) if err != nil { log.Error("Error in getting minimum stake amount: ", err) return err @@ -539,7 +527,7 @@ func (*UtilsStruct) InitiatePropose(ctx context.Context, client *ethclient.Clien log.Error("Stake is below minimum required. Kindly add stake to continue voting.") return nil } - lastProposal, err := razorUtils.GetEpochLastProposed(ctx, client, staker.Id) + lastProposal, err := razorUtils.GetEpochLastProposed(rpcParameters, staker.Id) if err != nil { return errors.New("Error in fetching last proposal: " + err.Error()) } @@ -548,7 +536,7 @@ func (*UtilsStruct) InitiatePropose(ctx context.Context, client *ethclient.Clien log.Debugf("Since last propose was at epoch: %d, won't propose again in epoch: %d", epoch, lastProposal) return nil } - lastReveal, err := razorUtils.GetEpochLastRevealed(ctx, client, staker.Id) + lastReveal, err := razorUtils.GetEpochLastRevealed(rpcParameters, staker.Id) if err != nil { return errors.New("Error in fetching last reveal: " + err.Error()) } @@ -559,7 +547,7 @@ func (*UtilsStruct) InitiatePropose(ctx context.Context, client *ethclient.Clien } log.Debugf("InitiatePropose: Calling Propose() with arguments staker = %+v, epoch = %d, blockNumber = %s, rogueData = %+v", staker, epoch, latestHeader.Number, rogueData) - err = cmdUtils.Propose(ctx, client, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) + err = cmdUtils.Propose(rpcParameters, config, account, staker, epoch, latestHeader, stateBuffer, rogueData) if err != nil { return errors.New("Propose error: " + err.Error()) } diff --git a/core/types/transaction.go b/core/types/transaction.go index 75819cac..0d7ce718 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -1,12 +1,10 @@ package types import ( - "github.com/ethereum/go-ethereum/ethclient" "math/big" ) type TransactionOptions struct { - Client *ethclient.Client EtherValue *big.Int Amount *big.Int ChainId *big.Int diff --git a/endpoints.json b/endpoints.json new file mode 100644 index 00000000..bddd3552 --- /dev/null +++ b/endpoints.json @@ -0,0 +1,6 @@ +[ + "https://andromeda02.skale.prod.chorus1.net:10072", + "https://skale-figment-9.skale.figment.io:10008", + "https://skale-figment-2.skale.figment.io:10072", + "https://node03.skale.prod.chorus1.net:10072" +] \ No newline at end of file diff --git a/utils/asset.go b/utils/asset.go index a19c4725..2a454edb 100644 --- a/utils/asset.go +++ b/utils/asset.go @@ -1,12 +1,12 @@ package utils import ( - "context" "encoding/hex" "encoding/json" "errors" "math/big" "os" + "razor/RPC" "razor/cache" "razor/core" "razor/core/types" @@ -29,22 +29,30 @@ func (*UtilsStruct) GetCollectionManagerWithOpts(client *ethclient.Client) (*bin return UtilsInterface.GetCollectionManager(client), UtilsInterface.GetOptions() } -func (*UtilsStruct) GetNumCollections(ctx context.Context, client *ethclient.Client) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetNumCollections", client) +func (*UtilsStruct) GetNumCollections(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetNumCollections") if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetJobs(ctx context.Context, client *ethclient.Client) ([]bindings.StructsJob, error) { +func (*UtilsStruct) GetNumJobs(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetNumJobs") + if err != nil { + return 0, err + } + return returnedValues[0].Interface().(uint16), nil +} + +func (*UtilsStruct) GetJobs(rpcParameters RPC.RPCParameters) ([]bindings.StructsJob, error) { var jobs []bindings.StructsJob - numJobs, err := AssetManagerInterface.GetNumJobs(client) + numJobs, err := UtilsInterface.GetNumJobs(rpcParameters) if err != nil { return nil, err } for i := 1; i <= int(numJobs); i++ { - job, err := UtilsInterface.GetActiveJob(ctx, client, uint16(i)) + job, err := UtilsInterface.GetActiveJob(rpcParameters, uint16(i)) if err != nil { return nil, err } @@ -53,22 +61,22 @@ func (*UtilsStruct) GetJobs(ctx context.Context, client *ethclient.Client) ([]bi return jobs, nil } -func (*UtilsStruct) GetNumActiveCollections(ctx context.Context, client *ethclient.Client) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetNumActiveCollections", client) +func (*UtilsStruct) GetNumActiveCollections(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetNumActiveCollections") if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetAllCollections(ctx context.Context, client *ethclient.Client) ([]bindings.StructsCollection, error) { +func (*UtilsStruct) GetAllCollections(rpcParameters RPC.RPCParameters) ([]bindings.StructsCollection, error) { var collections []bindings.StructsCollection - numCollections, err := UtilsInterface.GetNumCollections(ctx, client) + numCollections, err := UtilsInterface.GetNumCollections(rpcParameters) if err != nil { return nil, err } for i := 1; i <= int(numCollections); i++ { - collection, err := AssetManagerInterface.GetCollection(client, uint16(i)) + collection, err := UtilsInterface.GetCollection(rpcParameters, uint16(i)) if err != nil { return nil, err } @@ -77,37 +85,45 @@ func (*UtilsStruct) GetAllCollections(ctx context.Context, client *ethclient.Cli return collections, nil } -func (*UtilsStruct) GetCollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (bindings.StructsCollection, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetCollection", client, collectionId) +func (*UtilsStruct) GetCollection(rpcParameters RPC.RPCParameters, collectionId uint16) (bindings.StructsCollection, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetCollection", collectionId) if err != nil { return bindings.StructsCollection{}, err } return returnedValues[0].Interface().(bindings.StructsCollection), nil } -func (*UtilsStruct) GetActiveCollectionIds(ctx context.Context, client *ethclient.Client) ([]uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetActiveCollections", client) +func (*UtilsStruct) GetActiveCollectionIds(rpcParameters RPC.RPCParameters) ([]uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetActiveCollections") if err != nil { return nil, err } return returnedValues[0].Interface().([]uint16), nil } -func (*UtilsStruct) GetAggregatedDataOfCollection(ctx context.Context, client *ethclient.Client, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) { +func (*UtilsStruct) GetActiveStatus(rpcParameters RPC.RPCParameters, id uint16) (bool, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetActiveStatus", id) + if err != nil { + return false, err + } + return returnedValues[0].Interface().(bool), nil +} + +func (*UtilsStruct) GetAggregatedDataOfCollection(rpcParameters RPC.RPCParameters, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) { activeCollection, err := UtilsInterface.GetActiveCollection(commitParams.CollectionsCache, collectionId) if err != nil { log.Error(err) return nil, err } //Supply previous epoch to Aggregate in case if last reported value is required. - collectionData, aggregationError := UtilsInterface.Aggregate(ctx, client, epoch-1, activeCollection, commitParams) + collectionData, aggregationError := UtilsInterface.Aggregate(rpcParameters, epoch-1, activeCollection, commitParams) if aggregationError != nil { return nil, aggregationError } return collectionData, nil } -func (*UtilsStruct) Aggregate(ctx context.Context, client *ethclient.Client, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) { +func (*UtilsStruct) Aggregate(rpcParameters RPC.RPCParameters, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) { var jobs []bindings.StructsJob var overriddenJobIds []uint16 @@ -136,7 +152,7 @@ func (*UtilsStruct) Aggregate(ctx context.Context, client *ethclient.Client, pre } // Overriding the jobs from contracts with official jobs present in asset.go - overrideJobs, overriddenJobIdsFromJSONfile := UtilsInterface.HandleOfficialJobsFromJSONFile(client, collection, dataString, commitParams) + overrideJobs, overriddenJobIdsFromJSONfile := UtilsInterface.HandleOfficialJobsFromJSONFile(collection, dataString, commitParams) jobs = append(jobs, overrideJobs...) overriddenJobIds = append(overriddenJobIds, overriddenJobIdsFromJSONfile...) @@ -165,7 +181,7 @@ func (*UtilsStruct) Aggregate(ctx context.Context, client *ethclient.Client, pre } dataToCommit, weight := UtilsInterface.GetDataToCommitFromJobs(jobs, commitParams) if len(dataToCommit) == 0 { - prevCommitmentData, err := UtilsInterface.FetchPreviousValue(ctx, client, previousEpoch, collection.Id) + prevCommitmentData, err := UtilsInterface.FetchPreviousValue(rpcParameters, previousEpoch, collection.Id) if err != nil { return nil, err } @@ -174,8 +190,8 @@ func (*UtilsStruct) Aggregate(ctx context.Context, client *ethclient.Client, pre return performAggregation(dataToCommit, weight, collection.AggregationMethod) } -func (*UtilsStruct) GetActiveJob(ctx context.Context, client *ethclient.Client, jobId uint16) (bindings.StructsJob, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "Jobs", client, jobId) +func (*UtilsStruct) GetActiveJob(rpcParameters RPC.RPCParameters, jobId uint16) (bindings.StructsJob, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "Jobs", jobId) if err != nil { return bindings.StructsJob{}, err } @@ -300,10 +316,10 @@ func (*UtilsStruct) GetDataToCommitFromJob(job bindings.StructsJob, commitParams return MultiplyWithPower(datum, job.Power), err } -func (*UtilsStruct) GetAssignedCollections(ctx context.Context, client *ethclient.Client, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) { +func (*UtilsStruct) GetAssignedCollections(rpcParameters RPC.RPCParameters, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) { assignedCollections := make(map[int]bool) var seqAllottedCollections []*big.Int - toAssign, err := UtilsInterface.ToAssign(ctx, client) + toAssign, err := UtilsInterface.ToAssign(rpcParameters) if err != nil { return nil, nil, err } @@ -315,24 +331,24 @@ func (*UtilsStruct) GetAssignedCollections(ctx context.Context, client *ethclien return assignedCollections, seqAllottedCollections, nil } -func (*UtilsStruct) GetLeafIdOfACollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetLeafIdOfACollection", client, collectionId) +func (*UtilsStruct) GetLeafIdOfACollection(rpcParameters RPC.RPCParameters, collectionId uint16) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetLeafIdOfACollection", collectionId) if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetCollectionIdFromIndex(ctx context.Context, client *ethclient.Client, medianIndex uint16) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetCollectionIdFromIndex", client, medianIndex) +func (*UtilsStruct) GetCollectionIdFromIndex(rpcParameters RPC.RPCParameters, medianIndex uint16) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetCollectionIdFromIndex", medianIndex) if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetCollectionIdFromLeafId(ctx context.Context, client *ethclient.Client, leafId uint16) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, AssetManagerInterface, "GetCollectionIdFromLeafId", client, leafId) +func (*UtilsStruct) GetCollectionIdFromLeafId(rpcParameters RPC.RPCParameters, leafId uint16) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, AssetManagerInterface, "GetCollectionIdFromLeafId", leafId) if err != nil { return 0, err } @@ -390,7 +406,7 @@ func ConvertCustomJobToStructJob(customJob types.CustomJob) bindings.StructsJob } } -func (*UtilsStruct) HandleOfficialJobsFromJSONFile(client *ethclient.Client, collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) { +func (*UtilsStruct) HandleOfficialJobsFromJSONFile(collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) { var overrideJobs []bindings.StructsJob var overriddenJobIds []uint16 @@ -437,7 +453,7 @@ func (*UtilsStruct) HandleOfficialJobsFromJSONFile(client *ethclient.Client, col } // InitJobsCache initializes the jobs cache with data fetched from the blockchain -func InitJobsCache(ctx context.Context, client *ethclient.Client, jobsCache *cache.JobsCache) error { +func InitJobsCache(rpcParameters RPC.RPCParameters, jobsCache *cache.JobsCache) error { jobsCache.Mu.Lock() defer jobsCache.Mu.Unlock() @@ -446,12 +462,12 @@ func InitJobsCache(ctx context.Context, client *ethclient.Client, jobsCache *cac delete(jobsCache.Jobs, k) } - numJobs, err := AssetManagerInterface.GetNumJobs(client) + numJobs, err := UtilsInterface.GetNumJobs(rpcParameters) if err != nil { return err } for i := 1; i <= int(numJobs); i++ { - job, err := UtilsInterface.GetActiveJob(ctx, client, uint16(i)) + job, err := UtilsInterface.GetActiveJob(rpcParameters, uint16(i)) if err != nil { return err } @@ -461,7 +477,7 @@ func InitJobsCache(ctx context.Context, client *ethclient.Client, jobsCache *cac } // InitCollectionsCache initializes the collections cache with data fetched from the blockchain -func InitCollectionsCache(client *ethclient.Client, collectionsCache *cache.CollectionsCache) error { +func InitCollectionsCache(rpcParameters RPC.RPCParameters, collectionsCache *cache.CollectionsCache) error { collectionsCache.Mu.Lock() defer collectionsCache.Mu.Unlock() @@ -470,12 +486,12 @@ func InitCollectionsCache(client *ethclient.Client, collectionsCache *cache.Coll delete(collectionsCache.Collections, k) } - numCollections, err := AssetManagerInterface.GetNumCollections(client) + numCollections, err := UtilsInterface.GetNumCollections(rpcParameters) if err != nil { return err } for i := 1; i <= int(numCollections); i++ { - collection, err := AssetManagerInterface.GetCollection(client, uint16(i)) + collection, err := UtilsInterface.GetCollection(rpcParameters, uint16(i)) if err != nil { return err } diff --git a/utils/batch.go b/utils/batch.go index a7a5bfdb..5ce06863 100644 --- a/utils/batch.go +++ b/utils/batch.go @@ -7,22 +7,22 @@ import ( "github.com/avast/retry-go" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/rpc" + "razor/RPC" "razor/core" ) //Each batch call may require multiple arguments therefore defining args as [][]interface{} // BatchCall performs a batch call to the Ethereum client, using the provided contract ABI, address, method name, and arguments. -func (c ClientStruct) BatchCall(client *ethclient.Client, contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([][]interface{}, error) { +func (c ClientStruct) BatchCall(rpcParameters RPC.RPCParameters, contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([][]interface{}, error) { calls, err := ClientInterface.CreateBatchCalls(contractABI, contractAddress, methodName, args) if err != nil { log.Errorf("Error in creating batch calls: %v", err) return nil, err } - err = performBatchCallWithRetry(client, calls) + err = performBatchCallWithRetry(rpcParameters, calls) if err != nil { log.Errorf("Error in performing batch call: %v", err) return nil, err @@ -63,8 +63,13 @@ func (c ClientStruct) CreateBatchCalls(contractABI *abi.ABI, contractAddress, me return calls, nil } -func (c ClientStruct) PerformBatchCall(client *ethclient.Client, calls []rpc.BatchElem) error { - err := client.Client().BatchCallContext(context.Background(), calls) +func (c ClientStruct) PerformBatchCall(rpcParameters RPC.RPCParameters, calls []rpc.BatchElem) error { + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + return err + } + + err = client.Client().BatchCallContext(context.Background(), calls) if err != nil { return err } @@ -72,9 +77,9 @@ func (c ClientStruct) PerformBatchCall(client *ethclient.Client, calls []rpc.Bat } // performBatchCallWithRetry performs the batch call to the Ethereum client with retry logic. -func performBatchCallWithRetry(client *ethclient.Client, calls []rpc.BatchElem) error { +func performBatchCallWithRetry(rpcParameters RPC.RPCParameters, calls []rpc.BatchElem) error { err := retry.Do(func() error { - err := ClientInterface.PerformBatchCall(client, calls) + err := ClientInterface.PerformBatchCall(rpcParameters, calls) if err != nil { log.Errorf("Error in performing batch call, retrying: %v", err) return err diff --git a/utils/block.go b/utils/block.go index af86f14c..55314e9f 100644 --- a/utils/block.go +++ b/utils/block.go @@ -1,9 +1,10 @@ package utils import ( - "context" "errors" + "github.com/ethereum/go-ethereum/common" "math/big" + "razor/RPC" Types "razor/core/types" "razor/pkg/bindings" @@ -15,24 +16,24 @@ func (*UtilsStruct) GetBlockManagerWithOpts(client *ethclient.Client) (*bindings return UtilsInterface.GetBlockManager(client), UtilsInterface.GetOptions() } -func (*UtilsStruct) GetNumberOfProposedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (uint8, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetNumProposedBlocks", client, epoch) +func (*UtilsStruct) GetNumberOfProposedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (uint8, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetNumProposedBlocks", epoch) if err != nil { return 0, err } return returnedValues[0].Interface().(uint8), nil } -func (*UtilsStruct) GetProposedBlock(ctx context.Context, client *ethclient.Client, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetProposedBlock", client, epoch, proposedBlockId) +func (*UtilsStruct) GetProposedBlock(rpcParameters RPC.RPCParameters, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetProposedBlock", epoch, proposedBlockId) if err != nil { return bindings.StructsBlock{}, err } return returnedValues[0].Interface().(bindings.StructsBlock), nil } -func (*UtilsStruct) FetchPreviousValue(ctx context.Context, client *ethclient.Client, epoch uint32, assetId uint16) (*big.Int, error) { - block, err := UtilsInterface.GetBlock(ctx, client, epoch) +func (*UtilsStruct) FetchPreviousValue(rpcParameters RPC.RPCParameters, epoch uint32, assetId uint16) (*big.Int, error) { + block, err := UtilsInterface.GetBlock(rpcParameters, epoch) if err != nil { return big.NewInt(0), err } @@ -42,24 +43,24 @@ func (*UtilsStruct) FetchPreviousValue(ctx context.Context, client *ethclient.Cl return block.Medians[assetId-1], nil } -func (*UtilsStruct) GetBlock(ctx context.Context, client *ethclient.Client, epoch uint32) (bindings.StructsBlock, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetBlock", client, epoch) +func (*UtilsStruct) GetBlock(rpcParameters RPC.RPCParameters, epoch uint32) (bindings.StructsBlock, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetBlock", epoch) if err != nil { return bindings.StructsBlock{}, err } return returnedValues[0].Interface().(bindings.StructsBlock), nil } -func (*UtilsStruct) GetMinStakeAmount(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "MinStake", client) +func (*UtilsStruct) GetMinStakeAmount(rpcParameters RPC.RPCParameters) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "MinStake") if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } -func (*UtilsStruct) GetStateBuffer(ctx context.Context, client *ethclient.Client) (uint64, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "StateBuffer", client) +func (*UtilsStruct) GetStateBuffer(rpcParameters RPC.RPCParameters) (uint64, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "StateBuffer") if err != nil { return 0, err } @@ -67,31 +68,31 @@ func (*UtilsStruct) GetStateBuffer(ctx context.Context, client *ethclient.Client return uint64(stateBufferUint8), nil } -func (*UtilsStruct) GetMaxAltBlocks(ctx context.Context, client *ethclient.Client) (uint8, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "MaxAltBlocks", client) +func (*UtilsStruct) GetMaxAltBlocks(rpcParameters RPC.RPCParameters) (uint8, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "MaxAltBlocks") if err != nil { return 0, err } return returnedValues[0].Interface().(uint8), nil } -func (*UtilsStruct) GetSortedProposedBlockId(ctx context.Context, client *ethclient.Client, epoch uint32, index *big.Int) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "SortedProposedBlockIds", client, epoch, index) +func (*UtilsStruct) GetSortedProposedBlockId(rpcParameters RPC.RPCParameters, epoch uint32, index *big.Int) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "SortedProposedBlockIds", epoch, index) if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) GetSortedProposedBlockIds(ctx context.Context, client *ethclient.Client, epoch uint32) ([]uint32, error) { - numberOfProposedBlocks, err := UtilsInterface.GetNumberOfProposedBlocks(ctx, client, epoch) +func (*UtilsStruct) GetSortedProposedBlockIds(rpcParameters RPC.RPCParameters, epoch uint32) ([]uint32, error) { + numberOfProposedBlocks, err := UtilsInterface.GetNumberOfProposedBlocks(rpcParameters, epoch) if err != nil { log.Error(err) return nil, err } var sortedProposedBlockIds []uint32 for i := 0; i < int(numberOfProposedBlocks); i++ { - id, err := UtilsInterface.GetSortedProposedBlockId(ctx, client, epoch, big.NewInt(int64(i))) + id, err := UtilsInterface.GetSortedProposedBlockId(rpcParameters, epoch, big.NewInt(int64(i))) if err != nil { log.Error(err) return nil, err @@ -101,26 +102,34 @@ func (*UtilsStruct) GetSortedProposedBlockIds(ctx context.Context, client *ethcl return sortedProposedBlockIds, nil } -func (*UtilsStruct) GetBlockIndexToBeConfirmed(ctx context.Context, client *ethclient.Client) (int8, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetBlockIndexToBeConfirmed", client) +func (*UtilsStruct) GetBlockIndexToBeConfirmed(rpcParameters RPC.RPCParameters) (int8, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetBlockIndexToBeConfirmed") if err != nil { return 0, err } return returnedValues[0].Interface().(int8), nil } -func (*UtilsStruct) GetEpochLastProposed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetEpochLastProposed", client, stakerId) +func (*UtilsStruct) GetEpochLastProposed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetEpochLastProposed", stakerId) if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) GetConfirmedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (Types.ConfirmedBlock, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, BlockManagerInterface, "GetConfirmedBlocks", client, epoch) +func (*UtilsStruct) GetConfirmedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (Types.ConfirmedBlock, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "GetConfirmedBlocks", epoch) if err != nil { return Types.ConfirmedBlock{}, err } return returnedValues[0].Interface().(Types.ConfirmedBlock), nil } + +func (*UtilsStruct) Disputes(rpcParameters RPC.RPCParameters, epoch uint32, address common.Address) (Types.DisputesStruct, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, BlockManagerInterface, "Disputes", epoch, address) + if err != nil { + return Types.DisputesStruct{}, err + } + return returnedValues[0].Interface().(Types.DisputesStruct), nil +} diff --git a/utils/client_methods.go b/utils/client_methods.go index 9ef33989..ee5198ee 100644 --- a/utils/client_methods.go +++ b/utils/client_methods.go @@ -5,54 +5,62 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" "math/big" + "razor/RPC" ) -func (*ClientStruct) GetNonceAtWithRetry(ctx context.Context, client *ethclient.Client, accountAddress common.Address) (uint64, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "NonceAt", client, context.Background(), accountAddress) +func (*ClientStruct) GetNonceAtWithRetry(rpcParameters RPC.RPCParameters, accountAddress common.Address) (uint64, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "NonceAt", context.Background(), accountAddress) if err != nil { return 0, err } return returnedValues[0].Interface().(uint64), nil } -func (*ClientStruct) GetLatestBlockWithRetry(ctx context.Context, client *ethclient.Client) (*types.Header, error) { +func (*ClientStruct) GetLatestBlockWithRetry(rpcParameters RPC.RPCParameters) (*types.Header, error) { var blockNumberArgument *big.Int - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "HeaderByNumber", client, context.Background(), blockNumberArgument) + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "HeaderByNumber", context.Background(), blockNumberArgument) if err != nil { return nil, err } return returnedValues[0].Interface().(*types.Header), nil } -func (*ClientStruct) SuggestGasPriceWithRetry(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "SuggestGasPrice", client, context.Background()) +func (*ClientStruct) GetBlockByNumberWithRetry(rpcParameters RPC.RPCParameters, blockNumber *big.Int) (*types.Header, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "HeaderByNumber", context.Background(), blockNumber) + if err != nil { + return nil, err + } + return returnedValues[0].Interface().(*types.Header), nil +} + +func (*ClientStruct) SuggestGasPriceWithRetry(rpcParameters RPC.RPCParameters) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "SuggestGasPrice", context.Background()) if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } -func (*ClientStruct) EstimateGasWithRetry(ctx context.Context, client *ethclient.Client, message ethereum.CallMsg) (uint64, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "EstimateGas", client, context.Background(), message) +func (*ClientStruct) EstimateGasWithRetry(rpcParameters RPC.RPCParameters, message ethereum.CallMsg) (uint64, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "EstimateGas", context.Background(), message) if err != nil { return 0, err } return returnedValues[0].Interface().(uint64), nil } -func (*ClientStruct) FilterLogsWithRetry(ctx context.Context, client *ethclient.Client, query ethereum.FilterQuery) ([]types.Log, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "FilterLogs", client, context.Background(), query) +func (*ClientStruct) FilterLogsWithRetry(rpcParameters RPC.RPCParameters, query ethereum.FilterQuery) ([]types.Log, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "FilterLogs", context.Background(), query) if err != nil { return nil, err } return returnedValues[0].Interface().([]types.Log), nil } -func (*ClientStruct) BalanceAtWithRetry(ctx context.Context, client *ethclient.Client, account common.Address) (*big.Int, error) { +func (*ClientStruct) BalanceAtWithRetry(rpcParameters RPC.RPCParameters, account common.Address) (*big.Int, error) { var blockNumberArgument *big.Int - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, ClientInterface, "BalanceAt", client, context.Background(), account, blockNumberArgument) + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "BalanceAt", context.Background(), account, blockNumberArgument) if err != nil { return nil, err } diff --git a/utils/common.go b/utils/common.go index 2f92efea..a694ea1d 100644 --- a/utils/common.go +++ b/utils/common.go @@ -3,16 +3,18 @@ package utils import ( "context" "errors" - Types "github.com/ethereum/go-ethereum/core/types" "math/big" "os" "path/filepath" + "razor/RPC" "razor/accounts" "razor/core" "razor/core/types" "razor/logger" "time" + Types "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" solsha3 "github.com/miguelmota/go-solidity-sha3" @@ -28,12 +30,17 @@ func (*UtilsStruct) ConnectToClient(provider string) *ethclient.Client { return client } -func (*UtilsStruct) FetchBalance(client *ethclient.Client, accountAddress string) (*big.Int, error) { +func (*UtilsStruct) FetchBalance(rpcParameters RPC.RPCParameters, accountAddress string) (*big.Int, error) { address := common.HexToAddress(accountAddress) - erc20Contract := UtilsInterface.GetTokenManager(client) - opts := UtilsInterface.GetOptions() + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, CoinInterface, "BalanceOf", address) + if err != nil { + return big.NewInt(0), err + } + return returnedValues[0].Interface().(*big.Int), nil +} - returnedValues, err := InvokeFunctionWithRetryAttempts(context.Background(), CoinInterface, "BalanceOf", erc20Contract, &opts, address) +func (*UtilsStruct) Allowance(rpcParameters RPC.RPCParameters, owner common.Address, spender common.Address) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, CoinInterface, "Allowance", owner, spender) if err != nil { return big.NewInt(0), err } @@ -50,16 +57,18 @@ func (*UtilsStruct) GetBufferedState(header *Types.Header, stateBuffer uint64, b return int64(state % core.NumberOfStates), nil } -func (*UtilsStruct) CheckTransactionReceipt(client *ethclient.Client, _txHash string) int { +func (*UtilsStruct) CheckTransactionReceipt(rpcParameters RPC.RPCParameters, _txHash string) int { txHash := common.HexToHash(_txHash) - tx, err := ClientInterface.TransactionReceipt(client, context.Background(), txHash) + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, ClientInterface, "TransactionReceipt", rpcParameters.Ctx, txHash) if err != nil { return -1 } - return int(tx.Status) + + txnReceipt := returnedValues[0].Interface().(*Types.Receipt) + return int(txnReceipt.Status) } -func (*UtilsStruct) WaitForBlockCompletion(client *ethclient.Client, hashToRead string) error { +func (*UtilsStruct) WaitForBlockCompletion(rpcParameters RPC.RPCParameters, hashToRead string) error { ctx, cancel := context.WithTimeout(context.Background(), core.BlockCompletionTimeout*time.Second) defer cancel() @@ -70,7 +79,7 @@ func (*UtilsStruct) WaitForBlockCompletion(client *ethclient.Client, hashToRead return errors.New("timeout exceeded for transaction mining") default: log.Debug("Checking if transaction is mined....") - transactionStatus := UtilsInterface.CheckTransactionReceipt(client, hashToRead) + transactionStatus := UtilsInterface.CheckTransactionReceipt(rpcParameters, hashToRead) if transactionStatus == 0 { err := errors.New("transaction mining unsuccessful") @@ -127,8 +136,8 @@ func (*UtilsStruct) IsFlagPassed(name string) bool { return found } -func (*UtilsStruct) CheckEthBalanceIsZero(ctx context.Context, client *ethclient.Client, address string) { - ethBalance, err := ClientInterface.BalanceAtWithRetry(ctx, client, common.HexToAddress(address)) +func (*UtilsStruct) CheckEthBalanceIsZero(rpcParameters RPC.RPCParameters, address string) { + ethBalance, err := ClientInterface.BalanceAtWithRetry(rpcParameters, common.HexToAddress(address)) if err != nil { log.Fatalf("Error in fetching sFUEL balance of the account: %s\n%s", address, err) } @@ -156,15 +165,15 @@ func GetStateName(stateNumber int64) string { return stateName } -func (*UtilsStruct) AssignStakerId(ctx context.Context, flagSet *pflag.FlagSet, client *ethclient.Client, address string) (uint32, error) { +func (*UtilsStruct) AssignStakerId(rpcParameters RPC.RPCParameters, flagSet *pflag.FlagSet, address string) (uint32, error) { if UtilsInterface.IsFlagPassed("stakerId") { return UtilsInterface.GetUint32(flagSet, "stakerId") } - return UtilsInterface.GetStakerId(ctx, client, address) + return UtilsInterface.GetStakerId(rpcParameters, address) } -func (*UtilsStruct) GetEpoch(ctx context.Context, client *ethclient.Client) (uint32, error) { - latestHeader, err := ClientInterface.GetLatestBlockWithRetry(ctx, client) +func (*UtilsStruct) GetEpoch(rpcParameters RPC.RPCParameters) (uint32, error) { + latestHeader, err := ClientInterface.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in fetching block: ", err) return 0, err @@ -173,13 +182,13 @@ func (*UtilsStruct) GetEpoch(ctx context.Context, client *ethclient.Client) (uin return uint32(epoch), nil } -func (*UtilsStruct) CalculateBlockTime(ctx context.Context, client *ethclient.Client) int64 { - latestBlock, err := ClientInterface.GetLatestBlockWithRetry(ctx, client) +func (*UtilsStruct) CalculateBlockTime(rpcParameters RPC.RPCParameters) int64 { + latestBlock, err := ClientInterface.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Fatalf("Error in fetching latest Block: %s", err) } latestBlockNumber := latestBlock.Number - lastSecondBlock, err := ClientInterface.HeaderByNumber(client, context.Background(), big.NewInt(1).Sub(latestBlockNumber, big.NewInt(1))) + lastSecondBlock, err := ClientInterface.GetBlockByNumberWithRetry(rpcParameters, big.NewInt(1).Sub(latestBlockNumber, big.NewInt(1))) if err != nil { log.Fatalf("Error in fetching last second Block: %s", err) } @@ -206,8 +215,8 @@ func (*UtilsStruct) Prng(max uint32, prngHashes []byte) *big.Int { return sum.Mod(sum, maxBigInt) } -func (*UtilsStruct) EstimateBlockNumberAtEpochBeginning(client *ethclient.Client, currentBlockNumber *big.Int) (*big.Int, error) { - block, err := ClientInterface.HeaderByNumber(client, context.Background(), currentBlockNumber) +func (*UtilsStruct) EstimateBlockNumberAtEpochBeginning(rpcParameters RPC.RPCParameters, currentBlockNumber *big.Int) (*big.Int, error) { + block, err := ClientInterface.GetBlockByNumberWithRetry(rpcParameters, currentBlockNumber) if err != nil { log.Error("Error in fetching block: ", err) return nil, err @@ -215,7 +224,7 @@ func (*UtilsStruct) EstimateBlockNumberAtEpochBeginning(client *ethclient.Client currentEpoch := block.Time / core.EpochLength previousBlockNumber := block.Number.Uint64() - core.StateLength - previousBlock, err := ClientInterface.HeaderByNumber(client, context.Background(), big.NewInt(int64(previousBlockNumber))) + previousBlock, err := ClientInterface.GetBlockByNumberWithRetry(rpcParameters, big.NewInt(int64(previousBlockNumber))) if err != nil { log.Error("Err in fetching Previous block: ", err) return nil, err @@ -224,7 +233,7 @@ func (*UtilsStruct) EstimateBlockNumberAtEpochBeginning(client *ethclient.Client previousBlockAssumedTimestamp := block.Time - core.EpochLength previousEpoch := previousBlockActualTimestamp / core.EpochLength if previousBlockActualTimestamp > previousBlockAssumedTimestamp && previousEpoch != currentEpoch-1 { - return UtilsInterface.EstimateBlockNumberAtEpochBeginning(client, big.NewInt(int64(previousBlockNumber))) + return UtilsInterface.EstimateBlockNumberAtEpochBeginning(rpcParameters, big.NewInt(int64(previousBlockNumber))) } return big.NewInt(int64(previousBlockNumber)), nil diff --git a/utils/interface.go b/utils/interface.go index f9000127..56ab1687 100644 --- a/utils/interface.go +++ b/utils/interface.go @@ -7,6 +7,7 @@ import ( "io/fs" "math/big" "os" + "razor/RPC" "razor/cache" "razor/core/types" "razor/pkg/bindings" @@ -72,67 +73,74 @@ var GasInterface GasUtils type Utils interface { MultiplyFloatAndBigInt(bigIntVal *big.Int, floatingVal float64) *big.Int - GetTxnOpts(ctx context.Context, transactionData types.TransactionOptions) *bind.TransactOpts + GetTxnOpts(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions) *bind.TransactOpts GetBlockManager(client *ethclient.Client) *bindings.BlockManager GetOptions() bind.CallOpts - GetNumberOfProposedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (uint8, error) - GetSortedProposedBlockId(ctx context.Context, client *ethclient.Client, epoch uint32, index *big.Int) (uint32, error) - FetchPreviousValue(ctx context.Context, client *ethclient.Client, epoch uint32, assetId uint16) (*big.Int, error) - GetBlock(ctx context.Context, client *ethclient.Client, epoch uint32) (bindings.StructsBlock, error) - GetMaxAltBlocks(ctx context.Context, client *ethclient.Client) (uint8, error) - GetMinSafeRazor(ctx context.Context, client *ethclient.Client) (*big.Int, error) - GetMinStakeAmount(ctx context.Context, client *ethclient.Client) (*big.Int, error) - GetStateBuffer(ctx context.Context, client *ethclient.Client) (uint64, error) - GetProposedBlock(ctx context.Context, client *ethclient.Client, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) - GetSortedProposedBlockIds(ctx context.Context, client *ethclient.Client, epoch uint32) ([]uint32, error) - GetBlockIndexToBeConfirmed(ctx context.Context, client *ethclient.Client) (int8, error) + GetNumberOfProposedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (uint8, error) + GetSortedProposedBlockId(rpcParameters RPC.RPCParameters, epoch uint32, index *big.Int) (uint32, error) + FetchPreviousValue(rpcParameters RPC.RPCParameters, epoch uint32, assetId uint16) (*big.Int, error) + GetBlock(rpcParameters RPC.RPCParameters, epoch uint32) (bindings.StructsBlock, error) + GetMaxAltBlocks(rpcParameters RPC.RPCParameters) (uint8, error) + GetMinSafeRazor(rpcParameters RPC.RPCParameters) (*big.Int, error) + GetMinStakeAmount(rpcParameters RPC.RPCParameters) (*big.Int, error) + GetStateBuffer(rpcParameters RPC.RPCParameters) (uint64, error) + GetProposedBlock(rpcParameters RPC.RPCParameters, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) + GetSortedProposedBlockIds(rpcParameters RPC.RPCParameters, epoch uint32) ([]uint32, error) + GetBlockIndexToBeConfirmed(rpcParameters RPC.RPCParameters) (int8, error) GetBlockManagerWithOpts(client *ethclient.Client) (*bindings.BlockManager, bind.CallOpts) GetStakeManager(client *ethclient.Client) *bindings.StakeManager GetStakeManagerWithOpts(client *ethclient.Client) (*bindings.StakeManager, bind.CallOpts) - GetStaker(ctx context.Context, client *ethclient.Client, stakerId uint32) (bindings.StructsStaker, error) - GetStake(ctx context.Context, client *ethclient.Client, stakerId uint32) (*big.Int, error) - GetStakerId(ctx context.Context, client *ethclient.Client, address string) (uint32, error) - GetNumberOfStakers(ctx context.Context, client *ethclient.Client) (uint32, error) - GetLock(ctx context.Context, client *ethclient.Client, address string, stakerId uint32, lockType uint8) (types.Locks, error) - GetWithdrawInitiationPeriod(ctx context.Context, client *ethclient.Client) (uint16, error) - GetMaxCommission(ctx context.Context, client *ethclient.Client) (uint8, error) - GetEpochLimitForUpdateCommission(ctx context.Context, client *ethclient.Client) (uint16, error) + GetStaker(rpcParameters RPC.RPCParameters, stakerId uint32) (bindings.StructsStaker, error) + GetStake(rpcParameters RPC.RPCParameters, stakerId uint32) (*big.Int, error) + GetStakerId(rpcParameters RPC.RPCParameters, address string) (uint32, error) + GetNumberOfStakers(rpcParameters RPC.RPCParameters) (uint32, error) + GetLock(rpcParameters RPC.RPCParameters, address string, stakerId uint32, lockType uint8) (types.Locks, error) + GetWithdrawInitiationPeriod(rpcParameters RPC.RPCParameters) (uint16, error) + GetMaxCommission(rpcParameters RPC.RPCParameters) (uint8, error) + GetEpochLimitForUpdateCommission(rpcParameters RPC.RPCParameters) (uint16, error) + StakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) (types.Staker, error) + GetMaturity(rpcParameters RPC.RPCParameters, age uint32) (uint16, error) + GetBountyLock(rpcParameters RPC.RPCParameters, bountyId uint32) (types.BountyLock, error) GetVoteManagerWithOpts(client *ethclient.Client) (*bindings.VoteManager, bind.CallOpts) - GetCommitment(ctx context.Context, client *ethclient.Client, address string) (types.Commitment, error) - GetVoteValue(ctx context.Context, client *ethclient.Client, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) - GetInfluenceSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) - GetStakeSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) - GetTotalInfluenceRevealed(ctx context.Context, client *ethclient.Client, epoch uint32, medianIndex uint16) (*big.Int, error) - GetEpochLastCommitted(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) - GetEpochLastRevealed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) + GetCommitment(rpcParameters RPC.RPCParameters, address string) (types.Commitment, error) + GetVoteValue(rpcParameters RPC.RPCParameters, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) + GetInfluenceSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) + GetStakeSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) + GetTotalInfluenceRevealed(rpcParameters RPC.RPCParameters, epoch uint32, medianIndex uint16) (*big.Int, error) + GetEpochLastCommitted(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) + GetEpochLastRevealed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) GetVoteManager(client *ethclient.Client) *bindings.VoteManager GetCollectionManager(client *ethclient.Client) *bindings.CollectionManager GetCollectionManagerWithOpts(client *ethclient.Client) (*bindings.CollectionManager, bind.CallOpts) - GetNumCollections(ctx context.Context, client *ethclient.Client) (uint16, error) - GetActiveJob(ctx context.Context, client *ethclient.Client, jobId uint16) (bindings.StructsJob, error) - GetCollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (bindings.StructsCollection, error) + GetNumCollections(rpcParameters RPC.RPCParameters) (uint16, error) + GetNumJobs(rpcParameters RPC.RPCParameters) (uint16, error) + GetActiveJob(rpcParameters RPC.RPCParameters, jobId uint16) (bindings.StructsJob, error) + GetCollection(rpcParameters RPC.RPCParameters, collectionId uint16) (bindings.StructsCollection, error) GetActiveCollection(collectionsCache *cache.CollectionsCache, collectionId uint16) (bindings.StructsCollection, error) - Aggregate(ctx context.Context, client *ethclient.Client, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) + Aggregate(rpcParameters RPC.RPCParameters, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) GetDataToCommitFromJobs(jobs []bindings.StructsJob, commitParams *types.CommitParams) ([]*big.Int, []uint8) GetDataToCommitFromJob(job bindings.StructsJob, commitParams *types.CommitParams) (*big.Int, error) - GetAssignedCollections(ctx context.Context, client *ethclient.Client, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) - GetLeafIdOfACollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (uint16, error) - GetCollectionIdFromIndex(ctx context.Context, client *ethclient.Client, medianIndex uint16) (uint16, error) - GetCollectionIdFromLeafId(ctx context.Context, client *ethclient.Client, leafId uint16) (uint16, error) - GetNumActiveCollections(ctx context.Context, client *ethclient.Client) (uint16, error) - GetAggregatedDataOfCollection(ctx context.Context, client *ethclient.Client, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) - GetJobs(ctx context.Context, client *ethclient.Client) ([]bindings.StructsJob, error) - GetAllCollections(ctx context.Context, client *ethclient.Client) ([]bindings.StructsCollection, error) - GetActiveCollectionIds(ctx context.Context, client *ethclient.Client) ([]uint16, error) - HandleOfficialJobsFromJSONFile(client *ethclient.Client, collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) + GetAssignedCollections(rpcParameters RPC.RPCParameters, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) + GetLeafIdOfACollection(rpcParameters RPC.RPCParameters, collectionId uint16) (uint16, error) + GetSaltFromBlockchain(rpcParameters RPC.RPCParameters) ([32]byte, error) + GetCollectionIdFromIndex(rpcParameters RPC.RPCParameters, medianIndex uint16) (uint16, error) + GetCollectionIdFromLeafId(rpcParameters RPC.RPCParameters, leafId uint16) (uint16, error) + GetNumActiveCollections(rpcParameters RPC.RPCParameters) (uint16, error) + GetAggregatedDataOfCollection(rpcParameters RPC.RPCParameters, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) + GetJobs(rpcParameters RPC.RPCParameters) ([]bindings.StructsJob, error) + GetAllCollections(rpcParameters RPC.RPCParameters) ([]bindings.StructsCollection, error) + GetActiveCollectionIds(rpcParameters RPC.RPCParameters) ([]uint16, error) + GetActiveStatus(rpcParameters RPC.RPCParameters, id uint16) (bool, error) + HandleOfficialJobsFromJSONFile(collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) ConnectToClient(provider string) *ethclient.Client - FetchBalance(client *ethclient.Client, accountAddress string) (*big.Int, error) + FetchBalance(rpcParameters RPC.RPCParameters, accountAddress string) (*big.Int, error) + Allowance(rpcParameters RPC.RPCParameters, owner common.Address, spender common.Address) (*big.Int, error) GetBufferedState(header *Types.Header, stateBuffer uint64, buffer int32) (int64, error) - WaitForBlockCompletion(client *ethclient.Client, hashToRead string) error - CheckEthBalanceIsZero(ctx context.Context, client *ethclient.Client, address string) - AssignStakerId(ctx context.Context, flagSet *pflag.FlagSet, client *ethclient.Client, address string) (uint32, error) - GetEpoch(ctx context.Context, client *ethclient.Client) (uint32, error) - CalculateBlockTime(ctx context.Context, client *ethclient.Client) int64 + WaitForBlockCompletion(rpcManager RPC.RPCParameters, hashToRead string) error + CheckEthBalanceIsZero(rpcParameters RPC.RPCParameters, address string) + AssignStakerId(rpcParameters RPC.RPCParameters, flagSet *pflag.FlagSet, address string) (uint32, error) + GetEpoch(rpcParameters RPC.RPCParameters) (uint32, error) + CalculateBlockTime(rpcParameters RPC.RPCParameters) int64 IsFlagPassed(name string) bool GetTokenManager(client *ethclient.Client) *bindings.RAZOR GetStakedToken(client *ethclient.Client, tokenAddress common.Address) *bindings.StakedToken @@ -142,22 +150,23 @@ type Utils interface { WriteDataToJSON(fileName string, data map[string]*types.StructsJob) error DeleteJobFromJSON(fileName string, jobId string) error AddJobToJSON(fileName string, job *types.StructsJob) error - CheckTransactionReceipt(client *ethclient.Client, _txHash string) int + CheckTransactionReceipt(rpcManager RPC.RPCParameters, _txHash string) int CalculateSalt(epoch uint32, medians []*big.Int) [32]byte - ToAssign(ctx context.Context, client *ethclient.Client) (uint16, error) + ToAssign(rpcParameters RPC.RPCParameters) (uint16, error) Prng(max uint32, prngHashes []byte) *big.Int GetRemainingTimeOfCurrentState(block *Types.Header, stateBuffer uint64, bufferPercent int32) (int64, error) SecondsToReadableTime(input int) string - EstimateBlockNumberAtEpochBeginning(client *ethclient.Client, currentBlockNumber *big.Int) (*big.Int, error) - GetEpochLastProposed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) - GetConfirmedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (types.ConfirmedBlock, error) + EstimateBlockNumberAtEpochBeginning(rpcParameters RPC.RPCParameters, currentBlockNumber *big.Int) (*big.Int, error) + GetEpochLastProposed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) + GetConfirmedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (types.ConfirmedBlock, error) + Disputes(rpcParameters RPC.RPCParameters, epoch uint32, address common.Address) (types.DisputesStruct, error) CheckAmountAndBalance(amountInWei *big.Int, balance *big.Int) *big.Int PasswordPrompt() string AssignPassword(flagSet *pflag.FlagSet) string PrivateKeyPrompt() string GetRogueRandomValue(value int) *big.Int GetStakedTokenManagerWithOpts(client *ethclient.Client, tokenAddress common.Address) (*bindings.StakedToken, bind.CallOpts) - GetStakerSRZRBalance(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker) (*big.Int, error) + GetStakerSRZRBalance(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker) (*big.Int, error) CheckPassword(account types.Account) error AccountManagerForKeystore() (types.AccountManagerInterface, error) } @@ -174,15 +183,16 @@ type ClientUtils interface { SuggestGasPrice(client *ethclient.Client, ctx context.Context) (*big.Int, error) EstimateGas(client *ethclient.Client, ctx context.Context, msg ethereum.CallMsg) (uint64, error) FilterLogs(client *ethclient.Client, ctx context.Context, q ethereum.FilterQuery) ([]Types.Log, error) - SuggestGasPriceWithRetry(ctx context.Context, client *ethclient.Client) (*big.Int, error) - EstimateGasWithRetry(ctx context.Context, client *ethclient.Client, message ethereum.CallMsg) (uint64, error) - GetLatestBlockWithRetry(ctx context.Context, client *ethclient.Client) (*Types.Header, error) - FilterLogsWithRetry(ctx context.Context, client *ethclient.Client, query ethereum.FilterQuery) ([]Types.Log, error) - BalanceAtWithRetry(ctx context.Context, client *ethclient.Client, account common.Address) (*big.Int, error) - GetNonceAtWithRetry(ctx context.Context, client *ethclient.Client, accountAddress common.Address) (uint64, error) - PerformBatchCall(client *ethclient.Client, calls []rpc.BatchElem) error + SuggestGasPriceWithRetry(rpcParameters RPC.RPCParameters) (*big.Int, error) + EstimateGasWithRetry(rpcParameters RPC.RPCParameters, message ethereum.CallMsg) (uint64, error) + GetLatestBlockWithRetry(rpcParameters RPC.RPCParameters) (*Types.Header, error) + GetBlockByNumberWithRetry(rpcParameters RPC.RPCParameters, blockNumber *big.Int) (*Types.Header, error) + FilterLogsWithRetry(rpcParameters RPC.RPCParameters, query ethereum.FilterQuery) ([]Types.Log, error) + BalanceAtWithRetry(rpcParameters RPC.RPCParameters, account common.Address) (*big.Int, error) + GetNonceAtWithRetry(rpcParameters RPC.RPCParameters, accountAddress common.Address) (uint64, error) + PerformBatchCall(rpcParameters RPC.RPCParameters, calls []rpc.BatchElem) error CreateBatchCalls(contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([]rpc.BatchElem, error) - BatchCall(client *ethclient.Client, contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([][]interface{}, error) + BatchCall(rpcParameters RPC.RPCParameters, contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([][]interface{}, error) } type TimeUtils interface { @@ -197,7 +207,8 @@ type OSUtils interface { } type CoinUtils interface { - BalanceOf(erc20Contract *bindings.RAZOR, opts *bind.CallOpts, account common.Address) (*big.Int, error) + BalanceOf(client *ethclient.Client, account common.Address) (*big.Int, error) + Allowance(client *ethclient.Client, owner common.Address, spender common.Address) (*big.Int, error) } type MerkleTreeInterface interface { @@ -245,6 +256,9 @@ type StakeManagerUtils interface { MaxCommission(client *ethclient.Client) (uint8, error) EpochLimitForUpdateCommission(client *ethclient.Client) (uint16, error) WithdrawInitiationPeriod(client *ethclient.Client) (uint16, error) + StakerInfo(client *ethclient.Client, stakerId uint32) (types.Staker, error) + GetMaturity(client *ethclient.Client, age uint32) (uint16, error) + GetBountyLock(client *ethclient.Client, bountyId uint32) (types.BountyLock, error) } type AssetManagerUtils interface { @@ -254,6 +268,7 @@ type AssetManagerUtils interface { GetJob(client *ethclient.Client, id uint16) (bindings.StructsJob, error) GetCollection(client *ethclient.Client, id uint16) (bindings.StructsCollection, error) GetActiveCollections(client *ethclient.Client) ([]uint16, error) + GetActiveStatus(client *ethclient.Client, id uint16) (bool, error) Jobs(client *ethclient.Client, id uint16) (bindings.StructsJob, error) GetCollectionIdFromIndex(client *ethclient.Client, index uint16) (uint16, error) GetCollectionIdFromLeafId(client *ethclient.Client, leafId uint16) (uint16, error) @@ -309,9 +324,9 @@ type FileUtils interface { } type GasUtils interface { - GetGasPrice(ctx context.Context, client *ethclient.Client, config types.Configurations) *big.Int - GetGasLimit(ctx context.Context, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) - IncreaseGasLimitValue(ctx context.Context, client *ethclient.Client, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) + GetGasPrice(rpcParameters RPC.RPCParameters, config types.Configurations) *big.Int + GetGasLimit(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) + IncreaseGasLimitValue(rpcParameters RPC.RPCParameters, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) } type UtilsStruct struct{} diff --git a/utils/mocks/abi_utils.go b/utils/mocks/abi_utils.go index fe7e6470..263ca979 100644 --- a/utils/mocks/abi_utils.go +++ b/utils/mocks/abi_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -23,6 +23,10 @@ func (_m *ABIUtils) Pack(parsedData abi.ABI, name string, args ...interface{}) ( ret := _m.Called(_ca...) var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(abi.ABI, string, ...interface{}) ([]byte, error)); ok { + return rf(parsedData, name, args...) + } if rf, ok := ret.Get(0).(func(abi.ABI, string, ...interface{}) []byte); ok { r0 = rf(parsedData, name, args...) } else { @@ -31,7 +35,6 @@ func (_m *ABIUtils) Pack(parsedData abi.ABI, name string, args ...interface{}) ( } } - var r1 error if rf, ok := ret.Get(1).(func(abi.ABI, string, ...interface{}) error); ok { r1 = rf(parsedData, name, args...) } else { @@ -46,13 +49,16 @@ func (_m *ABIUtils) Parse(reader io.Reader) (abi.ABI, error) { ret := _m.Called(reader) var r0 abi.ABI + var r1 error + if rf, ok := ret.Get(0).(func(io.Reader) (abi.ABI, error)); ok { + return rf(reader) + } if rf, ok := ret.Get(0).(func(io.Reader) abi.ABI); ok { r0 = rf(reader) } else { r0 = ret.Get(0).(abi.ABI) } - var r1 error if rf, ok := ret.Get(1).(func(io.Reader) error); ok { r1 = rf(reader) } else { @@ -62,13 +68,12 @@ func (_m *ABIUtils) Parse(reader io.Reader) (abi.ABI, error) { return r0, r1 } -type mockConstructorTestingTNewABIUtils interface { +// NewABIUtils creates a new instance of ABIUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewABIUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewABIUtils creates a new instance of ABIUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewABIUtils(t mockConstructorTestingTNewABIUtils) *ABIUtils { +}) *ABIUtils { mock := &ABIUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/asset_manager_utils.go b/utils/mocks/asset_manager_utils.go index 09faa71e..6714520f 100644 --- a/utils/mocks/asset_manager_utils.go +++ b/utils/mocks/asset_manager_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ func (_m *AssetManagerUtils) GetActiveCollections(client *ethclient.Client) ([]u ret := _m.Called(client) var r0 []uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) ([]uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) []uint16); ok { r0 = rf(client) } else { @@ -27,7 +31,6 @@ func (_m *AssetManagerUtils) GetActiveCollections(client *ethclient.Client) ([]u } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -37,18 +40,45 @@ func (_m *AssetManagerUtils) GetActiveCollections(client *ethclient.Client) ([]u return r0, r1 } +// GetActiveStatus provides a mock function with given fields: client, id +func (_m *AssetManagerUtils) GetActiveStatus(client *ethclient.Client, id uint16) (bool, error) { + ret := _m.Called(client, id) + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (bool, error)); ok { + return rf(client, id) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) bool); ok { + r0 = rf(client, id) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { + r1 = rf(client, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetCollection provides a mock function with given fields: client, id func (_m *AssetManagerUtils) GetCollection(client *ethclient.Client, id uint16) (bindings.StructsCollection, error) { ret := _m.Called(client, id) var r0 bindings.StructsCollection + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (bindings.StructsCollection, error)); ok { + return rf(client, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) bindings.StructsCollection); ok { r0 = rf(client, id) } else { r0 = ret.Get(0).(bindings.StructsCollection) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, id) } else { @@ -63,13 +93,16 @@ func (_m *AssetManagerUtils) GetCollectionIdFromIndex(client *ethclient.Client, ret := _m.Called(client, index) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (uint16, error)); ok { + return rf(client, index) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) uint16); ok { r0 = rf(client, index) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, index) } else { @@ -84,13 +117,16 @@ func (_m *AssetManagerUtils) GetCollectionIdFromLeafId(client *ethclient.Client, ret := _m.Called(client, leafId) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (uint16, error)); ok { + return rf(client, leafId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) uint16); ok { r0 = rf(client, leafId) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, leafId) } else { @@ -105,13 +141,16 @@ func (_m *AssetManagerUtils) GetJob(client *ethclient.Client, id uint16) (bindin ret := _m.Called(client, id) var r0 bindings.StructsJob + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (bindings.StructsJob, error)); ok { + return rf(client, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) bindings.StructsJob); ok { r0 = rf(client, id) } else { r0 = ret.Get(0).(bindings.StructsJob) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, id) } else { @@ -126,13 +165,16 @@ func (_m *AssetManagerUtils) GetLeafIdOfACollection(client *ethclient.Client, co ret := _m.Called(client, collectionId) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (uint16, error)); ok { + return rf(client, collectionId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) uint16); ok { r0 = rf(client, collectionId) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, collectionId) } else { @@ -147,13 +189,16 @@ func (_m *AssetManagerUtils) GetNumActiveCollections(client *ethclient.Client) ( ret := _m.Called(client) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint16); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -168,13 +213,16 @@ func (_m *AssetManagerUtils) GetNumCollections(client *ethclient.Client) (uint16 ret := _m.Called(client) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint16); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -189,13 +237,16 @@ func (_m *AssetManagerUtils) GetNumJobs(client *ethclient.Client) (uint16, error ret := _m.Called(client) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint16); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -210,13 +261,16 @@ func (_m *AssetManagerUtils) Jobs(client *ethclient.Client, id uint16) (bindings ret := _m.Called(client, id) var r0 bindings.StructsJob + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) (bindings.StructsJob, error)); ok { + return rf(client, id) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint16) bindings.StructsJob); ok { r0 = rf(client, id) } else { r0 = ret.Get(0).(bindings.StructsJob) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint16) error); ok { r1 = rf(client, id) } else { @@ -226,13 +280,12 @@ func (_m *AssetManagerUtils) Jobs(client *ethclient.Client, id uint16) (bindings return r0, r1 } -type mockConstructorTestingTNewAssetManagerUtils interface { +// NewAssetManagerUtils creates a new instance of AssetManagerUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAssetManagerUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewAssetManagerUtils creates a new instance of AssetManagerUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewAssetManagerUtils(t mockConstructorTestingTNewAssetManagerUtils) *AssetManagerUtils { +}) *AssetManagerUtils { mock := &AssetManagerUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/bind_utils.go b/utils/mocks/bind_utils.go index 170527af..408a3672 100644 --- a/utils/mocks/bind_utils.go +++ b/utils/mocks/bind_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -21,6 +21,10 @@ func (_m *BindUtils) NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainI ret := _m.Called(key, chainID) var r0 *bind.TransactOpts + var r1 error + if rf, ok := ret.Get(0).(func(*ecdsa.PrivateKey, *big.Int) (*bind.TransactOpts, error)); ok { + return rf(key, chainID) + } if rf, ok := ret.Get(0).(func(*ecdsa.PrivateKey, *big.Int) *bind.TransactOpts); ok { r0 = rf(key, chainID) } else { @@ -29,7 +33,6 @@ func (_m *BindUtils) NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainI } } - var r1 error if rf, ok := ret.Get(1).(func(*ecdsa.PrivateKey, *big.Int) error); ok { r1 = rf(key, chainID) } else { @@ -39,13 +42,12 @@ func (_m *BindUtils) NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainI return r0, r1 } -type mockConstructorTestingTNewBindUtils interface { +// NewBindUtils creates a new instance of BindUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBindUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewBindUtils creates a new instance of BindUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBindUtils(t mockConstructorTestingTNewBindUtils) *BindUtils { +}) *BindUtils { mock := &BindUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/bindings_utils.go b/utils/mocks/bindings_utils.go index 63e9e013..bbdfca74 100644 --- a/utils/mocks/bindings_utils.go +++ b/utils/mocks/bindings_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -21,6 +21,10 @@ func (_m *BindingsUtils) NewBlockManager(address common.Address, client *ethclie ret := _m.Called(address, client) var r0 *bindings.BlockManager + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.BlockManager, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.BlockManager); ok { r0 = rf(address, client) } else { @@ -29,7 +33,6 @@ func (_m *BindingsUtils) NewBlockManager(address common.Address, client *ethclie } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -44,6 +47,10 @@ func (_m *BindingsUtils) NewCollectionManager(address common.Address, client *et ret := _m.Called(address, client) var r0 *bindings.CollectionManager + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.CollectionManager, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.CollectionManager); ok { r0 = rf(address, client) } else { @@ -52,7 +59,6 @@ func (_m *BindingsUtils) NewCollectionManager(address common.Address, client *et } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -67,6 +73,10 @@ func (_m *BindingsUtils) NewRAZOR(address common.Address, client *ethclient.Clie ret := _m.Called(address, client) var r0 *bindings.RAZOR + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.RAZOR, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.RAZOR); ok { r0 = rf(address, client) } else { @@ -75,7 +85,6 @@ func (_m *BindingsUtils) NewRAZOR(address common.Address, client *ethclient.Clie } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -90,6 +99,10 @@ func (_m *BindingsUtils) NewStakeManager(address common.Address, client *ethclie ret := _m.Called(address, client) var r0 *bindings.StakeManager + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.StakeManager, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.StakeManager); ok { r0 = rf(address, client) } else { @@ -98,7 +111,6 @@ func (_m *BindingsUtils) NewStakeManager(address common.Address, client *ethclie } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -113,6 +125,10 @@ func (_m *BindingsUtils) NewStakedToken(address common.Address, client *ethclien ret := _m.Called(address, client) var r0 *bindings.StakedToken + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.StakedToken, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.StakedToken); ok { r0 = rf(address, client) } else { @@ -121,7 +137,6 @@ func (_m *BindingsUtils) NewStakedToken(address common.Address, client *ethclien } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -136,6 +151,10 @@ func (_m *BindingsUtils) NewVoteManager(address common.Address, client *ethclien ret := _m.Called(address, client) var r0 *bindings.VoteManager + var r1 error + if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) (*bindings.VoteManager, error)); ok { + return rf(address, client) + } if rf, ok := ret.Get(0).(func(common.Address, *ethclient.Client) *bindings.VoteManager); ok { r0 = rf(address, client) } else { @@ -144,7 +163,6 @@ func (_m *BindingsUtils) NewVoteManager(address common.Address, client *ethclien } } - var r1 error if rf, ok := ret.Get(1).(func(common.Address, *ethclient.Client) error); ok { r1 = rf(address, client) } else { @@ -154,13 +172,12 @@ func (_m *BindingsUtils) NewVoteManager(address common.Address, client *ethclien return r0, r1 } -type mockConstructorTestingTNewBindingsUtils interface { +// NewBindingsUtils creates a new instance of BindingsUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBindingsUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewBindingsUtils creates a new instance of BindingsUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewBindingsUtils(t mockConstructorTestingTNewBindingsUtils) *BindingsUtils { +}) *BindingsUtils { mock := &BindingsUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/client_utils.go b/utils/mocks/client_utils.go index 819cc74b..496dac48 100644 --- a/utils/mocks/client_utils.go +++ b/utils/mocks/client_utils.go @@ -4,6 +4,7 @@ package mocks import ( big "math/big" + RPC "razor/RPC" abi "github.com/ethereum/go-ethereum/accounts/abi" @@ -53,25 +54,25 @@ func (_m *ClientUtils) BalanceAt(client *ethclient.Client, ctx context.Context, return r0, r1 } -// BalanceAtWithRetry provides a mock function with given fields: ctx, client, account -func (_m *ClientUtils) BalanceAtWithRetry(ctx context.Context, client *ethclient.Client, account common.Address) (*big.Int, error) { - ret := _m.Called(ctx, client, account) +// BalanceAtWithRetry provides a mock function with given fields: rpcParameters, account +func (_m *ClientUtils) BalanceAtWithRetry(rpcParameters RPC.RPCParameters, account common.Address) (*big.Int, error) { + ret := _m.Called(rpcParameters, account) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, common.Address) (*big.Int, error)); ok { - return rf(ctx, client, account) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address) (*big.Int, error)); ok { + return rf(rpcParameters, account) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, common.Address) *big.Int); ok { - r0 = rf(ctx, client, account) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address) *big.Int); ok { + r0 = rf(rpcParameters, account) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, common.Address) error); ok { - r1 = rf(ctx, client, account) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, common.Address) error); ok { + r1 = rf(rpcParameters, account) } else { r1 = ret.Error(1) } @@ -79,25 +80,25 @@ func (_m *ClientUtils) BalanceAtWithRetry(ctx context.Context, client *ethclient return r0, r1 } -// BatchCall provides a mock function with given fields: client, contractABI, contractAddress, methodName, args -func (_m *ClientUtils) BatchCall(client *ethclient.Client, contractABI *abi.ABI, contractAddress string, methodName string, args [][]interface{}) ([][]interface{}, error) { - ret := _m.Called(client, contractABI, contractAddress, methodName, args) +// BatchCall provides a mock function with given fields: rpcParameters, contractABI, contractAddress, methodName, args +func (_m *ClientUtils) BatchCall(rpcParameters RPC.RPCParameters, contractABI *abi.ABI, contractAddress string, methodName string, args [][]interface{}) ([][]interface{}, error) { + ret := _m.Called(rpcParameters, contractABI, contractAddress, methodName, args) var r0 [][]interface{} var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, *abi.ABI, string, string, [][]interface{}) ([][]interface{}, error)); ok { - return rf(client, contractABI, contractAddress, methodName, args) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *abi.ABI, string, string, [][]interface{}) ([][]interface{}, error)); ok { + return rf(rpcParameters, contractABI, contractAddress, methodName, args) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, *abi.ABI, string, string, [][]interface{}) [][]interface{}); ok { - r0 = rf(client, contractABI, contractAddress, methodName, args) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *abi.ABI, string, string, [][]interface{}) [][]interface{}); ok { + r0 = rf(rpcParameters, contractABI, contractAddress, methodName, args) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([][]interface{}) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, *abi.ABI, string, string, [][]interface{}) error); ok { - r1 = rf(client, contractABI, contractAddress, methodName, args) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *abi.ABI, string, string, [][]interface{}) error); ok { + r1 = rf(rpcParameters, contractABI, contractAddress, methodName, args) } else { r1 = ret.Error(1) } @@ -155,23 +156,23 @@ func (_m *ClientUtils) EstimateGas(client *ethclient.Client, ctx context.Context return r0, r1 } -// EstimateGasWithRetry provides a mock function with given fields: ctx, client, message -func (_m *ClientUtils) EstimateGasWithRetry(ctx context.Context, client *ethclient.Client, message ethereum.CallMsg) (uint64, error) { - ret := _m.Called(ctx, client, message) +// EstimateGasWithRetry provides a mock function with given fields: rpcParameters, message +func (_m *ClientUtils) EstimateGasWithRetry(rpcParameters RPC.RPCParameters, message ethereum.CallMsg) (uint64, error) { + ret := _m.Called(rpcParameters, message) var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, ethereum.CallMsg) (uint64, error)); ok { - return rf(ctx, client, message) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, ethereum.CallMsg) (uint64, error)); ok { + return rf(rpcParameters, message) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, ethereum.CallMsg) uint64); ok { - r0 = rf(ctx, client, message) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, ethereum.CallMsg) uint64); ok { + r0 = rf(rpcParameters, message) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, ethereum.CallMsg) error); ok { - r1 = rf(ctx, client, message) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, ethereum.CallMsg) error); ok { + r1 = rf(rpcParameters, message) } else { r1 = ret.Error(1) } @@ -205,25 +206,25 @@ func (_m *ClientUtils) FilterLogs(client *ethclient.Client, ctx context.Context, return r0, r1 } -// FilterLogsWithRetry provides a mock function with given fields: ctx, client, query -func (_m *ClientUtils) FilterLogsWithRetry(ctx context.Context, client *ethclient.Client, query ethereum.FilterQuery) ([]types.Log, error) { - ret := _m.Called(ctx, client, query) +// FilterLogsWithRetry provides a mock function with given fields: rpcParameters, query +func (_m *ClientUtils) FilterLogsWithRetry(rpcParameters RPC.RPCParameters, query ethereum.FilterQuery) ([]types.Log, error) { + ret := _m.Called(rpcParameters, query) var r0 []types.Log var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, ethereum.FilterQuery) ([]types.Log, error)); ok { - return rf(ctx, client, query) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, ethereum.FilterQuery) ([]types.Log, error)); ok { + return rf(rpcParameters, query) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, ethereum.FilterQuery) []types.Log); ok { - r0 = rf(ctx, client, query) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, ethereum.FilterQuery) []types.Log); ok { + r0 = rf(rpcParameters, query) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]types.Log) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, ethereum.FilterQuery) error); ok { - r1 = rf(ctx, client, query) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, ethereum.FilterQuery) error); ok { + r1 = rf(rpcParameters, query) } else { r1 = ret.Error(1) } @@ -231,25 +232,25 @@ func (_m *ClientUtils) FilterLogsWithRetry(ctx context.Context, client *ethclien return r0, r1 } -// GetLatestBlockWithRetry provides a mock function with given fields: ctx, client -func (_m *ClientUtils) GetLatestBlockWithRetry(ctx context.Context, client *ethclient.Client) (*types.Header, error) { - ret := _m.Called(ctx, client) +// GetBlockByNumberWithRetry provides a mock function with given fields: rpcParameters, blockNumber +func (_m *ClientUtils) GetBlockByNumberWithRetry(rpcParameters RPC.RPCParameters, blockNumber *big.Int) (*types.Header, error) { + ret := _m.Called(rpcParameters, blockNumber) var r0 *types.Header var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (*types.Header, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int) (*types.Header, error)); ok { + return rf(rpcParameters, blockNumber) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) *types.Header); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int) *types.Header); ok { + r0 = rf(rpcParameters, blockNumber) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.Header) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int) error); ok { + r1 = rf(rpcParameters, blockNumber) } else { r1 = ret.Error(1) } @@ -257,23 +258,49 @@ func (_m *ClientUtils) GetLatestBlockWithRetry(ctx context.Context, client *ethc return r0, r1 } -// GetNonceAtWithRetry provides a mock function with given fields: ctx, client, accountAddress -func (_m *ClientUtils) GetNonceAtWithRetry(ctx context.Context, client *ethclient.Client, accountAddress common.Address) (uint64, error) { - ret := _m.Called(ctx, client, accountAddress) +// GetLatestBlockWithRetry provides a mock function with given fields: rpcParameters +func (_m *ClientUtils) GetLatestBlockWithRetry(rpcParameters RPC.RPCParameters) (*types.Header, error) { + ret := _m.Called(rpcParameters) + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (*types.Header, error)); ok { + return rf(rpcParameters) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) *types.Header); ok { + r0 = rf(rpcParameters) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetNonceAtWithRetry provides a mock function with given fields: rpcParameters, accountAddress +func (_m *ClientUtils) GetNonceAtWithRetry(rpcParameters RPC.RPCParameters, accountAddress common.Address) (uint64, error) { + ret := _m.Called(rpcParameters, accountAddress) var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, common.Address) (uint64, error)); ok { - return rf(ctx, client, accountAddress) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address) (uint64, error)); ok { + return rf(rpcParameters, accountAddress) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, common.Address) uint64); ok { - r0 = rf(ctx, client, accountAddress) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address) uint64); ok { + r0 = rf(rpcParameters, accountAddress) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, common.Address) error); ok { - r1 = rf(ctx, client, accountAddress) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, common.Address) error); ok { + r1 = rf(rpcParameters, accountAddress) } else { r1 = ret.Error(1) } @@ -331,13 +358,13 @@ func (_m *ClientUtils) NonceAt(client *ethclient.Client, ctx context.Context, ac return r0, r1 } -// PerformBatchCall provides a mock function with given fields: client, calls -func (_m *ClientUtils) PerformBatchCall(client *ethclient.Client, calls []rpc.BatchElem) error { - ret := _m.Called(client, calls) +// PerformBatchCall provides a mock function with given fields: rpcParameters, calls +func (_m *ClientUtils) PerformBatchCall(rpcParameters RPC.RPCParameters, calls []rpc.BatchElem) error { + ret := _m.Called(rpcParameters, calls) var r0 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, []rpc.BatchElem) error); ok { - r0 = rf(client, calls) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, []rpc.BatchElem) error); ok { + r0 = rf(rpcParameters, calls) } else { r0 = ret.Error(0) } @@ -371,25 +398,25 @@ func (_m *ClientUtils) SuggestGasPrice(client *ethclient.Client, ctx context.Con return r0, r1 } -// SuggestGasPriceWithRetry provides a mock function with given fields: ctx, client -func (_m *ClientUtils) SuggestGasPriceWithRetry(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - ret := _m.Called(ctx, client) +// SuggestGasPriceWithRetry provides a mock function with given fields: rpcParameters +func (_m *ClientUtils) SuggestGasPriceWithRetry(rpcParameters RPC.RPCParameters) (*big.Int, error) { + ret := _m.Called(rpcParameters) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (*big.Int, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (*big.Int, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) *big.Int); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) *big.Int); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } diff --git a/utils/mocks/coin_utils.go b/utils/mocks/coin_utils.go index b885937b..08b05174 100644 --- a/utils/mocks/coin_utils.go +++ b/utils/mocks/coin_utils.go @@ -1,14 +1,12 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks import ( big "math/big" - bindings "razor/pkg/bindings" - - bind "github.com/ethereum/go-ethereum/accounts/abi/bind" common "github.com/ethereum/go-ethereum/common" + ethclient "github.com/ethereum/go-ethereum/ethclient" mock "github.com/stretchr/testify/mock" ) @@ -18,22 +16,25 @@ type CoinUtils struct { mock.Mock } -// BalanceOf provides a mock function with given fields: erc20Contract, opts, account -func (_m *CoinUtils) BalanceOf(erc20Contract *bindings.RAZOR, opts *bind.CallOpts, account common.Address) (*big.Int, error) { - ret := _m.Called(erc20Contract, opts, account) +// Allowance provides a mock function with given fields: client, owner, spender +func (_m *CoinUtils) Allowance(client *ethclient.Client, owner common.Address, spender common.Address) (*big.Int, error) { + ret := _m.Called(client, owner, spender) var r0 *big.Int - if rf, ok := ret.Get(0).(func(*bindings.RAZOR, *bind.CallOpts, common.Address) *big.Int); ok { - r0 = rf(erc20Contract, opts, account) + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address) (*big.Int, error)); ok { + return rf(client, owner, spender) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address) *big.Int); ok { + r0 = rf(client, owner, spender) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - var r1 error - if rf, ok := ret.Get(1).(func(*bindings.RAZOR, *bind.CallOpts, common.Address) error); ok { - r1 = rf(erc20Contract, opts, account) + if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address, common.Address) error); ok { + r1 = rf(client, owner, spender) } else { r1 = ret.Error(1) } @@ -41,13 +42,38 @@ func (_m *CoinUtils) BalanceOf(erc20Contract *bindings.RAZOR, opts *bind.CallOpt return r0, r1 } -type mockConstructorTestingTNewCoinUtils interface { - mock.TestingT - Cleanup(func()) +// BalanceOf provides a mock function with given fields: client, account +func (_m *CoinUtils) BalanceOf(client *ethclient.Client, account common.Address) (*big.Int, error) { + ret := _m.Called(client, account) + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address) (*big.Int, error)); ok { + return rf(client, account) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address) *big.Int); ok { + r0 = rf(client, account) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address) error); ok { + r1 = rf(client, account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } // NewCoinUtils creates a new instance of CoinUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewCoinUtils(t mockConstructorTestingTNewCoinUtils) *CoinUtils { +// The first argument is typically a *testing.T value. +func NewCoinUtils(t interface { + mock.TestingT + Cleanup(func()) +}) *CoinUtils { mock := &CoinUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/eth_client_utils.go b/utils/mocks/eth_client_utils.go index 3ca9afc9..d1d0dfb1 100644 --- a/utils/mocks/eth_client_utils.go +++ b/utils/mocks/eth_client_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -17,6 +17,10 @@ func (_m *EthClientUtils) Dial(rawurl string) (*ethclient.Client, error) { ret := _m.Called(rawurl) var r0 *ethclient.Client + var r1 error + if rf, ok := ret.Get(0).(func(string) (*ethclient.Client, error)); ok { + return rf(rawurl) + } if rf, ok := ret.Get(0).(func(string) *ethclient.Client); ok { r0 = rf(rawurl) } else { @@ -25,7 +29,6 @@ func (_m *EthClientUtils) Dial(rawurl string) (*ethclient.Client, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(rawurl) } else { @@ -35,13 +38,12 @@ func (_m *EthClientUtils) Dial(rawurl string) (*ethclient.Client, error) { return r0, r1 } -type mockConstructorTestingTNewEthClientUtils interface { +// NewEthClientUtils creates a new instance of EthClientUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewEthClientUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewEthClientUtils creates a new instance of EthClientUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewEthClientUtils(t mockConstructorTestingTNewEthClientUtils) *EthClientUtils { +}) *EthClientUtils { mock := &EthClientUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/flag_set_utils.go b/utils/mocks/flag_set_utils.go index 1887c99a..796caec4 100644 --- a/utils/mocks/flag_set_utils.go +++ b/utils/mocks/flag_set_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -17,13 +17,16 @@ func (_m *FlagSetUtils) GetLogFileName(flagSet *pflag.FlagSet) (string, error) { ret := _m.Called(flagSet) var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(*pflag.FlagSet) (string, error)); ok { + return rf(flagSet) + } if rf, ok := ret.Get(0).(func(*pflag.FlagSet) string); ok { r0 = rf(flagSet) } else { r0 = ret.Get(0).(string) } - var r1 error if rf, ok := ret.Get(1).(func(*pflag.FlagSet) error); ok { r1 = rf(flagSet) } else { @@ -33,13 +36,12 @@ func (_m *FlagSetUtils) GetLogFileName(flagSet *pflag.FlagSet) (string, error) { return r0, r1 } -type mockConstructorTestingTNewFlagSetUtils interface { +// NewFlagSetUtils creates a new instance of FlagSetUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFlagSetUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewFlagSetUtils creates a new instance of FlagSetUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewFlagSetUtils(t mockConstructorTestingTNewFlagSetUtils) *FlagSetUtils { +}) *FlagSetUtils { mock := &FlagSetUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/gas_utils.go b/utils/mocks/gas_utils.go index b0d357dc..7b144237 100644 --- a/utils/mocks/gas_utils.go +++ b/utils/mocks/gas_utils.go @@ -3,13 +3,10 @@ package mocks import ( - context "context" big "math/big" + RPC "razor/RPC" bind "github.com/ethereum/go-ethereum/accounts/abi/bind" - - ethclient "github.com/ethereum/go-ethereum/ethclient" - mock "github.com/stretchr/testify/mock" types "razor/core/types" @@ -20,23 +17,23 @@ type GasUtils struct { mock.Mock } -// GetGasLimit provides a mock function with given fields: ctx, transactionData, txnOpts -func (_m *GasUtils) GetGasLimit(ctx context.Context, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) { - ret := _m.Called(ctx, transactionData, txnOpts) +// GetGasLimit provides a mock function with given fields: rpcParameters, transactionData, txnOpts +func (_m *GasUtils) GetGasLimit(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) { + ret := _m.Called(rpcParameters, transactionData, txnOpts) var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.TransactionOptions, *bind.TransactOpts) (uint64, error)); ok { - return rf(ctx, transactionData, txnOpts) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, *bind.TransactOpts) (uint64, error)); ok { + return rf(rpcParameters, transactionData, txnOpts) } - if rf, ok := ret.Get(0).(func(context.Context, types.TransactionOptions, *bind.TransactOpts) uint64); ok { - r0 = rf(ctx, transactionData, txnOpts) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions, *bind.TransactOpts) uint64); ok { + r0 = rf(rpcParameters, transactionData, txnOpts) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, types.TransactionOptions, *bind.TransactOpts) error); ok { - r1 = rf(ctx, transactionData, txnOpts) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, types.TransactionOptions, *bind.TransactOpts) error); ok { + r1 = rf(rpcParameters, transactionData, txnOpts) } else { r1 = ret.Error(1) } @@ -44,13 +41,13 @@ func (_m *GasUtils) GetGasLimit(ctx context.Context, transactionData types.Trans return r0, r1 } -// GetGasPrice provides a mock function with given fields: ctx, client, config -func (_m *GasUtils) GetGasPrice(ctx context.Context, client *ethclient.Client, config types.Configurations) *big.Int { - ret := _m.Called(ctx, client, config) +// GetGasPrice provides a mock function with given fields: rpcParameters, config +func (_m *GasUtils) GetGasPrice(rpcParameters RPC.RPCParameters, config types.Configurations) *big.Int { + ret := _m.Called(rpcParameters, config) var r0 *big.Int - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, types.Configurations) *big.Int); ok { - r0 = rf(ctx, client, config) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.Configurations) *big.Int); ok { + r0 = rf(rpcParameters, config) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) @@ -60,23 +57,23 @@ func (_m *GasUtils) GetGasPrice(ctx context.Context, client *ethclient.Client, c return r0 } -// IncreaseGasLimitValue provides a mock function with given fields: ctx, client, gasLimit, gasLimitMultiplier -func (_m *GasUtils) IncreaseGasLimitValue(ctx context.Context, client *ethclient.Client, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) { - ret := _m.Called(ctx, client, gasLimit, gasLimitMultiplier) +// IncreaseGasLimitValue provides a mock function with given fields: rpcParameters, gasLimit, gasLimitMultiplier +func (_m *GasUtils) IncreaseGasLimitValue(rpcParameters RPC.RPCParameters, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) { + ret := _m.Called(rpcParameters, gasLimit, gasLimitMultiplier) var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint64, float32) (uint64, error)); ok { - return rf(ctx, client, gasLimit, gasLimitMultiplier) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint64, float32) (uint64, error)); ok { + return rf(rpcParameters, gasLimit, gasLimitMultiplier) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint64, float32) uint64); ok { - r0 = rf(ctx, client, gasLimit, gasLimitMultiplier) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint64, float32) uint64); ok { + r0 = rf(rpcParameters, gasLimit, gasLimitMultiplier) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint64, float32) error); ok { - r1 = rf(ctx, client, gasLimit, gasLimitMultiplier) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint64, float32) error); ok { + r1 = rf(rpcParameters, gasLimit, gasLimitMultiplier) } else { r1 = ret.Error(1) } diff --git a/utils/mocks/io_utils.go b/utils/mocks/io_utils.go index 0515dfe4..53abf824 100644 --- a/utils/mocks/io_utils.go +++ b/utils/mocks/io_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ func (_m *IOUtils) ReadAll(body io.ReadCloser) ([]byte, error) { ret := _m.Called(body) var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(io.ReadCloser) ([]byte, error)); ok { + return rf(body) + } if rf, ok := ret.Get(0).(func(io.ReadCloser) []byte); ok { r0 = rf(body) } else { @@ -26,7 +30,6 @@ func (_m *IOUtils) ReadAll(body io.ReadCloser) ([]byte, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(io.ReadCloser) error); ok { r1 = rf(body) } else { @@ -36,13 +39,12 @@ func (_m *IOUtils) ReadAll(body io.ReadCloser) ([]byte, error) { return r0, r1 } -type mockConstructorTestingTNewIOUtils interface { +// NewIOUtils creates a new instance of IOUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIOUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewIOUtils creates a new instance of IOUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewIOUtils(t mockConstructorTestingTNewIOUtils) *IOUtils { +}) *IOUtils { mock := &IOUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/json_utils.go b/utils/mocks/json_utils.go index d679371c..0ed54661 100644 --- a/utils/mocks/json_utils.go +++ b/utils/mocks/json_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -14,6 +14,10 @@ func (_m *JsonUtils) Marshal(v interface{}) ([]byte, error) { ret := _m.Called(v) var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) ([]byte, error)); ok { + return rf(v) + } if rf, ok := ret.Get(0).(func(interface{}) []byte); ok { r0 = rf(v) } else { @@ -22,7 +26,6 @@ func (_m *JsonUtils) Marshal(v interface{}) ([]byte, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(interface{}) error); ok { r1 = rf(v) } else { @@ -46,13 +49,12 @@ func (_m *JsonUtils) Unmarshal(data []byte, v interface{}) error { return r0 } -type mockConstructorTestingTNewJsonUtils interface { +// NewJsonUtils creates a new instance of JsonUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewJsonUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewJsonUtils creates a new instance of JsonUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewJsonUtils(t mockConstructorTestingTNewJsonUtils) *JsonUtils { +}) *JsonUtils { mock := &JsonUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/merkle_tree_interface.go b/utils/mocks/merkle_tree_interface.go index 60b8654f..04793ec8 100644 --- a/utils/mocks/merkle_tree_interface.go +++ b/utils/mocks/merkle_tree_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ func (_m *MerkleTreeInterface) CreateMerkle(values []*big.Int) ([][][]byte, erro ret := _m.Called(values) var r0 [][][]byte + var r1 error + if rf, ok := ret.Get(0).(func([]*big.Int) ([][][]byte, error)); ok { + return rf(values) + } if rf, ok := ret.Get(0).(func([]*big.Int) [][][]byte); ok { r0 = rf(values) } else { @@ -26,7 +30,6 @@ func (_m *MerkleTreeInterface) CreateMerkle(values []*big.Int) ([][][]byte, erro } } - var r1 error if rf, ok := ret.Get(1).(func([]*big.Int) error); ok { r1 = rf(values) } else { @@ -41,6 +44,10 @@ func (_m *MerkleTreeInterface) GetMerkleRoot(tree [][][]byte) ([32]byte, error) ret := _m.Called(tree) var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func([][][]byte) ([32]byte, error)); ok { + return rf(tree) + } if rf, ok := ret.Get(0).(func([][][]byte) [32]byte); ok { r0 = rf(tree) } else { @@ -49,7 +56,6 @@ func (_m *MerkleTreeInterface) GetMerkleRoot(tree [][][]byte) ([32]byte, error) } } - var r1 error if rf, ok := ret.Get(1).(func([][][]byte) error); ok { r1 = rf(tree) } else { @@ -75,13 +81,12 @@ func (_m *MerkleTreeInterface) GetProofPath(tree [][][]byte, assetId uint16) [][ return r0 } -type mockConstructorTestingTNewMerkleTreeInterface interface { +// NewMerkleTreeInterface creates a new instance of MerkleTreeInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMerkleTreeInterface(t interface { mock.TestingT Cleanup(func()) -} - -// NewMerkleTreeInterface creates a new instance of MerkleTreeInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMerkleTreeInterface(t mockConstructorTestingTNewMerkleTreeInterface) *MerkleTreeInterface { +}) *MerkleTreeInterface { mock := &MerkleTreeInterface{} mock.Mock.Test(t) diff --git a/utils/mocks/os_utils.go b/utils/mocks/os_utils.go index 4d1e4fe4..d9a0da04 100644 --- a/utils/mocks/os_utils.go +++ b/utils/mocks/os_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -19,6 +19,10 @@ func (_m *OSUtils) Open(name string) (*os.File, error) { ret := _m.Called(name) var r0 *os.File + var r1 error + if rf, ok := ret.Get(0).(func(string) (*os.File, error)); ok { + return rf(name) + } if rf, ok := ret.Get(0).(func(string) *os.File); ok { r0 = rf(name) } else { @@ -27,7 +31,6 @@ func (_m *OSUtils) Open(name string) (*os.File, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(name) } else { @@ -42,6 +45,10 @@ func (_m *OSUtils) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, ret := _m.Called(name, flag, perm) var r0 *os.File + var r1 error + if rf, ok := ret.Get(0).(func(string, int, fs.FileMode) (*os.File, error)); ok { + return rf(name, flag, perm) + } if rf, ok := ret.Get(0).(func(string, int, fs.FileMode) *os.File); ok { r0 = rf(name, flag, perm) } else { @@ -50,7 +57,6 @@ func (_m *OSUtils) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, } } - var r1 error if rf, ok := ret.Get(1).(func(string, int, fs.FileMode) error); ok { r1 = rf(name, flag, perm) } else { @@ -65,6 +71,10 @@ func (_m *OSUtils) ReadFile(filename string) ([]byte, error) { ret := _m.Called(filename) var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return rf(filename) + } if rf, ok := ret.Get(0).(func(string) []byte); ok { r0 = rf(filename) } else { @@ -73,7 +83,6 @@ func (_m *OSUtils) ReadFile(filename string) ([]byte, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(filename) } else { @@ -97,13 +106,12 @@ func (_m *OSUtils) WriteFile(name string, data []byte, perm fs.FileMode) error { return r0 } -type mockConstructorTestingTNewOSUtils interface { +// NewOSUtils creates a new instance of OSUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewOSUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewOSUtils creates a new instance of OSUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewOSUtils(t mockConstructorTestingTNewOSUtils) *OSUtils { +}) *OSUtils { mock := &OSUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/path_utils.go b/utils/mocks/path_utils.go index a08d4489..876a3bca 100644 --- a/utils/mocks/path_utils.go +++ b/utils/mocks/path_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -14,13 +14,16 @@ func (_m *PathUtils) GetDefaultPath() (string, error) { ret := _m.Called() var r0 string + var r1 error + if rf, ok := ret.Get(0).(func() (string, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { r0 = ret.Get(0).(string) } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -35,13 +38,16 @@ func (_m *PathUtils) GetJobFilePath() (string, error) { ret := _m.Called() var r0 string + var r1 error + if rf, ok := ret.Get(0).(func() (string, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { r0 = ret.Get(0).(string) } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { @@ -51,13 +57,12 @@ func (_m *PathUtils) GetJobFilePath() (string, error) { return r0, r1 } -type mockConstructorTestingTNewPathUtils interface { +// NewPathUtils creates a new instance of PathUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPathUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewPathUtils creates a new instance of PathUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewPathUtils(t mockConstructorTestingTNewPathUtils) *PathUtils { +}) *PathUtils { mock := &PathUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/retry_utils.go b/utils/mocks/retry_utils.go index aa02f7b8..956abb7a 100644 --- a/utils/mocks/retry_utils.go +++ b/utils/mocks/retry_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -28,13 +28,12 @@ func (_m *RetryUtils) RetryAttempts(numberOfAttempts uint) retry.Option { return r0 } -type mockConstructorTestingTNewRetryUtils interface { +// NewRetryUtils creates a new instance of RetryUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRetryUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewRetryUtils creates a new instance of RetryUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewRetryUtils(t mockConstructorTestingTNewRetryUtils) *RetryUtils { +}) *RetryUtils { mock := &RetryUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/stake_manager_utils.go b/utils/mocks/stake_manager_utils.go index 57a42b7e..ac953028 100644 --- a/utils/mocks/stake_manager_utils.go +++ b/utils/mocks/stake_manager_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -25,13 +25,16 @@ func (_m *StakeManagerUtils) EpochLimitForUpdateCommission(client *ethclient.Cli ret := _m.Called(client) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint16); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -41,18 +44,69 @@ func (_m *StakeManagerUtils) EpochLimitForUpdateCommission(client *ethclient.Cli return r0, r1 } +// GetBountyLock provides a mock function with given fields: client, bountyId +func (_m *StakeManagerUtils) GetBountyLock(client *ethclient.Client, bountyId uint32) (types.BountyLock, error) { + ret := _m.Called(client, bountyId) + + var r0 types.BountyLock + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) (types.BountyLock, error)); ok { + return rf(client, bountyId) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) types.BountyLock); ok { + r0 = rf(client, bountyId) + } else { + r0 = ret.Get(0).(types.BountyLock) + } + + if rf, ok := ret.Get(1).(func(*ethclient.Client, uint32) error); ok { + r1 = rf(client, bountyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetMaturity provides a mock function with given fields: client, age +func (_m *StakeManagerUtils) GetMaturity(client *ethclient.Client, age uint32) (uint16, error) { + ret := _m.Called(client, age) + + var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) (uint16, error)); ok { + return rf(client, age) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) uint16); ok { + r0 = rf(client, age) + } else { + r0 = ret.Get(0).(uint16) + } + + if rf, ok := ret.Get(1).(func(*ethclient.Client, uint32) error); ok { + r1 = rf(client, age) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetNumStakers provides a mock function with given fields: client func (_m *StakeManagerUtils) GetNumStakers(client *ethclient.Client) (uint32, error) { ret := _m.Called(client) var r0 uint32 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint32, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint32); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint32) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -67,13 +121,16 @@ func (_m *StakeManagerUtils) GetStaker(client *ethclient.Client, stakerId uint32 ret := _m.Called(client, stakerId) var r0 bindings.StructsStaker + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) (bindings.StructsStaker, error)); ok { + return rf(client, stakerId) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) bindings.StructsStaker); ok { r0 = rf(client, stakerId) } else { r0 = ret.Get(0).(bindings.StructsStaker) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, uint32) error); ok { r1 = rf(client, stakerId) } else { @@ -88,13 +145,16 @@ func (_m *StakeManagerUtils) GetStakerId(client *ethclient.Client, address commo ret := _m.Called(client, address) var r0 uint32 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address) (uint32, error)); ok { + return rf(client, address) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address) uint32); ok { r0 = rf(client, address) } else { r0 = ret.Get(0).(uint32) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address) error); ok { r1 = rf(client, address) } else { @@ -109,13 +169,16 @@ func (_m *StakeManagerUtils) Locks(client *ethclient.Client, address common.Addr ret := _m.Called(client, address, address1, lockType) var r0 types.Locks + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address, uint8) (types.Locks, error)); ok { + return rf(client, address, address1, lockType) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address, uint8) types.Locks); ok { r0 = rf(client, address, address1, lockType) } else { r0 = ret.Get(0).(types.Locks) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address, common.Address, uint8) error); ok { r1 = rf(client, address, address1, lockType) } else { @@ -130,13 +193,16 @@ func (_m *StakeManagerUtils) MaxCommission(client *ethclient.Client) (uint8, err ret := _m.Called(client) var r0 uint8 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint8, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint8); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint8) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -151,6 +217,10 @@ func (_m *StakeManagerUtils) MinSafeRazor(client *ethclient.Client) (*big.Int, e ret := _m.Called(client) var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (*big.Int, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) *big.Int); ok { r0 = rf(client) } else { @@ -159,7 +229,6 @@ func (_m *StakeManagerUtils) MinSafeRazor(client *ethclient.Client) (*big.Int, e } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -169,18 +238,45 @@ func (_m *StakeManagerUtils) MinSafeRazor(client *ethclient.Client) (*big.Int, e return r0, r1 } +// StakerInfo provides a mock function with given fields: client, stakerId +func (_m *StakeManagerUtils) StakerInfo(client *ethclient.Client, stakerId uint32) (types.Staker, error) { + ret := _m.Called(client, stakerId) + + var r0 types.Staker + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) (types.Staker, error)); ok { + return rf(client, stakerId) + } + if rf, ok := ret.Get(0).(func(*ethclient.Client, uint32) types.Staker); ok { + r0 = rf(client, stakerId) + } else { + r0 = ret.Get(0).(types.Staker) + } + + if rf, ok := ret.Get(1).(func(*ethclient.Client, uint32) error); ok { + r1 = rf(client, stakerId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // WithdrawInitiationPeriod provides a mock function with given fields: client func (_m *StakeManagerUtils) WithdrawInitiationPeriod(client *ethclient.Client) (uint16, error) { ret := _m.Called(client) var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client) (uint16, error)); ok { + return rf(client) + } if rf, ok := ret.Get(0).(func(*ethclient.Client) uint16); ok { r0 = rf(client) } else { r0 = ret.Get(0).(uint16) } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client) error); ok { r1 = rf(client) } else { @@ -190,13 +286,12 @@ func (_m *StakeManagerUtils) WithdrawInitiationPeriod(client *ethclient.Client) return r0, r1 } -type mockConstructorTestingTNewStakeManagerUtils interface { +// NewStakeManagerUtils creates a new instance of StakeManagerUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStakeManagerUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewStakeManagerUtils creates a new instance of StakeManagerUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStakeManagerUtils(t mockConstructorTestingTNewStakeManagerUtils) *StakeManagerUtils { +}) *StakeManagerUtils { mock := &StakeManagerUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/staked_token_utils.go b/utils/mocks/staked_token_utils.go index a502ee96..6acdb5a6 100644 --- a/utils/mocks/staked_token_utils.go +++ b/utils/mocks/staked_token_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -21,6 +21,10 @@ func (_m *StakedTokenUtils) BalanceOf(client *ethclient.Client, tokenAddress com ret := _m.Called(client, tokenAddress, address) var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address) (*big.Int, error)); ok { + return rf(client, tokenAddress, address) + } if rf, ok := ret.Get(0).(func(*ethclient.Client, common.Address, common.Address) *big.Int); ok { r0 = rf(client, tokenAddress, address) } else { @@ -29,7 +33,6 @@ func (_m *StakedTokenUtils) BalanceOf(client *ethclient.Client, tokenAddress com } } - var r1 error if rf, ok := ret.Get(1).(func(*ethclient.Client, common.Address, common.Address) error); ok { r1 = rf(client, tokenAddress, address) } else { @@ -39,13 +42,12 @@ func (_m *StakedTokenUtils) BalanceOf(client *ethclient.Client, tokenAddress com return r0, r1 } -type mockConstructorTestingTNewStakedTokenUtils interface { +// NewStakedTokenUtils creates a new instance of StakedTokenUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewStakedTokenUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewStakedTokenUtils creates a new instance of StakedTokenUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewStakedTokenUtils(t mockConstructorTestingTNewStakedTokenUtils) *StakedTokenUtils { +}) *StakedTokenUtils { mock := &StakedTokenUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/time_utils.go b/utils/mocks/time_utils.go index 118542be..ef3af8cb 100644 --- a/utils/mocks/time_utils.go +++ b/utils/mocks/time_utils.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.14.0. DO NOT EDIT. +// Code generated by mockery v2.30.1. DO NOT EDIT. package mocks @@ -18,13 +18,12 @@ func (_m *TimeUtils) Sleep(duration time.Duration) { _m.Called(duration) } -type mockConstructorTestingTNewTimeUtils interface { +// NewTimeUtils creates a new instance of TimeUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTimeUtils(t interface { mock.TestingT Cleanup(func()) -} - -// NewTimeUtils creates a new instance of TimeUtils. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewTimeUtils(t mockConstructorTestingTNewTimeUtils) *TimeUtils { +}) *TimeUtils { mock := &TimeUtils{} mock.Mock.Test(t) diff --git a/utils/mocks/utils.go b/utils/mocks/utils.go index 51e0457c..97dce4ec 100644 --- a/utils/mocks/utils.go +++ b/utils/mocks/utils.go @@ -4,6 +4,8 @@ package mocks import ( big "math/big" + RPC "razor/RPC" + bindings "razor/pkg/bindings" bind "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -12,8 +14,6 @@ import ( common "github.com/ethereum/go-ethereum/common" - context "context" - coretypes "github.com/ethereum/go-ethereum/core/types" ethclient "github.com/ethereum/go-ethereum/ethclient" @@ -70,25 +70,51 @@ func (_m *Utils) AddJobToJSON(fileName string, job *types.StructsJob) error { return r0 } -// Aggregate provides a mock function with given fields: ctx, client, previousEpoch, collection, commitParams -func (_m *Utils) Aggregate(ctx context.Context, client *ethclient.Client, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) { - ret := _m.Called(ctx, client, previousEpoch, collection, commitParams) +// Aggregate provides a mock function with given fields: rpcParameters, previousEpoch, collection, commitParams +func (_m *Utils) Aggregate(rpcParameters RPC.RPCParameters, previousEpoch uint32, collection bindings.StructsCollection, commitParams *types.CommitParams) (*big.Int, error) { + ret := _m.Called(rpcParameters, previousEpoch, collection, commitParams) + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, bindings.StructsCollection, *types.CommitParams) (*big.Int, error)); ok { + return rf(rpcParameters, previousEpoch, collection, commitParams) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, bindings.StructsCollection, *types.CommitParams) *big.Int); ok { + r0 = rf(rpcParameters, previousEpoch, collection, commitParams) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, bindings.StructsCollection, *types.CommitParams) error); ok { + r1 = rf(rpcParameters, previousEpoch, collection, commitParams) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Allowance provides a mock function with given fields: rpcParameters, owner, spender +func (_m *Utils) Allowance(rpcParameters RPC.RPCParameters, owner common.Address, spender common.Address) (*big.Int, error) { + ret := _m.Called(rpcParameters, owner, spender) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, bindings.StructsCollection, *types.CommitParams) (*big.Int, error)); ok { - return rf(ctx, client, previousEpoch, collection, commitParams) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address, common.Address) (*big.Int, error)); ok { + return rf(rpcParameters, owner, spender) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, bindings.StructsCollection, *types.CommitParams) *big.Int); ok { - r0 = rf(ctx, client, previousEpoch, collection, commitParams) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, common.Address, common.Address) *big.Int); ok { + r0 = rf(rpcParameters, owner, spender) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, bindings.StructsCollection, *types.CommitParams) error); ok { - r1 = rf(ctx, client, previousEpoch, collection, commitParams) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, common.Address, common.Address) error); ok { + r1 = rf(rpcParameters, owner, spender) } else { r1 = ret.Error(1) } @@ -110,23 +136,23 @@ func (_m *Utils) AssignPassword(flagSet *pflag.FlagSet) string { return r0 } -// AssignStakerId provides a mock function with given fields: ctx, flagSet, client, address -func (_m *Utils) AssignStakerId(ctx context.Context, flagSet *pflag.FlagSet, client *ethclient.Client, address string) (uint32, error) { - ret := _m.Called(ctx, flagSet, client, address) +// AssignStakerId provides a mock function with given fields: rpcParameters, flagSet, address +func (_m *Utils) AssignStakerId(rpcParameters RPC.RPCParameters, flagSet *pflag.FlagSet, address string) (uint32, error) { + ret := _m.Called(rpcParameters, flagSet, address) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *pflag.FlagSet, *ethclient.Client, string) (uint32, error)); ok { - return rf(ctx, flagSet, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *pflag.FlagSet, string) (uint32, error)); ok { + return rf(rpcParameters, flagSet, address) } - if rf, ok := ret.Get(0).(func(context.Context, *pflag.FlagSet, *ethclient.Client, string) uint32); ok { - r0 = rf(ctx, flagSet, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *pflag.FlagSet, string) uint32); ok { + r0 = rf(rpcParameters, flagSet, address) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *pflag.FlagSet, *ethclient.Client, string) error); ok { - r1 = rf(ctx, flagSet, client, address) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *pflag.FlagSet, string) error); ok { + r1 = rf(rpcParameters, flagSet, address) } else { r1 = ret.Error(1) } @@ -134,13 +160,13 @@ func (_m *Utils) AssignStakerId(ctx context.Context, flagSet *pflag.FlagSet, cli return r0, r1 } -// CalculateBlockTime provides a mock function with given fields: ctx, client -func (_m *Utils) CalculateBlockTime(ctx context.Context, client *ethclient.Client) int64 { - ret := _m.Called(ctx, client) +// CalculateBlockTime provides a mock function with given fields: rpcParameters +func (_m *Utils) CalculateBlockTime(rpcParameters RPC.RPCParameters) int64 { + ret := _m.Called(rpcParameters) var r0 int64 - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) int64); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) int64); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(int64) } @@ -180,9 +206,9 @@ func (_m *Utils) CheckAmountAndBalance(amountInWei *big.Int, balance *big.Int) * return r0 } -// CheckEthBalanceIsZero provides a mock function with given fields: ctx, client, address -func (_m *Utils) CheckEthBalanceIsZero(ctx context.Context, client *ethclient.Client, address string) { - _m.Called(ctx, client, address) +// CheckEthBalanceIsZero provides a mock function with given fields: rpcParameters, address +func (_m *Utils) CheckEthBalanceIsZero(rpcParameters RPC.RPCParameters, address string) { + _m.Called(rpcParameters, address) } // CheckPassword provides a mock function with given fields: account @@ -199,13 +225,13 @@ func (_m *Utils) CheckPassword(account types.Account) error { return r0 } -// CheckTransactionReceipt provides a mock function with given fields: client, _txHash -func (_m *Utils) CheckTransactionReceipt(client *ethclient.Client, _txHash string) int { - ret := _m.Called(client, _txHash) +// CheckTransactionReceipt provides a mock function with given fields: rpcManager, _txHash +func (_m *Utils) CheckTransactionReceipt(rpcManager RPC.RPCParameters, _txHash string) int { + ret := _m.Called(rpcManager, _txHash) var r0 int - if rf, ok := ret.Get(0).(func(*ethclient.Client, string) int); ok { - r0 = rf(client, _txHash) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) int); ok { + r0 = rf(rpcManager, _txHash) } else { r0 = ret.Get(0).(int) } @@ -243,25 +269,49 @@ func (_m *Utils) DeleteJobFromJSON(fileName string, jobId string) error { return r0 } -// EstimateBlockNumberAtEpochBeginning provides a mock function with given fields: client, currentBlockNumber -func (_m *Utils) EstimateBlockNumberAtEpochBeginning(client *ethclient.Client, currentBlockNumber *big.Int) (*big.Int, error) { - ret := _m.Called(client, currentBlockNumber) +// Disputes provides a mock function with given fields: rpcParameters, epoch, address +func (_m *Utils) Disputes(rpcParameters RPC.RPCParameters, epoch uint32, address common.Address) (types.DisputesStruct, error) { + ret := _m.Called(rpcParameters, epoch, address) + + var r0 types.DisputesStruct + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, common.Address) (types.DisputesStruct, error)); ok { + return rf(rpcParameters, epoch, address) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, common.Address) types.DisputesStruct); ok { + r0 = rf(rpcParameters, epoch, address) + } else { + r0 = ret.Get(0).(types.DisputesStruct) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, common.Address) error); ok { + r1 = rf(rpcParameters, epoch, address) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EstimateBlockNumberAtEpochBeginning provides a mock function with given fields: rpcParameters, currentBlockNumber +func (_m *Utils) EstimateBlockNumberAtEpochBeginning(rpcParameters RPC.RPCParameters, currentBlockNumber *big.Int) (*big.Int, error) { + ret := _m.Called(rpcParameters, currentBlockNumber) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, *big.Int) (*big.Int, error)); ok { - return rf(client, currentBlockNumber) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int) (*big.Int, error)); ok { + return rf(rpcParameters, currentBlockNumber) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, *big.Int) *big.Int); ok { - r0 = rf(client, currentBlockNumber) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, *big.Int) *big.Int); ok { + r0 = rf(rpcParameters, currentBlockNumber) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, *big.Int) error); ok { - r1 = rf(client, currentBlockNumber) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, *big.Int) error); ok { + r1 = rf(rpcParameters, currentBlockNumber) } else { r1 = ret.Error(1) } @@ -269,25 +319,25 @@ func (_m *Utils) EstimateBlockNumberAtEpochBeginning(client *ethclient.Client, c return r0, r1 } -// FetchBalance provides a mock function with given fields: client, accountAddress -func (_m *Utils) FetchBalance(client *ethclient.Client, accountAddress string) (*big.Int, error) { - ret := _m.Called(client, accountAddress) +// FetchBalance provides a mock function with given fields: rpcParameters, accountAddress +func (_m *Utils) FetchBalance(rpcParameters RPC.RPCParameters, accountAddress string) (*big.Int, error) { + ret := _m.Called(rpcParameters, accountAddress) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, string) (*big.Int, error)); ok { - return rf(client, accountAddress) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) (*big.Int, error)); ok { + return rf(rpcParameters, accountAddress) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, string) *big.Int); ok { - r0 = rf(client, accountAddress) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) *big.Int); ok { + r0 = rf(rpcParameters, accountAddress) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, string) error); ok { - r1 = rf(client, accountAddress) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string) error); ok { + r1 = rf(rpcParameters, accountAddress) } else { r1 = ret.Error(1) } @@ -295,25 +345,25 @@ func (_m *Utils) FetchBalance(client *ethclient.Client, accountAddress string) ( return r0, r1 } -// FetchPreviousValue provides a mock function with given fields: ctx, client, epoch, assetId -func (_m *Utils) FetchPreviousValue(ctx context.Context, client *ethclient.Client, epoch uint32, assetId uint16) (*big.Int, error) { - ret := _m.Called(ctx, client, epoch, assetId) +// FetchPreviousValue provides a mock function with given fields: rpcParameters, epoch, assetId +func (_m *Utils) FetchPreviousValue(rpcParameters RPC.RPCParameters, epoch uint32, assetId uint16) (*big.Int, error) { + ret := _m.Called(rpcParameters, epoch, assetId) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint16) (*big.Int, error)); ok { - return rf(ctx, client, epoch, assetId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint16) (*big.Int, error)); ok { + return rf(rpcParameters, epoch, assetId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint16) *big.Int); ok { - r0 = rf(ctx, client, epoch, assetId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint16) *big.Int); ok { + r0 = rf(rpcParameters, epoch, assetId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint16) error); ok { - r1 = rf(ctx, client, epoch, assetId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint16) error); ok { + r1 = rf(rpcParameters, epoch, assetId) } else { r1 = ret.Error(1) } @@ -345,25 +395,25 @@ func (_m *Utils) GetActiveCollection(collectionsCache *cache.CollectionsCache, c return r0, r1 } -// GetActiveCollectionIds provides a mock function with given fields: ctx, client -func (_m *Utils) GetActiveCollectionIds(ctx context.Context, client *ethclient.Client) ([]uint16, error) { - ret := _m.Called(ctx, client) +// GetActiveCollectionIds provides a mock function with given fields: rpcParameters +func (_m *Utils) GetActiveCollectionIds(rpcParameters RPC.RPCParameters) ([]uint16, error) { + ret := _m.Called(rpcParameters) var r0 []uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) ([]uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) ([]uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) []uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) []uint16); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]uint16) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -371,23 +421,47 @@ func (_m *Utils) GetActiveCollectionIds(ctx context.Context, client *ethclient.C return r0, r1 } -// GetActiveJob provides a mock function with given fields: ctx, client, jobId -func (_m *Utils) GetActiveJob(ctx context.Context, client *ethclient.Client, jobId uint16) (bindings.StructsJob, error) { - ret := _m.Called(ctx, client, jobId) +// GetActiveJob provides a mock function with given fields: rpcParameters, jobId +func (_m *Utils) GetActiveJob(rpcParameters RPC.RPCParameters, jobId uint16) (bindings.StructsJob, error) { + ret := _m.Called(rpcParameters, jobId) var r0 bindings.StructsJob var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) (bindings.StructsJob, error)); ok { - return rf(ctx, client, jobId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (bindings.StructsJob, error)); ok { + return rf(rpcParameters, jobId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) bindings.StructsJob); ok { - r0 = rf(ctx, client, jobId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) bindings.StructsJob); ok { + r0 = rf(rpcParameters, jobId) } else { r0 = ret.Get(0).(bindings.StructsJob) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16) error); ok { - r1 = rf(ctx, client, jobId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, jobId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetActiveStatus provides a mock function with given fields: rpcParameters, id +func (_m *Utils) GetActiveStatus(rpcParameters RPC.RPCParameters, id uint16) (bool, error) { + ret := _m.Called(rpcParameters, id) + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (bool, error)); ok { + return rf(rpcParameters, id) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) bool); ok { + r0 = rf(rpcParameters, id) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, id) } else { r1 = ret.Error(1) } @@ -395,25 +469,25 @@ func (_m *Utils) GetActiveJob(ctx context.Context, client *ethclient.Client, job return r0, r1 } -// GetAggregatedDataOfCollection provides a mock function with given fields: ctx, client, collectionId, epoch, commitParams -func (_m *Utils) GetAggregatedDataOfCollection(ctx context.Context, client *ethclient.Client, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) { - ret := _m.Called(ctx, client, collectionId, epoch, commitParams) +// GetAggregatedDataOfCollection provides a mock function with given fields: rpcParameters, collectionId, epoch, commitParams +func (_m *Utils) GetAggregatedDataOfCollection(rpcParameters RPC.RPCParameters, collectionId uint16, epoch uint32, commitParams *types.CommitParams) (*big.Int, error) { + ret := _m.Called(rpcParameters, collectionId, epoch, commitParams) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16, uint32, *types.CommitParams) (*big.Int, error)); ok { - return rf(ctx, client, collectionId, epoch, commitParams) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16, uint32, *types.CommitParams) (*big.Int, error)); ok { + return rf(rpcParameters, collectionId, epoch, commitParams) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16, uint32, *types.CommitParams) *big.Int); ok { - r0 = rf(ctx, client, collectionId, epoch, commitParams) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16, uint32, *types.CommitParams) *big.Int); ok { + r0 = rf(rpcParameters, collectionId, epoch, commitParams) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16, uint32, *types.CommitParams) error); ok { - r1 = rf(ctx, client, collectionId, epoch, commitParams) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16, uint32, *types.CommitParams) error); ok { + r1 = rf(rpcParameters, collectionId, epoch, commitParams) } else { r1 = ret.Error(1) } @@ -421,25 +495,25 @@ func (_m *Utils) GetAggregatedDataOfCollection(ctx context.Context, client *ethc return r0, r1 } -// GetAllCollections provides a mock function with given fields: ctx, client -func (_m *Utils) GetAllCollections(ctx context.Context, client *ethclient.Client) ([]bindings.StructsCollection, error) { - ret := _m.Called(ctx, client) +// GetAllCollections provides a mock function with given fields: rpcParameters +func (_m *Utils) GetAllCollections(rpcParameters RPC.RPCParameters) ([]bindings.StructsCollection, error) { + ret := _m.Called(rpcParameters) var r0 []bindings.StructsCollection var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) ([]bindings.StructsCollection, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) ([]bindings.StructsCollection, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) []bindings.StructsCollection); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) []bindings.StructsCollection); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]bindings.StructsCollection) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -447,34 +521,34 @@ func (_m *Utils) GetAllCollections(ctx context.Context, client *ethclient.Client return r0, r1 } -// GetAssignedCollections provides a mock function with given fields: ctx, client, numActiveCollections, seed -func (_m *Utils) GetAssignedCollections(ctx context.Context, client *ethclient.Client, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) { - ret := _m.Called(ctx, client, numActiveCollections, seed) +// GetAssignedCollections provides a mock function with given fields: rpcParameters, numActiveCollections, seed +func (_m *Utils) GetAssignedCollections(rpcParameters RPC.RPCParameters, numActiveCollections uint16, seed []byte) (map[int]bool, []*big.Int, error) { + ret := _m.Called(rpcParameters, numActiveCollections, seed) var r0 map[int]bool var r1 []*big.Int var r2 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16, []byte) (map[int]bool, []*big.Int, error)); ok { - return rf(ctx, client, numActiveCollections, seed) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16, []byte) (map[int]bool, []*big.Int, error)); ok { + return rf(rpcParameters, numActiveCollections, seed) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16, []byte) map[int]bool); ok { - r0 = rf(ctx, client, numActiveCollections, seed) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16, []byte) map[int]bool); ok { + r0 = rf(rpcParameters, numActiveCollections, seed) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(map[int]bool) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16, []byte) []*big.Int); ok { - r1 = rf(ctx, client, numActiveCollections, seed) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16, []byte) []*big.Int); ok { + r1 = rf(rpcParameters, numActiveCollections, seed) } else { if ret.Get(1) != nil { r1 = ret.Get(1).([]*big.Int) } } - if rf, ok := ret.Get(2).(func(context.Context, *ethclient.Client, uint16, []byte) error); ok { - r2 = rf(ctx, client, numActiveCollections, seed) + if rf, ok := ret.Get(2).(func(RPC.RPCParameters, uint16, []byte) error); ok { + r2 = rf(rpcParameters, numActiveCollections, seed) } else { r2 = ret.Error(2) } @@ -482,23 +556,23 @@ func (_m *Utils) GetAssignedCollections(ctx context.Context, client *ethclient.C return r0, r1, r2 } -// GetBlock provides a mock function with given fields: ctx, client, epoch -func (_m *Utils) GetBlock(ctx context.Context, client *ethclient.Client, epoch uint32) (bindings.StructsBlock, error) { - ret := _m.Called(ctx, client, epoch) +// GetBlock provides a mock function with given fields: rpcParameters, epoch +func (_m *Utils) GetBlock(rpcParameters RPC.RPCParameters, epoch uint32) (bindings.StructsBlock, error) { + ret := _m.Called(rpcParameters, epoch) var r0 bindings.StructsBlock var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (bindings.StructsBlock, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (bindings.StructsBlock, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) bindings.StructsBlock); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) bindings.StructsBlock); ok { + r0 = rf(rpcParameters, epoch) } else { r0 = ret.Get(0).(bindings.StructsBlock) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Error(1) } @@ -506,23 +580,23 @@ func (_m *Utils) GetBlock(ctx context.Context, client *ethclient.Client, epoch u return r0, r1 } -// GetBlockIndexToBeConfirmed provides a mock function with given fields: ctx, client -func (_m *Utils) GetBlockIndexToBeConfirmed(ctx context.Context, client *ethclient.Client) (int8, error) { - ret := _m.Called(ctx, client) +// GetBlockIndexToBeConfirmed provides a mock function with given fields: rpcParameters +func (_m *Utils) GetBlockIndexToBeConfirmed(rpcParameters RPC.RPCParameters) (int8, error) { + ret := _m.Called(rpcParameters) var r0 int8 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (int8, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (int8, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) int8); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) int8); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(int8) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -572,6 +646,30 @@ func (_m *Utils) GetBlockManagerWithOpts(client *ethclient.Client) (*bindings.Bl return r0, r1 } +// GetBountyLock provides a mock function with given fields: rpcParameters, bountyId +func (_m *Utils) GetBountyLock(rpcParameters RPC.RPCParameters, bountyId uint32) (types.BountyLock, error) { + ret := _m.Called(rpcParameters, bountyId) + + var r0 types.BountyLock + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (types.BountyLock, error)); ok { + return rf(rpcParameters, bountyId) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) types.BountyLock); ok { + r0 = rf(rpcParameters, bountyId) + } else { + r0 = ret.Get(0).(types.BountyLock) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, bountyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetBufferedState provides a mock function with given fields: header, stateBuffer, buffer func (_m *Utils) GetBufferedState(header *coretypes.Header, stateBuffer uint64, buffer int32) (int64, error) { ret := _m.Called(header, stateBuffer, buffer) @@ -596,23 +694,23 @@ func (_m *Utils) GetBufferedState(header *coretypes.Header, stateBuffer uint64, return r0, r1 } -// GetCollection provides a mock function with given fields: ctx, client, collectionId -func (_m *Utils) GetCollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (bindings.StructsCollection, error) { - ret := _m.Called(ctx, client, collectionId) +// GetCollection provides a mock function with given fields: rpcParameters, collectionId +func (_m *Utils) GetCollection(rpcParameters RPC.RPCParameters, collectionId uint16) (bindings.StructsCollection, error) { + ret := _m.Called(rpcParameters, collectionId) var r0 bindings.StructsCollection var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) (bindings.StructsCollection, error)); ok { - return rf(ctx, client, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (bindings.StructsCollection, error)); ok { + return rf(rpcParameters, collectionId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) bindings.StructsCollection); ok { - r0 = rf(ctx, client, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) bindings.StructsCollection); ok { + r0 = rf(rpcParameters, collectionId) } else { r0 = ret.Get(0).(bindings.StructsCollection) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16) error); ok { - r1 = rf(ctx, client, collectionId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, collectionId) } else { r1 = ret.Error(1) } @@ -620,23 +718,23 @@ func (_m *Utils) GetCollection(ctx context.Context, client *ethclient.Client, co return r0, r1 } -// GetCollectionIdFromIndex provides a mock function with given fields: ctx, client, medianIndex -func (_m *Utils) GetCollectionIdFromIndex(ctx context.Context, client *ethclient.Client, medianIndex uint16) (uint16, error) { - ret := _m.Called(ctx, client, medianIndex) +// GetCollectionIdFromIndex provides a mock function with given fields: rpcParameters, medianIndex +func (_m *Utils) GetCollectionIdFromIndex(rpcParameters RPC.RPCParameters, medianIndex uint16) (uint16, error) { + ret := _m.Called(rpcParameters, medianIndex) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) (uint16, error)); ok { - return rf(ctx, client, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (uint16, error)); ok { + return rf(rpcParameters, medianIndex) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) uint16); ok { - r0 = rf(ctx, client, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) uint16); ok { + r0 = rf(rpcParameters, medianIndex) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16) error); ok { - r1 = rf(ctx, client, medianIndex) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, medianIndex) } else { r1 = ret.Error(1) } @@ -644,23 +742,23 @@ func (_m *Utils) GetCollectionIdFromIndex(ctx context.Context, client *ethclient return r0, r1 } -// GetCollectionIdFromLeafId provides a mock function with given fields: ctx, client, leafId -func (_m *Utils) GetCollectionIdFromLeafId(ctx context.Context, client *ethclient.Client, leafId uint16) (uint16, error) { - ret := _m.Called(ctx, client, leafId) +// GetCollectionIdFromLeafId provides a mock function with given fields: rpcParameters, leafId +func (_m *Utils) GetCollectionIdFromLeafId(rpcParameters RPC.RPCParameters, leafId uint16) (uint16, error) { + ret := _m.Called(rpcParameters, leafId) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) (uint16, error)); ok { - return rf(ctx, client, leafId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (uint16, error)); ok { + return rf(rpcParameters, leafId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) uint16); ok { - r0 = rf(ctx, client, leafId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) uint16); ok { + r0 = rf(rpcParameters, leafId) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16) error); ok { - r1 = rf(ctx, client, leafId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, leafId) } else { r1 = ret.Error(1) } @@ -710,23 +808,23 @@ func (_m *Utils) GetCollectionManagerWithOpts(client *ethclient.Client) (*bindin return r0, r1 } -// GetCommitment provides a mock function with given fields: ctx, client, address -func (_m *Utils) GetCommitment(ctx context.Context, client *ethclient.Client, address string) (types.Commitment, error) { - ret := _m.Called(ctx, client, address) +// GetCommitment provides a mock function with given fields: rpcParameters, address +func (_m *Utils) GetCommitment(rpcParameters RPC.RPCParameters, address string) (types.Commitment, error) { + ret := _m.Called(rpcParameters, address) var r0 types.Commitment var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) (types.Commitment, error)); ok { - return rf(ctx, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) (types.Commitment, error)); ok { + return rf(rpcParameters, address) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) types.Commitment); ok { - r0 = rf(ctx, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) types.Commitment); ok { + r0 = rf(rpcParameters, address) } else { r0 = ret.Get(0).(types.Commitment) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, string) error); ok { - r1 = rf(ctx, client, address) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string) error); ok { + r1 = rf(rpcParameters, address) } else { r1 = ret.Error(1) } @@ -734,23 +832,23 @@ func (_m *Utils) GetCommitment(ctx context.Context, client *ethclient.Client, ad return r0, r1 } -// GetConfirmedBlocks provides a mock function with given fields: ctx, client, epoch -func (_m *Utils) GetConfirmedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (types.ConfirmedBlock, error) { - ret := _m.Called(ctx, client, epoch) +// GetConfirmedBlocks provides a mock function with given fields: rpcParameters, epoch +func (_m *Utils) GetConfirmedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (types.ConfirmedBlock, error) { + ret := _m.Called(rpcParameters, epoch) var r0 types.ConfirmedBlock var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (types.ConfirmedBlock, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (types.ConfirmedBlock, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) types.ConfirmedBlock); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) types.ConfirmedBlock); ok { + r0 = rf(rpcParameters, epoch) } else { r0 = ret.Get(0).(types.ConfirmedBlock) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Error(1) } @@ -812,23 +910,23 @@ func (_m *Utils) GetDataToCommitFromJobs(jobs []bindings.StructsJob, commitParam return r0, r1 } -// GetEpoch provides a mock function with given fields: ctx, client -func (_m *Utils) GetEpoch(ctx context.Context, client *ethclient.Client) (uint32, error) { - ret := _m.Called(ctx, client) +// GetEpoch provides a mock function with given fields: rpcParameters +func (_m *Utils) GetEpoch(rpcParameters RPC.RPCParameters) (uint32, error) { + ret := _m.Called(rpcParameters) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint32, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint32, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint32); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint32); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -836,23 +934,23 @@ func (_m *Utils) GetEpoch(ctx context.Context, client *ethclient.Client) (uint32 return r0, r1 } -// GetEpochLastCommitted provides a mock function with given fields: ctx, client, stakerId -func (_m *Utils) GetEpochLastCommitted(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - ret := _m.Called(ctx, client, stakerId) +// GetEpochLastCommitted provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) GetEpochLastCommitted(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + ret := _m.Called(rpcParameters, stakerId) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (uint32, error)); ok { - return rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (uint32, error)); ok { + return rf(rpcParameters, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) uint32); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) uint32); ok { + r0 = rf(rpcParameters, stakerId) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) } else { r1 = ret.Error(1) } @@ -860,23 +958,23 @@ func (_m *Utils) GetEpochLastCommitted(ctx context.Context, client *ethclient.Cl return r0, r1 } -// GetEpochLastProposed provides a mock function with given fields: ctx, client, stakerId -func (_m *Utils) GetEpochLastProposed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - ret := _m.Called(ctx, client, stakerId) +// GetEpochLastProposed provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) GetEpochLastProposed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + ret := _m.Called(rpcParameters, stakerId) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (uint32, error)); ok { - return rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (uint32, error)); ok { + return rf(rpcParameters, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) uint32); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) uint32); ok { + r0 = rf(rpcParameters, stakerId) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) } else { r1 = ret.Error(1) } @@ -884,23 +982,23 @@ func (_m *Utils) GetEpochLastProposed(ctx context.Context, client *ethclient.Cli return r0, r1 } -// GetEpochLastRevealed provides a mock function with given fields: ctx, client, stakerId -func (_m *Utils) GetEpochLastRevealed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - ret := _m.Called(ctx, client, stakerId) +// GetEpochLastRevealed provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) GetEpochLastRevealed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + ret := _m.Called(rpcParameters, stakerId) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (uint32, error)); ok { - return rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (uint32, error)); ok { + return rf(rpcParameters, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) uint32); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) uint32); ok { + r0 = rf(rpcParameters, stakerId) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) } else { r1 = ret.Error(1) } @@ -908,23 +1006,23 @@ func (_m *Utils) GetEpochLastRevealed(ctx context.Context, client *ethclient.Cli return r0, r1 } -// GetEpochLimitForUpdateCommission provides a mock function with given fields: ctx, client -func (_m *Utils) GetEpochLimitForUpdateCommission(ctx context.Context, client *ethclient.Client) (uint16, error) { - ret := _m.Called(ctx, client) +// GetEpochLimitForUpdateCommission provides a mock function with given fields: rpcParameters +func (_m *Utils) GetEpochLimitForUpdateCommission(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -932,25 +1030,25 @@ func (_m *Utils) GetEpochLimitForUpdateCommission(ctx context.Context, client *e return r0, r1 } -// GetInfluenceSnapshot provides a mock function with given fields: ctx, client, stakerId, epoch -func (_m *Utils) GetInfluenceSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) { - ret := _m.Called(ctx, client, stakerId, epoch) +// GetInfluenceSnapshot provides a mock function with given fields: rpcParameters, stakerId, epoch +func (_m *Utils) GetInfluenceSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) { + ret := _m.Called(rpcParameters, stakerId, epoch) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) (*big.Int, error)); ok { - return rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) (*big.Int, error)); ok { + return rf(rpcParameters, stakerId, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) *big.Int); ok { - r0 = rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) *big.Int); ok { + r0 = rf(rpcParameters, stakerId, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint32) error); ok { - r1 = rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint32) error); ok { + r1 = rf(rpcParameters, stakerId, epoch) } else { r1 = ret.Error(1) } @@ -958,25 +1056,25 @@ func (_m *Utils) GetInfluenceSnapshot(ctx context.Context, client *ethclient.Cli return r0, r1 } -// GetJobs provides a mock function with given fields: ctx, client -func (_m *Utils) GetJobs(ctx context.Context, client *ethclient.Client) ([]bindings.StructsJob, error) { - ret := _m.Called(ctx, client) +// GetJobs provides a mock function with given fields: rpcParameters +func (_m *Utils) GetJobs(rpcParameters RPC.RPCParameters) ([]bindings.StructsJob, error) { + ret := _m.Called(rpcParameters) var r0 []bindings.StructsJob var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) ([]bindings.StructsJob, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) ([]bindings.StructsJob, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) []bindings.StructsJob); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) []bindings.StructsJob); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]bindings.StructsJob) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -984,23 +1082,23 @@ func (_m *Utils) GetJobs(ctx context.Context, client *ethclient.Client) ([]bindi return r0, r1 } -// GetLeafIdOfACollection provides a mock function with given fields: ctx, client, collectionId -func (_m *Utils) GetLeafIdOfACollection(ctx context.Context, client *ethclient.Client, collectionId uint16) (uint16, error) { - ret := _m.Called(ctx, client, collectionId) +// GetLeafIdOfACollection provides a mock function with given fields: rpcParameters, collectionId +func (_m *Utils) GetLeafIdOfACollection(rpcParameters RPC.RPCParameters, collectionId uint16) (uint16, error) { + ret := _m.Called(rpcParameters, collectionId) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) (uint16, error)); ok { - return rf(ctx, client, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) (uint16, error)); ok { + return rf(rpcParameters, collectionId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint16) uint16); ok { - r0 = rf(ctx, client, collectionId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint16) uint16); ok { + r0 = rf(rpcParameters, collectionId) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint16) error); ok { - r1 = rf(ctx, client, collectionId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint16) error); ok { + r1 = rf(rpcParameters, collectionId) } else { r1 = ret.Error(1) } @@ -1008,23 +1106,23 @@ func (_m *Utils) GetLeafIdOfACollection(ctx context.Context, client *ethclient.C return r0, r1 } -// GetLock provides a mock function with given fields: ctx, client, address, stakerId, lockType -func (_m *Utils) GetLock(ctx context.Context, client *ethclient.Client, address string, stakerId uint32, lockType uint8) (types.Locks, error) { - ret := _m.Called(ctx, client, address, stakerId, lockType) +// GetLock provides a mock function with given fields: rpcParameters, address, stakerId, lockType +func (_m *Utils) GetLock(rpcParameters RPC.RPCParameters, address string, stakerId uint32, lockType uint8) (types.Locks, error) { + ret := _m.Called(rpcParameters, address, stakerId, lockType) var r0 types.Locks var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string, uint32, uint8) (types.Locks, error)); ok { - return rf(ctx, client, address, stakerId, lockType) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string, uint32, uint8) (types.Locks, error)); ok { + return rf(rpcParameters, address, stakerId, lockType) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string, uint32, uint8) types.Locks); ok { - r0 = rf(ctx, client, address, stakerId, lockType) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string, uint32, uint8) types.Locks); ok { + r0 = rf(rpcParameters, address, stakerId, lockType) } else { r0 = ret.Get(0).(types.Locks) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, string, uint32, uint8) error); ok { - r1 = rf(ctx, client, address, stakerId, lockType) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string, uint32, uint8) error); ok { + r1 = rf(rpcParameters, address, stakerId, lockType) } else { r1 = ret.Error(1) } @@ -1032,23 +1130,47 @@ func (_m *Utils) GetLock(ctx context.Context, client *ethclient.Client, address return r0, r1 } -// GetMaxAltBlocks provides a mock function with given fields: ctx, client -func (_m *Utils) GetMaxAltBlocks(ctx context.Context, client *ethclient.Client) (uint8, error) { - ret := _m.Called(ctx, client) +// GetMaturity provides a mock function with given fields: rpcParameters, age +func (_m *Utils) GetMaturity(rpcParameters RPC.RPCParameters, age uint32) (uint16, error) { + ret := _m.Called(rpcParameters, age) + + var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (uint16, error)); ok { + return rf(rpcParameters, age) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) uint16); ok { + r0 = rf(rpcParameters, age) + } else { + r0 = ret.Get(0).(uint16) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, age) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetMaxAltBlocks provides a mock function with given fields: rpcParameters +func (_m *Utils) GetMaxAltBlocks(rpcParameters RPC.RPCParameters) (uint8, error) { + ret := _m.Called(rpcParameters) var r0 uint8 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint8, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint8, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint8); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint8); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint8) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1056,23 +1178,23 @@ func (_m *Utils) GetMaxAltBlocks(ctx context.Context, client *ethclient.Client) return r0, r1 } -// GetMaxCommission provides a mock function with given fields: ctx, client -func (_m *Utils) GetMaxCommission(ctx context.Context, client *ethclient.Client) (uint8, error) { - ret := _m.Called(ctx, client) +// GetMaxCommission provides a mock function with given fields: rpcParameters +func (_m *Utils) GetMaxCommission(rpcParameters RPC.RPCParameters) (uint8, error) { + ret := _m.Called(rpcParameters) var r0 uint8 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint8, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint8, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint8); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint8); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint8) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1080,25 +1202,25 @@ func (_m *Utils) GetMaxCommission(ctx context.Context, client *ethclient.Client) return r0, r1 } -// GetMinSafeRazor provides a mock function with given fields: ctx, client -func (_m *Utils) GetMinSafeRazor(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - ret := _m.Called(ctx, client) +// GetMinSafeRazor provides a mock function with given fields: rpcParameters +func (_m *Utils) GetMinSafeRazor(rpcParameters RPC.RPCParameters) (*big.Int, error) { + ret := _m.Called(rpcParameters) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (*big.Int, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (*big.Int, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) *big.Int); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) *big.Int); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1106,25 +1228,49 @@ func (_m *Utils) GetMinSafeRazor(ctx context.Context, client *ethclient.Client) return r0, r1 } -// GetMinStakeAmount provides a mock function with given fields: ctx, client -func (_m *Utils) GetMinStakeAmount(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - ret := _m.Called(ctx, client) +// GetMinStakeAmount provides a mock function with given fields: rpcParameters +func (_m *Utils) GetMinStakeAmount(rpcParameters RPC.RPCParameters) (*big.Int, error) { + ret := _m.Called(rpcParameters) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (*big.Int, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (*big.Int, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) *big.Int); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) *big.Int); ok { + r0 = rf(rpcParameters) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetNumActiveCollections provides a mock function with given fields: rpcParameters +func (_m *Utils) GetNumActiveCollections(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) + + var r0 uint16 + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) + } else { + r0 = ret.Get(0).(uint16) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1132,23 +1278,23 @@ func (_m *Utils) GetMinStakeAmount(ctx context.Context, client *ethclient.Client return r0, r1 } -// GetNumActiveCollections provides a mock function with given fields: ctx, client -func (_m *Utils) GetNumActiveCollections(ctx context.Context, client *ethclient.Client) (uint16, error) { - ret := _m.Called(ctx, client) +// GetNumCollections provides a mock function with given fields: rpcParameters +func (_m *Utils) GetNumCollections(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1156,23 +1302,23 @@ func (_m *Utils) GetNumActiveCollections(ctx context.Context, client *ethclient. return r0, r1 } -// GetNumCollections provides a mock function with given fields: ctx, client -func (_m *Utils) GetNumCollections(ctx context.Context, client *ethclient.Client) (uint16, error) { - ret := _m.Called(ctx, client) +// GetNumJobs provides a mock function with given fields: rpcParameters +func (_m *Utils) GetNumJobs(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1180,23 +1326,23 @@ func (_m *Utils) GetNumCollections(ctx context.Context, client *ethclient.Client return r0, r1 } -// GetNumberOfProposedBlocks provides a mock function with given fields: ctx, client, epoch -func (_m *Utils) GetNumberOfProposedBlocks(ctx context.Context, client *ethclient.Client, epoch uint32) (uint8, error) { - ret := _m.Called(ctx, client, epoch) +// GetNumberOfProposedBlocks provides a mock function with given fields: rpcParameters, epoch +func (_m *Utils) GetNumberOfProposedBlocks(rpcParameters RPC.RPCParameters, epoch uint32) (uint8, error) { + ret := _m.Called(rpcParameters, epoch) var r0 uint8 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (uint8, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (uint8, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) uint8); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) uint8); ok { + r0 = rf(rpcParameters, epoch) } else { r0 = ret.Get(0).(uint8) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Error(1) } @@ -1204,23 +1350,23 @@ func (_m *Utils) GetNumberOfProposedBlocks(ctx context.Context, client *ethclien return r0, r1 } -// GetNumberOfStakers provides a mock function with given fields: ctx, client -func (_m *Utils) GetNumberOfStakers(ctx context.Context, client *ethclient.Client) (uint32, error) { - ret := _m.Called(ctx, client) +// GetNumberOfStakers provides a mock function with given fields: rpcParameters +func (_m *Utils) GetNumberOfStakers(rpcParameters RPC.RPCParameters) (uint32, error) { + ret := _m.Called(rpcParameters) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint32, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint32, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint32); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint32); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1242,23 +1388,23 @@ func (_m *Utils) GetOptions() bind.CallOpts { return r0 } -// GetProposedBlock provides a mock function with given fields: ctx, client, epoch, proposedBlockId -func (_m *Utils) GetProposedBlock(ctx context.Context, client *ethclient.Client, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) { - ret := _m.Called(ctx, client, epoch, proposedBlockId) +// GetProposedBlock provides a mock function with given fields: rpcParameters, epoch, proposedBlockId +func (_m *Utils) GetProposedBlock(rpcParameters RPC.RPCParameters, epoch uint32, proposedBlockId uint32) (bindings.StructsBlock, error) { + ret := _m.Called(rpcParameters, epoch, proposedBlockId) var r0 bindings.StructsBlock var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) (bindings.StructsBlock, error)); ok { - return rf(ctx, client, epoch, proposedBlockId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) (bindings.StructsBlock, error)); ok { + return rf(rpcParameters, epoch, proposedBlockId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) bindings.StructsBlock); ok { - r0 = rf(ctx, client, epoch, proposedBlockId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) bindings.StructsBlock); ok { + r0 = rf(rpcParameters, epoch, proposedBlockId) } else { r0 = ret.Get(0).(bindings.StructsBlock) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint32) error); ok { - r1 = rf(ctx, client, epoch, proposedBlockId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint32) error); ok { + r1 = rf(rpcParameters, epoch, proposedBlockId) } else { r1 = ret.Error(1) } @@ -1306,23 +1452,49 @@ func (_m *Utils) GetRogueRandomValue(value int) *big.Int { return r0 } -// GetSortedProposedBlockId provides a mock function with given fields: ctx, client, epoch, index -func (_m *Utils) GetSortedProposedBlockId(ctx context.Context, client *ethclient.Client, epoch uint32, index *big.Int) (uint32, error) { - ret := _m.Called(ctx, client, epoch, index) +// GetSaltFromBlockchain provides a mock function with given fields: rpcParameters +func (_m *Utils) GetSaltFromBlockchain(rpcParameters RPC.RPCParameters) ([32]byte, error) { + ret := _m.Called(rpcParameters) + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) ([32]byte, error)); ok { + return rf(rpcParameters) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) [32]byte); ok { + r0 = rf(rpcParameters) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetSortedProposedBlockId provides a mock function with given fields: rpcParameters, epoch, index +func (_m *Utils) GetSortedProposedBlockId(rpcParameters RPC.RPCParameters, epoch uint32, index *big.Int) (uint32, error) { + ret := _m.Called(rpcParameters, epoch, index) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, *big.Int) (uint32, error)); ok { - return rf(ctx, client, epoch, index) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, *big.Int) (uint32, error)); ok { + return rf(rpcParameters, epoch, index) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, *big.Int) uint32); ok { - r0 = rf(ctx, client, epoch, index) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, *big.Int) uint32); ok { + r0 = rf(rpcParameters, epoch, index) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, *big.Int) error); ok { - r1 = rf(ctx, client, epoch, index) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, *big.Int) error); ok { + r1 = rf(rpcParameters, epoch, index) } else { r1 = ret.Error(1) } @@ -1330,25 +1502,25 @@ func (_m *Utils) GetSortedProposedBlockId(ctx context.Context, client *ethclient return r0, r1 } -// GetSortedProposedBlockIds provides a mock function with given fields: ctx, client, epoch -func (_m *Utils) GetSortedProposedBlockIds(ctx context.Context, client *ethclient.Client, epoch uint32) ([]uint32, error) { - ret := _m.Called(ctx, client, epoch) +// GetSortedProposedBlockIds provides a mock function with given fields: rpcParameters, epoch +func (_m *Utils) GetSortedProposedBlockIds(rpcParameters RPC.RPCParameters, epoch uint32) ([]uint32, error) { + ret := _m.Called(rpcParameters, epoch) var r0 []uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) ([]uint32, error)); ok { - return rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) ([]uint32, error)); ok { + return rf(rpcParameters, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) []uint32); ok { - r0 = rf(ctx, client, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) []uint32); ok { + r0 = rf(rpcParameters, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]uint32) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, epoch) } else { r1 = ret.Error(1) } @@ -1356,25 +1528,25 @@ func (_m *Utils) GetSortedProposedBlockIds(ctx context.Context, client *ethclien return r0, r1 } -// GetStake provides a mock function with given fields: ctx, client, stakerId -func (_m *Utils) GetStake(ctx context.Context, client *ethclient.Client, stakerId uint32) (*big.Int, error) { - ret := _m.Called(ctx, client, stakerId) +// GetStake provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) GetStake(rpcParameters RPC.RPCParameters, stakerId uint32) (*big.Int, error) { + ret := _m.Called(rpcParameters, stakerId) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (*big.Int, error)); ok { - return rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (*big.Int, error)); ok { + return rf(rpcParameters, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) *big.Int); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) *big.Int); ok { + r0 = rf(rpcParameters, stakerId) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) } else { r1 = ret.Error(1) } @@ -1424,25 +1596,25 @@ func (_m *Utils) GetStakeManagerWithOpts(client *ethclient.Client) (*bindings.St return r0, r1 } -// GetStakeSnapshot provides a mock function with given fields: ctx, client, stakerId, epoch -func (_m *Utils) GetStakeSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) { - ret := _m.Called(ctx, client, stakerId, epoch) +// GetStakeSnapshot provides a mock function with given fields: rpcParameters, stakerId, epoch +func (_m *Utils) GetStakeSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) { + ret := _m.Called(rpcParameters, stakerId, epoch) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) (*big.Int, error)); ok { - return rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) (*big.Int, error)); ok { + return rf(rpcParameters, stakerId, epoch) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32) *big.Int); ok { - r0 = rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32) *big.Int); ok { + r0 = rf(rpcParameters, stakerId, epoch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint32) error); ok { - r1 = rf(ctx, client, stakerId, epoch) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint32) error); ok { + r1 = rf(rpcParameters, stakerId, epoch) } else { r1 = ret.Error(1) } @@ -1492,23 +1664,23 @@ func (_m *Utils) GetStakedTokenManagerWithOpts(client *ethclient.Client, tokenAd return r0, r1 } -// GetStaker provides a mock function with given fields: ctx, client, stakerId -func (_m *Utils) GetStaker(ctx context.Context, client *ethclient.Client, stakerId uint32) (bindings.StructsStaker, error) { - ret := _m.Called(ctx, client, stakerId) +// GetStaker provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) GetStaker(rpcParameters RPC.RPCParameters, stakerId uint32) (bindings.StructsStaker, error) { + ret := _m.Called(rpcParameters, stakerId) var r0 bindings.StructsStaker var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) (bindings.StructsStaker, error)); ok { - return rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (bindings.StructsStaker, error)); ok { + return rf(rpcParameters, stakerId) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32) bindings.StructsStaker); ok { - r0 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) bindings.StructsStaker); ok { + r0 = rf(rpcParameters, stakerId) } else { r0 = ret.Get(0).(bindings.StructsStaker) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32) error); ok { - r1 = rf(ctx, client, stakerId) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) } else { r1 = ret.Error(1) } @@ -1516,23 +1688,23 @@ func (_m *Utils) GetStaker(ctx context.Context, client *ethclient.Client, staker return r0, r1 } -// GetStakerId provides a mock function with given fields: ctx, client, address -func (_m *Utils) GetStakerId(ctx context.Context, client *ethclient.Client, address string) (uint32, error) { - ret := _m.Called(ctx, client, address) +// GetStakerId provides a mock function with given fields: rpcParameters, address +func (_m *Utils) GetStakerId(rpcParameters RPC.RPCParameters, address string) (uint32, error) { + ret := _m.Called(rpcParameters, address) var r0 uint32 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) (uint32, error)); ok { - return rf(ctx, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) (uint32, error)); ok { + return rf(rpcParameters, address) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, string) uint32); ok { - r0 = rf(ctx, client, address) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) uint32); ok { + r0 = rf(rpcParameters, address) } else { r0 = ret.Get(0).(uint32) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, string) error); ok { - r1 = rf(ctx, client, address) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, string) error); ok { + r1 = rf(rpcParameters, address) } else { r1 = ret.Error(1) } @@ -1540,25 +1712,25 @@ func (_m *Utils) GetStakerId(ctx context.Context, client *ethclient.Client, addr return r0, r1 } -// GetStakerSRZRBalance provides a mock function with given fields: ctx, client, staker -func (_m *Utils) GetStakerSRZRBalance(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker) (*big.Int, error) { - ret := _m.Called(ctx, client, staker) +// GetStakerSRZRBalance provides a mock function with given fields: rpcParameters, staker +func (_m *Utils) GetStakerSRZRBalance(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker) (*big.Int, error) { + ret := _m.Called(rpcParameters, staker) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, bindings.StructsStaker) (*big.Int, error)); ok { - return rf(ctx, client, staker) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, bindings.StructsStaker) (*big.Int, error)); ok { + return rf(rpcParameters, staker) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, bindings.StructsStaker) *big.Int); ok { - r0 = rf(ctx, client, staker) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, bindings.StructsStaker) *big.Int); ok { + r0 = rf(rpcParameters, staker) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, bindings.StructsStaker) error); ok { - r1 = rf(ctx, client, staker) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, bindings.StructsStaker) error); ok { + r1 = rf(rpcParameters, staker) } else { r1 = ret.Error(1) } @@ -1566,23 +1738,23 @@ func (_m *Utils) GetStakerSRZRBalance(ctx context.Context, client *ethclient.Cli return r0, r1 } -// GetStateBuffer provides a mock function with given fields: ctx, client -func (_m *Utils) GetStateBuffer(ctx context.Context, client *ethclient.Client) (uint64, error) { - ret := _m.Called(ctx, client) +// GetStateBuffer provides a mock function with given fields: rpcParameters +func (_m *Utils) GetStateBuffer(rpcParameters RPC.RPCParameters) (uint64, error) { + ret := _m.Called(rpcParameters) var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint64, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint64, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint64); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint64); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1606,25 +1778,25 @@ func (_m *Utils) GetTokenManager(client *ethclient.Client) *bindings.RAZOR { return r0 } -// GetTotalInfluenceRevealed provides a mock function with given fields: ctx, client, epoch, medianIndex -func (_m *Utils) GetTotalInfluenceRevealed(ctx context.Context, client *ethclient.Client, epoch uint32, medianIndex uint16) (*big.Int, error) { - ret := _m.Called(ctx, client, epoch, medianIndex) +// GetTotalInfluenceRevealed provides a mock function with given fields: rpcParameters, epoch, medianIndex +func (_m *Utils) GetTotalInfluenceRevealed(rpcParameters RPC.RPCParameters, epoch uint32, medianIndex uint16) (*big.Int, error) { + ret := _m.Called(rpcParameters, epoch, medianIndex) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint16) (*big.Int, error)); ok { - return rf(ctx, client, epoch, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint16) (*big.Int, error)); ok { + return rf(rpcParameters, epoch, medianIndex) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint16) *big.Int); ok { - r0 = rf(ctx, client, epoch, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint16) *big.Int); ok { + r0 = rf(rpcParameters, epoch, medianIndex) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint16) error); ok { - r1 = rf(ctx, client, epoch, medianIndex) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint16) error); ok { + r1 = rf(rpcParameters, epoch, medianIndex) } else { r1 = ret.Error(1) } @@ -1632,13 +1804,13 @@ func (_m *Utils) GetTotalInfluenceRevealed(ctx context.Context, client *ethclien return r0, r1 } -// GetTxnOpts provides a mock function with given fields: ctx, transactionData -func (_m *Utils) GetTxnOpts(ctx context.Context, transactionData types.TransactionOptions) *bind.TransactOpts { - ret := _m.Called(ctx, transactionData) +// GetTxnOpts provides a mock function with given fields: rpcParameters, transactionData +func (_m *Utils) GetTxnOpts(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions) *bind.TransactOpts { + ret := _m.Called(rpcParameters, transactionData) var r0 *bind.TransactOpts - if rf, ok := ret.Get(0).(func(context.Context, types.TransactionOptions) *bind.TransactOpts); ok { - r0 = rf(ctx, transactionData) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, types.TransactionOptions) *bind.TransactOpts); ok { + r0 = rf(rpcParameters, transactionData) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*bind.TransactOpts) @@ -1714,25 +1886,25 @@ func (_m *Utils) GetVoteManagerWithOpts(client *ethclient.Client) (*bindings.Vot return r0, r1 } -// GetVoteValue provides a mock function with given fields: ctx, client, epoch, stakerId, medianIndex -func (_m *Utils) GetVoteValue(ctx context.Context, client *ethclient.Client, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) { - ret := _m.Called(ctx, client, epoch, stakerId, medianIndex) +// GetVoteValue provides a mock function with given fields: rpcParameters, epoch, stakerId, medianIndex +func (_m *Utils) GetVoteValue(rpcParameters RPC.RPCParameters, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) { + ret := _m.Called(rpcParameters, epoch, stakerId, medianIndex) var r0 *big.Int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32, uint16) (*big.Int, error)); ok { - return rf(ctx, client, epoch, stakerId, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32, uint16) (*big.Int, error)); ok { + return rf(rpcParameters, epoch, stakerId, medianIndex) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client, uint32, uint32, uint16) *big.Int); ok { - r0 = rf(ctx, client, epoch, stakerId, medianIndex) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32, uint32, uint16) *big.Int); ok { + r0 = rf(rpcParameters, epoch, stakerId, medianIndex) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*big.Int) } } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client, uint32, uint32, uint16) error); ok { - r1 = rf(ctx, client, epoch, stakerId, medianIndex) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32, uint32, uint16) error); ok { + r1 = rf(rpcParameters, epoch, stakerId, medianIndex) } else { r1 = ret.Error(1) } @@ -1740,23 +1912,23 @@ func (_m *Utils) GetVoteValue(ctx context.Context, client *ethclient.Client, epo return r0, r1 } -// GetWithdrawInitiationPeriod provides a mock function with given fields: ctx, client -func (_m *Utils) GetWithdrawInitiationPeriod(ctx context.Context, client *ethclient.Client) (uint16, error) { - ret := _m.Called(ctx, client) +// GetWithdrawInitiationPeriod provides a mock function with given fields: rpcParameters +func (_m *Utils) GetWithdrawInitiationPeriod(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1764,25 +1936,25 @@ func (_m *Utils) GetWithdrawInitiationPeriod(ctx context.Context, client *ethcli return r0, r1 } -// HandleOfficialJobsFromJSONFile provides a mock function with given fields: client, collection, dataString, commitParams -func (_m *Utils) HandleOfficialJobsFromJSONFile(client *ethclient.Client, collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) { - ret := _m.Called(client, collection, dataString, commitParams) +// HandleOfficialJobsFromJSONFile provides a mock function with given fields: collection, dataString, commitParams +func (_m *Utils) HandleOfficialJobsFromJSONFile(collection bindings.StructsCollection, dataString string, commitParams *types.CommitParams) ([]bindings.StructsJob, []uint16) { + ret := _m.Called(collection, dataString, commitParams) var r0 []bindings.StructsJob var r1 []uint16 - if rf, ok := ret.Get(0).(func(*ethclient.Client, bindings.StructsCollection, string, *types.CommitParams) ([]bindings.StructsJob, []uint16)); ok { - return rf(client, collection, dataString, commitParams) + if rf, ok := ret.Get(0).(func(bindings.StructsCollection, string, *types.CommitParams) ([]bindings.StructsJob, []uint16)); ok { + return rf(collection, dataString, commitParams) } - if rf, ok := ret.Get(0).(func(*ethclient.Client, bindings.StructsCollection, string, *types.CommitParams) []bindings.StructsJob); ok { - r0 = rf(client, collection, dataString, commitParams) + if rf, ok := ret.Get(0).(func(bindings.StructsCollection, string, *types.CommitParams) []bindings.StructsJob); ok { + r0 = rf(collection, dataString, commitParams) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]bindings.StructsJob) } } - if rf, ok := ret.Get(1).(func(*ethclient.Client, bindings.StructsCollection, string, *types.CommitParams) []uint16); ok { - r1 = rf(client, collection, dataString, commitParams) + if rf, ok := ret.Get(1).(func(bindings.StructsCollection, string, *types.CommitParams) []uint16); ok { + r1 = rf(collection, dataString, commitParams) } else { if ret.Get(1) != nil { r1 = ret.Get(1).([]uint16) @@ -1906,23 +2078,47 @@ func (_m *Utils) SecondsToReadableTime(input int) string { return r0 } -// ToAssign provides a mock function with given fields: ctx, client -func (_m *Utils) ToAssign(ctx context.Context, client *ethclient.Client) (uint16, error) { - ret := _m.Called(ctx, client) +// StakerInfo provides a mock function with given fields: rpcParameters, stakerId +func (_m *Utils) StakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) (types.Staker, error) { + ret := _m.Called(rpcParameters, stakerId) + + var r0 types.Staker + var r1 error + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) (types.Staker, error)); ok { + return rf(rpcParameters, stakerId) + } + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, uint32) types.Staker); ok { + r0 = rf(rpcParameters, stakerId) + } else { + r0 = ret.Get(0).(types.Staker) + } + + if rf, ok := ret.Get(1).(func(RPC.RPCParameters, uint32) error); ok { + r1 = rf(rpcParameters, stakerId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ToAssign provides a mock function with given fields: rpcParameters +func (_m *Utils) ToAssign(rpcParameters RPC.RPCParameters) (uint16, error) { + ret := _m.Called(rpcParameters) var r0 uint16 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) (uint16, error)); ok { - return rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) (uint16, error)); ok { + return rf(rpcParameters) } - if rf, ok := ret.Get(0).(func(context.Context, *ethclient.Client) uint16); ok { - r0 = rf(ctx, client) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters) uint16); ok { + r0 = rf(rpcParameters) } else { r0 = ret.Get(0).(uint16) } - if rf, ok := ret.Get(1).(func(context.Context, *ethclient.Client) error); ok { - r1 = rf(ctx, client) + if rf, ok := ret.Get(1).(func(RPC.RPCParameters) error); ok { + r1 = rf(rpcParameters) } else { r1 = ret.Error(1) } @@ -1930,13 +2126,13 @@ func (_m *Utils) ToAssign(ctx context.Context, client *ethclient.Client) (uint16 return r0, r1 } -// WaitForBlockCompletion provides a mock function with given fields: client, hashToRead -func (_m *Utils) WaitForBlockCompletion(client *ethclient.Client, hashToRead string) error { - ret := _m.Called(client, hashToRead) +// WaitForBlockCompletion provides a mock function with given fields: rpcManager, hashToRead +func (_m *Utils) WaitForBlockCompletion(rpcManager RPC.RPCParameters, hashToRead string) error { + ret := _m.Called(rpcManager, hashToRead) var r0 error - if rf, ok := ret.Get(0).(func(*ethclient.Client, string) error); ok { - r0 = rf(client, hashToRead) + if rf, ok := ret.Get(0).(func(RPC.RPCParameters, string) error); ok { + r0 = rf(rpcManager, hashToRead) } else { r0 = ret.Error(0) } diff --git a/utils/options.go b/utils/options.go index f7fe7536..b666a45b 100644 --- a/utils/options.go +++ b/utils/options.go @@ -3,13 +3,12 @@ package utils import ( "context" "errors" + "razor/RPC" "razor/core/types" "strings" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/ethclient" - "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -25,7 +24,7 @@ func (*UtilsStruct) GetOptions() bind.CallOpts { } } -func (*UtilsStruct) GetTxnOpts(ctx context.Context, transactionData types.TransactionOptions) *bind.TransactOpts { +func (*UtilsStruct) GetTxnOpts(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions) *bind.TransactOpts { log.Debug("Getting transaction options...") account := transactionData.Account if account.AccountManager == nil { @@ -34,21 +33,21 @@ func (*UtilsStruct) GetTxnOpts(ctx context.Context, transactionData types.Transa privateKey, err := account.AccountManager.GetPrivateKey(account.Address, account.Password) CheckError("Error in fetching private key: ", err) - nonce, err := ClientInterface.GetNonceAtWithRetry(ctx, transactionData.Client, common.HexToAddress(account.Address)) + nonce, err := ClientInterface.GetNonceAtWithRetry(rpcParameters, common.HexToAddress(account.Address)) CheckError("Error in fetching nonce: ", err) - gasPrice := GasInterface.GetGasPrice(ctx, transactionData.Client, transactionData.Config) + gasPrice := GasInterface.GetGasPrice(rpcParameters, transactionData.Config) txnOpts, err := BindInterface.NewKeyedTransactorWithChainID(privateKey, transactionData.ChainId) CheckError("Error in getting transactor: ", err) txnOpts.Nonce = big.NewInt(int64(nonce)) txnOpts.GasPrice = gasPrice txnOpts.Value = transactionData.EtherValue - gasLimit, err := GasInterface.GetGasLimit(ctx, transactionData, txnOpts) + gasLimit, err := GasInterface.GetGasLimit(rpcParameters, transactionData, txnOpts) if err != nil { errString := err.Error() if ContainsStringFromArray(errString, []string{"500", "501", "502", "503", "504"}) || errString == errors.New("intrinsic gas too low").Error() { - latestBlock, err := ClientInterface.GetLatestBlockWithRetry(ctx, transactionData.Client) + latestBlock, err := ClientInterface.GetLatestBlockWithRetry(rpcParameters) CheckError("Error in fetching block: ", err) txnOpts.GasLimit = latestBlock.GasLimit @@ -63,7 +62,7 @@ func (*UtilsStruct) GetTxnOpts(ctx context.Context, transactionData types.Transa return txnOpts } -func (*GasStruct) GetGasPrice(ctx context.Context, client *ethclient.Client, config types.Configurations) *big.Int { +func (*GasStruct) GetGasPrice(rpcParameters RPC.RPCParameters, config types.Configurations) *big.Int { var gas *big.Int if config.GasPrice != 0 { gas = big.NewInt(1).Mul(big.NewInt(int64(config.GasPrice)), big.NewInt(1e9)) @@ -71,7 +70,7 @@ func (*GasStruct) GetGasPrice(ctx context.Context, client *ethclient.Client, con gas = big.NewInt(0) } var err error - suggestedGasPrice, err := ClientInterface.SuggestGasPriceWithRetry(ctx, client) + suggestedGasPrice, err := ClientInterface.SuggestGasPriceWithRetry(rpcParameters) if err != nil { log.Error(err) return UtilsInterface.MultiplyFloatAndBigInt(gas, float64(config.GasMultiplier)) @@ -86,7 +85,7 @@ func (*GasStruct) GetGasPrice(ctx context.Context, client *ethclient.Client, con return gasPrice } -func (*GasStruct) GetGasLimit(ctx context.Context, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) { +func (*GasStruct) GetGasLimit(rpcParameters RPC.RPCParameters, transactionData types.TransactionOptions, txnOpts *bind.TransactOpts) (uint64, error) { if transactionData.MethodName == "" { return 0, nil } @@ -110,14 +109,14 @@ func (*GasStruct) GetGasLimit(ctx context.Context, transactionData types.Transac } var gasLimit uint64 if transactionData.MethodName == "reveal" { - gasLimit, err = getGasLimitForReveal(ctx, transactionData.Client) + gasLimit, err = getGasLimitForReveal(rpcParameters) if err != nil { log.Error("GetGasLimit: Error in getting gasLimit for reveal transaction: ", err) return transactionData.Config.GasLimitOverride, err } log.Debug("Calculated gas limit for reveal: ", gasLimit) } else { - gasLimit, err = ClientInterface.EstimateGasWithRetry(ctx, transactionData.Client, msg) + gasLimit, err = ClientInterface.EstimateGasWithRetry(rpcParameters, msg) if err != nil { log.Error("GetGasLimit: Error in getting gasLimit: ", err) //If estimateGas throws an error for a transaction than gasLimit should be picked up from the config @@ -126,17 +125,17 @@ func (*GasStruct) GetGasLimit(ctx context.Context, transactionData types.Transac } log.Debug("Estimated Gas: ", gasLimit) } - return GasInterface.IncreaseGasLimitValue(ctx, transactionData.Client, gasLimit, transactionData.Config.GasLimitMultiplier) + return GasInterface.IncreaseGasLimitValue(rpcParameters, gasLimit, transactionData.Config.GasLimitMultiplier) } -func (*GasStruct) IncreaseGasLimitValue(ctx context.Context, client *ethclient.Client, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) { +func (*GasStruct) IncreaseGasLimitValue(rpcParameters RPC.RPCParameters, gasLimit uint64, gasLimitMultiplier float32) (uint64, error) { if gasLimit == 0 || gasLimitMultiplier <= 0 { return gasLimit, nil } gasLimitIncremented := float64(gasLimitMultiplier) * float64(gasLimit) gasLimit = uint64(gasLimitIncremented) - latestBlock, err := ClientInterface.GetLatestBlockWithRetry(ctx, client) + latestBlock, err := ClientInterface.GetLatestBlockWithRetry(rpcParameters) if err != nil { log.Error("Error in fetching block: ", err) return 0, err @@ -149,8 +148,8 @@ func (*GasStruct) IncreaseGasLimitValue(ctx context.Context, client *ethclient.C return gasLimit, nil } -func getGasLimitForReveal(ctx context.Context, client *ethclient.Client) (uint64, error) { - toAssign, err := UtilsInterface.ToAssign(ctx, client) +func getGasLimitForReveal(rpcParameters RPC.RPCParameters) (uint64, error) { + toAssign, err := UtilsInterface.ToAssign(rpcParameters) if err != nil { return 0, err } diff --git a/utils/stake.go b/utils/stake.go index c11a55a2..06244a77 100644 --- a/utils/stake.go +++ b/utils/stake.go @@ -1,8 +1,8 @@ package utils import ( - "context" "math/big" + "razor/RPC" "razor/core/types" "razor/pkg/bindings" @@ -15,16 +15,16 @@ func (*UtilsStruct) GetStakeManagerWithOpts(client *ethclient.Client) (*bindings return UtilsInterface.GetStakeManager(client), UtilsInterface.GetOptions() } -func (*UtilsStruct) GetStakerId(ctx context.Context, client *ethclient.Client, address string) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "GetStakerId", client, common.HexToAddress(address)) +func (*UtilsStruct) GetStakerId(rpcParameters RPC.RPCParameters, address string) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetStakerId", common.HexToAddress(address)) if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) GetStake(ctx context.Context, client *ethclient.Client, stakerId uint32) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "GetStaker", client, stakerId) +func (*UtilsStruct) GetStake(rpcParameters RPC.RPCParameters, stakerId uint32) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetStaker", stakerId) if err != nil { return nil, err } @@ -32,62 +32,86 @@ func (*UtilsStruct) GetStake(ctx context.Context, client *ethclient.Client, stak return staker.Stake, nil } -func (*UtilsStruct) GetStaker(ctx context.Context, client *ethclient.Client, stakerId uint32) (bindings.StructsStaker, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "GetStaker", client, stakerId) +func (*UtilsStruct) GetStaker(rpcParameters RPC.RPCParameters, stakerId uint32) (bindings.StructsStaker, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetStaker", stakerId) if err != nil { return bindings.StructsStaker{}, err } return returnedValues[0].Interface().(bindings.StructsStaker), nil } -func (*UtilsStruct) GetNumberOfStakers(ctx context.Context, client *ethclient.Client) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "GetNumStakers", client) +func (*UtilsStruct) GetNumberOfStakers(rpcParameters RPC.RPCParameters) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetNumStakers") if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) GetLock(ctx context.Context, client *ethclient.Client, address string, stakerId uint32, lockType uint8) (types.Locks, error) { - staker, err := UtilsInterface.GetStaker(ctx, client, stakerId) +func (*UtilsStruct) GetLock(rpcParameters RPC.RPCParameters, address string, stakerId uint32, lockType uint8) (types.Locks, error) { + staker, err := UtilsInterface.GetStaker(rpcParameters, stakerId) if err != nil { return types.Locks{}, err } - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "Locks", client, common.HexToAddress(address), staker.TokenAddress, lockType) + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "Locks", common.HexToAddress(address), staker.TokenAddress, lockType) if err != nil { return types.Locks{}, err } return returnedValues[0].Interface().(types.Locks), nil } -func (*UtilsStruct) GetWithdrawInitiationPeriod(ctx context.Context, client *ethclient.Client) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "WithdrawInitiationPeriod", client) +func (*UtilsStruct) GetWithdrawInitiationPeriod(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "WithdrawInitiationPeriod") if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetMaxCommission(ctx context.Context, client *ethclient.Client) (uint8, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "MaxCommission", client) +func (*UtilsStruct) GetMaxCommission(rpcParameters RPC.RPCParameters) (uint8, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "MaxCommission") if err != nil { return 0, err } return returnedValues[0].Interface().(uint8), nil } -func (*UtilsStruct) GetEpochLimitForUpdateCommission(ctx context.Context, client *ethclient.Client) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "EpochLimitForUpdateCommission", client) +func (*UtilsStruct) GetEpochLimitForUpdateCommission(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "EpochLimitForUpdateCommission") if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } -func (*UtilsStruct) GetMinSafeRazor(ctx context.Context, client *ethclient.Client) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakeManagerInterface, "MinSafeRazor", client) +func (*UtilsStruct) GetMinSafeRazor(rpcParameters RPC.RPCParameters) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "MinSafeRazor") if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } + +func (*UtilsStruct) StakerInfo(rpcParameters RPC.RPCParameters, stakerId uint32) (types.Staker, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "StakerInfo", stakerId) + if err != nil { + return types.Staker{}, err + } + return returnedValues[0].Interface().(types.Staker), nil +} + +func (*UtilsStruct) GetMaturity(rpcParameters RPC.RPCParameters, age uint32) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetMaturity", age) + if err != nil { + return 0, err + } + return returnedValues[0].Interface().(uint16), nil +} + +func (*UtilsStruct) GetBountyLock(rpcParameters RPC.RPCParameters, bountyId uint32) (types.BountyLock, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakeManagerInterface, "GetBountyLock", bountyId) + if err != nil { + return types.BountyLock{}, err + } + return returnedValues[0].Interface().(types.BountyLock), nil +} diff --git a/utils/stakedToken.go b/utils/stakedToken.go index dabdab28..f37f42a8 100644 --- a/utils/stakedToken.go +++ b/utils/stakedToken.go @@ -1,11 +1,11 @@ package utils import ( - "context" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "math/big" + "razor/RPC" "razor/pkg/bindings" ) @@ -13,8 +13,8 @@ func (*UtilsStruct) GetStakedTokenManagerWithOpts(client *ethclient.Client, toke return UtilsInterface.GetStakedToken(client, tokenAddress), UtilsInterface.GetOptions() } -func (*UtilsStruct) GetStakerSRZRBalance(ctx context.Context, client *ethclient.Client, staker bindings.StructsStaker) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, StakedTokenInterface, "BalanceOf", client, staker.TokenAddress, staker.Address) +func (*UtilsStruct) GetStakerSRZRBalance(rpcParameters RPC.RPCParameters, staker bindings.StructsStaker) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, StakedTokenInterface, "BalanceOf", staker.TokenAddress, staker.Address) if err != nil { log.Error("Error in getting sRZRBalance: ", err) return nil, err diff --git a/utils/struct-utils.go b/utils/struct-utils.go index 216e8511..f78f2328 100644 --- a/utils/struct-utils.go +++ b/utils/struct-utils.go @@ -9,12 +9,13 @@ import ( "io/fs" "math/big" "os" - "razor/client" + "razor/RPC" "razor/core" coretypes "razor/core/types" "razor/path" "razor/pkg/bindings" "reflect" + "strings" "time" "github.com/avast/retry-go" @@ -110,30 +111,37 @@ func CheckIfAnyError(result []reflect.Value) error { return nil } -func InvokeFunctionWithRetryAttempts(ctx context.Context, interfaceName interface{}, methodName string, args ...interface{}) ([]reflect.Value, error) { +func InvokeFunctionWithRetryAttempts(rpcParameters RPC.RPCParameters, interfaceName interface{}, methodName string, args ...interface{}) ([]reflect.Value, error) { var returnedValues []reflect.Value var err error var contextError bool - inputs := make([]reflect.Value, len(args)) - for i := range args { - inputs[i] = reflect.ValueOf(args[i]) + + // Ensure inputs has space for the client and any additional arguments + inputs := make([]reflect.Value, len(args)+1) + + // Always use the current best client for each retry + client, err := rpcParameters.RPCManager.GetBestRPCClient() + if err != nil { + log.Errorf("Failed to get current best client: %v", err) + return returnedValues, err } - alternateProvider := client.GetAlternateProvider() - switchToAlternateClient := client.GetSwitchToAlternateClientStatus() - if switchToAlternateClient && alternateProvider != "" { - // Changing client argument to alternate client - log.Debug("Making this RPC call using alternate RPC provider!") - inputs = client.ReplaceClientWithAlternateClient(inputs) + + // Set the client as the first argument + inputs[0] = reflect.ValueOf(client) + // Add the rest of the args to inputs starting from index 1 + for i := 0; i < len(args); i++ { + inputs[i+1] = reflect.ValueOf(args[i]) } + err = retry.Do( func() error { // Check if the context has been cancelled or timed out select { - case <-ctx.Done(): + case <-rpcParameters.Ctx.Done(): // If context is done, return the context error timeout log.Debugf("Context timed out for method: %s", methodName) contextError = true - return retry.Unrecoverable(ctx.Err()) + return retry.Unrecoverable(rpcParameters.Ctx.Err()) default: // Proceed with the RPC call returnedValues = reflect.ValueOf(interfaceName).MethodByName(methodName).Call(inputs) @@ -148,20 +156,61 @@ func InvokeFunctionWithRetryAttempts(ctx context.Context, interfaceName interfac }, RetryInterface.RetryAttempts(core.MaxRetries), retry.Delay(time.Second*time.Duration(core.RetryDelayDuration)), retry.DelayType(retry.FixedDelay)) if err != nil { if contextError { - // Skip the alternate client switch when the error is context-related - log.Warnf("Skipping alternate client switch due to context error: %v", err) + // If context error, we don't switch the client + log.Warnf("Skipping switching to the next best client due to context error: %v", err) return returnedValues, err } - if !switchToAlternateClient && alternateProvider != "" { + + // Only switch to the next best client if the error is identified as an RPC error + if isRPCError(err) { log.Errorf("%v error after retries: %v", methodName, err) - log.Info("Switching RPC to alternate RPC") - client.SetSwitchToAlternateClientStatus(true) - go client.StartTimerForAlternateClient(core.SwitchClientDuration) + log.Info("Attempting to switch to a new best RPC endpoint...") + + // Attempt to switch to the next best client + switchErr := rpcParameters.RPCManager.SwitchToNextBestRPCClient() + if switchErr != nil { + log.Errorf("Failed to switch to the next best client: %v", switchErr) + return returnedValues, switchErr + } } } return returnedValues, err } +func isRPCError(err error) bool { + // Check for common RPC error patterns + if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) { + return true + } + + // Add other checks based on specific RPC errors (timeouts, connection issues, etc.) + if strings.Contains(err.Error(), "connection refused") || + strings.Contains(err.Error(), "connection reset by peer") || + strings.Contains(err.Error(), "EOF") || + strings.Contains(err.Error(), "dial") || + strings.Contains(err.Error(), "no such host") || + strings.Contains(err.Error(), "i/o timeout") { + return true + } + + // Check for HTTP 500–504 errors + if strings.Contains(err.Error(), "500") || + strings.Contains(err.Error(), "501") || + strings.Contains(err.Error(), "502") || + strings.Contains(err.Error(), "503") || + strings.Contains(err.Error(), "504") { + return true + } + + // Check for the custom RPC timeout error + if strings.Contains(err.Error(), "RPC timeout error") { + return true + } + + // If it's not an RPC error, return false + return false +} + func (b BlockManagerStruct) GetBlockIndexToBeConfirmed(client *ethclient.Client) (int8, error) { blockManager, opts := UtilsInterface.GetBlockManagerWithOpts(client) returnedValues := InvokeFunctionWithTimeout(blockManager, "BlockIndexToBeConfirmed", &opts) @@ -357,6 +406,22 @@ func (b BlockManagerStruct) GetConfirmedBlocks(client *ethclient.Client, epoch u }), nil } +func (b BlockManagerStruct) Disputes(client *ethclient.Client, epoch uint32, address common.Address) (coretypes.DisputesStruct, error) { + blockManager, opts := UtilsInterface.GetBlockManagerWithOpts(client) + returnedValues := InvokeFunctionWithTimeout(blockManager, "Disputes", &opts, epoch, address) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return coretypes.DisputesStruct{}, returnedError + } + disputesMapping := returnedValues[0].Interface().(struct { + LeafId uint16 + LastVisitedValue *big.Int + AccWeight *big.Int + Median *big.Int + }) + return disputesMapping, nil +} + func (s StakeManagerStruct) GetStakerId(client *ethclient.Client, address common.Address) (uint32, error) { stakeManager, opts := UtilsInterface.GetStakeManagerWithOpts(client) returnedValues := InvokeFunctionWithTimeout(stakeManager, "GetStakerId", &opts, address) @@ -431,6 +496,55 @@ func (s StakeManagerStruct) GetStaker(client *ethclient.Client, stakerId uint32) return returnedValues[0].Interface().(bindings.StructsStaker), nil } +func (s StakeManagerStruct) StakerInfo(client *ethclient.Client, stakerId uint32) (coretypes.Staker, error) { + stakeManager, opts := UtilsInterface.GetStakeManagerWithOpts(client) + returnedValues := InvokeFunctionWithTimeout(stakeManager, "Stakers", &opts, stakerId) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return coretypes.Staker{}, returnedError + } + staker := returnedValues[0].Interface().(struct { + AcceptDelegation bool + IsSlashed bool + Commission uint8 + Id uint32 + Age uint32 + Address common.Address + TokenAddress common.Address + EpochFirstStakedOrLastPenalized uint32 + EpochCommissionLastUpdated uint32 + Stake *big.Int + StakerReward *big.Int + }) + return staker, nil +} + +func (s StakeManagerStruct) GetMaturity(client *ethclient.Client, age uint32) (uint16, error) { + stakeManager, opts := UtilsInterface.GetStakeManagerWithOpts(client) + index := age / 10000 + returnedValues := InvokeFunctionWithTimeout(stakeManager, "Maturities", opts, big.NewInt(int64(index))) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return 0, returnedError + } + return returnedValues[0].Interface().(uint16), nil +} + +func (s StakeManagerStruct) GetBountyLock(client *ethclient.Client, bountyId uint32) (coretypes.BountyLock, error) { + stakeManager, opts := UtilsInterface.GetStakeManagerWithOpts(client) + returnedValues := InvokeFunctionWithTimeout(stakeManager, "BountyLocks", &opts, bountyId) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return coretypes.BountyLock{}, returnedError + } + bountyLock := returnedValues[0].Interface().(struct { + RedeemAfter uint32 + BountyHunter common.Address + Amount *big.Int + }) + return bountyLock, nil +} + func (a AssetManagerStruct) GetNumCollections(client *ethclient.Client) (uint16, error) { collectionManager, opts := UtilsInterface.GetCollectionManagerWithOpts(client) returnedValues := InvokeFunctionWithTimeout(collectionManager, "GetNumCollections", &opts) @@ -461,6 +575,16 @@ func (a AssetManagerStruct) GetActiveCollections(client *ethclient.Client) ([]ui return returnedValues[0].Interface().([]uint16), nil } +func (a AssetManagerStruct) GetActiveStatus(client *ethclient.Client, id uint16) (bool, error) { + collectionManager, opts := UtilsInterface.GetCollectionManagerWithOpts(client) + returnedValues := InvokeFunctionWithTimeout(collectionManager, "GetCollectionStatus", &opts, id) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return false, returnedError + } + return returnedValues[0].Interface().(bool), nil +} + func (a AssetManagerStruct) Jobs(client *ethclient.Client, id uint16) (bindings.StructsJob, error) { collectionManager, opts := UtilsInterface.GetCollectionManagerWithOpts(client) returnedValues := InvokeFunctionWithTimeout(collectionManager, "Jobs", &opts, id) @@ -692,8 +816,22 @@ func (c ClientStruct) FilterLogs(client *ethclient.Client, ctx context.Context, return returnedValues[0].Interface().([]types.Log), nil } -func (c CoinStruct) BalanceOf(erc20Contract *bindings.RAZOR, opts *bind.CallOpts, account common.Address) (*big.Int, error) { - returnedValues := InvokeFunctionWithTimeout(erc20Contract, "BalanceOf", opts, account) +func (c CoinStruct) BalanceOf(client *ethclient.Client, account common.Address) (*big.Int, error) { + tokenManager := UtilsInterface.GetTokenManager(client) + opts := UtilsInterface.GetOptions() + returnedValues := InvokeFunctionWithTimeout(tokenManager, "BalanceOf", &opts, account) + returnedError := CheckIfAnyError(returnedValues) + if returnedError != nil { + return nil, returnedError + } + return returnedValues[0].Interface().(*big.Int), nil +} + +//This function is used to check the allowance of staker +func (c CoinStruct) Allowance(client *ethclient.Client, owner common.Address, spender common.Address) (*big.Int, error) { + tokenManager := UtilsInterface.GetTokenManager(client) + opts := UtilsInterface.GetOptions() + returnedValues := InvokeFunctionWithTimeout(tokenManager, "Allowance", &opts, owner, spender) returnedError := CheckIfAnyError(returnedValues) if returnedError != nil { return nil, returnedError diff --git a/utils/vote.go b/utils/vote.go index 7fb1531f..a0b0d62b 100644 --- a/utils/vote.go +++ b/utils/vote.go @@ -1,8 +1,8 @@ package utils import ( - "context" "math/big" + "razor/RPC" "razor/core/types" "razor/pkg/bindings" @@ -14,12 +14,12 @@ func (*UtilsStruct) GetVoteManagerWithOpts(client *ethclient.Client) (*bindings. return UtilsInterface.GetVoteManager(client), UtilsInterface.GetOptions() } -func (*UtilsStruct) GetCommitment(ctx context.Context, client *ethclient.Client, address string) (types.Commitment, error) { - stakerId, err := UtilsInterface.GetStakerId(ctx, client, address) +func (*UtilsStruct) GetCommitment(rpcParameters RPC.RPCParameters, address string) (types.Commitment, error) { + stakerId, err := UtilsInterface.GetStakerId(rpcParameters, address) if err != nil { return types.Commitment{}, err } - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetCommitment", client, stakerId) + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetCommitment", stakerId) if err != nil { return types.Commitment{}, err } @@ -27,58 +27,66 @@ func (*UtilsStruct) GetCommitment(ctx context.Context, client *ethclient.Client, return commitment, nil } -func (*UtilsStruct) GetVoteValue(ctx context.Context, client *ethclient.Client, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetVoteValue", client, epoch, stakerId, medianIndex) +func (*UtilsStruct) GetVoteValue(rpcParameters RPC.RPCParameters, epoch uint32, stakerId uint32, medianIndex uint16) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetVoteValue", epoch, stakerId, medianIndex) if err != nil { return big.NewInt(0), err } return returnedValues[0].Interface().(*big.Int), nil } -func (*UtilsStruct) GetInfluenceSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetInfluenceSnapshot", client, epoch, stakerId) +func (*UtilsStruct) GetInfluenceSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetInfluenceSnapshot", epoch, stakerId) if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } -func (*UtilsStruct) GetStakeSnapshot(ctx context.Context, client *ethclient.Client, stakerId uint32, epoch uint32) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetStakeSnapshot", client, epoch, stakerId) +func (*UtilsStruct) GetStakeSnapshot(rpcParameters RPC.RPCParameters, stakerId uint32, epoch uint32) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetStakeSnapshot", epoch, stakerId) if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } -func (*UtilsStruct) GetTotalInfluenceRevealed(ctx context.Context, client *ethclient.Client, epoch uint32, medianIndex uint16) (*big.Int, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetTotalInfluenceRevealed", client, epoch, medianIndex) +func (*UtilsStruct) GetTotalInfluenceRevealed(rpcParameters RPC.RPCParameters, epoch uint32, medianIndex uint16) (*big.Int, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetTotalInfluenceRevealed", epoch, medianIndex) if err != nil { return nil, err } return returnedValues[0].Interface().(*big.Int), nil } -func (*UtilsStruct) GetEpochLastCommitted(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetEpochLastCommitted", client, stakerId) +func (*UtilsStruct) GetEpochLastCommitted(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetEpochLastCommitted", stakerId) if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) GetEpochLastRevealed(ctx context.Context, client *ethclient.Client, stakerId uint32) (uint32, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "GetEpochLastRevealed", client, stakerId) +func (*UtilsStruct) GetEpochLastRevealed(rpcParameters RPC.RPCParameters, stakerId uint32) (uint32, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetEpochLastRevealed", stakerId) if err != nil { return 0, err } return returnedValues[0].Interface().(uint32), nil } -func (*UtilsStruct) ToAssign(ctx context.Context, client *ethclient.Client) (uint16, error) { - returnedValues, err := InvokeFunctionWithRetryAttempts(ctx, VoteManagerInterface, "ToAssign", client) +func (*UtilsStruct) ToAssign(rpcParameters RPC.RPCParameters) (uint16, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "ToAssign") if err != nil { return 0, err } return returnedValues[0].Interface().(uint16), nil } + +func (*UtilsStruct) GetSaltFromBlockchain(rpcParameters RPC.RPCParameters) ([32]byte, error) { + returnedValues, err := InvokeFunctionWithRetryAttempts(rpcParameters, VoteManagerInterface, "GetSaltFromBlockchain") + if err != nil { + return [32]byte{}, err + } + return returnedValues[0].Interface().([32]byte), nil +}