More work on the bitcoin hotwallet; running into throttling at the Blockchain API
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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"])
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user