Skip to content

Commit aaa0132

Browse files
Add mempool.space API
1 parent 43e8d6e commit aaa0132

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SharpPusher
2+
// Copyright (c) 2017 Coding Enthusiast
3+
// Distributed under the MIT software license, see the accompanying
4+
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+
using Autarkysoft.Bitcoin.Encoders;
7+
using SharpPusher.Models;
8+
using System;
9+
using System.Net.Http;
10+
using System.Threading.Tasks;
11+
12+
namespace SharpPusher.Services.PushServices
13+
{
14+
public class MempoolSpace : IApi
15+
{
16+
public string ApiName => "Mempool.space";
17+
18+
public async Task<Response> PushTx(string txHex)
19+
{
20+
Response resp = new();
21+
using HttpClient client = new();
22+
23+
try
24+
{
25+
string url = "https://mempool.space/api/tx";
26+
HttpResponseMessage httpResp = await client.PostAsync(url, new StringContent(txHex));
27+
if (!httpResp.IsSuccessStatusCode)
28+
{
29+
resp.SetError("API response doesn't indicate success.");
30+
return resp;
31+
}
32+
33+
string t = await httpResp.Content.ReadAsStringAsync();
34+
if (t.Length == 64 && Base16.IsValid(t))
35+
{
36+
resp.SetMessage($"Successfully done. Tx ID: {t}");
37+
}
38+
else
39+
{
40+
resp.SetError(t);
41+
}
42+
}
43+
catch (Exception ex)
44+
{
45+
string errMsg = (ex.InnerException == null) ? ex.Message : ex.Message + " " + ex.InnerException;
46+
resp.SetError(errMsg);
47+
}
48+
49+
return resp;
50+
}
51+
}
52+
}

SharpPusher/ViewModels/MainWindowViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private void SetApiList()
7171
case Networks.Bitcoin:
7272
ApiList =
7373
[
74+
new MempoolSpace(),
7475
new Blockchair(Blockchair.Chain.BTC),
7576
new BlockCypher(),
7677
new P2P(true)

0 commit comments

Comments
 (0)