Ejemplo n.º 1
0
        /// <summary>
        /// Add a transfer from url, If you want to upload a torrent file, use /files/upload endpoint.
        /// </summary>
        public async Task <Transfer> AddTransfer(AddTransferRequest request)
        {
            var response = await _apiClient.ExecutePostWithResponseAsync <AddTransferResponse>("transfers/add", request);

            return(response.Transfer);
        }
Ejemplo n.º 2
0
        public async Task ExecuteCircleWithdrawalInBlockchainAsync(WithdrawalEntity withdrawalEntity)
        {
            var circleAsset =
                _circleAssetMapper.AssetToCircleTokenAsset(withdrawalEntity.BrokerId, withdrawalEntity.AssetSymbol);

            if (circleAsset == null)
            {
                throw new Exception(
                          $"[CryptoWithdrawalRequest] Cannot found circle coin association for asset {withdrawalEntity.AssetSymbol}, broker {withdrawalEntity.BrokerId}");
            }

            var circleBlockchain =
                _circleBlockchainMapper.BlockchainToCircleBlockchain(withdrawalEntity.BrokerId,
                                                                     withdrawalEntity.Blockchain);

            if (circleBlockchain == null)
            {
                throw new Exception(
                          $"[CryptoWithdrawalRequest] Cannot found circle blockchain association for blockchain {withdrawalEntity.Blockchain}, broker {withdrawalEntity.BrokerId}");
            }

            var amount = (withdrawalEntity.AssetSymbol == withdrawalEntity.FeeAssetSymbol)
                ? withdrawalEntity.Amount - withdrawalEntity.FeeAmount
                : withdrawalEntity.Amount;

            var address    = withdrawalEntity.ToAddress;
            var addressTag = withdrawalEntity.ToTag;

            //var tagSeparator = circleBlockchain.TagSeparator;
            //if (string.IsNullOrEmpty(tagSeparator))
            //{
            //    address = withdrawalEntity.ToAddress;
            //    addressTag = null;
            //}
            //else
            //{
            //    address = withdrawalEntity.ToAddress.Split(tagSeparator)[0];
            //    addressTag = withdrawalEntity.ToAddress.Split(tagSeparator)[1];
            //}


            var addTransferRequest = new AddTransferRequest
            {
                BrokerId       = withdrawalEntity.BrokerId,
                ClientId       = withdrawalEntity.ClientId,
                IdempotencyKey = withdrawalEntity.TransactionId,
                SourceId       = circleAsset.CircleWalletId,
                Amount         = (double)amount,
                Currency       = circleAsset.CircleAsset,
                DstAddress     = address,
                DstAddressTag  = addressTag,
                DstChain       = circleBlockchain.CircleBlockchain
            };

            addTransferRequest.AddToActivityAsJsonTag("transfer-request");

            var transferResult = await _circlePaymentsService.AddCircleTransfer(addTransferRequest);

            _logger.LogInformation("[CryptoWithdrawalRequest] Withdrawal in Circle ({operationIdText}): {jsonText}",
                                   withdrawalEntity.TransactionId, JsonConvert.SerializeObject(transferResult));

            transferResult.AddToActivityAsJsonTag("transfer-result");

            if (!transferResult.IsSuccess)
            {
                throw new Exception(
                          $"[CryptoWithdrawalRequest] Cannot execute withdrawal in Circle ({withdrawalEntity.TransactionId}): {JsonConvert.SerializeObject(transferResult)}");
            }

            var txid = transferResult.Data?.TransactionHash;

            withdrawalEntity.Status           = WithdrawalStatus.BlockchainProcessing;
            withdrawalEntity.Txid             = txid;
            withdrawalEntity.ExternalSystemId = transferResult.Data?.Id;
        }