From 3ffbaaa7fdb7d8c22f3b9f35c9c6784d82dd9b11 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 12 Oct 2015 13:07:18 +0200 Subject: [PATCH] More work on hot payouts - last commit before live payouts --- Database/Database-HotBitcoinAddresses.cs | 23 ++++++++++++++++++++ Logic/Financial/BitcoinTransactionInput.cs | 16 ++++++++++++++ Logic/Financial/HotBitcoinAddressUnspent.cs | 5 +++++ Logic/Financial/HotBitcoinAddressUnspents.cs | 3 ++- Logic/Financial/Payouts.cs | 10 +++++---- Site5/Pages/v5/Financial/Donate.aspx.cs | 2 +- 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/Database/Database-HotBitcoinAddresses.cs b/Database/Database-HotBitcoinAddresses.cs index 55007dc0..c2f6d50f 100644 --- a/Database/Database-HotBitcoinAddresses.cs +++ b/Database/Database-HotBitcoinAddresses.cs @@ -120,6 +120,29 @@ namespace Swarmops.Database } } + public BasicHotBitcoinAddressUnspent GetHotBitcoinAddressUnspent(int hotBitcoinAddressUnspentId) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = + GetDbCommand( + "SELECT" + hotBitcoinAddressUnspentFieldSequence + "WHERE HotBitcoinAddressUnspentId=" + hotBitcoinAddressUnspentId + ";", connection); + + using (DbDataReader reader = command.ExecuteReader()) + { + if (reader.Read()) + { + return ReadHotBitcoinAddressUnspentFromDataReader(reader); + } + + throw new ArgumentException("Unknown HotBitcoinAddressUnspent Id: " + hotBitcoinAddressUnspentId); + } + } + } + + public BasicHotBitcoinAddressUnspent[] GetHotBitcoinAddressUnspents(params object[] conditions) // the typical condition would be a HotBitcoinAddress, here { diff --git a/Logic/Financial/BitcoinTransactionInput.cs b/Logic/Financial/BitcoinTransactionInput.cs index 52dad22e..73ecd8fe 100644 --- a/Logic/Financial/BitcoinTransactionInput.cs +++ b/Logic/Financial/BitcoinTransactionInput.cs @@ -16,6 +16,12 @@ namespace Swarmops.Logic.Financial public string TransactionHash { get; set; } public Int32 TransactionOutputIndex { get; set; } public string BitcoinAddress { get; set; } + public int HotBitcoinAddressUnspentId { get; set; } + + public HotBitcoinAddressUnspent AsUnspent + { + get { return HotBitcoinAddressUnspent.FromIdentity (this.HotBitcoinAddressUnspentId); } + } } public class BitcoinTransactionInputs: List @@ -61,5 +67,15 @@ namespace Swarmops.Logic.Financial { get { return this.Sum (input => input.AmountSatoshis); } } + + public HotBitcoinAddressUnspents AsUnspents + { + get + { + HotBitcoinAddressUnspents unspents = new HotBitcoinAddressUnspents(); + this.ForEach (item => unspents.Add (item.AsUnspent)); + return unspents; + } + } } } diff --git a/Logic/Financial/HotBitcoinAddressUnspent.cs b/Logic/Financial/HotBitcoinAddressUnspent.cs index 5be895a5..ffff3d3d 100644 --- a/Logic/Financial/HotBitcoinAddressUnspent.cs +++ b/Logic/Financial/HotBitcoinAddressUnspent.cs @@ -20,6 +20,11 @@ namespace Swarmops.Logic.Financial return new HotBitcoinAddressUnspent (basic); } + public static HotBitcoinAddressUnspent FromIdentity (int hotBitcoinAddressUnspentId) + { + return FromBasic (SwarmDb.GetDatabaseForReading().GetHotBitcoinAddressUnspent (hotBitcoinAddressUnspentId)); + } + public HotBitcoinAddress Address { get { return HotBitcoinAddress.FromIdentity (base.HotBitcoinAddressId); } diff --git a/Logic/Financial/HotBitcoinAddressUnspents.cs b/Logic/Financial/HotBitcoinAddressUnspents.cs index dd1b8ef5..8c736ea1 100644 --- a/Logic/Financial/HotBitcoinAddressUnspents.cs +++ b/Logic/Financial/HotBitcoinAddressUnspents.cs @@ -36,7 +36,8 @@ namespace Swarmops.Logic.Financial BitcoinAddress = address.Address, PrivateKey = address.PrivateKey, TransactionHash = unspent.TransactionHash, - TransactionOutputIndex = unspent.TransactionOutputIndex + TransactionOutputIndex = unspent.TransactionOutputIndex, + HotBitcoinAddressUnspentId = unspent.Identity }; result.Add (input); diff --git a/Logic/Financial/Payouts.cs b/Logic/Financial/Payouts.cs index 612637b7..96bce6a6 100644 --- a/Logic/Financial/Payouts.cs +++ b/Logic/Financial/Payouts.cs @@ -500,7 +500,7 @@ namespace Swarmops.Logic.Financial TransactionBuilder txBuilder = new TransactionBuilder(); foreach (Payout payout in orgPayouts) { - if (payout.ExpectedTransactionDate < utcNow) + if (payout.ExpectedTransactionDate > utcNow) { continue; // payout is not due yet } @@ -511,7 +511,7 @@ namespace Swarmops.Logic.Financial // If the payout address is still in quarantine, don't pay out yet string addressSetTime = payout.RecipientPerson.BitcoinPayoutAddressTimeSet; - if (addressSetTime.Length > 4 && DateTime.Parse (addressSetTime, CultureInfo.InvariantCulture).AddHours (48) < utcNow) + if (addressSetTime.Length > 4 && DateTime.Parse (addressSetTime, CultureInfo.InvariantCulture).AddHours (48) > utcNow) { continue; // still in quarantine } @@ -688,7 +688,7 @@ namespace Swarmops.Logic.Financial // Delete inputs, adjust balance for addresses // TODO - // inputs.DeleteAll(); + // inputs.AsUnspents.DeleteAll(); // Register new balance of change address, should have increased by satoshisInput-satoshisUsed @@ -704,7 +704,7 @@ namespace Swarmops.Logic.Financial string spec = string.Empty; for (int index = 0; index < notificationSpecLookup[personId].Count; index++) { - spec += String.Format(" * {0,-30} {1,14:N2} {2:-4}\r\n", notificationSpecLookup[personId][index], (notificationAmountLookup[personId][index]/100.0).ToString("N2"), currencyCode); + spec += String.Format(" * {0,-40} {1,14:N2} {2,-4}\r\n", notificationSpecLookup[personId][index], notificationAmountLookup[personId][index]/100.0, currencyCode); } spec = spec.TrimEnd(); @@ -725,6 +725,8 @@ namespace Swarmops.Logic.Financial // Create the master payout from its prototype + // TODO + // Ledger entries // TODO diff --git a/Site5/Pages/v5/Financial/Donate.aspx.cs b/Site5/Pages/v5/Financial/Donate.aspx.cs index 0375f22f..61a90fa0 100644 --- a/Site5/Pages/v5/Financial/Donate.aspx.cs +++ b/Site5/Pages/v5/Financial/Donate.aspx.cs @@ -24,7 +24,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial this.PageAccessRequired = new Access (this.CurrentOrganization, AccessAspect.Participant); // TEMP - Payouts.PerformAutomated(); + //Payouts.PerformAutomated(); /* TEMP TEMP TEMP - REMOVE THIS CODE */ /*