Beispiel #1
0
        protected async Task PerformTransfer(TransferPayloadDto transaction)
        {
            if (config.DryRun)
            {
                var amounts = transaction.Destinations.Select(d => MoneroUtils.AtomicToMonero(d.Amount));
                logger.LogInformation("DRY RUN: Transfer " + string.Join(',', amounts));
            }
            else
            {
                logger.LogInformation($"Executing transfer..");
                try
                {
                    var transferResult = await wallet.TransferAsync(transaction);

                    logger.LogInformation($"Transfer {MoneroUtils.AtomicToMonero(transferResult.Amount)}" +
                                          $" with fee {MoneroUtils.AtomicToMonero(transferResult.Fee)} ({ transferResult.TxHash})");
                }
                catch (RpcResponseException ex)
                {
                    if (ex.ResponseError.Code == -37 || ex.ResponseError.Code == -17)
                    {
                        // not enough money. Fee is not considered.
                        logger.LogWarning($"Transfer of {MoneroUtils.AtomicToMonero(SplitAmount)} failed due to {ex.Message}. Stopping.");
                        return;
                    }
                    throw;
                }
            }
        }
        public void ShouldDiceAccordingToConfiguration()
        {
            var transfers = new List <IncomingTransferDto>()
            {
                new IncomingTransferDto
                {
                    Amount = MoneroUtils.MoneroToAtomic(1500),
                }
            };

            var result = dicer.PerformDiceTest(transfers, testAddress);

            // 2 transfers
            Assert.AreEqual(2, result.Count());

            // first 10 of 100, second 5 of 100
            Assert.AreEqual(10, result.ElementAt(0).Destinations.Count);
            Assert.AreEqual(5, result.ElementAt(1).Destinations.Count);

            Assert.IsTrue(result.All(t => t.Destinations.All(d => d.Amount == MoneroUtils.MoneroToAtomic(config.SplitAmount))));
            Assert.IsTrue(result.All(t => t.Destinations.All(d => d.Address == testAddress)));
        }
Beispiel #3
0
        protected IEnumerable <TransferPayloadDto> PerformDice(
            IEnumerable <IncomingTransferDto> transfers,
            string targetAddress)
        {
            var transfersToSplit = transfers
                                   .Where(t => t.Amount > SplitAmount)
                                   .OrderBy(t => t.Amount);

            logger.LogInformation($"{transfersToSplit.Count()} will be diced.");

            var newTransfers = new List <TransferPayloadDto>();
            TransferPayloadDto currentTransfer = null;

            foreach (var transfer in transfersToSplit)
            {
                var transferAmount = transfer.Amount / SplitAmount;

                logger.LogInformation($"Dicing {MoneroUtils.AtomicToMonero(transfer.Amount)}" +
                                      $" into {transferAmount} of {MoneroUtils.AtomicToMonero(SplitAmount)}");

                for (uint i = 0; i < transferAmount; i++)
                {
                    if (currentTransfer == null ||
                        currentTransfer.Destinations.Count >= OutputsPerTransfer)
                    {
                        currentTransfer = new TransferPayloadDto();
                        newTransfers.Add(currentTransfer);
                    }

                    currentTransfer.Destinations.Add(new TransferPayloadDestinationDto
                    {
                        Address = targetAddress,
                        Amount  = SplitAmount
                    });
                }
            }
            return(newTransfers);
        }
Beispiel #4
0
        public async Task <double> QueryHumanFriendlyBalanceAsync()
        {
            var response = await CallAsync <BalanceDto>(new RpcRequestPayload("get_balance"));

            return(MoneroUtils.AtomicToMonero(response.Result.Balance));
        }