private ContractDeployment GetContractDeployment <T>() where T : ContractDeploymentMessage, new() { T contract = new T(); ContractDeployment deployment = null; WatchContractDeployment watchContractDeployment = null; SimpleStorageDeployment simpleStorageDeployment = null; if (contract is WatchContractDeployment) { watchContractDeployment = contract as WatchContractDeployment; } else if (contract is SimpleStorageDeployment) { simpleStorageDeployment = contract as SimpleStorageDeployment; } try { deployment = this.context.ContractDeployments.Where(s => s.ByteCode == contract.ByteCode && s.ServerUrl == this.url).First(); } catch (InvalidOperationException ex) { logger.LogError($"contract does not currently exist: {ex}"); } if (deployment == null) { deployment = new ContractDeployment(); if (watchContractDeployment != null) { watchContractDeployment.GasPrice = 0; TransactionReceipt receipt = WatchContractService.DeployContractAndWaitForReceiptAsync(web3, watchContractDeployment).GetAwaiter().GetResult(); deployment.DeploymentAddress = receipt.ContractAddress; deployment.ByteCode = watchContractDeployment.ByteCode; } else if (simpleStorageDeployment != null) { simpleStorageDeployment.GasPrice = 0; TransactionReceipt receipt = SimpleStorageService.DeployContractAndWaitForReceiptAsync(web3, simpleStorageDeployment).GetAwaiter().GetResult(); deployment.DeploymentAddress = receipt.ContractAddress; deployment.ByteCode = simpleStorageDeployment.ByteCode; } deployment.ServerUrl = this.url; this.context.Add(deployment); this.context.SaveChanges(); } return(deployment); }
public static Task <string> DeployContractAsync(Nethereum.Web3.Web3 web3, WatchContractDeployment watchContractDeployment) { return(web3.Eth.GetContractDeploymentHandler <WatchContractDeployment>().SendRequestAsync(watchContractDeployment)); }
public static async Task <WatchContractService> DeployContractAndGetServiceAsync(Nethereum.Web3.Web3 web3, WatchContractDeployment watchContractDeployment, CancellationTokenSource cancellationTokenSource = null) { var receipt = await DeployContractAndWaitForReceiptAsync(web3, watchContractDeployment, cancellationTokenSource); return(new WatchContractService(web3, receipt.ContractAddress)); }
public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Nethereum.Web3.Web3 web3, WatchContractDeployment watchContractDeployment, CancellationTokenSource cancellationTokenSource = null) { return(web3.Eth.GetContractDeploymentHandler <WatchContractDeployment>().SendRequestAndWaitForReceiptAsync(watchContractDeployment, cancellationTokenSource)); }