public async Task <OffchainResult> CreateDirectTransfer(string clientId, string assetId, decimal amount, string prevTempPrivateKey)
        {
            var credentials = await _walletCredentialsRepository.GetAsync(clientId);

            var request = new { clientId, assetId, amount, prevTempPrivateKey };

            await _logger.WriteInfoAsync("CreateDirectTransfer", request.ToJson(), "Transfer requested");

            var offchainTransferResult = await _bitcoinApiClient.OffchainTransferAsync(new OffchainTransferData
            {
                Amount  = -amount,
                AssetId = assetId,
                ClientPrevPrivateKey = prevTempPrivateKey,
                ClientPubKey         = credentials.PublicKey,
                Required             = false
            });

            var createTransferResult = await _offchainTransferRepository.CreateTransfer(Guid.NewGuid().ToString(), clientId, assetId, amount, OffchainTransferType.DirectTransferFromClient, offchainTransferResult.TransferId?.ToString());

            if (offchainTransferResult.HasError)
            {
                return(await InternalErrorProcessing("CreateTransfer", offchainTransferResult.Error, credentials, createTransferResult, false));
            }

            var result = new OffchainResult
            {
                TransferId      = createTransferResult.Id,
                TransactionHex  = offchainTransferResult.Transaction,
                OperationResult = OffchainOperationResult.Transfer
            };

            await _logger.WriteInfoAsync("CreateDirectTransfer", request.ToJson(), new { result.TransferId, result.OperationResult }.ToJson());

            return(result);
        }
Beispiel #2
0
        private async Task AddRequest(string client, string asset, decimal amount,
                                      OffchainTransferType type = OffchainTransferType.FromHub, string order = null)
        {
            var guid = Guid.NewGuid().ToString();

            var transfer = await _offchainTransferRepository.CreateTransfer(guid, client, asset, amount, type, null, order);

            await _offchainRequestRepository.CreateRequest(transfer.Id, client, asset, RequestType.RequestTransfer, type);
        }
        public async Task CreateOffchainRequestAndNotify(
            string transactionId,
            string clientId,
            string assetId,
            decimal amount,
            string orderId,
            OffchainTransferType type)
        {
            await _offchainTransferRepository.CreateTransfer(transactionId, clientId, assetId, amount, type, null, orderId);

            await _offchainRequestRepository.CreateRequest(transactionId, clientId, assetId, RequestType.RequestTransfer, type, null);
        }