-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new method to broadcast bitcoin transactions directly to bitcoi…
…n nodes in a decentralized way avoiding third parties.
- Loading branch information
1 parent
dcd98c2
commit c88cf3e
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SharpPusher | ||
// Copyright (c) 2017 Coding Enthusiast | ||
// Distributed under the MIT software license, see the accompanying | ||
// file LICENCE or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
using Autarkysoft.Bitcoin; | ||
using Autarkysoft.Bitcoin.Blockchain.Transactions; | ||
using Autarkysoft.Bitcoin.Clients; | ||
using Autarkysoft.Bitcoin.P2PNetwork.Messages; | ||
using Autarkysoft.Bitcoin.P2PNetwork.Messages.MessagePayloads; | ||
using System.Threading.Tasks; | ||
|
||
namespace SharpPusher.Services | ||
{ | ||
public class P2P : Api | ||
{ | ||
public P2P(bool isMainNet) | ||
{ | ||
netType = isMainNet ? NetworkType.MainNet : NetworkType.TestNet; | ||
} | ||
|
||
|
||
private readonly NetworkType netType; | ||
|
||
public static readonly string[] DnsMain = new string[] | ||
{ | ||
"seed.bitcoin.sipa.be", // Pieter Wuille, only supports x1, x5, x9, and xd | ||
"dnsseed.bluematt.me", // Matt Corallo, only supports x9 | ||
"dnsseed.bitcoin.dashjr.org", // Luke Dashjr | ||
"seed.bitcoinstats.com", // Christian Decker, supports x1 - xf | ||
"seed.bitcoin.jonasschnelli.ch", // Jonas Schnelli, only supports x1, x5, x9, and xd | ||
"seed.btc.petertodd.org", // Peter Todd, only supports x1, x5, x9, and xd | ||
"seed.bitcoin.sprovoost.nl", // Sjors Provoost | ||
"dnsseed.emzy.de", // Stephan Oeste | ||
"seed.bitcoin.wiz.biz", // Jason Maurice | ||
}; | ||
|
||
public static readonly string[] DnsTest = new string[] | ||
{ | ||
"testnet-seed.bitcoin.jonasschnelli.ch", | ||
"seed.tbtc.petertodd.org", | ||
"seed.testnet.bitcoin.sprovoost.nl", | ||
"testnet-seed.bluematt.me", | ||
}; | ||
|
||
|
||
public override string ApiName => "P2P"; | ||
|
||
public override async Task<Response<string>> PushTx(string txHex) | ||
{ | ||
Transaction tx = new(txHex); | ||
Message msg = new(new TxPayload(tx), netType); | ||
|
||
MinimalClientSettings settings = new(netType, 4, null) | ||
{ | ||
DnsSeeds = netType == NetworkType.MainNet ? DnsMain : DnsTest | ||
}; | ||
MinimalClient client = new(settings); | ||
client.Start(); | ||
await Task.Delay(TimeConstants.OneSecond_Milliseconds * 3); | ||
client.Send(msg); | ||
|
||
return new Response<string>() | ||
{ | ||
Result = $"Transaction was sent to {settings.MaxConnectionCount} nodes. " + | ||
$"Transaction ID: {tx.GetTransactionId()}" | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters