private IList <ITransaction> ExecutePayments(IEnumerable <KeyValuePair <string, List <ITransaction> > > paymentsToExecute) { var executed = new List <ITransaction>(); try { // filter out users whom total amount doesn't exceed the configured minimum payment amount. var filtered = paymentsToExecute.Where( x => x.Value.Sum(y => y.Payment.Amount) >= (decimal)_poolConfig.Payments.Minimum) .ToDictionary(x => x.Key, x => x.Value); if (filtered.Count <= 0) // make sure we have payments to execute even after our filter. { return(executed); } // coin daemon expects us to handle outputs in <wallet_address,amount> format, create the data structure so. var outputs = filtered.ToDictionary(x => x.Key, x => x.Value.Sum(y => y.Payment.Amount)); _logger.Debug("Payment Outputs: {0}", outputs); // send the payments all-together. var txHash = _daemonClient.SendMany(_poolAccount, outputs); // loop through all executed payments filtered.ToList().ForEach(x => x.Value.ForEach(y => { y.TxHash = txHash; // set transaction id. y.Payment.Completed = true; // set as completed. })); executed = filtered.SelectMany(x => x.Value).ToList(); return(executed); } catch (RpcException e) { _logger.Error("An error occured while trying to execute payment; {0}", e.Message); return(executed); } }
private void ExecutePayments(IList <IWorkerBalance> workerBalances) { var payments = new Dictionary <string, decimal>(); try { decimal totalAmountToPay = 0; foreach (var balance in workerBalances) { if (balance.BalanceInSatoshis >= _paymentThresholdInSatoshis) // if worker's balance exceed's threshold, add him to payment list. { totalAmountToPay += balance.Balance; payments.Add(balance.Worker, balance.Balance); } } if (totalAmountToPay <= 0) { _logger.Information("No pending payments found."); return; } var txid = _daemonClient.SendMany(_poolAccount, payments); // send the payments // mark the paid ones. foreach (var balance in workerBalances.Where(balance => balance.BalanceInSatoshis >= _paymentThresholdInSatoshis)) { balance.Paid = true; } _logger.Information("Paid a total of {0} coins to {1} workers.", totalAmountToPay, workerBalances.Count); } catch (RpcException e) { _logger.Error("Payment failed: {0} [{1}] - payouts: {2}.", e.Message, e.Code, payments); } }