Some improvements to autopayouts
This commit is contained in:
@@ -179,6 +179,7 @@ namespace Swarmops.Logic.Communications.Payload
|
||||
Bitcoin_Shortage_Urgent,
|
||||
Bitcoin_Shortage_Critical,
|
||||
Bitcoin_Hotwallet_Outflow,
|
||||
Bitcoin_PrivateKeyError,
|
||||
BitcoinPayoutAddress_Set,
|
||||
BitcoinPayoutAddress_Bad,
|
||||
BitcoinPayoutAddress_PleaseSet,
|
||||
|
||||
@@ -708,6 +708,14 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
if (!txBuilder.Verify (txReady))
|
||||
{
|
||||
// Transaction was not signed with the correct keys. This is a serious condition.
|
||||
|
||||
NotificationStrings primaryStrings = new NotificationStrings();
|
||||
primaryStrings[NotificationString.OrganizationName] = organization.Name;
|
||||
|
||||
OutboundComm.CreateNotification (organization, NotificationResource.Bitcoin_PrivateKeyError,
|
||||
primaryStrings);
|
||||
|
||||
throw new InvalidOperationException("Transaction is not signed enough");
|
||||
}
|
||||
|
||||
@@ -715,10 +723,15 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
BitcoinUtility.BroadcastTransaction (txReady);
|
||||
|
||||
// Delete inputs, adjust balance for addresses
|
||||
// Delete all old inputs, adjust balance for addresses (re-register unused inputs)
|
||||
|
||||
inputs.AsUnspents.DeleteAll();
|
||||
|
||||
foreach (BitcoinTransactionInput input in inputs)
|
||||
{
|
||||
BitcoinUtility.TestUnspents (input.BitcoinAddress);
|
||||
}
|
||||
|
||||
// Register new balance of change address, should have increased by (satoshisInput-satoshisUsed)
|
||||
|
||||
BitcoinUtility.TestUnspents (HotBitcoinAddress.OrganizationWalletZero (organization).Address);
|
||||
@@ -745,7 +758,7 @@ namespace Swarmops.Logic.Financial
|
||||
primaryStrings[NotificationString.EmbeddedPreformattedText] = spec;
|
||||
secondaryStrings["AmountFloat"] = (nativeCentsPersonLookup[personId]/100.0).ToString ("N2");
|
||||
secondaryStrings["BitcoinAmountFloat"] = (satoshiPersonLookup[personId]/100.0).ToString ("N2");
|
||||
secondaryStrings["BitcoinAddress"] = person.BitcoinPayoutAddress; // potential rare race condition
|
||||
secondaryStrings["BitcoinAddress"] = person.BitcoinPayoutAddress; // warn: potential rare race condition here
|
||||
|
||||
OutboundComm.CreateNotification (organization, NotificationResource.Bitcoin_PaidOut, primaryStrings,
|
||||
secondaryStrings, People.FromSingle(person));
|
||||
@@ -766,7 +779,7 @@ namespace Swarmops.Logic.Financial
|
||||
(new Swarmops.Logic.Financial.Money (satoshisUsed, Currency.Bitcoin).ToCurrency (
|
||||
organization.Currency).Cents/100.0).ToString ("N2", CultureInfo.InvariantCulture);
|
||||
masterSecondaryStrings["BitcoinAmountFloat"] = (satoshisUsed/100.0).ToString ("N2", CultureInfo.InvariantCulture);
|
||||
masterSecondaryStrings["PayoutCount"] = bitcoinPayouts.Count.ToString("N0", CultureInfo.InvariantCulture);
|
||||
masterSecondaryStrings["PaymentCount"] = bitcoinPayouts.Count.ToString("N0", CultureInfo.InvariantCulture);
|
||||
|
||||
OutboundComm.CreateNotification (organization, NotificationResource.Bitcoin_Hotwallet_Outflow,
|
||||
masterPrimaryStrings, masterSecondaryStrings);
|
||||
@@ -774,6 +787,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
|
||||
|
||||
masterPayout.BindToTransactionAndClose (ledgerTransaction, null);
|
||||
}
|
||||
|
||||
+18
@@ -100,6 +100,24 @@ namespace Swarmops.Logic.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to When attempting an automated payment from the hotwallet, the private key used to sign does not match the public keys used to gather the funds necessary. This is a serious condition..
|
||||
/// </summary>
|
||||
internal static string Bitcoin_PrivateKeyError_Body {
|
||||
get {
|
||||
return ResourceManager.GetString("Bitcoin_PrivateKeyError_Body", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [[OrganizationName] - URGENT] Bitcoin private key error; can't pay.
|
||||
/// </summary>
|
||||
internal static string Bitcoin_PrivateKeyError_Subject {
|
||||
get {
|
||||
return ResourceManager.GetString("Bitcoin_PrivateKeyError_Subject", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Swarmops is trying to make payments of [CurrencyCode] [AmountNeededFloat], but only [CurrencyCode] [AmountWalletFloat] is available in the bitcoin hotwallet. Swarmops is unable to make further payments at this time.
|
||||
///
|
||||
|
||||
@@ -173,6 +173,12 @@ You should already see the transaction in your wallet and it should achieve spen
|
||||
<data name="Bitcoin_PaidOut_Subject" xml:space="preserve">
|
||||
<value>[[OrganizationName]] Funds paid to you: [CurrencyCode] [AmountFloat]</value>
|
||||
</data>
|
||||
<data name="Bitcoin_PrivateKeyError_Body" xml:space="preserve">
|
||||
<value>When attempting an automated payment from the hotwallet, the private key used to sign does not match the public keys used to gather the funds necessary. This is a serious condition.</value>
|
||||
</data>
|
||||
<data name="Bitcoin_PrivateKeyError_Subject" xml:space="preserve">
|
||||
<value>[[OrganizationName] - URGENT] Bitcoin private key error; can't pay</value>
|
||||
</data>
|
||||
<data name="Bitcoin_Shortage_Critical_Body" xml:space="preserve">
|
||||
<value>Swarmops is trying to make payments of [CurrencyCode] [AmountNeededFloat], but only [CurrencyCode] [AmountWalletFloat] is available in the bitcoin hotwallet. Swarmops is unable to make further payments at this time.
|
||||
|
||||
|
||||
@@ -38,9 +38,7 @@ namespace Swarmops
|
||||
|
||||
// BEGIN TEST CODE
|
||||
|
||||
/* string[] testStrings =
|
||||
BitcoinUtility.GetInputAddressesForTransaction (
|
||||
"206a3a272d96e9cef929f88ae690c5556cee0a1e8eaca2858f8d858ee2e2cc66");*/
|
||||
// Payouts.PerformAutomated();
|
||||
|
||||
// END TEST CODE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user