Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 2
0
        public async Task <TransferResultDto> TransferAsync(TransferPayloadDto dto)
        {
            var payload  = new RpcRequestPayload <TransferPayloadDto>("transfer", dto);
            var response = await CallAsync <TransferResultDto>(payload);

            return(response.Result);
        }
Exemplo n.º 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);
        }