Skip to content

Commit 204badc

Browse files
Remove dead balance APIs. the remaining 2 already support bech32 address
1 parent e6685f3 commit 204badc

File tree

5 files changed

+81
-122
lines changed

5 files changed

+81
-122
lines changed

WatchOnlyBitcoinWallet/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("3.2.0.0")]
55-
[assembly: AssemblyFileVersion("3.2.0.0")]
54+
[assembly: AssemblyVersion("3.2.1.0")]
55+
[assembly: AssemblyFileVersion("3.2.1.0")]

WatchOnlyBitcoinWallet/Services/Api.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public enum PriceServiceNames
1616
}
1717
public enum BalanceServiceNames
1818
{
19-
BlockchainInfo,
20-
BlockExplorer,
2119
BlockCypher,
2220
Blockonomics
2321
}
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Net.Http;
4-
using System.Threading.Tasks;
1+
//using System;
2+
//using System.Collections.Generic;
3+
//using System.Net.Http;
4+
//using System.Threading.Tasks;
55

6-
namespace WatchOnlyBitcoinWallet.Services.BalanceServices
7-
{
8-
public class BlockExplorer : BalanceApi
9-
{
10-
public override async Task<Response> UpdateBalancesAsync(List<Models.BitcoinAddress> addrList)
11-
{
12-
Response resp = new Response();
6+
//namespace WatchOnlyBitcoinWallet.Services.BalanceServices
7+
//{
8+
// public class BlockExplorer : BalanceApi
9+
// {
10+
// public override async Task<Response> UpdateBalancesAsync(List<Models.BitcoinAddress> addrList)
11+
// {
12+
// Response resp = new Response();
1313

14-
using (HttpClient client = new HttpClient())
15-
{
16-
foreach (var addr in addrList)
17-
{
18-
try
19-
{
20-
string result = await client.GetStringAsync("https://blockexplorer.com/api/addr/" + addr.Address + "/balance");
21-
decimal bal = Int64.Parse(result) * Satoshi;
22-
addr.Difference = bal - addr.Balance;
23-
addr.Balance = bal;
24-
}
25-
catch (Exception ex)
26-
{
27-
string errMsg = (ex.InnerException == null) ? ex.Message : ex.Message + " " + ex.InnerException;
28-
resp.Errors.Add(errMsg);
29-
break;
30-
}
31-
}
32-
}
14+
// using (HttpClient client = new HttpClient())
15+
// {
16+
// foreach (var addr in addrList)
17+
// {
18+
// try
19+
// {
20+
// string result = await client.GetStringAsync("https://blockexplorer.com/api/addr/" + addr.Address + "/balance");
21+
// decimal bal = Int64.Parse(result) * Satoshi;
22+
// addr.Difference = bal - addr.Balance;
23+
// addr.Balance = bal;
24+
// }
25+
// catch (Exception ex)
26+
// {
27+
// string errMsg = (ex.InnerException == null) ? ex.Message : ex.Message + " " + ex.InnerException;
28+
// resp.Errors.Add(errMsg);
29+
// break;
30+
// }
31+
// }
32+
// }
3333

34-
return resp;
35-
}
34+
// return resp;
35+
// }
3636

37-
public override Task<Response> UpdateTransactionListAsync(List<Models.BitcoinAddress> addrList)
38-
{
39-
throw new NotImplementedException();
40-
}
37+
// public override Task<Response> UpdateTransactionListAsync(List<Models.BitcoinAddress> addrList)
38+
// {
39+
// throw new NotImplementedException();
40+
// }
4141

42-
}
43-
}
42+
// }
43+
//}
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
using Newtonsoft.Json.Linq;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Threading.Tasks;
5-
using WatchOnlyBitcoinWallet.Models;
1+
//using Newtonsoft.Json.Linq;
2+
//using System;
3+
//using System.Collections.Generic;
4+
//using System.Threading.Tasks;
5+
//using WatchOnlyBitcoinWallet.Models;
66

7-
namespace WatchOnlyBitcoinWallet.Services.BalanceServices
8-
{
9-
public class BlockchainInfo : BalanceApi
10-
{
11-
public override async Task<Response> UpdateBalancesAsync(List<BitcoinAddress> addrList)
12-
{
13-
Response resp = new Response();
14-
foreach (var addr in addrList)
15-
{
16-
string url = "https://blockchain.info/address/" + addr.Address + "?format=json&limit=0";
17-
Response<JObject> apiResp = await SendApiRequestAsync(url);
18-
if (apiResp.Errors.Any())
19-
{
20-
resp.Errors.AddRange(apiResp.Errors);
21-
break;
22-
}
23-
decimal bal = (Int64)apiResp.Result["final_balance"] * Satoshi;
24-
addr.Difference = bal - addr.Balance;
25-
addr.Balance = bal;
26-
}
27-
return resp;
28-
}
7+
//namespace WatchOnlyBitcoinWallet.Services.BalanceServices
8+
//{
9+
// public class BlockchainInfo : BalanceApi
10+
// {
11+
// public override async Task<Response> UpdateBalancesAsync(List<BitcoinAddress> addrList)
12+
// {
13+
// Response resp = new Response();
14+
// foreach (var addr in addrList)
15+
// {
16+
// string url = "https://blockchain.info/address/" + addr.Address + "?format=json&limit=0";
17+
// Response<JObject> apiResp = await SendApiRequestAsync(url);
18+
// if (apiResp.Errors.Any())
19+
// {
20+
// resp.Errors.AddRange(apiResp.Errors);
21+
// break;
22+
// }
23+
// decimal bal = (Int64)apiResp.Result["final_balance"] * Satoshi;
24+
// addr.Difference = bal - addr.Balance;
25+
// addr.Balance = bal;
26+
// }
27+
// return resp;
28+
// }
2929

30-
public override Task<Response> UpdateTransactionListAsync(List<BitcoinAddress> addrList)
31-
{
32-
throw new System.NotImplementedException();
33-
}
30+
// public override Task<Response> UpdateTransactionListAsync(List<BitcoinAddress> addrList)
31+
// {
32+
// throw new System.NotImplementedException();
33+
// }
3434

35-
}
36-
}
35+
// }
36+
//}

WatchOnlyBitcoinWallet/ViewModels/MainWindowViewModel.cs

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -210,67 +210,28 @@ private async void GetBalance()
210210
BalanceApi api = null;
211211
switch (SettingsInstance.SelectedBalanceApi)
212212
{
213-
case BalanceServiceNames.BlockchainInfo:
214-
api = new BlockchainInfo();
215-
break;
216-
case BalanceServiceNames.BlockExplorer:
217-
api = new BlockExplorer();
218-
break;
219213
case BalanceServiceNames.BlockCypher:
220214
api = new BlockCypher();
221215
break;
222216
case BalanceServiceNames.Blockonomics:
223217
api = new Blockonomics();
224218
break;
225219
default:
226-
api = new BlockchainInfo();
220+
api = new BlockCypher();
227221
break;
228222
}
229223

230-
// Not all exchanges support Bech32 addresses!
231-
// The following "if" is to solve that.
232-
bool hasSegWit = AddressList.Any(x => x.Address.StartsWith("bc1", System.StringComparison.InvariantCultureIgnoreCase));
233-
if (hasSegWit && !SettingsInstance.SelectedBalanceApi.Equals(BalanceServiceNames.Blockonomics))
224+
Response resp = await api.UpdateBalancesAsync(AddressList.ToList());
225+
if (resp.Errors.Any())
234226
{
235-
BalanceApi segApi = new Blockonomics();
236-
List<BitcoinAddress> legacyAddrs = new List<BitcoinAddress>(AddressList.Where(x =>
237-
!x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase)));
238-
List<BitcoinAddress> segWitAddrs = new List<BitcoinAddress>(AddressList.Where(x =>
239-
x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase)));
240-
241-
Response respSW = await segApi.UpdateBalancesAsync(segWitAddrs);
242-
if (respSW.Errors.Any())
243-
{
244-
Errors = "SegWit API error: " + respSW.Errors.GetErrors();
245-
Status = "Error in SegWit API! Continue updating legacy balances...";
246-
}
247-
Response resp = await api.UpdateBalancesAsync(legacyAddrs);
248-
if (resp.Errors.Any())
249-
{
250-
Errors = resp.Errors.GetErrors();
251-
Status = "Encountered an error!";
252-
}
253-
else
254-
{
255-
DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
256-
RaisePropertyChanged("BitcoinBalance");
257-
Status = "Balance Update Success!";
258-
}
227+
Errors = resp.Errors.GetErrors();
228+
Status = "Encountered an error!";
259229
}
260230
else
261231
{
262-
Response resp = await api.UpdateBalancesAsync(AddressList.ToList());
263-
if (resp.Errors.Any())
264-
{
265-
Errors = resp.Errors.GetErrors();
266-
Status = "Encountered an error!";
267-
}
268-
else
269-
{
270-
DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
271-
RaisePropertyChanged("BitcoinBalance");
272-
Status = "Balance Update Success!";
273-
}
232+
DataManager.WriteFile(AddressList, DataManager.FileType.Wallet);
233+
RaisePropertyChanged("BitcoinBalance");
234+
Status = "Balance Update Success!";
274235
}
275236

276237
IsReceiving = false;

0 commit comments

Comments
 (0)