using System.Threading; using System.Threading.Tasks; using Nethereum.ABI.FunctionEncoding; using Nethereum.Hex.HexTypes; using Nethereum.RPC.Eth.DTOs; using Nethereum.RPC.TransactionManagers; using Nethereum.RPC.TransactionTypes; namespace Nethereum.Contracts { public class DeployContract : IDeployContract { private readonly DeployContractTransactionBuilder _deployContractTransactionBuilder; public DeployContract(ITransactionManager transactionManager) { TransactionManager = transactionManager; _deployContractTransactionBuilder = new DeployContractTransactionBuilder(); } public ITransactionManager TransactionManager { get; set; } public string GetData(string contractByteCode, string abi, params object[] values) { return _deployContractTransactionBuilder.GetData(contractByteCode, abi, values); } public string GetData(string contractByteCode, TConstructorParams inputParams) { return _deployContractTransactionBuilder.GetData(contractByteCode, inputParams); } #if !DOTNET35 public Task EstimateGasAsync(string abi, string contractByteCode, string from, params object[] values) { var callInput = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, values); return TransactionManager.EstimateGasAsync(callInput); } public Task EstimateGasAsync(string contractByteCode, string from, TConstructorParams inputParams) { var callInput = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, inputParams); return TransactionManager.EstimateGasAsync(callInput); } public Task EstimateGasAsync(string contractByteCode, string from, HexBigInteger gas, TConstructorParams inputParams) { var callInput = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, inputParams); return TransactionManager.EstimateGasAsync(callInput); } public Task EstimateGasAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger value, TConstructorParams inputParams) { var callInput = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, null, value, inputParams); return TransactionManager.EstimateGasAsync(callInput); } public Task SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger value, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, value, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, gasPrice, value, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, HexBigInteger nonce, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, gasPrice, value, nonce, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string abi, string contractByteCode, string from, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(HexBigInteger type, string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(type, abi, contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, values); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas) { return TransactionManager.SendTransactionAsync(new TransactionInput(contractByteCode, gas, from)); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value) { return TransactionManager.SendTransactionAsync(new TransactionInput(contractByteCode, null, from, gas, gasPrice, value)); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce) { return TransactionManager.SendTransactionAsync(new TransactionInput(TransactionType.EIP1559.AsHexBigInteger(), contractByteCode, null, from, gas, value, maxFeePerGas, maxPriorityFeePerGas)); } public Task SendRequestAsync(HexBigInteger type, string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce) { return TransactionManager.SendTransactionAsync(new TransactionInput(type, contractByteCode, null, from, gas, value, maxFeePerGas, maxPriorityFeePerGas)); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger value) { return TransactionManager.SendTransactionAsync(new TransactionInput(contractByteCode, null, from, gas, value)); } public Task SendRequestAsync(string contractByteCode, string from) { return TransactionManager.SendTransactionAsync(new TransactionInput(contractByteCode, null, from)); } public Task SendRequestAsync(string contractByteCode, string from, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, gasPrice, value, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, gasPrice, value, nonce, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAsync(HexBigInteger type, string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams) { var transaction = _deployContractTransactionBuilder.BuildTransaction(type, contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, inputParams); return TransactionManager.SendTransactionAsync(transaction); } public Task SendRequestAndWaitForReceiptAsync(string abi, string contractByteCode, string from, HexBigInteger gas, CancellationTokenSource receiptRequestCancellationToken = null, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, values); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger value, CancellationTokenSource receiptRequestCancellationToken = null, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, value, values); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string abi, string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, CancellationTokenSource receiptRequestCancellationToken = null, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, gas, gasPrice, value, values); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string abi, string contractByteCode, string from, CancellationTokenSource receiptRequestCancellationToken = null, params object[] values) { var transaction = _deployContractTransactionBuilder.BuildTransaction(abi, contractByteCode, from, values); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, CancellationTokenSource receiptRequestCancellationToken = null) { _deployContractTransactionBuilder.EnsureByteCodeDoesNotContainPlaceholders(contractByteCode); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync( new TransactionInput(contractByteCode, gas, from), receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, CancellationTokenSource receiptRequestCancellationToken = null) { _deployContractTransactionBuilder.EnsureByteCodeDoesNotContainPlaceholders(contractByteCode); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync( new TransactionInput(contractByteCode, null, from, gas, gasPrice, value), receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger value, CancellationTokenSource receiptRequestCancellationToken = null) { _deployContractTransactionBuilder.EnsureByteCodeDoesNotContainPlaceholders(contractByteCode); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync( new TransactionInput(contractByteCode, null, from, gas, value), receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, CancellationTokenSource receiptRequestCancellationToken = null) { _deployContractTransactionBuilder.EnsureByteCodeDoesNotContainPlaceholders(contractByteCode); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync( new TransactionInput(contractByteCode, null, from), receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, gasPrice, value, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger gasPrice, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, gasPrice, value, nonce, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } public Task SendRequestAndWaitForReceiptAsync(HexBigInteger type, string contractByteCode, string from, HexBigInteger gas, HexBigInteger maxFeePerGas, HexBigInteger maxPriorityFeePerGas, HexBigInteger value, HexBigInteger nonce, TConstructorParams inputParams, CancellationTokenSource receiptRequestCancellationToken = null) { var transaction = _deployContractTransactionBuilder.BuildTransaction(type, contractByteCode, from, gas, maxFeePerGas, maxPriorityFeePerGas, value, nonce, inputParams); return TransactionManager.TransactionReceiptService.DeployContractAndWaitForReceiptAsync(transaction, receiptRequestCancellationToken); } #endif } }