Closed sipsorcery closed 7 years ago
I think you should not use the behaviors yourself, this is way too tricky, take a look at https://github.com/NicolasDorier/NBitcoin.SPVSample this show how to use the SPVWallet class.
Thanks for the response.
I have spent a fair bit of time trawling over the SPV sample as well as the NBitCoin source and also the eBook. I'm not specifically interested in writing a wallet and am instead attempting to get a better understanding of the BitCoin protocol.
The specific sample code above is to try and get a grip on BIP-0037 regarding Bloom filters. After some more testing I think the sample above is working but is just very slow due to frequent node disconnects related to false positive rate on the bloom filter.
Is there a different way to interact with filters using NBitCoin other than the TrackerBehavior? I suspect if I want more control over the BloomFilter I should start looking at a node.SendMessage approach rather than behaviors?
Frankly speaking, I would advise you against BIP37. This is leaking privacy and very difficult to get right. I think either using a block explorer or having a full block SPV (where client download a full block and check its transaction inside) are better solutions for efficiency, user experience, and privacy.
If you want to play with Bloom Filter to understand things, just connect to your own node with Node.ConnectToLocal()
, and send the messages directly to it.
You can check how the RPC Tests are done in NBitcoin. I am using a NodeBuilder
class which popup a bitcoin core on regtest under the hood. This allows you to test code against bitcoin core in a very repeatable way.
Behavior are for reusable, easy to attach logic to the node you connect. If your goal is to learn the protocol, just use node.SendMessageAsync
and node.CreateListener()/listener.Receive
Ok I'll play around with the direct messages rather than behaviors then, thanks for the pointers.
The pattern for not missing messages is
using(var listener = node.CreateListener())
{
node.SendMessageAsync();
listener.Receive()....
}
I'm attempting to find all the transactions related to a specific address using a Bloom Filter. I've used this previous issue as my stating point.
The testnet address I'm tracking has 4 transactions but my demo program only ever detects the first transaction.
My code is below and undoubtedly I'm doing something silly. I have deliberately removed the persistence of the blockchain to file while I'm messing around.
The output from running the program is:
Sample Code
`namespace BitCoinTest { class Program { static Network _network = Network.TestNet;
}`