public async Task <bool> ReleaseContract(string name, string abi, string byteCode, int gas) { // check contractName var existing = await this.GetContractFromTableStorage(name); if (existing != null) { throw new Exception($"Contract {name} is present in storage"); } try { var resultUnlocking = await _web3.Personal.UnlockAccount.SendRequestAsync(_accountAddress, _password, 60); if (resultUnlocking) { var transactionHash = await _web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, _accountAddress, new Nethereum.Hex.HexTypes.HexBigInteger(gas), 2); EthereumContractInfo eci = new EthereumContractInfo(name, abi, byteCode, transactionHash); return(await SaveContractToTableStorage(eci)); } } catch (Exception exc) { Console.WriteLine(exc.Message); return(false); } return(false); }
public async Task <bool> SaveContractToTableStorage(EthereumContractInfo contract) { StorageCredentials credentials = new StorageCredentials(_storageAccount, _storageKey); CloudStorageAccount account = new CloudStorageAccount(credentials, true); var client = account.CreateCloudTableClient(); var tableRef = client.GetTableReference("ethtransactions"); await tableRef.CreateIfNotExistsAsync(); TableOperation ops = TableOperation.InsertOrMerge(contract); await tableRef.ExecuteAsync(ops); return(true); }
public async Task <IActionResult> ImportContract(IFormFile file) { if (file == null || file.Length == 0) { ViewData["Message"] = "Not a valid file."; return(RedirectToAction("Index")); } var fileContent = GetFileContents(file); var contractInfo = new EthereumContractInfo(_contractName, abi, byteCode, file.FileName); contractInfo.TransactionHash = await _service.ReleaseContract(contractInfo, gas, fileContent); contractInfo.RowKey = contractInfo.TransactionHash; await _service.TryGetContractAddress(contractInfo); await _service.SaveContractInfoToTableStorage(contractInfo); return(RedirectToAction("Index")); }
private void SaveContractInfo(EthereumContractInfo contractInfo) { }