More work on hot payouts - last commit before live payouts

This commit is contained in:
Rick Falkvinge
2015-10-12 13:07:18 +02:00
parent 960d1fd6e4
commit 3ffbaaa7fd
6 changed files with 53 additions and 6 deletions
+23
View File
@@ -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
{
@@ -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<BitcoinTransactionInput>
@@ -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;
}
}
}
}
@@ -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); }
+2 -1
View File
@@ -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);
+6 -4
View File
@@ -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
+1 -1
View File
@@ -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 */
/*