Skip to content

Commit

Permalink
Version 0.11.0:
Browse files Browse the repository at this point in the history
Remove dead APIs
Introduce new API using Blockchair.com for both bitcoin and BCH
Some code cleanup
  • Loading branch information
Coding-Enthusiast committed Apr 6, 2021
1 parent 26aa491 commit 013a793
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 76 deletions.
48 changes: 20 additions & 28 deletions SharpPusher/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ public MainWindowViewModel()
BroadcastTxCommand = new BindableCommand(BroadcastTx, CanBroadcast);

Version ver = Assembly.GetExecutingAssembly().GetName().Version;
versionString = string.Format("Version {0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
VersionString = ver.ToString(3);
}

public string VersionString { get; }

private string versionString;
public string VersionString
{
get { return versionString; }
}


private string rawTx;
private string _rawTx;
public string RawTx
{
get { return rawTx; }
get => _rawTx;
set
{
if (SetField(ref rawTx, value))
if (SetField(ref _rawTx, value))
{
BroadcastTxCommand.RaiseCanExecuteChanged();
}
Expand All @@ -50,13 +45,13 @@ public enum Networks

public ObservableCollection<Networks> NetworkList { get; set; }

private Networks selectedNetwork;
private Networks _selNet;
public Networks SelectedNetwork
{
get { return selectedNetwork; }
get { return _selNet; }
set
{
if (SetField(ref selectedNetwork, value))
if (SetField(ref _selNet, value))
{
SetApiList();
}
Expand All @@ -69,52 +64,50 @@ private void SetApiList()
case Networks.Bitcoin:
ApiList = new ObservableCollection<Api>()
{
new Blockr(),
new Blockchair(Blockchair.Chain.BTC),
new Smartbit(),
new BlockCypher(),
new BlockExplorer(),
//new BlockchainInfo() /*I can't get BLockchain.info API to work, and the code is exact copy of their repository! So I'll just remove it for now (only from this list) until I can fix it.*/
};
break;
case Networks.BitcoinCash:
ApiList = new ObservableCollection<Api>()
{
new BlockDozer(),
new Blockchair(Blockchair.Chain.BCH),
};
break;
}
}


private ObservableCollection<Api> apiList;
private ObservableCollection<Api> _apiList;
public ObservableCollection<Api> ApiList
{
get { return apiList; }
set { SetField(ref apiList, value); }
get => _apiList;
set => SetField(ref _apiList, value);
}


private Api selectedApi;
private Api _selApi;
public Api SelectedApi
{
get { return selectedApi; }
get => _selApi;
set
{
if (SetField(ref selectedApi, value))
if (SetField(ref _selApi, value))
{
BroadcastTxCommand.RaiseCanExecuteChanged();
}
}
}


private bool isSending;
private bool _isSending;
public bool IsSending
{
get { return isSending; }
get => _isSending;
set
{
if (SetField(ref isSending, value))
if (SetField(ref _isSending, value))
{
BroadcastTxCommand.RaiseCanExecuteChanged();
}
Expand Down Expand Up @@ -144,7 +137,7 @@ private async void BroadcastTx()
}
private bool CanBroadcast()
{
if (!string.IsNullOrWhiteSpace(RawTx) && !IsSending && selectedApi != null)
if (!string.IsNullOrWhiteSpace(RawTx) && !IsSending && SelectedApi != null)
{
return true;
}
Expand All @@ -153,6 +146,5 @@ private bool CanBroadcast()
return false;
}
}

}
}
4 changes: 2 additions & 2 deletions SharpPusher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.10.0.0")]
[assembly: AssemblyFileVersion("0.10.0.0")]
[assembly: AssemblyVersion("0.11.0.0")]
[assembly: AssemblyFileVersion("0.11.0.0")]
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace SharpPusher.Services.PushServices
{
public class BlockDozer : Api
public sealed class Blockchair : Api
{
public override string ApiName
public Blockchair(Chain chain)
{
get { return "BlockDozer"; }
this.chain = chain;
}

public enum Chain
{
BTC,
BCH
}

private readonly Chain chain;

public override string ApiName => "Blockchair";

public override async Task<Response<string>> PushTx(string txHex)
{
Response<string> resp = new Response<string>();
Expand All @@ -21,11 +32,12 @@ public override async Task<Response<string>> PushTx(string txHex)
{
try
{
string url = "http://blockdozer.com/insight-api/tx/send";
string chainName = chain == Chain.BTC ? "bitcoin" : "bitcoin-cash";
string url = $"https://api.blockchair.com/{chainName}/push/transaction";

var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>( "rawtx", txHex)
new KeyValuePair<string, string>("data", txHex)
});

HttpResponseMessage httpResp = await client.PostAsync(url, content);
Expand All @@ -34,7 +46,12 @@ public override async Task<Response<string>> PushTx(string txHex)
if (httpResp.IsSuccessStatusCode)
{
JObject jResult = JObject.Parse(result);
resp.Result = "Successfully done. Tx ID: " + jResult["txid"].ToString();
resp.Result = "Successfully done. Tx ID: " + jResult["data"]["transaction_hash"].ToString();
}
else if (httpResp.StatusCode == HttpStatusCode.BadRequest)
{
JObject jResult = JObject.Parse(result);
resp.Result = "Bad request: " + jResult["context"]["error"].ToString();
}
else
{
Expand All @@ -50,6 +67,5 @@ public override async Task<Response<string>> PushTx(string txHex)

return resp;
}

}
}
37 changes: 0 additions & 37 deletions SharpPusher/Services/PushServices/Blockr.cs

This file was deleted.

3 changes: 1 addition & 2 deletions SharpPusher/SharpPusher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@
<Compile Include="Services\Api.cs" />
<Compile Include="Services\ErrorCollection.cs" />
<Compile Include="Services\PushServices\BlockchainInfo.cs" />
<Compile Include="Services\PushServices\Blockchair.cs" />
<Compile Include="Services\PushServices\BlockCypher.cs" />
<Compile Include="Services\PushServices\BlockDozer.cs" />
<Compile Include="Services\PushServices\BlockExplorer.cs" />
<Compile Include="Services\PushServices\Blockr.cs" />
<Compile Include="Services\PushServices\Smartbit.cs" />
<Compile Include="Services\Response.cs" />
<Page Include="MainWindow.xaml">
Expand Down

0 comments on commit 013a793

Please sign in to comment.