public async Task <SmartContract> CreateSmartContract(SmartContract smartContract) { try { var smartContractAbiFunctions = JsonConvert.DeserializeObject <List <SmartContractAbi> >(smartContract.Abi); List <SmartContractFunction> smartContractFunctions = null; if (smartContractAbiFunctions != null && smartContractAbiFunctions.Count > 0) { smartContractFunctions = new List <SmartContractFunction>(); int sequence = 1; foreach (var smartContractAbiFunction in smartContractAbiFunctions) { if (smartContractAbiFunction.Type.ToLower() != "constructor" && smartContractAbiFunction.Type.ToLower() != "event") { SmartContractFunction smartContractFunction = new SmartContractFunction() { FunctionName = smartContractAbiFunction.Name, FunctionType = smartContractAbiFunction.Type, Sequence = sequence++ }; smartContractFunctions.Add(smartContractFunction); } } } var smartContractUpdated = await this.smartContractDb.Create(smartContract, smartContractFunctions); return(smartContractUpdated); } catch (Exception ex) { this.logger.LogException(ex, $"Error occured in {typeof(SmartContractManager)}.CreateSmartContract"); throw; } }
public async Task <List <SmartContractFunction> > GetSmartContractFunctions(int smartContractId) { List <SmartContractFunction> smartContractFunctions = new List <SmartContractFunction>(); using (SqlConnection conn = new SqlConnection(DbConfiguration.ConnectionString)) { SqlCommand sqlcmd = new SqlCommand(StoredProcedures.GetSmartContractFunctions, conn); sqlcmd.CommandType = System.Data.CommandType.StoredProcedure; sqlcmd.Parameters.Add(new SqlParameter() { ParameterName = "@smartContractId", SqlDbType = System.Data.SqlDbType.Int, Value = smartContractId }); conn.Open(); var reader = await sqlcmd.ExecuteReaderAsync(); while (reader.Read()) { SmartContractFunction smartContractFunction = new SmartContractFunction(); smartContractFunction.SmartContractFunctionId = Convert.ToInt32(reader["SmartContractFunctionId"]); smartContractFunction.SmartContractId = Convert.ToInt32(reader["SmartContractId"]); smartContractFunction.FunctionName = reader["FunctionName"]?.ToString(); smartContractFunction.FunctionType = reader["FunctionType"]?.ToString(); smartContractFunction.Sequence = Convert.ToInt32(reader["Sequence"]); smartContractFunction.CreatedDatetime = string.IsNullOrEmpty(reader["CreatedDatetime"]?.ToString()) ? DateTime.MinValue : Convert.ToDateTime(reader["CreatedDatetime"]); smartContractFunction.UpdatedDatetime = string.IsNullOrEmpty(reader["UpdatedDatetime"]?.ToString()) ? DateTime.MinValue : Convert.ToDateTime(reader["UpdatedDatetime"]); smartContractFunctions.Add(smartContractFunction); } } return(smartContractFunctions); }