From d163901bd7c955dc9e019ddd1ffcd415c8f98f5a Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 4 Mar 2019 06:37:37 +0100 Subject: [PATCH] blockexplorer.com's cash explorer has stopped working --- Logic/Financial/BitcoinUtility.cs | 12 ++++++++---- Logic/Support/BlockchainTransaction.cs | 6 ++---- Logic/Support/SharpCashAddr.cs | 2 +- Site/Pages/v5/Financial/Donate.aspx | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Logic/Financial/BitcoinUtility.cs b/Logic/Financial/BitcoinUtility.cs index 5c1265a1..82f66665 100644 --- a/Logic/Financial/BitcoinUtility.cs +++ b/Logic/Financial/BitcoinUtility.cs @@ -597,7 +597,7 @@ namespace Swarmops.Logic.Financial case BitcoinChain.Cash: - client.UploadValues("https://bitcoincash.blockexplorer.com/api/tx/send", + client.UploadValues("https://bch-insight.bitpay.com/api/tx/send", new NameValueCollection() { {"rawtx", transaction.ToHex()} @@ -664,7 +664,7 @@ namespace Swarmops.Logic.Financial try { - string legacyAddress = BitcoinCashAddressConversion.CashAddressToLegacyAddresss(address, out dummy1, + string legacyAddress = BitcoinCashAddressConversion.CashAddressToLegacyAddress(address, out dummy1, out dummy2); // If this doesn't throw, we have a valid legacy address @@ -688,7 +688,7 @@ namespace Swarmops.Logic.Financial try { - BitcoinCashAddressConversion.CashAddressToLegacyAddresss(address, out dummy1, out dummy2); + BitcoinCashAddressConversion.CashAddressToLegacyAddress(address, out dummy1, out dummy2); // If this doesn't throw, we already have a valid bitcoincash address // Just strip the prefix if there is one @@ -820,9 +820,10 @@ namespace Swarmops.Logic.Financial public static void CheckColdStorageCash(FinancialAccount account, string bitcoinMachineAddress, Dictionary addressAccountLookup) { + string bitcoinCashAddress = EnsureCashAddressWithoutPrefix(bitcoinMachineAddress); JObject addressData = JObject.Parse( - new WebClient().DownloadString("https://bitcoincash.blockexplorer.com/api/txs/?address=" + bitcoinMachineAddress)); + new WebClient().DownloadString("https://bch-insight.bitpay.com/api/txs/?address=" + bitcoinCashAddress)); List transactionList = new List(); @@ -1271,6 +1272,9 @@ namespace Swarmops.Logic.Financial JObject feeData = JObject.Parse( new WebClient().DownloadString("https://bitcoinlegacy.blockexplorer.com/api/utils/estimatefee?nbBlocks=" + blocksWait.ToString(CultureInfo.InvariantCulture))); double feeWholeCoins = Double.Parse((string)feeData[blocksWait.ToString(CultureInfo.InvariantCulture)], NumberStyles.AllowDecimalPoint); // rounding errors are okay, don't use Formatting fn + + // TODO: I saw this function return -1 once, just once. Will need to catch that. + satoshisPerThousandBytes = Convert.ToInt64(feeWholeCoins * _satoshisPerBitcoin); } diff --git a/Logic/Support/BlockchainTransaction.cs b/Logic/Support/BlockchainTransaction.cs index 22bf438e..43d49a79 100644 --- a/Logic/Support/BlockchainTransaction.cs +++ b/Logic/Support/BlockchainTransaction.cs @@ -108,10 +108,8 @@ namespace Swarmops.Logic.Support newRow.Address = (string) json["scriptPubKey"]["addresses"][0]; } - if (newRow.Address.StartsWith("bitcoincash:")) // make sure we're using the same machine readable format - { - newRow.Address = BitcoinUtility.EnsureLegacyAddress(newRow.Address); - } + // Ensure we have a protocol-level address + newRow.Address = BitcoinUtility.EnsureLegacyAddress(newRow.Address); string valueSatoshisString = (string) json["valueSat"]; if (!string.IsNullOrEmpty(valueSatoshisString)) diff --git a/Logic/Support/SharpCashAddr.cs b/Logic/Support/SharpCashAddr.cs index 168399bc..db244628 100644 --- a/Logic/Support/SharpCashAddr.cs +++ b/Logic/Support/SharpCashAddr.cs @@ -181,7 +181,7 @@ namespace Swarmops.Logic.Support } return ret.ToString(); } - public static string CashAddressToLegacyAddresss(string cashAddress, out bool isP2PKH, out bool mainnet) { + public static string CashAddressToLegacyAddress(string cashAddress, out bool isP2PKH, out bool mainnet) { cashAddress = cashAddress.ToLower(); if (cashAddress.Length != 54 && cashAddress.Length != 42 && cashAddress.Length != 50) { if (cashAddress.StartsWith("bchreg:")) diff --git a/Site/Pages/v5/Financial/Donate.aspx b/Site/Pages/v5/Financial/Donate.aspx index f3568bd6..cb1772f0 100644 --- a/Site/Pages/v5/Financial/Donate.aspx +++ b/Site/Pages/v5/Financial/Donate.aspx @@ -2,7 +2,7 @@ <%@ Import Namespace="Swarmops.Logic.Support" %> - +