More work on the bitcoin hotwallet; running into throttling at the Blockchain API

This commit is contained in:
Rick Falkvinge
2015-10-07 23:46:51 +02:00
parent 382c4d11db
commit 02964020cc
5 changed files with 40 additions and 3 deletions
+6 -1
View File
@@ -344,6 +344,11 @@ namespace Swarmops.Common.Enums
/// <summary>
/// For cold wallets, we may prefer listing the public addresses directly
/// </summary>
BudgetBitcoinPublicAddress
BudgetBitcoinPublicAddress,
/// <summary>
/// For a bitcoin transaction, its hash on the blockchain
/// </summary>
FinancialTransactionBlockchainHash
}
}
+11 -1
View File
@@ -50,8 +50,18 @@ namespace Swarmops.Logic.Financial
bool result = false;
HotBitcoinAddress hotAddress = null;
var addressInfoResult =
JObject.Parse (
new WebClient().DownloadString (
"https://blockchain.info/address/" + address + "?format=json"));
if ((int) addressInfoResult["final_balance"] == 0)
{
return false; // no funds on address at all at this time
}
var unspentJsonResult =
JObject.Parse(new WebClient().DownloadString("https://blockchain.info/unspent?active=" + address));
JObject.Parse(new WebClient().DownloadString("https://blockchain.info/unspent?active=" + address)); // warn: will 500 if no unspent outpoints
foreach (var unspentJson in unspentJsonResult["unspent_outputs"])
{
+14
View File
@@ -145,6 +145,20 @@ namespace Swarmops.Logic.Financial
}
}
public string BlockchainHash
{
get
{
return
ObjectOptionalData.ForObject (this)
.GetOptionalDataString (ObjectOptionalDataType.FinancialTransactionBlockchainHash);
}
set
{
ObjectOptionalData.ForObject (this).SetOptionalDataString (ObjectOptionalDataType.FinancialTransactionBlockchainHash, value);
}
}
public IHasIdentity Dependency
{
set
+6 -1
View File
@@ -47,7 +47,12 @@
};
}
function checkTransactionReceived (hash) {
function checkTransactionReceived(hash) {
if (hash == null) {
hash = "";
}
SwarmopsJS.ajaxCall('/Pages/v5/Financial/Donate.aspx/CheckTransactionReceived',
{ guid: guid, txHash: hash },
function (data) {
+3
View File
@@ -31,6 +31,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.LiteralBitcoinAddress.Text = address.Address;
string guid = Guid.NewGuid().ToString ("N");
GuidCache.Set (guid, address.Address);
this.LiteralGuid.Text = guid;
// TEST TEST TEST
/*
@@ -102,6 +103,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
DateTime.UtcNow, "Donation (bitcoin to hotwallet)");
ledgerTx.AddRow (authData.CurrentOrganization.FinancialAccounts.IncomeDonations, -satoshisReceived, authData.CurrentUser);
ledgerTx.AddRow (authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, satoshisReceived, authData.CurrentUser);
ledgerTx.BlockchainHash = txHash;
if (satoshisReceived % 100 == 0)
{
@@ -123,6 +125,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
DateTime.UtcNow, "Donation (bitcoin to hotwallet)");
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.IncomeDonations, -nativeCents, authData.CurrentUser);
ledgerTx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot, nativeCents, authData.CurrentUser);
ledgerTx.BlockchainHash = txHash;
}
return new AjaxCallResult() {DisplayMessage = successMessage, Success = true};