Hey guys,
I've posted the new version of the library up to git
here. You can just pull the DLLs as binaries for ease of use (note the Masterchest DLL references the other two also so pull all three DLLs).
Please don't hesitate to ask any questions, I'll try and put some more detailed documentation together, but at the moment I'm trying to stay focused on the DEx implementation in my wallet and on masterchest.info.
Thanks!
Masterchest Library, a 2 minute overview:Requirements: .NET 4, bitcoind/qt RPC server with transaction indexing enabled (disabled by default in 0.8+, add txindex=1 in bitcoin.conf and then start with -reindex to readd transaction index).
With thanks to BouncyCastle & Newtonsoft.
Quick function reference:
- decryptmastercoinpacket
- encryptmastercoinpacket
- encodetx
- encodeselltx
- encodeaccepttx
- getaddresses
- getblock
- getblockhash
- getblockcount
- getblocktemplate
- gettransaction
- getmastercointransaction
- getrandombyte
- ismastercointx
- validateecdsa
- rpccall
- sha256hash
As you leverage these functions in Visual Studio you'll be prompted for the correct parameters and their types so they should be quite self explanatory to use, but feel free to ask any questions
There are a number of other functions in the library that the above functions use (eg byte conversions etc) - if you need them look over the source, but they shouldn't be required externally to the library.
Example transactions broadcast today via the library:
Simple Send:
ba63aa51cbf233a63db56b2dfb731c4f609b728125d1154fbc5453ec841c07ccSell Offer:
21055eae2c3b4d900755378f099fe06d7f28666a4156c8449a46493ecd86a8d4Accept Offer:
1c974ad343431897a919635c7d2ec55c537d3efddf38f6e1ffdb9b1eaa0edeb2I also funded the accept offer but this wasn't done via the library as it's just a bitcoin transaction with no Mastercoin data - so far I've had no need to build a library function for it)
Purchase:
ba1f6a49255a05f9e4f694f8bef542ccba27f8b1a3372cf7651401e21b77337a Additionally a few updates on my previous post on example usage of the library:
Firstly we need to init - so let's reference the Masterchest DLL and import masterchest.mlib.
Then we'll start off by creating a bitcoin connection and mlib instance:
'Create a new mlib instance
Dim mlib As New Masterchest.mlib
'Create a bitcoind/qt connection:
Dim bitcoin_con As New bitcoinrpcconnection
bitcoin_con.bitcoinrpcserver = "127.0.0.1"
bitcoin_con.bitcoinrpcport = 8332
bitcoin_con.bitcoinrpcuser = "bitcoin"
bitcoin_con.bitcoinrpcpassword = "password"
Let's say we want to get the transactions in a block and look for Mastercoin transactions.
We start off by getting the blockhash for the block we want to parse, let's say 270788:
Dim blockhash As Blockhash = mlib.getblockhash(bitcoin_con, 270788)
Then we retrieve the actual block:
Dim block As Block = mlib.getblock(bitcoin_con, blockhash.result)
Make a string array of all the transaction IDs in the block:
Dim txarray() As String = block.result.tx.ToArray
So now we have a simple string array of all the transaction IDs in the block. We could now loop through them and check for Mastercoin transactions. Let's say txarray(1) is a25bdaa0e372704878666df3e54ab647d523de6911f3405e3ddfb9029170855c (that tx is in our example block of 270788). Let's see if that's a Mastercoin transaction:
*Note we're skipping txarray(0) here as that's coinbase (ie the bitcoins generated for that block).
Dim txtype As String = mlib.ismastercointx(bitcoin_con, txarray(1))
OK, so txtype came back as "simple". We now know this transaction is a Mastercoin transaction, a simple send. We can now proceed to decode it (ismastercointx
will return "none" if it's not a Mastercoin transaction and you can safely skip that transaction).
We decode with getmastercointransaction, passing the type parameter we've just obtained to tell the library what type of object we're decoding to:
Dim tx As mastercointx = mlib.getmastercointransaction(bitcoin_con, txarray(1), "simple")
That's it. You can then enumerate the object properties, for example tx.fromadd for the from address.
Supported values for the type parameter for getmastercointransaction are currently:
* generate (object type: mastercointx)
* simple (object type: mastercointx)
* selloffer (object type: mastercointx_selloffer)
* acceptoffer (object type: mastercointx_acceptoffer)
So that's a very brief introduction to parsing transactions with the library - allowing easy parsing of simple sends and exchange transactions. All the de-obfuscation and packet re-construction etc is done in the library so we don't have to worry about that.
How about getting all the addresses in the wallet and their bitcoin balances (for fees etc):
Dim addresses As List(Of btcaddressbal) = mlib.getaddresses(bitcoin_con)
Now let's say you wanted to encode transactions as Class B multisig:
Simple send:
Dim rawtx As String = mlib.encodetx(bitcoin_con, "FROMADDRESS", "TOADDRESS", curtype_int, amount_long)
Sell offer:
Dim rawtx As String = mlib.encodeselltx(bitcoin_con, "FROMADDRESS", curtype_int, saleamount_long, offeramount_long, minfee_long, timelimit_int)
Accept offer:
Dim rawtx As String = mlib.encodeaccepttx(bitcoin_con, "FROMADDRESS", "TOADDRESS", curtype_int, purchaseamount_long)
Simple as that, just one-liners. Vin selection and obfuscation etc is all handled within the library. You then take rawtx (which is now a valid bitcoin transaction hex with the Mastercoin transaction within) and throw it to the signrawtransaction and sendrawtransaction commands (the library also has a built in RPC caller for any RPC calls that aren't specifically handled in the library - mlib.rpccall).
A note about payments for exchange transactions, I return "unknown" via the 'ismastercointx' function because in a purchase whilst there is an output to the Exodus address, there are no Mastercoin data packets (hence no transaction type bytes) so we don't know what it is - could be a purchase, could be a bad transaction, a bitcoin transaction sending BTC into the Exodus address etc. But as it has an output to Exodus we might need it, so we return "unknown" instead of "none".