Fine tuned bitcoin transaction input selection

This commit is contained in:
Rick Falkvinge
2016-01-07 11:46:46 +01:00
parent ec3ee87276
commit 1a7c4aab34
4 changed files with 17 additions and 7 deletions
+14 -5
View File
@@ -668,6 +668,7 @@ namespace Swarmops.Logic.Financial
Dictionary<int, List<string>> notificationSpecLookup = new Dictionary<int, List<string>>();
Dictionary<int, List<Int64>> notificationAmountLookup = new Dictionary<int, List<Int64>>();
Payout masterPayoutPrototype = Payout.Empty;
HotBitcoinAddress changeAddress = HotBitcoinAddress.OrganizationWalletZero (organization);
foreach (Payout payout in bitcoinPayouts)
{
@@ -689,7 +690,7 @@ namespace Swarmops.Logic.Financial
// Set change address to wallet slush
txBuilder.SetChange (new BitcoinAddress (HotBitcoinAddress.OrganizationWalletZero (organization).Address));
txBuilder.SetChange (new BitcoinAddress (changeAddress.Address));
// Add fee
@@ -724,18 +725,26 @@ namespace Swarmops.Logic.Financial
BitcoinUtility.BroadcastTransaction (txReady);
// Note the transaction hash
string transactionHash = txReady.GetHash().ToString();
// Delete all old inputs, adjust balance for addresses (re-register unused inputs)
inputs.AsUnspents.DeleteAll();
foreach (BitcoinTransactionInput input in inputs)
// Log the new unspent created by change (if there is any)
if (satoshisInput - satoshisUsed > 0)
{
BitcoinUtility.TestUnspents (input.BitcoinAddress);
SwarmDb.GetDatabaseForWriting()
.CreateHotBitcoinAddressUnspentConditional(changeAddress.Identity, transactionHash,
+ /* the change address seems to always get index 0? is this a safe assumption? */ 0, satoshisInput - satoshisUsed, /* confirmation count*/ 0);
}
// Register new balance of change address, should have increased by (satoshisInput-satoshisUsed)
BitcoinUtility.TestUnspents (HotBitcoinAddress.OrganizationWalletZero (organization).Address);
// TODO
// Send notifications
@@ -788,7 +797,7 @@ namespace Swarmops.Logic.Financial
FinancialTransaction ledgerTransaction = FinancialTransaction.Create (organization, utcNow,
"Bitcoin automated payout");
ledgerTransaction.AddRow (organization.FinancialAccounts.AssetsBitcoinHot, -masterPayoutPrototype.AmountCents, null).NativeAmountCents = new Swarmops.Logic.Financial.Money(satoshisUsed, Currency.Bitcoin);
ledgerTransaction.BlockchainHash = txReady.GetHash().ToString(); // TODO: VERIFY THIS
ledgerTransaction.BlockchainHash = transactionHash;
masterPayout.BindToTransactionAndClose (ledgerTransaction, null);
}
@@ -61,7 +61,7 @@ namespace Swarmops.Logic.Resources {
}
/// <summary>
/// Looks up a localized string similar to The bitcoin hotwallet for [OrganizationName] just made [PaymentCount] automatic payments totalling [CurrencyCode] [AmountFloat], or expressed in bitcoin, [BitcoinAmountFloat] microbitcoins..
/// Looks up a localized string similar to The bitcoin hotwallet for [OrganizationName] just made [PaymentCount] automatic payment(s) totalling [CurrencyCode] [AmountFloat] ([BitcoinAmountFloat] microbitcoin or &quot;bits&quot;)..
/// </summary>
internal static string Bitcoin_Hotwallet_Outflow_Body {
get {
@@ -158,7 +158,7 @@ If you did not set this payout address (it may be worth double checking the addr
<value>[[OrganizationName]] Bitcoin payout address set</value>
</data>
<data name="Bitcoin_Hotwallet_Outflow_Body" xml:space="preserve">
<value>The bitcoin hotwallet for [OrganizationName] just made [PaymentCount] automatic payments totalling [CurrencyCode] [AmountFloat], or expressed in bitcoin, [BitcoinAmountFloat] microbitcoins.</value>
<value>The bitcoin hotwallet for [OrganizationName] just made [PaymentCount] automatic payment(s) totalling [CurrencyCode] [AmountFloat] ([BitcoinAmountFloat] microbitcoin or "bits").</value>
</data>
<data name="Bitcoin_Hotwallet_Outflow_Subject" xml:space="preserve">
<value>[[OrganizationName]] Hotwallet Payout: [CurrencyCode] [AmountFloat]</value>
+1
View File
@@ -41,6 +41,7 @@ namespace Swarmops
// HotBitcoinAddresses testAddresses = HotBitcoinAddresses.ForOrganization (Organization.FromIdentity (2));
// testAddresses.UpdateBalances();
// BitcoinUtility.TestUnspents ("19WEHvYWG5gvPf7X3USXwS7QdFfE1dGSQF");
// Payouts.PerformAutomated();