<% } %>
diff --git a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx
index b18d9d92..9b75f2a0 100644
--- a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx
+++ b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx
@@ -2,96 +2,123 @@
<%@ Import Namespace="Swarmops.Logic.Support" %>
+
+
+
+
+
+
0.001
+
Received in echo test (<%=CurrentOrganization.Currency.DisplayCode %>)
+
+
+
+
-0.001
+
Miner fees paid
+
+
+
+
0.001
+
Successfully returned
+
+
+
+
+
+
+
-
+
Bitcoin hotwallet is not enabled

- This organization has not enabled its bitcoin hotwallet in Swarmops. Therefore, direct donations are not available.
+ This organization has not enabled its bitcoin hotwallet in Swarmops. Therefore, echo tests are not available.
Contact the administrator for <%=this.CurrentOrganization.Name %> and ask them to enable the bitcoin hotwallet.
+
diff --git a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs
index 8e3e963d..98db4711 100644
--- a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs
+++ b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs
@@ -10,6 +10,8 @@ using System.Web.UI.WebControls;
using NBitcoin;
using Swarmops.Common.Enums;
using Swarmops.Logic.Cache;
+using Swarmops.Logic.Communications;
+using Swarmops.Logic.Communications.Payload;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
@@ -25,74 +27,56 @@ namespace Swarmops.Frontend.Pages.v5.Admin
// This page is copied from Donate, with the echo payout added to the end
-
- /* TEMP TEMP TEMP - REMOVE THIS CODE */
- /*
- Organization fwn = Organization.FromIdentity (2);
-
- Salaries salaries = Salaries.ForOrganization (fwn);
- foreach (Salary salary in salaries)
- {
- if (salary.PayrollItem.Person.BitcoinPayoutAddress.Length > 0 && salary.Attested == false)
- {
- salary.Attest (salary.PayrollItem.Person); // null for system apparently isn't allowed here
- }
- }*/
-
this.PageTitle = Resources.Pages.Admin.BitcoinEchoTest_PageTitle;
this.InfoBoxLiteral = Resources.Pages.Admin.BitcoinEchoTest_Info;
this.LabelStatus.Text = Resources.Pages.Admin.BitcoinEchoTest_StatusInitial;
- this.LiteralTxDetected.Text = JavascriptEscape (Resources.Pages.Admin.BitcoinEchoTest_TransactionDetected);
+ this.SuppressStatisticHeaders = true;
if (this.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot == null)
{
this.PanelDisabled.Visible = true;
this.PanelEnabled.Visible = false;
- this.LiteralEnable.Text = @"false";
}
- HotBitcoinAddress address = HotBitcoinAddress.Create (this.CurrentOrganization, BitcoinChain.Cash,
- BitcoinUtility.BitcoinDonationsIndex, this.CurrentUser.Identity);
+ HotBitcoinAddress address = HotBitcoinAddress.Create(this.CurrentOrganization, BitcoinChain.Cash,
+ BitcoinUtility.BitcoinEchoTestIndex, this.CurrentUser.Identity);
- this.LiteralBitcoinAddress.Text = address.Address;
- string guid = Guid.NewGuid().ToString ("N");
- GuidCache.Set (guid, address.Address);
- this.LiteralGuid.Text = guid;
+ this.BitcoinCashAddressUsed = address.Address;
+ string guid = Guid.NewGuid().ToString("N");
+ GuidCache.Set(guid, address.Address);
+ this.TransactionGuid = guid;
- // TEST TEST TEST
- /*
- BitcoinSecret secretKey = address.PrivateKey;
- Coin[] spendableCoin = BitcoinUtility.GetSpendableCoin (secretKey);
+ // Calculate conversion rate (satoshi-cents to unit-cents, so we're good, even if the conversion rate
+ // is calculated on microbitcoin to whole units)
- TransactionBuilder txBuild = new TransactionBuilder();
- Transaction tx = txBuild.AddCoins (spendableCoin)
- .AddKeys (secretKey)
- .Send (new BitcoinAddress (BitcoinUtility.BitcoinTestAddress), new Satoshis (address.UnspentSatoshis - BitcoinUtility.FeeSatoshisPerThousandBytes))
- .SendFees (new Satoshis(BitcoinUtility.FeeSatoshisPerThousandBytes))
- .SetChange (secretKey.GetAddress())
- .BuildTransaction (true);
+ this.ConversionRateSatoshisToCents = Currency.BitcoinCash.GetConversionRate(CurrentOrganization.Currency);
- bool test = txBuild.Verify (tx);
- if (!test)
- {
- throw new InvalidOperationException("Tx is not properly signed");
- }
+ // BEGIN TEST CODE
- BitcoinUtility.BroadcastTransaction (tx);*/
+ // END TEST CODE
- this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle;
- this.LabelExplainBitcoinDonation.Text = String.Format (Resources.Pages.Financial.Donate_Explain,
+ this.BoxTitle.Text = Resources.Pages.Admin.BitcoinEchoTest_PageTitle;
+ this.LabelExplainBitcoinEchoTest.Text = String.Format (Resources.Pages.Admin.BitcoinEchoTest_Explain,
CurrentOrganization.Name, address.Address);
this.ImageBitcoinQr.ImageUrl =
"https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoincash:" +
HttpUtility.UrlEncode (address.Address + "?label=" +
- Uri.EscapeDataString (String.Format (Resources.Pages.Financial.Donate_TxLabel,
- CurrentOrganization.Name))); // URI scheme doesn't like &, =
+ Uri.EscapeDataString ("Swarmops Bitcoin Echo Test")); // URI scheme doesn't like &, =
}
+
+ public static Int64 EchoFeeSatoshis
+ {
+ get { return BitcoinUtility.EchoFeeSatoshis; }
+ }
+
+ public string BitcoinCashAddressUsed { get; private set; }
+ public string TransactionGuid { get; private set; }
+ public double ConversionRateSatoshisToCents { get; private set; }
+
[WebMethod]
- static public AjaxCallResult CheckTransactionReceived (string guid, string txHash)
+ static public AjaxCallResult ProcessTransactionReceived (string guid, string txHash)
{
AuthenticationData authData = GetAuthenticationDataAndCulture(); // just to make sure we're called properly
BitcoinChain chain = BitcoinChain.Cash;
@@ -101,9 +85,6 @@ namespace Swarmops.Frontend.Pages.v5.Admin
if (BitcoinUtility.TestUnspents (chain, bitcoinAddress))
{
HotBitcoinAddressUnspents unspents = HotBitcoinAddress.FromAddress (chain, bitcoinAddress).Unspents;
-
- // TODO: Update the HotBitcoinAddress with the new amount?
-
Int64 satoshisReceived = unspents.Last().AmountSatoshis;
if (unspents.Last().TransactionHash != txHash && txHash.Length > 0)
@@ -112,28 +93,96 @@ namespace Swarmops.Frontend.Pages.v5.Admin
Debugger.Break();
}
+ HotBitcoinAddressUnspent utxoToReturn = unspents.Last();
+
Swarmops.Logic.Financial.Money moneyReceived = new Swarmops.Logic.Financial.Money(satoshisReceived,
- Currency.BitcoinCore);
+ Currency.BitcoinCash);
// Make sure that the hotwallet native currency is bitcoin
- authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.ForeignCurrency = Currency.BitcoinCore;
+ authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.ForeignCurrency = Currency.BitcoinCash;
// Create success message and ledger transaction
string successMessage = string.Empty;
// TODO: Get the tx, get the input
- string returnAddress = BitcoinUtility.GetInputAddressesForTransaction(BitcoinUtility.GetNetworkFromChain(chain), txHash) [0]; // assumes at least one input address
+ string returnAddress = BitcoinUtility.GetInputAddressesForTransaction(chain, txHash) [0]; // assumes at least one input address
+
+ // Return the money, too. Set fee for a 300-byte transaction.
+
+ TransactionBuilder txBuilder = new TransactionBuilder();
+ txBuilder = txBuilder.SendFees(new Satoshis(EchoFeeSatoshis));
+ txBuilder = txBuilder.AddCoins(utxoToReturn.AsInputs.Coins);
+ txBuilder = txBuilder.AddKeys(utxoToReturn.AsInputs.PrivateKeys);
+
+ // change address equals return address, although it should be empty
+
+ if (returnAddress.StartsWith("1")) // regular address
+ {
+ txBuilder = txBuilder.Send(new BitcoinPubKeyAddress(returnAddress),
+ new Satoshis(satoshisReceived - EchoFeeSatoshis));
+ txBuilder.SetChange(new BitcoinPubKeyAddress(returnAddress));
+ }
+ else if (returnAddress.StartsWith("3")) // multisig
+ {
+ txBuilder = txBuilder.Send(new BitcoinScriptAddress(returnAddress, Network.Main),
+ new Satoshis(satoshisReceived - EchoFeeSatoshis));
+ txBuilder.SetChange(new BitcoinScriptAddress(returnAddress, Network.Main));
+ }
+
+
+
+ // Sign transaction - ready to execute
+
+ Transaction txReady = txBuilder.BuildTransaction(true);
+
+ // Verify that transaction is ready
+
+ if (!txBuilder.Verify(txReady))
+ {
+ // Transaction was not signed with the correct keys. This is a serious condition.
+
+ NotificationStrings primaryStrings = new NotificationStrings();
+ primaryStrings[NotificationString.OrganizationName] = authData.CurrentOrganization.Name;
+
+ OutboundComm.CreateNotification(authData.CurrentOrganization, NotificationResource.Bitcoin_PrivateKeyError,
+ primaryStrings);
+
+ throw new InvalidOperationException("Transaction is not signed enough");
+ }
+
+ // Broadcast transaction
+
+ BitcoinUtility.BroadcastTransaction(txReady, BitcoinChain.Cash);
+
+ // Note the transaction hash
+
+ string returnTxHash = txReady.GetHash().ToString();
+
+ // Delete all old inputs, adjust balance for addresses (re-register unused inputs)
+
+ utxoToReturn.Delete();
+ HotBitcoinAddresses.UpdateAllUnspentTotals();
+
+ string tx1Description = "Bitcoin technical echo test (will be repaid immediately)";
+ string tx2Description = "Bitcoin echo test repayment";
+
if (authData.CurrentOrganization.Currency.IsBitcoinCash)
{
// The ledger is native bitcoin, so cent units are satoshis
- FinancialTransaction ledgerTx = FinancialTransaction.Create (authData.CurrentOrganization,
- DateTime.UtcNow, "Bitcoin echo test (will be repaid immediately)");
- ledgerTx.AddRow (authData.CurrentOrganization.FinancialAccounts.DebtsOther, -satoshisReceived, authData.CurrentUser);
- ledgerTx.AddRow (authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, satoshisReceived, authData.CurrentUser);
- ledgerTx.BlockchainHash = txHash;
+ FinancialTransaction ledgerTx1 = FinancialTransaction.Create(authData.CurrentOrganization,
+ DateTime.UtcNow, tx1Description);
+ ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, -(satoshisReceived), authData.CurrentUser);
+ ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, satoshisReceived, authData.CurrentUser);
+ ledgerTx1.BlockchainHash = txHash;
+
+ FinancialTransaction ledgerTx2 = FinancialTransaction.Create(authData.CurrentOrganization,
+ DateTime.UtcNow, tx2Description);
+ ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, satoshisReceived, authData.CurrentUser);
+ ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, -satoshisReceived, authData.CurrentUser);
+ ledgerTx2.BlockchainHash = returnTxHash;
if (satoshisReceived % 100 == 0)
{
@@ -146,24 +195,30 @@ namespace Swarmops.Frontend.Pages.v5.Admin
(satoshisReceived / 100.0).ToString("N2"));
}
- // TODO: Log the payout back, as an inbound invoice for immediate payout
+ // TODO: Second tx
}
else
{
// The ledger is NOT native bitcoin, so we'll need to convert currencies
- long orgNativeCents = moneyReceived.ToCurrency (authData.CurrentOrganization.Currency).Cents;
- FinancialTransaction ledgerTx = FinancialTransaction.Create(authData.CurrentOrganization,
- DateTime.UtcNow, "Bitcoin echo test (will be repaid immediately)");
- ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, -orgNativeCents, authData.CurrentUser);
- ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.BitcoinCash);
- ledgerTx.BlockchainHash = txHash;
+ long orgNativeCents = moneyReceived.ToCurrency(authData.CurrentOrganization.Currency).Cents;
+ FinancialTransaction ledgerTx1 = FinancialTransaction.Create(authData.CurrentOrganization,
+ DateTime.UtcNow, tx1Description);
+ ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, -orgNativeCents, authData.CurrentUser);
+ ledgerTx1.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(satoshisReceived, Currency.BitcoinCash);
+ ledgerTx1.BlockchainHash = txHash;
+
+ FinancialTransaction ledgerTx2 = FinancialTransaction.Create(authData.CurrentOrganization,
+ DateTime.UtcNow, tx2Description);
+ ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsOther, orgNativeCents, authData.CurrentUser);
+ ledgerTx2.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, -orgNativeCents, authData.CurrentUser).AmountForeignCents = new Swarmops.Logic.Financial.Money(-satoshisReceived, Currency.BitcoinCash);
+ ledgerTx2.BlockchainHash = returnTxHash;
successMessage = string.Format(Resources.Pages.Admin.BitcoinEchoTest_FundsReceived,
authData.CurrentOrganization.Currency.DisplayCode, orgNativeCents/100.0, satoshisReceived/100.0);
- // TODO: Create a payout back for this amount -- needs to be specified in bitcoin cash -- as an inbound invoice
+ // TODO: Second tx
}
return new AjaxCallResult() {DisplayMessage = successMessage, Success = true};
@@ -174,5 +229,11 @@ namespace Swarmops.Frontend.Pages.v5.Admin
return new AjaxCallResult() {Success = false};
}
+
+ public string Localized_Verifying
+ {
+ get { return CommonV5.JavascriptEscape(Resources.Pages.Financial.Donate_TransactionDetected); }
+ }
+
}
}
\ No newline at end of file
diff --git a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.designer.cs b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.designer.cs
index b3d800ab..cd607863 100644
--- a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.designer.cs
+++ b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.designer.cs
@@ -12,42 +12,6 @@ namespace Swarmops.Frontend.Pages.v5.Admin {
public partial class BitcoinEchoTest {
- ///
- /// LiteralTxDetected control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.Literal LiteralTxDetected;
-
- ///
- /// LiteralBitcoinAddress control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.Literal LiteralBitcoinAddress;
-
- ///
- /// LiteralGuid control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.Literal LiteralGuid;
-
- ///
- /// LiteralEnable control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.Literal LiteralEnable;
-
///
/// PanelEnabled control.
///
@@ -67,13 +31,13 @@ namespace Swarmops.Frontend.Pages.v5.Admin {
protected global::System.Web.UI.WebControls.Label BoxTitle;
///
- /// LabelExplainBitcoinDonation control.
+ /// LabelExplainBitcoinEchoTest control.
///
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
- protected global::System.Web.UI.WebControls.Label LabelExplainBitcoinDonation;
+ protected global::System.Web.UI.WebControls.Label LabelExplainBitcoinEchoTest;
///
/// LabelStatus control.
diff --git a/Site/Pages/v5/Financial/Donate.aspx b/Site/Pages/v5/Financial/Donate.aspx
index d7a6a3d5..c3d200ad 100644
--- a/Site/Pages/v5/Financial/Donate.aspx
+++ b/Site/Pages/v5/Financial/Donate.aspx
@@ -28,8 +28,9 @@
if (outAddress == pageDonationAddress) {
+ $('#paraStatus').text(verifyingText);
var donatedSatoshis = data.vout[index][outAddress];
- donatedFunds += (donatedSatoshis * conversionRateSatoshisToCents / 100.0);
+ donatedFunds += Math.floor((donatedSatoshis * conversionRateSatoshisToCents) / 100.0);
odoDonatedCents.innerHTML = donatedFunds; // looks weird but $('#id') not used with odo
var json = {};
@@ -94,6 +95,7 @@
var donatedFunds = 0.001; // the 0.1 cents are necessary for an odometer workaround
var pageDonationAddress = SwarmopsJS.unescape('<%=this.BitcoinCashAddressUsed %>');
+ var verifyingText = SwarmopsJS.unescape('<%=this.Localized_Verifying%>');
var guid = SwarmopsJS.unescape('<%=this.TransactionGuid%>');
var conversionRateSatoshisToCents = <%= this.ConversionRateSatoshisToCents %>;
var completed = false;
diff --git a/Site/Pages/v5/Financial/Donate.aspx.cs b/Site/Pages/v5/Financial/Donate.aspx.cs
index 3be5e710..31fecb43 100644
--- a/Site/Pages/v5/Financial/Donate.aspx.cs
+++ b/Site/Pages/v5/Financial/Donate.aspx.cs
@@ -196,5 +196,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial
return new AjaxCallResult() {Success = false};
}
+
+
+ // -- Localizations below --
+
+ public string Localized_Verifying
+ {
+ get { return CommonV5.JavascriptEscape(Resources.Pages.Financial.Donate_TransactionDetected); }
+ }
}
}
\ No newline at end of file
diff --git a/Site/Site.csproj b/Site/Site.csproj
index 18d227c5..8f60f94e 100644
--- a/Site/Site.csproj
+++ b/Site/Site.csproj
@@ -51,8 +51,9 @@
True
-
- ..\External Libraries\NBitcoinDual.dll
+
+ ..\packages\NBitcoinBCC.1.0.16\lib\netstandard1.1\NBitcoinBCC.dll
+ True
..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
@@ -66,6 +67,14 @@
..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll
True
+
+
+
+
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+ True
+
diff --git a/Site/packages.config b/Site/packages.config
index 8f0560c1..5e345036 100644
--- a/Site/packages.config
+++ b/Site/packages.config
@@ -2,8 +2,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file