Author

Topic: NBitcoin : Almost full bitcoin implementation in .NET (Read 30758 times)

hero member
Activity: 765
Merit: 503
Is there any info on the Fee Policy implementation?  Not sure how to use it.  Im hoping it sets the miners fee in the TX builder.
member
Activity: 103
Merit: 327
UPDATE: We have just came out with the second edition of NBitcoin's documentation, what is a book, called "Programming The Blockchain in C#". 
Now everything has been moved to GitHub, contributions are welcomed! 
https://github.com/ProgrammingBlockchain/ProgrammingBlockchain
hero member
Activity: 714
Merit: 662
Yes it would be possible, but it depends on the differences. I don't know the differences though.
NBitcoin is only for Bitcoin though, but I'm not against adding things in the code to make it extensible for other altcoins.
I won't do it myself though, so I'm waiting PR.
newbie
Activity: 17
Merit: 0
Hi!

Assuming all the similarities between bitcoin and litecoin, would it be feasible / doable to adapt NBitcoin to also handle litecoin?
I mean not necessary in one codebase, but maybe as a child / side project.
How much work would that be?



hero member
Activity: 714
Merit: 662
Yes, you can check the book https://blockchainprogramming.azurewebsites.net/ to see how I to use coin selector to build transactions and a sample of SPV implementation on https://github.com/NicolasDorier/NBitcoin.SPVSample
sr. member
Activity: 364
Merit: 257
If you take a look at the NBitcoin repo https://github.com/NicolasDorier/NBitcoin you will see that it is a very active project. In fact, yesterday there was a new release with many improvements. For example, the latest version allows you to use the bitcoin core consensus library to validate transactions.

There are new features (see the TransactionBuilder and MoneyBag classes), improvements and, at the same time, NBitcoin is on sync with bitcoin core project. So, summarizing: there are a lot of news.      



I wonder if it does have some kind of coin selector and a wallet file format?
full member
Activity: 164
Merit: 128
Amazing times are coming
If you take a look at the NBitcoin repo https://github.com/NicolasDorier/NBitcoin you will see that it is a very active project. In fact, yesterday there was a new release with many improvements. For example, the latest version allows you to use the bitcoin core consensus library to validate transactions.

There are new features (see the TransactionBuilder and MoneyBag classes), improvements and, at the same time, NBitcoin is on sync with bitcoin core project. So, summarizing: there are a lot of news.      

hero member
Activity: 714
Merit: 662
Is there a new thread somewhere?  How could 4 months go by without anyone discussing NBitcoin?  
There was some about discussion on threads about Blockchain Programming in C# about it.
The rest happens on github/stackoverflow/mails. (no specific forum thread)
legendary
Activity: 1386
Merit: 1000
KawBet.com - Anonymous Bitcoin Casino & Sportsbook
Is there a new thread somewhere?  How could 4 months go by without anyone discussing NBitcoin? 
hero member
Activity: 765
Merit: 503
Is it possible to run it as a full node implementation? Basically with tx relay and wallet maintenance.


Yes it is, here to get started (assuming you run bitcoin core locally)
Obviously, you can also connect to other node as long as you know the IP.

Quote
using(var node = Node.ConnectToLocal(Network.Main))
{
   node.VersionHandshake();
   node.MessageReceived += (node,message) => //Do your stuff when new message here;
}

If you want to make a server,

Quote
using(var server = new NodeServer(Network.Main))
{
   server.Listen();
   server.NodeAdded += (s,node)=>//do stuff when node connect (Handshakes and Ping/Pong are handled automatically)
}

When trying to start as server, I'm getting this exception thrown on server.Listen()

An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in NBitcoin.dll

Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted

Any ideas?
 Roll Eyes I had bitcoind running using that port.
hero member
Activity: 765
Merit: 503
Actually, I'm a little busy to create an indexer.
So that will probably be a blockchain.info or blockexplorer.com backed by Microsoft Azure. (which is pure awesomeness)
I will release it entirely open source.

Doing a similar thing.  PM me Smiley
hero member
Activity: 714
Merit: 662
Got it - thanks

One advice, there is several test that are using these class.
If you have the xunit test running, they either the Trait "NodeServer" or "Network". It assume you have a local bitcoin instance on testnet.
You might learn how these class work with the tests.
sr. member
Activity: 467
Merit: 267
Got it - thanks
hero member
Activity: 714
Merit: 662
Thanks for your quick response, another question - is there support for the maintenance of the mempool and the set of unspent outputs? I couldn't find where transactions are checked for double spends for example.



No, this is yours to do.
NodeServer and Node are the class to send message and respond to messages you receive. (as a server, or as a client)
I have not coded a full node with this, but someone can.

In my code, I usually use NodeServer for mocking a fake bitcoin server (for unit testing), and I use Node to get notified from new Transactions, blocks, get the Headers chain, and download blocks.
sr. member
Activity: 467
Merit: 267
Thanks for your quick response, another question - is there support for the maintenance of the mempool and the set of unspent outputs? I couldn't find where transactions are checked for double spends for example.

hero member
Activity: 714
Merit: 662
Is it possible to run it as a full node implementation? Basically with tx relay and wallet maintenance.


Yes it is, here to get started (assuming you run bitcoin core locally)
Obviously, you can also connect to other node as long as you know the IP.

Quote
using(var node = Node.ConnectToLocal(Network.Main))
{
   node.VersionHandshake();
   node.MessageReceived += (node,message) => //Do your stuff when new message here;
}

If you want to make a server,

Quote
using(var server = new NodeServer(Network.Main))
{
   server.Listen();
   server.NodeAdded += (s,node)=>//do stuff when node connect (Handshakes and Ping/Pong are handled automatically)
}
sr. member
Activity: 467
Merit: 267
Is it possible to run it as a full node implementation? Basically with tx relay and wallet maintenance.
sr. member
Activity: 485
Merit: 274
If you ask, M$ will give you a free "Biz Spark" MSDN subscription, if you have a web site and pretend to be a start up.  I got one of the back of a couple of iPhone apps i wrote which i said i wanted to port to WinPhone. 

http://www.microsoft.com/bizspark/default.aspx
hero member
Activity: 714
Merit: 662
Yes from the OpenAsset protocol, I'm working right now on NBitcoin Indexer that will also support queries over colored coin wallets and balances ! Smiley
It already support indexing of ColoredTransactions.

Here some intro on the indexer (before I implemented CC) : http://www.codeproject.com/Articles/819567/NBitcoin-Indexer-A-scalable-and-fault-tolerant-blo
full member
Activity: 131
Merit: 100
The lib now can handle ColoredCoins!
hero member
Activity: 714
Merit: 662
Making your own Payload is not complicated,
I'll add it, but if you are stuck because of that take a look at the implementation of others. It takes literally 5 minutes.
full member
Activity: 131
Merit: 100
The Payloadclass for reject is missing Sad

https://en.bitcoin.it/wiki/Protocol_specification#reject

Maybe add it when you have time Smiley
legendary
Activity: 868
Merit: 1000
Great Work I am reading the code now!!
full member
Activity: 213
Merit: 100
Are you planning on including a actual Client to show off this nice BitcoinLib?

I have begun making a simple client using this library and will surely make it open source once it is completed more.

However, you can figure a lot out by playing with the library and checking out all the tests.
member
Activity: 66
Merit: 10
Are you planning on including a actual Client to show off this nice BitcoinLib?

@ThePok I'm not sure whether your refer to BitcoinLib, but there's another thread for it: https://bitcointalksearch.org/topic/bitcoinlib-net-bitcoin-litecoin-and-bitcoin-clones-library-rpc-wrapper-in-c-456322
hero member
Activity: 714
Merit: 662
Actually, I'm a little busy to create an indexer.
So that will probably be a blockchain.info or blockexplorer.com backed by Microsoft Azure. (which is pure awesomeness)
I will release it entirely open source.

Then my second project will be a WPF client app to track Colored Coins emission and trading.

If you intend to create a client with NBitcoin, I'll be glad to help you if any problem.
full member
Activity: 131
Merit: 100
Are you planning on including a actual Client to show off this nice BitcoinLib?
hero member
Activity: 714
Merit: 662
Pushed new small version update, some helper methods ToString(Network) or static Parse methods to get and parse wif format instead of having to pass by Base58Data classes. (For ExtKey, ExtPubKey, and Key)
DeathAndTaxes, I renamed BitcoinExtKey.Key to ExtKey and same for the BitcoinPubExtKey.
hero member
Activity: 714
Merit: 662
Oh i love it!

And so i donated Smiley

Finaly something that just works after hitting f5 Cheesy

You forgot Install-Package NBitcoin ... except if you cloned the repo where it compiles directly with F5 :p
I never managed to compile the Bitcoin Core source code by the way... Wink
Thanks a lot for the tip !
full member
Activity: 131
Merit: 100
Oh i love it!

And so i donated Smiley

Finaly something that just works after hitting f5 Cheesy
hero member
Activity: 714
Merit: 662
Great work, I'm surprised I haven't seen more replies here, as I remember reading this thread a few months ago.

Once I start getting my lazy ass motivated on furthering my programming knowledge I'll definitely be using your library. I've always wanted to make my own Bitcoin client, no matter how basic it is.



Spread the word Wink
full member
Activity: 213
Merit: 100
Great work, I'm surprised I haven't seen more replies here, as I remember reading this thread a few months ago.

Once I start getting my lazy ass motivated on furthering my programming knowledge I'll definitely be using your library. I've always wanted to make my own Bitcoin client, no matter how basic it is.

donator
Activity: 1218
Merit: 1079
Gerald Davis
Nice taking a look at it now.
hero member
Activity: 714
Merit: 662
Here you go. (Also on github, so you can just merge with your clone)
Quote
Update-Package NBitcoin
http://docs.nuget.org/docs/start-here/using-the-package-manager-console

The new version is 1.4.0.9
I fixed the bug where invalid script can get you into infinite loop. (Did not renamed the Key and PubKey properties though, I will surely do it later on)
hero member
Activity: 714
Merit: 662
You are correct, I will fix this bug tonight, you'll just have to Update-Package NBitcoin

I accept invalid script as parameters, because the coinbase script is arbritrary data.
Trying to .ToString an invalid script can't return something sensible, but at least, I will add a Script.IsValid on the Script class, and make .ToString() terminate correctly.

donator
Activity: 1218
Merit: 1079
Gerald Davis
On an unrelated issue.  There are some unspendable but still valid outputs in the UTXO which the library does not seem to handle properly.  The constructor for the Script class should probably check for cases where there is a OP_PUSHDATA1, OP_PUSHDATA2, or OP_PUSHDATA4 and insufficient bytes to complete the push. A good test case is TxID  ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767 as it is a complete mess.

For example index 4 has a PkScript (in hex) of 0x4d.  Just an OP_PUSHDATA2 with no data following.  This code runs infinitely

Code:
            var script = new Script(new Byte[]{0x4d}); // raw bytes from ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767:4
   string asm = scrip.ToString();

Yeah it would have been nice if since the genesis blocks invalid pushes produced invalid txns and thus this txn would never have made it into a block.  I haven't had a chance to take a close look but I believe the issue is in Op.ReadData().

Quote
      internal static byte[] ReadData(Op op, Stream stream, bool ignoreWrongPush = false)
      {
         var opcode = op.Code;
         uint len = 0;
         BitcoinStream bitStream = new BitcoinStream(stream, false);
         if(opcode == 0)
            return new byte[0];

         if((byte)OpcodeType.OP_1 <= (byte)opcode && (byte)opcode <= (byte)OpcodeType.OP_16)
         {
            return new byte[] { (byte)(opcode - OpcodeType.OP_1 + 1) };
         }

         if(opcode == OpcodeType.OP_1NEGATE)
         {
            return new byte[] { 0x81 };
         }

         if(0x01 <= (byte)opcode && (byte)opcode <= 0x4b)
            len = (uint)opcode;
         else if(opcode == OpcodeType.OP_PUSHDATA1) //fails to return if there is <1 bytes after opcode
            len = bitStream.ReadWrite((byte)0);
         else if(opcode == OpcodeType.OP_PUSHDATA2) //fails to return if there is <2 bytes after opcode
            len = bitStream.ReadWrite((ushort)0);
         else if(opcode == OpcodeType.OP_PUSHDATA4) //fails to return if there is <4 bytes after opcode
            len = bitStream.ReadWrite((uint)0);
         else
            throw new FormatException("Invalid opcode for pushing data : " + opcode);

         byte[] data = new byte[len];
         var readen = stream.Read(data, 0, data.Length);
         if(readen != data.Length && !ignoreWrongPush)
            throw new FormatException("Not enough bytes pushed with " + opcode.ToString() + " expected " + len + " but got " + readen);
         else if(readen != data.Length)
         {
            op.IncompleteData = true;
            Array.Resize(ref data, readen);
         }
         return data;
      }
donator
Activity: 1218
Merit: 1079
Gerald Davis
Yeah I got it working like that but I found it easier to modify BitcoinExtKey and BitcoinExtPubKey to have the Neuter and Derive methods to avoid excess swapping between types.  Also I think it would be more clear if the "Key" property in BitcoinExtKey (and "PubKey" in BitcoinExtPubKey) were named ExtKey and ExtPubKey as they do refer to the Extended Key and ExtPubKey.    Otherwise the accessor for the actual Key or PubKey becomes bitcoinExtKey.Key.Key and bitcoinExtPubKey.PubKey.PubKey.

Code:
            var masterPubKey = new BitcoinExtPubKey(masterPubKeyString, Network.Main);
            var masterServerWalletPubChain = masterPubKey.Derive(0);

...
       private BitcoinScriptAddress GenerateDepositAddresses(BitcoinExtPubKey parentExtPubKey, uint index)
        {
            BitcoinExtPubKey serverDepositPubChain1 = parentExtPubKey.Derive(1001);
            BitcoinExtPubKey serverDepositPubChain2 = parentExtPubKey.Derive(1002);
            BitcoinExtPubKey serverDepositPubChain3 = parentExtPubKey.Derive(1003);
           
            BitcoinExtPubKey extendedDepositPubKey1 = serverDepositPubChain1.Derive(index);
            BitcoinExtPubKey extendedDepositPubKey2 = serverDepositPubChain2.Derive(index);
            BitcoinExtPubKey extendedDepositPubKey3 = serverDepositPubChain3.Derive(index);

            var template = new PayToMultiSigTemplate();
            Script scriptPubKey = template.GenerateScriptPubKey(2, new[] { extendedDepositPubKey1.ExtPubKey.PubKey, extendedDepositPubKey2.ExtPubKey.PubKey, extendedDepositPubKey3.ExtPubKey.PubKey });
            return scriptPubKey.GetAddress(Network.Main);


hero member
Activity: 714
Merit: 662
BitcoinExtKey and BitcoinExtPubKey inherit from Base58Data as all base58Data it contains also information about the Network you are using (Main, TestNet or Reg).
ExtKey on the other hand, only contains the key information.

You can get the ExtKey from BitcoinExtKey by using the property BitcoinExtKey.Key.
However, to do the reverse, ExtKey need information about which Network to use to generate your base58 string.

So here is how your do to go back and forth :

Quote
String keyStr = "xprv9s21ZrQH143K4XUJvv1fQcoDGhLdtQUsfqX7zX4p5XvMtbh8bQxjjMRSTdeVakjmMtg52no13wj g16eSgKA32i1WRxSNYpDaRkF2GkG2NZc";
BitcoinExtKey base58key = new BitcoinExtKey(keyStr, Network.Main); //Would throw FormatException if the base58 is for Network.TestNet
ExtKey key = base58key.Key;
ExtPubKey pubkey = key.Neuter();

//Or, if you want NBitcoin to deduce the network from the base58 directly, this does exactly the same thing

base58key = Network.CreateFromBase58Data(keyStr);
key = base58key.Key;
pubkey = key.Neuter();

//Now, if you want to transform back in BitcoinExtKey

base58key = new BitcoinExtKey(key, Network.Main);  //Or Network.Main.CreateBitcoinExtKey(key)
string base58Str = base58key.ToString(); //base58Str == key

//If you want the PubKey in base58 :
var base58PubKey = new BitcoinExtPubKey(pubkey, Network.Main);  //Or Network.Main.CreateBitcoinExtPubKey(key)
base58Str = base58PubKey.ToString(); //xpub661MyMwAqRbcH1Yn2wYfmkjwpjB8HsCj34SinuURdsTLmQ2H8xGzH9jvJxMYRRKchqEYF3xEB1sXsnQTRKU8oNYDChLuYPgyBneJvdzhc1J
//BitcoinExtPubKey.PubKey to get back the ExtPubKey

So to respond to your question, the reason why there is both BitcoinExtKey and ExtKey is because BitcoinExtKey represents a base58 data, which contains more information that simply the ExtKey. (that has no Network information attached to ExtKey, just the strict cryptographic data)
This works the same for all base58Data. (Key vs BitcoinSecret for example)
donator
Activity: 1218
Merit: 1079
Gerald Davis
Glad to hear it.  I have a question on the difference between ExtKey and Bitcoin ExtKey (and likewise ExtPubKey and BitcoinExtPubKey).  If the BitcoinX class simply a wrapper around a generic ExtKey which contains the Bitcoin specific (i.e. BIP32) features?

I find myself needing to swap between them excessively.  That usually means I am missing something obvious.  My first thought is that you would be able to derive extended keys directly from the BitcoinExtKey class but those methods (Derive & Neuter are not implemented).  My assumption is that you are using these classes differently than I assumed they would be used.

Is there a reason that BitcoinExtKey and BitcoinExtPubKey do not implement derive and neuter or is it just that it hasn't been completed.  If it is the later I would gladly do a pull but I want to make sure I am not missing something obvious before I go down that road.
hero member
Activity: 714
Merit: 662
I will continue to maintain it. I intend to build my own project on top of it, also I am currently working with some bitcoin startup, and the community is very supportive, that get me a great incentive. Smiley
donator
Activity: 1218
Merit: 1079
Gerald Davis
Quote
Thanks for the tip, highly appreciate !!

No problem.  It is a very solid library.  I hope you continue to develop it.

Quote
You can use xUnit test runner in visual studio via extension gallery in vs or with http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099

Yeah I grabbed the runner and it works fine in VS 2013.  

Quote
yes I develop in C# professionally. ... Yes, I am a proponent of Test Driven Development.
I had a feeling.  Glad to see another C# developer involved in Bitcoin.  We are a rare breed but I think a solid .Net library will be essential as Bitcoin moves more into the mainstream.  

Quote
I'm using xUnit just because it was easier to run in a build environment in the past than mstest, and I never looked back.
I hear you.  The only times in recent history that I used mstest was when I was working for a company which required it (because they had been using it for years).  I have always used NUnit but have been meaning to learn about XUnit.  This will give me a good excuse.
hero member
Activity: 714
Merit: 662
Thanks for the tip, highly appreciate !! yes I develop in C# professionnally. Did NBitcoin so entrepreneurs can build business upon Bitcoin more easily.
You can use xUnit test runner in visual studio via extension gallery in vs or with http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099
Then it works as MSTest, and you can run/debug them directly in VS.

Yes, I am a proponent of Test Driven Development.
I ported the tests of Bitcoin Core or other bitcoin libraries before making its implementation.
The reason is that I wanted a class model similar to Bitcoin Core, this make porting easier and learning curve smooth.

I'm using xUnit just because it was easier to run in a build environment in the past than mstest, and I never looked back.
donator
Activity: 1218
Merit: 1079
Gerald Davis
A tip sent.  Please continue to development you got something good started here.  The library is very robust for something that was only started a few months ago.  I am also glad to see some good use of C#.  I prefer the syntax of C# or Java C++.  I assume you write C# professionally?   I was also glad to see unit testing, I assume you are a proponent of test driven development?  I don't have much experience with xUnit (mainly used NUnit and when forced Microsoft's test platform) but the syntax was easy to pick up.  Well at least the basis using a little google-fu as needed.
hero member
Activity: 714
Merit: 662
So I finally got around to taking a look at this library as I need to do some BIP32 work.  All I can say is I wish I had taken a closer look earlier.   This is solid work man.  I am surprised it hasn't been given more attention.  Bonus points for making it a nuget package.  

Is the tip address in your profile valid?  

Yes, this is valid Smiley

This lib is very new I started in April I think.

Here is some article to get you started. (some methods might be outdated)
Basic of Bitcoin  http://www.codeproject.com/Articles/768412/NBitcoin-The-most-complete-Bitcoin-port-Part-Crypt (maybe not for you)
Usage of Stealth Address and BIP38 http://www.codeproject.com/Articles/775226/NBitcoin-Cryptography-Part
Scanning of Blockchain http://www.codeproject.com/Articles/784519/NBitcoin-How-to-scan-the-Blockchain

I am working nowadays on a open source JSON service that would permit you to track any Account you want on the blockchain from the simple implementation of a "Scanner" talked in the article. (Colored Coin, stealth payment included)
This will be awesome ! Smiley

For the BIP32, look at the bip32_tests.cs tests, I'm using the same tests vectors as core.
The base58 representation is called BitcoinExtKey.
donator
Activity: 1218
Merit: 1079
Gerald Davis
So I finally got around to taking a look at this library as I need to do some BIP32 work.  All I can say is I wish I had taken a closer look earlier.   This is solid work man.  I am surprised it hasn't been given more attention.  Bonus points for making it a nuget package. 

Is the tip address in your profile valid? 
member
Activity: 104
Merit: 10
Great work thanks.I'll join to project in github.
hero member
Activity: 714
Merit: 662
Nicolas Dorier you have my respect, thank you!
Thanks, don't hesitate to share, ask features or tell issues on github Smiley
member
Activity: 89
Merit: 10
Nicolas Dorier you have my respect, thank you!
hero member
Activity: 714
Merit: 662
What problem are you trying to solve here? What does your .Net implementation give us that that Bitcoin-QT or talking to bitcoind over RPC doesn't?

I'm totally in favour of alternative clients, but all of them seem to solve a particular problem. Are you planning to simply keep up to date with the bitcoin-core changes? Are you planning to head in a different direction?

It depends on if you are talking about the crypto part goal, the node implementation goal, or the overall goal.

For the overall goal :
Actually Bitcoin code is in C++. Compiling it on a windows computer, or even linux, and playing by debugging tests is a big battle that will cost you lots of time.
In other words, you can't participate into the bitcoin code if you are not a linux wizard in C++.

With NBitcoin, you clone the project, open with visual studio, and you can directly compile and run tests.
There is no dependencies to compile and fetch on the net.
To use the NBitcoin library, you just use the Nuget Package manager that will automatically download and add reference to NBitcoin with dependencies so you can directly code without any hassle.
In clear : If you have visual studio, it takes 1 minutes to start using the lib in your code, and 1 minute to compile it yourself and run tets.
Also the C++ code is not always obvious to read for business developers (I guess that's ok enough for hackers though), the C# have a cleaner model. (But I try to get as close as I can to the C++ model)

For the crypto part :
You can generate keys or use BIP 32 without the need of any node server to install, which is huge depending on where you deploy your code. (Hosted website will not permit you to run a node server, and you should not need that if you just want to generate keys)

For the node client part :
I think that developers need an easy way to talk to the network.
Why should I be obliged to install bitcoind to use a JSON API, download the whole blockchain, to get informations about a block, when I can just connect to the network and ask for it by using the raw protocol ?
Why if I want just to parse a raw transaction, I need to host a server ?

For the node server part :
Well, this come for free once you coded the client part.
I just permit you to create a indexes on blocks, and soon, transactions without the need to install a dedicated server.
The goal will be to manually create transactions in code from your bitcoin wallet.

Anyway, for now, I'm always a little late on the node part behind bitcoin core, and I intend to follow their direction because they will always be used by the majority. (NBitcoin only limits to C# developers)
full member
Activity: 224
Merit: 100
Professional anarchist
It isn't a client, it is a library.

Aar, I see.

For the benefit of other .Net developers, I'm currently using BitcoinJ in a .Net application (https://github.com/XCoinr/Metrobit) by using IKVM to create a .Net dll from a BitcoinJ bundled jar. I will be writing a how-to when I've nailed the very basic functionality, but happy to share tips with anyone interested.
donator
Activity: 1218
Merit: 1079
Gerald Davis
Keep your implementation, maybe I am lacking feature that only you have. The ECDSA alternative is very intesting, I might try to make it works on x86. I add that to my check list..

I wouldn't kill yourself on x86 compatibility.  Honestly who has a machine that is running .net which isn't x64 at this point. Even in QT devs started using x64 builds because of performance and memory issues.  As the blockchain grows the memory demands will also grow with it.
donator
Activity: 1218
Merit: 1079
Gerald Davis
What problem are you trying to solve here? What does your .Net implementation give us that that Bitcoin-QT or talking to bitcoind over RPC doesn't?

I'm totally in favour of alternative clients, but all of them seem to solve a particular problem. Are you planning to simply keep up to date with the bitcoin-core changes? Are you planning to head in a different direction?

It isn't a client, it is a library.
full member
Activity: 224
Merit: 100
Professional anarchist
What problem are you trying to solve here? What does your .Net implementation give us that that Bitcoin-QT or talking to bitcoind over RPC doesn't?

I'm totally in favour of alternative clients, but all of them seem to solve a particular problem. Are you planning to simply keep up to date with the bitcoin-core changes? Are you planning to head in a different direction?
hero member
Activity: 714
Merit: 662
Air
Ahh damn, you beat me to it.  I wanted to have the first (mostly) independent full-node reimplementation in .NET.  I guess I'll have to focus on making mine the best.

Some things I've learned that may be relevant to your experiences too:
  • If you're willing to experiment with an x64-specific build, I would highly recommend checking out https://github.com/joshlang/Secp256k1.NET.  It made a world of difference in the time for my client to do the initial sync.  My super early WIP code uses it, with BouncyCastle as a fallback, like so (obviously doesn't have any special hashtype-related behavior).
  • There's no good LevelDB library on .NET; I think it would be a really big value-add to be able to run off the standard database from the Satoshi client, so just a couple of days ago, I dipped my feet into bitcoin's leveldb tree and started working on https://github.com/airbreather/LevelDB.NET.  It won't work on Mono, it's just a C++/CLI bridge, so I've got a fallback for some other things for the IL-only version.

EDIT: I accidentally a word.

Keep your implementation, maybe I am lacking feature that only you have. The ECDSA alternative is very intesting, I might try to make it works on x86. I add that to my check list..

For the DB, I am using SqLite as a NoSql store, it works well. The indexing of the 300 000 blocks take only 5 minutes. (Compared to the 5 hours of the core implementation when lvldb is corrupt) Sad
The size of the db afterward is 35 MB. I would have a problem though if I intend to index transactions. (It would take 170 GB given that 1 block = 5000 Tx)
The block files of the satoshi client are not from LevelDB, but raw blocks with a small header. I created the code to parse it (StoredBlock) as well to write it.

I created an article on only the crypto part I have coded : http://www.codeproject.com/Articles/768412/NBitcoin-The-most-complete-Bitcoin-port-Part-Crypt, maybe it can interest you.

Today, I am banging my head on the parsing of their wallet which is not a leveldb structure. I also need to make the RPC client/server part.

For LevelDB... I stopped to try when I could not compile that stuff on windows without installing X dependency.
newbie
Activity: 4
Merit: 0
Ahh damn, you beat me to it.  I wanted to have the first (mostly) independent full-node reimplementation in .NET.  I guess I'll have to focus on making mine the best.

Some things I've learned that may be relevant to your experiences too:
  • If you're willing to experiment with an x64-specific build, I would highly recommend checking out https://github.com/joshlang/Secp256k1.NET.  It made a world of difference in the time for my client to do the initial sync.  My super early WIP code uses it, with BouncyCastle as a fallback, like so (obviously doesn't have any special hashtype-related behavior).
  • There's no good LevelDB library on .NET; I think it would be a really big value-add to be able to run off the standard database from the Satoshi client, so just a couple of days ago, I dipped my feet into bitcoin's leveldb tree and started working on https://github.com/airbreather/LevelDB.NET.  It won't work on Mono, it's just a C++/CLI bridge, so I've got a fallback for some other things for the IL-only version.

EDIT: I accidentally a word.
hero member
Activity: 714
Merit: 662
Just added different network support.
Implementing bitcoin and sharing with this forum is the best way to learn for sure. Smiley
hero member
Activity: 714
Merit: 662
Thanks, it will definitively help me for the implementation. I note that.
I will keep reimplementing that in NBitcoin, since my goal is to have a full implementation of bitcoin, and not just the RPC part.
member
Activity: 66
Merit: 10
Very nice initiative and as @DeathAndTaxes said it's good to see more people getting involved with C# for Bitcoin.

I can now start implementing the rpc client. Smiley

Before you decide to reinvent the wheel I would suggest you take a look at this C# RPC API library & wrapper for Bitcoin, Litecoin and Bitcoin-based ALTs:

https://github.com/GeorgeKimionis/BitcoinLib

Some of BitcoinLib's features:

- Fully compatible and up-to-date with Bitcoin 0.9.1 RPC API.
- Design-by-contract, service-oriented architecture.
- Strongly-typed structures for complex RPC requests and responses.
- Implicit JSON casting for all RPC messages.
- Extended methods for every-day scenarios where the built-in methods fall short.
- Exposure of all RPC API's functionality as well as the extended methods through a single interface.
- Fallback mechanism for timed-out RPC requests.
- Custom RPC exceptions.
- Supports all Bitcoin clones.
- Can operate on unlimited daemons with a single library reference.
- Litecoin integration included.
- Each coin instance can be fully parametrized at run-time and implement its own constants.
- Console and web test clients out of the box with demo methods implemented in them.
- Testnet ready.
- Fully configurable.
donator
Activity: 1218
Merit: 1079
Gerald Davis
Well glad I could help.   Testnet exists for that exact purpose.  Depending on your testing needs you may also want to look into "testnet in a box" which is a self contained testnet that exists only on your system.

BTW I have no problem with you asking for tips just didn't want you wasting them thinking they need to be used for testing.  Glad to see some .net development.  Will take a look at your code this weekend.
hero member
Activity: 714
Merit: 662
I did not know about the test network .(seen in the code that we could change, but had no idea about an existing test network)
Thanks for the tips, I can now start implementing the rpc client. Smiley

Even if I ported the code, I am relatively new to bitcoin, I only knew the basics before starting to coding.
donator
Activity: 1218
Merit: 1079
Gerald Davis
Wow got to take a look at this.

Still you are kidding about needing coins to do testing right?
https://tpfaucet.appspot.com/
hero member
Activity: 714
Merit: 662
Hi all,

I passed the two last weeks, full time, porting the C++ code of bitcoin on C#.
It is the most complete and faithful porting I know of bitcoin.
Here is a copy paste of the info I put on the github page.

For those familiar with visual studio, it is available on nuget:
Install-Package NBitcoin

Why is it a big deal ? Because you can run it and debug into it without any linux-voodoo-setup to make it run.
Visual studio express for free, XUnit and you are up to go.

  • Full port of the test suite of bitcoin core with their own data
  • Full script evaluation and parsing
  • Recognize standard script and permit to create them
  • Object model faithful to the C++ API but with C# goodness
  • Simpler API (here is how to generate a key and get the address : new Key().PubKey.Address.ToString())
  • Bloom filter, partial merkle tree
  • Serialization of Blocks, Transactions, Script
  • Signing/verification with private keys, support compact signature for prooving ownership
  • Deterministic wallet : BIP 32

Then the RPC client part. Which I need your help because I don't have any satoshi myself, so I can't emit transactions for testing. If you like my work, submit the testing satoshis to 15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe Wink

Public classes are clean and easy to use, but the implementation is a little messy due to the fact that I'm using C# convention and C++ and the same time. (I will clean that up after the RPC client implementation)

I ported directly from the C++, except the OpenSSL part where I'm using BouncyCaslte instead. (BitcoinJ helped me a lot on the implementation)
I also ported OpenSSL bugs (you can't believe how much time it took me) Wink

Please, use the code to explore/learn/debug/play/sharing/create the licence is LGPL v3, so you should be good to go.
This is the simple way and most complete way to see the internal of bitcoin without going to C++ madness.

With no so much work, it should be Mono compliant. I don't have a lot of dependency on the Windows.

If you like my work, send some satoshi I can crucify for the testing of the RPC client. Wink

Info :
github : https://github.com/NicolasDorier/NBitcoin
bitcoin address : 15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe

Useful link :
Nuget site : https://www.nuget.org/packages/NBitcoin/
Visual studio express : http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
XUnit runner (only if using vs express) : http://xunit.codeplex.com/releases
Jump to: