Пример #1
0
        public async Task TransferAllAssetsToAddress(string clientId, string srcAddress, string srcPrivateKey, string destAddress)
        {
            var transactionId = Guid.NewGuid().ToString("N");
            var transfer      =
                await
                _transferEventsRepository.RegisterAsync(TransferEvent.CreateNewTransferAll(clientId, transactionId, srcAddress));

            var contextData = TransferContextData.Create(new TransferContextData.TransferModel
            {
                ClientId    = clientId,
                OperationId = transfer.Id
            });

            await _bitCoinTransactionsRepository.CreateAsync(transactionId, null, contextData);

            if (_baseSettings.UsePushPrivateKeyService)
            {
                await _srvBlockchainHelper.PushPrivateKey(srcPrivateKey);

                srcPrivateKey = null;
            }

            var  assets = (await _assetsDict.Values()).ToArray();
            bool needToTransferAssets = (await _srvBlockchainReader.GetBalancesForAdress(srcAddress, assets)).Any(x => x.Balance > 0);

            if (needToTransferAssets)
            {
                var queueMsg = await _bitCoinCommandProducer.TransferAllAssetsToAddress(transactionId, srcAddress, srcPrivateKey, destAddress);

                await _bitCoinTransactionsRepository.UpdateRequestAsync(transactionId, queueMsg);
            }
        }
Пример #2
0
        public static async Task <IBalanceRecord> GetBalanceForAdress(this ISrvBlockchainReader srvBlockchainReader, string address,
                                                                      IAsset asset)
        {
            var balance = await srvBlockchainReader.GetBalancesForAdress(address, new[] { asset });

            return(balance.FirstOrDefault());
        }