Db0026; work on hotwallet
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Swarmops.Database
|
||||
/// </summary>
|
||||
public static int DbVersionExpected
|
||||
{
|
||||
get { return 25; }
|
||||
get { return 26; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,4 +20,7 @@
|
||||
0020 - Added concurrency check to TerminatePositionAssignment [RF]
|
||||
0021 - Added PositionCustomTitles and its stored procedures [RF]
|
||||
0022 - Added VolunteerPositions and its stored procedures [RF]
|
||||
0023 - Added procs to change Facebook, Twitter, GPlus IDs [RF]
|
||||
0023 - Added procs to change Facebook, Twitter, GPlus IDs [RF]
|
||||
0024 - Maint on CreatePayrollItem [RF]
|
||||
0025 - Bugfix for 0024 [RF]
|
||||
0026 - Added first tables, procs for hot bitcoin wallets [RF]
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
CREATE TABLE `HotBitcoinAddresses` (
|
||||
`HotBitcoinAddressId` INT NOT NULL AUTO_INCREMENT,
|
||||
`OrganizationId` INT NOT NULL,
|
||||
`DerivationPath` VARCHAR(256) NOT NULL,
|
||||
`AddressString` VARCHAR(48) NOT NULL,
|
||||
`BalanceSatoshis` BIGINT NOT NULL,
|
||||
`ThroughputSatoshis` BIGINT NOT NULL,
|
||||
PRIMARY KEY (`HotBitcoinAddressId`),
|
||||
INDEX `Ix_Organization` (`OrganizationId` ASC),
|
||||
INDEX `Ix_Balance` (`BalanceSatoshis` ASC),
|
||||
INDEX `Ix_Used` (`ThroughputSatoshis` ASC))
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE TABLE `HotBitcoinAddressUnspents` (
|
||||
`HotBitcoinAddressUnspentId` INT NOT NULL AUTO_INCREMENT,
|
||||
`AmountSatoshis` BIGINT NOT NULL,
|
||||
`TransactionHash` VARCHAR(128) NOT NULL,
|
||||
`TransactionOutputIndex` INT NOT NULL,
|
||||
`ConfirmationCount` INT NOT NULL,
|
||||
PRIMARY KEY (`HotBitcoinAddressUnspentId`),
|
||||
INDEX `Ix_Confirmations` (`ConfirmationCount` ASC),
|
||||
INDEX `Ix_Amount` (`AmountSatoshis` ASC),
|
||||
INDEX `Ix_TxHash` (`TransactionHash` ASC))
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `CreateHotBitcoinAddress`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `CreateHotBitcoinAddress` (
|
||||
IN organizationId INT,
|
||||
IN derivationPath VARCHAR(256),
|
||||
IN addressString VARCHAR(48)
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO HotBitcoinAddresses
|
||||
(OrganizationId,DerivationPath,AddressString,BalanceSatoshis,ThroughputSatoshis)
|
||||
VALUES
|
||||
(organizationId,derivationPath,addressString,0,0);
|
||||
|
||||
SELECT LAST_INSERT_ID() AS Identity;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `SetHotBitcoinAddressBalance`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetHotBitcoinAddressBalance` (
|
||||
IN hotBitcoinAddressId INT,
|
||||
IN balanceSatoshis BIGINT
|
||||
)
|
||||
BEGIN
|
||||
UPDATE HotBitcoinAddresses
|
||||
SET HotBitcoinAddresses.BalanceSatoshis=balanceSatoshis
|
||||
WHERE HotBitcoinAddresses.HotBitcoinAddressId=hotBitcoinAddressId;
|
||||
|
||||
SELECT ROW_COUNT() AS RowsUpdated;
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `SetHotBitcoinAddressThroughput`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetHotBitcoinAddressThroughput` (
|
||||
IN hotBitcoinAddressId INT,
|
||||
IN throughputSatoshis BIGINT
|
||||
)
|
||||
BEGIN
|
||||
UPDATE HotBitcoinAddresses
|
||||
SET HotBitcoinAddresses.ThroughputSatoshis=throughputSatoshis
|
||||
WHERE HotBitcoinAddresses.HotBitcoinAddressId=hotBitcoinAddressId;
|
||||
|
||||
SELECT ROW_COUNT() AS RowsUpdated;
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `CreateHotBitcoinAddressUnspent`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `CreateHotBitcoinAddressUnspent` (
|
||||
IN amountSatoshis BIGINT,
|
||||
IN transactionHash VARCHAR(128),
|
||||
IN transactionOutputIndex INT,
|
||||
IN confirmationCount INT
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO HotBitcoinAddressUnspent
|
||||
(AmountSatoshis,TransactionHash,TransactionOutputIndex,ConfirmationCount)
|
||||
VALUES
|
||||
(amountSatoshis,transactionHash,transactionOutputIndex,confirmationCount);
|
||||
|
||||
SELECT LAST_INSERT_ID() AS Identity;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `SetHotBitcoinAddressUnspentConfirmations`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetHotBitcoinAddressUnspentConfirmations` (
|
||||
IN hotBitcoinAddressUnspentId INT,
|
||||
IN confirmationCount INT
|
||||
)
|
||||
BEGIN
|
||||
UPDATE HotBitcoinAddressUnspents
|
||||
SET HotBitcoinAddressUnspents.ConfirmationCount=confirmationCount
|
||||
WHERE HotBitcoinAddressUnspents.HotBitcoinAddressUnspentId=hotBitcoinAddressUnspentId;
|
||||
|
||||
SELECT ROW_COUNT() AS RowsUpdated;
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `DeleteHotBitcoinAddressUnspent`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `DeleteHotBitcoinAddressUnspent` (
|
||||
IN hotBitcoinAddressUnspentId INT
|
||||
)
|
||||
BEGIN
|
||||
DELETE FROM HotBitcoinAddressUnspents
|
||||
WHERE HotBitcoinAddressUnspents.HotBitcoinAddressUnspentId=hotBitcoinAddressUnspentId;
|
||||
|
||||
SELECT ROW_COUNT() AS RowsDeleted;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using NBitcoin;
|
||||
using NBitcoin.BouncyCastle.Asn1.Ocsp;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Swarmops.Logic.Financial
|
||||
@@ -34,11 +37,31 @@ namespace Swarmops.Logic.Financial
|
||||
TransactionOutputIndex = (UInt32) unspentJson["tx_output_n"]
|
||||
};
|
||||
|
||||
coinList.Add (txUnspent);
|
||||
coinList.Add (txUnspent); // invokes implicit conversion to NBitcoin.Coin
|
||||
}
|
||||
|
||||
return coinList.ToArray();
|
||||
}
|
||||
|
||||
static public void BroadcastTransaction (Transaction transaction)
|
||||
{
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
byte[] response = client.UploadValues("https://blockchain.info/pushtx?cors=true", new NameValueCollection()
|
||||
{
|
||||
{ "tx", transaction.ToHex() }
|
||||
});
|
||||
|
||||
// TODO: Exception handling
|
||||
}
|
||||
}
|
||||
|
||||
public const int BitcoinWalletIndex = 1;
|
||||
public const int BitcoinDonationsIndex = 2;
|
||||
public const int BitcoinLoansIndex = 3;
|
||||
public const int BitcoinAccountsReceivableIndex = 4;
|
||||
|
||||
public const string BitcoinTestAddress = "1JMpU3D6c5sruunMwzkt6p6PQzLcUYcL26";
|
||||
}
|
||||
|
||||
internal class BitcoinUnspentTransactionOutput
|
||||
|
||||
@@ -249,9 +249,5 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
public const int BitcoinWalletIndex = 1;
|
||||
public const int BitcoinDonationsIndex = 2;
|
||||
|
||||
public const string BitcoinTestAddress = "1JMpU3D6c5sruunMwzkt6p6PQzLcUYcL26";
|
||||
}
|
||||
}
|
||||
+18
@@ -60,6 +60,24 @@ namespace Swarmops.Logic.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [BitcoinAmount] millicoin was just transferred to your address by [OrganizationName]..
|
||||
/// </summary>
|
||||
internal static string Bitcoin_PaidOut_Body {
|
||||
get {
|
||||
return ResourceManager.GetString("Bitcoin_PaidOut_Body", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to [[OrganizationName]] Funds paid using bitcoin: [CurrencyCode] [BudgetAmountFloat].
|
||||
/// </summary>
|
||||
internal static string Bitcoin_PaidOut_Subject {
|
||||
get {
|
||||
return ResourceManager.GetString("Bitcoin_PaidOut_Subject", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 48 hours.
|
||||
///
|
||||
|
||||
@@ -149,6 +149,12 @@ If you did not set this payout address (it may be worth double checking the addr
|
||||
<data name="BitcoinPayoutAddress_Set_Subject" xml:space="preserve">
|
||||
<value>[[OrganizationName]] Bitcoin payout address set</value>
|
||||
</data>
|
||||
<data name="Bitcoin_PaidOut_Body" xml:space="preserve">
|
||||
<value>[BitcoinAmount] millicoin was just transferred to your address by [OrganizationName].</value>
|
||||
</data>
|
||||
<data name="Bitcoin_PaidOut_Subject" xml:space="preserve">
|
||||
<value>[[OrganizationName]] Funds paid using bitcoin: [CurrencyCode] [BudgetAmountFloat]</value>
|
||||
</data>
|
||||
<data name="CashAdvance_Attested_Body" xml:space="preserve">
|
||||
<value>Your requested cash advance with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat], concerning [RequestPurpose], has been attested by the budget owner. It will now proceed to payout to you.</value>
|
||||
</data>
|
||||
|
||||
@@ -335,6 +335,14 @@
|
||||
<data name="Donate_PageTitle" xml:space="preserve">
|
||||
<value>Donate</value>
|
||||
</data>
|
||||
<data name="Donate_TxLabel" xml:space="preserve">
|
||||
<value>Donation to {0}</value>
|
||||
<comment>The {0} is the organization name</comment>
|
||||
</data>
|
||||
<data name="Donate_TxLabel_Loan" xml:space="preserve">
|
||||
<value>Loan to {0}</value>
|
||||
<comment>The {0} is the organization name</comment>
|
||||
</data>
|
||||
<data name="FileExpenseClaim_Amount" xml:space="preserve">
|
||||
<value>Expense claim amount (in {0})</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
string bitcoinAddress =
|
||||
FinancialAccounts.BitcoinHotPublicRoot
|
||||
.Derive ((uint) this.CurrentOrganization.Identity)
|
||||
.Derive (FinancialAccounts.BitcoinDonationsIndex)
|
||||
.Derive (BitcoinUtility.BitcoinDonationsIndex)
|
||||
.Derive ((uint) this.CurrentUser.Identity)
|
||||
.PubKey.GetAddress (Network.Main)
|
||||
.ToString();
|
||||
@@ -31,7 +31,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
/*
|
||||
BitcoinSecret secretKey =
|
||||
FinancialAccounts.BitcoinHotPrivateRoot.Derive ((uint) this.CurrentOrganization.Identity)
|
||||
.Derive (FinancialAccounts.BitcoinDonationsIndex)
|
||||
.Derive (BitcoinUtility.BitcoinDonationsIndex)
|
||||
.Derive ((uint) this.CurrentUser.Identity)
|
||||
.PrivateKey
|
||||
.GetBitcoinSecret (Network.Main);
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
TransactionBuilder txBuild = new TransactionBuilder();
|
||||
Transaction tx = txBuild.AddCoins (spendableCoin)
|
||||
.AddKeys (secretKey)
|
||||
.Send (new BitcoinAddress (FinancialAccounts.BitcoinTestAddress), "0.001")
|
||||
.Send (new BitcoinAddress (BitcoinUtility.BitcoinTestAddress), "0.001")
|
||||
.SendFees ("0.0001")
|
||||
.SetChange (secretKey.GetAddress())
|
||||
.BuildTransaction (true);
|
||||
@@ -51,13 +52,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
throw new InvalidOperationException("Tx is not properly signed");
|
||||
}
|
||||
|
||||
string txHex = tx.ToHex();*/
|
||||
BitcoinUtility.BroadcastTransaction (tx);*/
|
||||
|
||||
this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle;
|
||||
this.LabelExplainBitcoinDonation.Text = String.Format(Resources.Pages.Financial.Donate_Explain, CurrentOrganization.Name, bitcoinAddress);
|
||||
|
||||
this.ImageBitcoinQr.ImageUrl =
|
||||
"https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoin:" + HttpUtility.UrlEncode(bitcoinAddress + "?label=" + CurrentOrganization.Name.Replace ("&","et").Replace ("=", string.Empty)); // URI scheme doesn't like &, =
|
||||
"https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=bitcoin:" + HttpUtility.UrlEncode(bitcoinAddress + "?label=" + Uri.EscapeDataString(String.Format(Resources.Pages.Financial.Donate_TxLabel, CurrentOrganization.Name))); // URI scheme doesn't like &, =
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user