private async Task DeploySampleContracts() { var reg = new SmartContractRegistration { Category = 1, ContractBytes = ByteString.CopyFrom(ContractCode), ContractHash = Hash.FromRawBytes(ContractCode) }; await SmartContractService.DeployContractAsync(ChainId1, ContractAddress1, reg, false); await SmartContractService.DeployContractAsync(ChainId2, ContractAddress2, reg, false); }
/// <summary> /// Creates a new chain with the provided ChainId and Smart Contract Zero. /// </summary> /// <returns>The new chain async.</returns> /// <param name="chainId">The new chain id which will be derived from the creator address.</param> /// <param name="smartContractRegistration">The smart contract registration containing the code of the SmartContractZero.</param> public async Task <IChain> CreateNewChainAsync(Hash chainId, List <SmartContractRegistration> smartContractRegistration) { try { // TODO: Centralize this function in Hash class // SmartContractZero address can be derived from ChainId foreach (var reg in smartContractRegistration) { var contractAddress = GenesisContractHash(chainId, (SmartContractType)reg.Type); await _smartContractService.DeployContractAsync(chainId, contractAddress, reg, true); } var builder = new GenesisBlockBuilder(); builder.Build(chainId); // add block to storage var blockchain = _chainService.GetBlockChain(chainId); await blockchain.AddBlocksAsync(new List <IBlock> { builder.Block }); var chain = new Chain { GenesisBlockHash = await blockchain.GetCurrentBlockHashAsync(), Id = chainId }; return(chain); } catch (Exception e) { _logger.Error("CreateNewChainAsync Error: " + e); return(null); } }
private async Task DeploySampleContracts() { var reg = new SmartContractRegistration { Category = 1, ContractBytes = ByteString.CopyFrom(ExampleContractCode), ContractHash = Hash.FromRawBytes(ExampleContractCode) }; await SmartContractService.DeployContractAsync(ChainId1, SampleContractAddress1, reg, true); await SmartContractService.DeployContractAsync(ChainId2, SampleContractAddress2, reg, true); Executive1 = await SmartContractService.GetExecutiveAsync(SampleContractAddress1, ChainId1); Executive2 = await SmartContractService.GetExecutiveAsync(SampleContractAddress2, ChainId2); }
public async Task DeployContractAsync(byte[] code, Address address) { var reg = new SmartContractRegistration { Category = 1, ContractBytes = ByteString.CopyFrom(code), ContractHash = Hash.FromRawBytes(code) }; await SmartContractService.DeployContractAsync(ChainId1, address, reg, false); }
public async Task <IActionResult> RunDeployContractAsync( [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req) { _logger.LogInformation("RunDeployContract"); string body = await req.ReadAsStringAsync(); var request = JsonConvert.DeserializeObject <SmartContractDeployRequest>(body); try { var result = await _service.DeployContractAsync(request); return(new JsonResult(result, JsonSerializerSettings)); } catch (Exception exception) { _logger.LogError(exception, "RunDeployContract failed"); return(new JsonResult(new { exception.Message }, JsonSerializerSettings)); } }
public async Task DeployContractAsync(ContractDto contractDto) { await _smartContractService.DeployContractAsync(contractDto); }
public async Task DeployContractAsync(Address contractAddress, SmartContractRegistration registration, bool isPrivileged, Hash name) { await _smartContractService.DeployContractAsync(contractAddress, registration, isPrivileged, name); }