public async Task <EthereumResponse <OperationResponse> > SendTransferAsync(Guid id, string sign, Asset asset, string fromAddress, string toAddress, decimal amount) { var response = await _ethereumApi.ApiExchangeTransferPostAsync(new TransferModel { Amount = EthServiceHelpers.ConvertToContract(amount, asset.MultiplierPower, asset.Accuracy), CoinAdapterAddress = asset.AssetAddress, ToAddress = toAddress, FromAddress = fromAddress, Id = id, Sign = sign }); if (response is ApiException error) { return(new EthereumResponse <OperationResponse> { Error = new ErrorResponse { Code = error.Error.Code.ToString(), Message = error.Error.Message } }); } if (response is OperationIdResponse res) { return(new EthereumResponse <OperationResponse> { Result = new OperationResponse { OperationId = res.OperationId } }); } throw new Exception("Unknown response"); }
public async Task <EthereumResponse <EstimationResponse> > EstimateCashOutAsync(Guid id, string sign, IAsset asset, string fromAddress, string toAddress, decimal amount) { var response = await _ethereumApi.ApiExchangeEstimateCashoutGasPostAsync(new TransferModel { Amount = EthServiceHelpers.ConvertToContract(amount, asset.MultiplierPower, asset.Accuracy), CoinAdapterAddress = asset.AssetAddress, ToAddress = toAddress, FromAddress = fromAddress, Id = id, Sign = sign }); var error = response as ApiException; if (error != null) { return(new EthereumResponse <EstimationResponse> { Error = new ErrorResponse { Code = error.Error.Code, Message = error.Error.Message } }); } EstimatedGasModel res = response as EstimatedGasModel; if (res != null) { return(new EthereumResponse <EstimationResponse> { Result = new EstimationResponse { GasAmount = res.EstimatedGas, IsAllowed = res.IsAllowed.Value } }); } throw new Exception("Unknown response"); }
public async Task <EthereumResponse <OperationResponse> > SendTransferWithChangeAsync(decimal change, string signFrom, Guid id, IAsset asset, string fromAddress, string toAddress, decimal amount) { var response = await _ethereumApi.ApiExchangeTransferWithChangePostAsync(new TransferWithChangeModel { Change = EthServiceHelpers.ConvertToContract(change, asset.MultiplierPower, asset.Accuracy), Amount = EthServiceHelpers.ConvertToContract(amount, asset.MultiplierPower, asset.Accuracy), SignFrom = signFrom, CoinAdapterAddress = asset.AssetAddress, ToAddress = toAddress, FromAddress = fromAddress, Id = id }); var error = response as ApiException; if (error != null) { return(new EthereumResponse <OperationResponse> { Error = new ErrorResponse { Code = error.Error.Code, Message = error.Error.Message } }); } var res = response as OperationIdResponse; if (res != null) { return(new EthereumResponse <OperationResponse> { Result = new OperationResponse { OperationId = res.OperationId } }); } throw new Exception("Unknown response"); }
public async Task <EthereumResponse <EthereumTransaction> > GetNewTxHashAndIdAsync(IAsset asset, string fromAddress, string toAddress, decimal amount) { var response = await _ethereumApi.ApiHashCalculateAndGetIdPostAsync(new BaseCoinRequestParametersModel { Amount = EthServiceHelpers.ConvertToContract(amount, asset.MultiplierPower, asset.Accuracy), CoinAdapterAddress = asset.AssetAddress, FromAddress = fromAddress, ToAddress = toAddress }); var error = response as ApiException; if (error != null) { return(new EthereumResponse <EthereumTransaction> { Error = new ErrorResponse { Code = error.Error.Code, Message = error.Error.Message } }); } var res = response as HashResponseWithId; if (res != null) { return(new EthereumResponse <EthereumTransaction> { Result = new EthereumTransaction { Hash = res.HashHex, OperationId = res.OperationId.GetValueOrDefault() } }); } throw new Exception("Unknown response"); }
public async Task <EthereumResponse <bool> > IsSignValid(Guid id, string sign, IAsset asset, string fromAddress, string toAddress, decimal amount) { var response = await _ethereumApi.ApiExchangeCheckSignPostAsync(new CheckSignModel { Amount = EthServiceHelpers.ConvertToContract(amount, asset.MultiplierPower, asset.Accuracy), CoinAdapterAddress = asset.AssetAddress, ToAddress = toAddress, FromAddress = fromAddress, Id = id, Sign = sign }); var error = response as ApiException; if (error != null) { return(new EthereumResponse <bool> { Error = new ErrorResponse { Code = error.Error.Code, Message = error.Error.Message } }); } var res = response as CheckSignResponse; if (res != null) { return(new EthereumResponse <bool> { Result = res.SignIsCorrect.GetValueOrDefault() }); } throw new Exception("Unknown response"); }