Bloom Filter Example#1
Conversation
|
utACK |
| // | ||
| // 1. Load blockchain headers from disk (if not available will be requested from | ||
| // the full node but that takes longer), | ||
| // 2. Connect to a full BitCoin node (this samle is hard coded to use the loopback |
| // any kind of use on the main BitCoin network. | ||
| // | ||
| // Dependencies: | ||
| // The program relies on NBitCoin (https://github.com/MetacoSA/NBitcoin) for the |
| // protocol. An invaluable tool for anyone attempting the same thing is WireShark | ||
| // (https://www.wireshark.org/) which has a builtin BitCoin protocol decoder. To | ||
| // use WireShark with the loopback adapter on Windows install Npcap (https://nmap.org/npcap/). | ||
| // |
There was a problem hiding this comment.
wow did not knew that awesome.
| // | ||
| // The command line used for the local bitcoin full node: | ||
| // "C:\Program Files\Bitcoin\daemon\bitcoind" -printtoconsole -datadir=f:\temp\bitcoind -server -testnet -debug=1 -bind=[::1]:18333 | ||
| // |
There was a problem hiding this comment.
Actually your code should work just fine with "C:\Program Files\Bitcoin\daemon\bitcoind" -testnet, but yeah your parameters are better to understand what is going on.
| var chain = new ConcurrentChain(_network); | ||
| Node node = null; | ||
|
|
||
| LoadChain(chain, ct).ContinueWith(t => |
There was a problem hiding this comment.
Can you use Async/Await instead of ContinueWith hacks ?
There was a problem hiding this comment.
You can't use await directly in main so it would require an additional method or lambda to switch. I don't find ContinueWith to be "hacky" it does a good job of conveying that the intention is to wait for a task to complete before continuing.
|
|
||
| NodeRequirement req = new NodeRequirement(); | ||
| req.RequiredServices = NodeServices.NODE_BLOOM; | ||
| req.SupportSPV = true; |
There was a problem hiding this comment.
Can you declare req next to where you use it?
Actually this code is optional, since your bitcoind supports bloomfilter, this code only make sure it does during the handshake (ie, if you disable bloomfilter with -peerbloomfilters=0, then the handshake will fail)
| parameters.IsRelay = false; | ||
|
|
||
| NodeRequirement req = new NodeRequirement(); | ||
| req.RequiredServices = NodeServices.NODE_BLOOM; |
There was a problem hiding this comment.
This is useless, SupportSPV makes sure of that for you.
It limits also to who you can be connected, old nodes support NODE_BLOOM without advertising for it. req.SupportSPV = true do the proper checks.
| tip = new ChainedBlock(header, header.GetHash(), prev); | ||
| chain.SetTip(tip); | ||
|
|
||
| ct.ThrowIfCancellationRequested(); |
There was a problem hiding this comment.
useless, you always call it at the beginning.
|
first time I see pattern matching in the wild. Made several point to improve. In general for such feature, I would advise people to encapsulate such code into a reusable |
|
I'm going to write a few more samples so I thin it'll work out easier to use my own repo. Closing this pull request. |
|
@sipsorcery Too bad you deleted it already, I'd like to see it reopened. |
A new sample program that demonstrates how to use a bloom filter with NBitcoin.