// [AuthKey] /// <summary> /// Упаковка транзакции /// Base58Check /// .Base58CheckEncoding /// .EncodePlain(BCTransactionTools.CreateByteHashByTransaction(transac)) /// </summary> /// <param name="publicKey"></param> /// <returns></returns> public IActionResult Pack(RequestApiModel model) { // Нужна проверка валидности AuthKey - guid InitAuthKey(model); ResponseApiModel res = new ResponseApiModel(); if (model.DelegateDisable || model.DelegateEnable || model.DateExpired != null) { res.DataResponse.TransactionPackagedStr = ServiceProvider .GetService <TransactionService>().PackTransactionByApiModelDelegation(model); } else { res.DataResponse = ServiceProvider .GetService <TransactionService>().PackTransactionByApiModel(model); } res.Success = true; //TODO: запись в базу, для логов. Обработка ошибок. Согласовать стандарт. return(new JsonResult(res));//"value"; }
//public ResponseFeeModel GetActualFee(RequestFeeModel) //{ // var res = new ResponseFeeModel(); // res.fee = 0.008740M; //} public ResponseApiModel GetContract(RequestKeyApiModel model) { var response = new ResponseApiModel(); using (var client = GetClientByModel(model)) { var address = SimpleBase.Base58.Bitcoin.Decode(model.PublicKey).ToArray(); SmartContractGetResult smartContractGetResult = client.SmartContractGet(null); var smartContractDataResult = client.SmartContractDataGet(address); var contractInfo = ToContractInfo(smartContractGetResult.SmartContract, smartContractDataResult); contractInfo.Found = smartContractGetResult.Status.Code == 0; if (contractInfo.Found && contractInfo.IsToken) { var tokenInfo = client.TokenInfoGet(address); if (tokenInfo?.Token != null) { contractInfo.Token = $"{tokenInfo.Token.Name} ({tokenInfo.Token.Code})"; } } foreach (var item in contractInfo.Methods.Split('\n')) { response.ListItem.Add(new ItemListApiModel() { Name = item, }); } } return(response); }
public static async Task <ResponseApiModel> UploadImagesAsync(List <HttpPostedFileBase> files, string objectId, string subDir) { var strError = string.Empty; var result = new ResponseApiModel(); var _baseUrl = string.Format("{0}/{1}", SystemSettings.SocialContainerServer, "api/upload/images"); try { using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { if (files.HasData()) { foreach (var item in files) { byte[] Bytes = new byte[item.InputStream.Length + 1]; item.InputStream.Read(Bytes, 0, Bytes.Length); var fileContent = new ByteArrayContent(Bytes); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = item.FileName }; content.Add(fileContent); } } //Extends parameters Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("ObjectId", objectId); parameters.Add("SubDir", subDir); HttpContent DictionaryItems = new FormUrlEncodedContent(parameters); content.Add(DictionaryItems, "MyFormData"); var response = client.PostAsync(_baseUrl, content).Result; //Trace log HttpStatusCodeTrace(response); // Parsing the returned result var responseString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <ResponseApiModel>(responseString); } } } catch (Exception ex) { strError = string.Format("Failed when calling api to UploadImagesAsync - {0} because: {1}", _baseUrl, ex.ToString()); logger.Error(strError); throw new CustomSystemException(ManagerResource.COMMON_ERROR_EXTERNALSERVICE_TIMEOUT); } return(result); }
private ResponseApiActionResult GetResponseApiActionResult(ResponseBllModel responseBllModel) { var responseApiModel = new ResponseApiModel { Result = responseBllModel.Result, ParameterName = responseBllModel.ParameterName, ErrorMessage = responseBllModel.ErrorMessage }; return(new ResponseApiActionResult(Request, responseApiModel)); }
public IActionResult Pack(RequestApiModel model) { ResponseApiModel res = new ResponseApiModel(); res.DataResponse.TransactionPackagedStr = ServiceProvider .GetService <TransactionService>() .PackTransactionByApiModel(model).TransactionPackagedStr;//changed to model res.Success = true; return(new JsonResult(res));//"value"; }
public ResponseApiModel GetLastBlockId(RequestGetterApiModel model) { var response = new ResponseApiModel(); using (var client = GetClientByModel(model)) { var res = client.SyncStateGet(); response.BlockId = res.LastBlock; } return(response); }
public ResponseApiModel GetListTransactionByBlockId(RequestGetterApiModel model) { var response = new ResponseApiModel(); using (var client = GetClientByModel(model)) { bool roundFee = false; var result = client.PoolTransactionsGet(model.BlockId, model.Offset, model.Limit); var listResult = result.Transactions.Select((t, i) => ToTransactionInfo(i + model.Offset + 1, t.Id, t.Trxn, roundFee)).ToArray(); response.BlockId = model.BlockId; response.ListTransactionInfo = listResult; } return(response); }
private static BancardResponse MapResponse(ResponseApiModel apiModel, bool isSuccessStatusCode) { var model = new BancardResponse { IsSuccessStatusCode = isSuccessStatusCode, Status = apiModel.Status, Messages = apiModel.Messages.Select(x => new BancardMessage { Key = x.Key, Level = x.Level, Description = x.Dsc }).ToList(), ProcessId = apiModel.ProcessId }; return(model); }
public IActionResult GetContract(RequestKeyApiModel model) { ResponseApiModel res; try { res = ServiceProvider.GetService <MonitorService>().GetContract(model); res.Success = true; } catch (Exception ex) { res = new ResponseApiModel(); res.Success = false; res.Message = ex.Message; } return(Ok(res)); }
public ActionResult <ResponseApiModel> GetListTransactionByBlockId(RequestGetterApiModel model) { ResponseApiModel res; try { res = ServiceProvider.GetService <MonitorService>().GetListTransactionByBlockId(model); res.Success = true; } catch (Exception ex) { res = new ResponseApiModel(); res.Success = false; res.Message = ex.Message; } return(Ok(res)); }
public static ResponseApiModel GetUsersOnline() { var strError = string.Empty; var result = new ResponseApiModel(); var _baseUrl = string.Format("{0}/{1}", SystemSettings.MyCloudServer, "home/usersonline"); try { var client = new HttpClient(); client.Timeout = TimeSpan.FromSeconds(SystemSettings.ExtenalSeviceTimeOutInSeconds); // We want the response to be JSON. client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Begin calling var response = new HttpResponseMessage(); //StringContent theContent = new StringContent(rawData, System.Text.Encoding.UTF8, "application/json"); // Post to the Server and parse the response. response = client.GetAsync(_baseUrl).Result; // Parsing the returned result var responseString = response.Content.ReadAsStringAsync().Result; result = JsonConvert.DeserializeObject <ResponseApiModel>(responseString); //Trace log HttpStatusCodeTrace(response); } catch (Exception ex) { strError = string.Format("Failed when calling api to GetUsersOnline - {0} because: {1}", _baseUrl, ex.ToString()); logger.Error(strError); throw new CustomSystemException(ManagerResource.COMMON_ERROR_EXTERNALSERVICE_TIMEOUT); } return(result); }
public ResponseApiModel Login([FromBody] User user) { ResponseApiModel responseAPIModel = new ResponseApiModel(); try { if (user.Email != null && user.Password != null) { var querylogin = (from lg in db.Users where lg.Email == user.Email && lg.Password == user.Password select new { lg.Email, lg.Password }).FirstOrDefault(); if (querylogin != null) { responseAPIModel.Data = querylogin; responseAPIModel.Status = APIStatus.Success; responseAPIModel.Message = "User Login Successful"; } else { responseAPIModel.Status = APIStatus.Failed; responseAPIModel.Message = "Invalid Credentials"; } } else { responseAPIModel.Status = APIStatus.Failed; responseAPIModel.Message = "Please enter username and password"; } } catch (Exception ex) { responseAPIModel.Status = APIStatus.Failed; responseAPIModel.Message = ex.Message; } return(responseAPIModel); }
public ResponseApiModel ExecuteTransaction(RequestApiModel request, int isDelegate = 0) { ResponseApiModel response = null; using (var client = GetClientByModel(request)) { //снова инициируем транзакцию var transac = InitTransaction(request); transac.Signature = SimpleBase.Base58.Bitcoin.Decode(request.TransactionSignature).ToArray(); if (request.DelegateEnable && !request.DelegateDisable) { transac.UserFields = new byte[15] { 0, 1, 5, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 } } ; else if (request.DelegateDisable && !request.DelegateEnable) { transac.UserFields = new byte[15] { 0, 1, 5, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0 } } ; TransactionFlowResult result = client.TransactionFlow(transac); response = new ResponseApiModel(); response.FlowResult = result; if (request.MethodApi == ApiMethodConstant.SmartDeploy) { response.DataResponse.PublicKey = SimpleBase.Base58.Bitcoin.Encode(transac.Target); } if (result.Status.Code > 0) { response.Success = false; response.Message = result.Status.Message; } else { response.Success = true; response.TransactionInnerId = transac.Id; if (result.Id != null) { response.TransactionId = $"{result.Id.PoolSeq}.{result.Id.Index + 1}"; } response.DataResponse.RecommendedFee = BCTransactionTools.GetDecimalByAmount(response.FlowResult.Fee); if (response.DataResponse.RecommendedFee == 0) { response.DataResponse.RecommendedFee = MinTransactionFee; } var sum = BCTransactionTools.GetDecimalByAmount(transac.Amount); if (sum > 0) { if (response.Amount == 0) { response.Amount = sum; } if (response.ActualSum == 0) { response.ActualSum = sum; } } //TODO: extract fee from node if (result.Fee != null) { response.ActualFee = BCTransactionTools.GetDecimalByAmount(result.Fee); if (response.ActualFee == 0M) { response.ActualFee = MinTransactionFee; } } if (result.ExtraFee != null) { response.ExtraFee = new List <EFeeItem>(); foreach (var eFee in result.ExtraFee) { var feeSum = BCTransactionTools.GetDecimalByAmount(eFee.Sum); response.ExtraFee.Add(new EFeeItem() { Fee = feeSum, Comment = eFee.Comment }); } } if (request.MethodApi == ApiMethodConstant.SmartMethodExecute) { if (result.Smart_contract_result != null) { try { response.DataResponse.SmartContractResult = result.Smart_contract_result.ToString(); } catch (Exception ex) { response.DataResponse.SmartContractResult = ""; } } } } } return(response); } }
public ResponseApiActionResult(HttpRequestMessage httpRequestMessage, ResponseApiModel responseApiModel) { HttpRequestMessage = httpRequestMessage; ResponseApiModel = responseApiModel; }