Pages:
Author

Topic: Blockchain security tracking/colored coins/smart contracts - short python script - page 4. (Read 8884 times)

sr. member
Activity: 362
Merit: 250
Can you automatically pay dividends to coloured coins?

Not yet, but it will be relatively trivial to implement. The script already produces a list of "shareholders" (as represented by their bitcoin addresses) and the share that they own.

From that, it's just a question of massaging the data to the right format and feeding it to the bitcoin json API.

I will see if I have the time to implement it this week, and pastebin a newer version.
legendary
Activity: 1372
Merit: 1003
Can you automatically pay dividends to coloured coins?
legendary
Activity: 1792
Merit: 1111
There are now many threads about "colored coins", "smart contracts" and otherwise tracking specific coins through the blockchain.



I think it is because the fail of GLBSE. The next generation of bitcoin security exchange will be colored-coin-based p2p system. The role of a centralized exchange (if any) is to facilitate bid/ask matching, to advertise IPO, and to rate the trustworthiness of security issuers.
sr. member
Activity: 362
Merit: 250
There are now many threads about "colored coins", "smart contracts" and otherwise tracking specific coins through the blockchain.

I have created a simple command-line Python program to handle tracking of "colored coins", "smart contracts" or "blockchain securities" in the blockchain.

There are other approaches, and the one I have taken is very simple, but it is a working solution (primitively duct-taped and glued together). I also have not read gone into the details of the other approaches, so it is probably safe to say that the method I have created is completely incompatible with the other methods (which are probably much smarter too).

But it is a live and implemented solution, which gives it an advantage over others. It is short, easy to modify and fun to play with. It might be useful for some adventurous security issuers who are looking for a solution now that GLBSE is shutting down.

Full source: http://pastebin.com/hbUz0vS9

Update Oct 15:

The source code has been updated, the new version includes functions to pay dividends to holders of the colored coins.

Also, it has been tested more thoroughly, and I have created a 12-step usage example that shows the current capabilities of the script.

Update Oct 18:

The source code has been updated, the new version includes the functions to include a transaction fee from an (uncolored!) address in your standard/satoshi-client wallet when transferring assets so that the transaction is more likely to confirm more quickly (command-line option -w , where is the fee you want to pay in BTC, e.g. -w 0.005 for half a bitcent).

Also, the tracking of colored coins is now also believed to be compatible with other approaches for "order-based" tracking, such as the one used in killerstorm's modified Satoshi client (however, I still want to build up a bunch of test-cases to see if the clients interpret all the cases in the same way).

Next, I think it is time to create ample test-cases, and tidy up the code - it has turned into a bit of a spaghetti-ball.

Usage example:
Code:

1. First run config setup:
$ python bitpaint.py
Configuration file bitpaint.conf not found. Creating one...
bitcoind rpc host (default: 127.0.0.1):
bitcoind rpc port (default: 8332):
bitcoind rpc username (default: ): ********
bitcoind rpc password (default: ): ********

2. Create address:
$ python bitpaint.py -n
Address added: 1AEn3U5MhedXYRbpxLKmkL4r5Kz1XkdZA

3. Transfer the colored coins to the address (sent 0.01 BTC to the address above using Satoshi client). Make a note of (1) the Transaction ID: 630bccacd6f4401fde53822af3f011daa47ec1bedd1702bf7d0be4391948f49b, (2) the output that was sent to the address above: 1.

4. "Paint" the output of the transaction, call the painted coins "BITFAIR-SHARES":
$ python bitpaint.py -p BITFAIR-SHARES:630bccacd6f4401fde53822af3f011daa47ec1bedd1702bf7d0be4391948f49b:1

5. Show the ownership info of the painted coins "BITFAIR-SHARES", the output is the owner address, the amount the address owns, and the transaction output which assigned ownership to that address, then a line with a total at the bottom:
$ python bitpaint.py -o BITFAIR-SHARES
*** BITFAIR-SHARES ***
1AEn3U5MhedXYRbpxLKmkL4r5Kz1XkdZA 0.01 630bccacd6f4401fde53822af3f011daa47ec1bedd1702bf7d0be4391948f49b:1
** Total BITFAIR-SHARES: 0.010000 **

6. Create three new addresses (could be done by another user, for example the buyer of the security - the buyers should also run the command in step 4 to initiate the coin tracking), and create a transaction that transfers 0.006 to the first address (represents 60% of "outstanding shares"), 0.003 to the second (represents 30% of "outstanding shares) and 0.001 to the third (represents 10% of "outstanding shares"):
$ python bitpaint.py -n
Address added: 1KbDEaZ99YJYaT62emhFwabFoqQ6LYdJg9
$ python bitpaint.py -n
Address added: 1DAHyXPNJjqLGFNqHhavrukWZ6XkY8Kj21
$ python bitpaint.py -n
Address added: 1Mhx4LMjbmN6KJ9B5BkdZ5zVWQP64F5TJC
$ python bitpaint.py -f 1AEn3U5MhedXYRbpxLKmkL4r5Kz1XkdZA:630bccacd6f4401fde53822af3f011daa47ec1bedd1702bf7d0be4391948f49b:1 -t 1KbDEaZ99YJYaT62emhFwabFoqQ6LYdJg9:0.006,1DAHyXPNJjqLGFNqHhavrukWZ6XkY8Kj21:0.003,1Mhx4LMjbmN6KJ9B5BkdZ5zVWQP64F5TJC:0.001 -w 0.005
01000000019bf4481939e40b7dbf0217ddbec17ea4da11f0f32a8253de1f40f4d6accc0b63010000008b483045022100dd23f8d8cc3c92314127badcdd50c22414fe1bdf50215c3edce89f0aa64836bd02200c940f4a5ca59c133f14269c3cc2568e8340ec09d90f65c3264f869e93f28e010141047002cabfc1da529ab13d035a60b11db585be5709ddd7d8ab5649ce5d71a279bcb681007bb929f8adf7d811726cd82da5aa1fa96cd736cca986a79c89186a1e29ffffffff03e0930400000000001976a91485636c3633be3a41ce4893dc84ab31fd2d96ea4f88aca0860100000000001976a914e3211d2305301fe6421dbf85685a2744ca51817e88acc0270900000000001976a914cbea9e8c8392abc07417f95bfcb2f21406c6599088ac00000000

7. The result of the former step is a hex-encoded raw transaction. Because it contains no transaction fees, the standard satoshi client will refuse to send it. However, the resulting hex-encoded raw transaction can be broadcast on the network using http://blockchain.info/pushtx. PS: At the moment, you cannot be sure that the transaction will be included in a block, since it contains no transaction fee (i.e. compensation to the miners). I am currently working on a solution to this.

8. Update list of BITFAIR-SHARES holders, and show it:
$ python bitpaint.py -u BITFAIR-SHARES
$ python bitpaint.py -o BITFAIR-SHARES
*** BITFAIR-SHARES ***
1DAHyXPNJjqLGFNqHhavrukWZ6XkY8Kj21 0.003 d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:0
1Mhx4LMjbmN6KJ9B5BkdZ5zVWQP64F5TJC 0.001 d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:1
1KbDEaZ99YJYaT62emhFwabFoqQ6LYdJg9 0.006 d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:2
** Total BITFAIR-SHARES: 0.010000 **

9. Pay dividends of 0.1 BTC in total from my wallet account named "bitpaint_donations" to the holders of the colored coins ("shareholders of BITFAIR-SHARES") (not sure if this works with an encrypted wallet, should be easy enough to fix for those who have it):
$ python bitpaint.py -d BITFAIR-SHARES:bitpaint_donations:.1

10. List what shares/colored coins are owned by me, their dividends (and address that the shares/dividends belong to, along with the transaction output that assigned the shares to my address):
$ python bitpaint.py -m
BITFAIR-SHARES 0.003 ( div: 0.03 ) 1DAHyXPNJjqLGFNqHhavrukWZ6XkY8Kj21 d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:0
BITFAIR-SHARES 0.001 ( div: 0.01 ) 1Mhx4LMjbmN6KJ9B5BkdZ5zVWQP64F5TJC d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:1
BITFAIR-SHARES 0.006 ( div: 0.06 ) 1KbDEaZ99YJYaT62emhFwabFoqQ6LYdJg9 d8e8dc799be1b552f29f8cbd2df24a1fcb9c2a9f4a43c9b4444b9dc329bbd17d:2

11. Forward dividends from my asset-addresses to one of my wallet addresses:
$ python bitpaint.py -x 1DAHyXPNJjqLGFNqHhavrukWZ6XkY8Kj21 -y 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr
0100000001cf707398596a9f8bf45e22e3f736b819f27ba6d10cb9c12f1ca23a9daf0c6f1d000000008c4930460221009eb892e079fd143fd5b1919c0c07073d1d45a671aabb05d2565721ae3f83aee6022100a60706b226ef968038ef654f8b782103170932201b7e9fc9320ec24027c56e14014104f7e514dad77c0dbf157c1cc88d610a512f9809785fda426ca7ee3c70df59afeee521ccb02f610536e093b954c4718a4b9d2c028aaec62ad2f138d0735a0d918dffffffff01a0252600000000001976a9143a572d6755022d568f7a78d0060234920486cd0f88ac00000000
Paid 0.025 to 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr
$ python bitpaint.py -x 1Mhx4LMjbmN6KJ9B5BkdZ5zVWQP64F5TJC -y 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr
0100000001cf707398596a9f8bf45e22e3f736b819f27ba6d10cb9c12f1ca23a9daf0c6f1d020000008a47304402203ff6f44811c8d772f16535a3482fcb88e0b992cf3f8574b78b32489146212a28022045e2fff119b1124035849f3d54b5f5fa3cf8ebf88463df38df1ee7f4ab4cf358014104dc22a7249282ba829c4351cd9255690aaaa9a9896bd9b95e6075d5a3ec34b305a6eab56f9524f7a4308f418bd4a6eabdaf887a4622874b32cb4f4f55c28e1092ffffffff0120a10700000000001976a9143a572d6755022d568f7a78d0060234920486cd0f88ac00000000
Paid 0.005 to 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr
$ python bitpaint.py -x 1KbDEaZ99YJYaT62emhFwabFoqQ6LYdJg9 -y 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr
0100000001cf707398596a9f8bf45e22e3f736b819f27ba6d10cb9c12f1ca23a9daf0c6f1d030000008c493046022100b440c8997b43067a2a96ece768487e6f219391491d83b384fe7408f106adea5b022100b7d47531358afdeb75cd4e98753309c175ce71e1d722ab851c363c0b9f80d2b50141043d0c63308cb4dcc98b966922a7f78435d44c89b63bf94485f0920c3434a5077c4004adb067ac319f3ee1b551b451a11154e0e1a8ba1c686d15bde93f89963044ffffffff0160ec5300000000001976a9143a572d6755022d568f7a78d0060234920486cd0f88ac00000000
Paid 0.055 to 16KUdKHHZ1AUVb4ZH6Q2VY55L3V3gCCSmr

12. The result of each command in the former step is a hex-encoded raw transaction. It contains a transaction fee of 0.005, to help it get mined into a block. The hex-encoded raw transaction can be broadcast on the network using http://blockchain.info/pushtx. Your client should see the transaction within seconds.


Planned features:
- GUI

Please be cautious when using it, but feel free to criticise, modify and contribute. And if you like it, support it: 1GsnaaAWYMb7yPwBQ19bSLLMTtsfSyjqg3.
Pages:
Jump to: