Pages:
Author

Topic: NBitcoin : Almost full bitcoin implementation in .NET - page 2. (Read 30659 times)

hero member
Activity: 714
Merit: 661
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: 661
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: 661
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: 661
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: 661
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: 661
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: 661
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: 661
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);


Pages:
Jump to: