/// <summary> /// Add inputs to a transaction until it has enough in value to meet its out value. /// </summary> /// <param name="hexString">he hex string of the raw transaction.</param> /// <param name="options">Founding options</param> /// <param name="isWitness">Whether the transaction hex is a serialized witness transaction.</param> /// <returns></returns> public async Task <string> FundRawTransaction(string hexString, FundOptions options, bool isWitness) { FundRawTransaction fundRawTransaction = new FundRawTransaction { HexString = hexString, FundOptions = options, IsWitness = isWitness }; string response = await httpRequest.SendReq(MethodName.fundrawtransaction, fundRawTransaction); return(response); }
public IActionResult AddFund([FromBody] FundOptions fundOptions) { var result = _fundservices.AddFund(fundOptions); if (!result.Success) { return(StatusCode((int)result.ErrorCode, result.ErrorText)); } return(Json(result.Data)); }
public Result <Fund> AddFund(FundOptions fundOptions) { if (fundOptions == null) { return(Result <Fund> .CreateFailed( StatusCode.BadRequest, "Null options")); } string userId = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var project = projectServices.FindProjectById(fundOptions.ProjectId); Fund fund = new Fund { UserId = userId, Project = project, FundAmount = fundOptions.FundAmount }; project.ProjectCurrentAmount += fund.FundAmount; project.ProjectProgress = project.ProjectCurrentAmount / project.ProjectTargetAmount; if (project.ProjectCurrentAmount >= project.ProjectTargetAmount) { project.IsComplete = true; } _db.Add(fund); _db.Update(project); var rows = 0; try { rows = _db.SaveChanges(); } catch (Exception ex) { return(Result <Fund> .CreateFailed( StatusCode.InternalServerError, ex.ToString())); } if (rows <= 0) { return(Result <Fund> .CreateFailed( StatusCode.InternalServerError, "Fund could not be updated")); } return(Result <Fund> .CreateSuccessful(fund)); }