{"id":431,"date":"2019-02-28T01:59:48","date_gmt":"2019-02-28T01:59:48","guid":{"rendered":"https:\/\/www.usesatoshi.com\/?p=431"},"modified":"2019-03-06T12:16:00","modified_gmt":"2019-03-06T12:16:00","slug":"install-python-in-ubuntu","status":"publish","type":"post","link":"https:\/\/www.usesatoshi.com\/index.php\/2019\/02\/28\/install-python-in-ubuntu\/","title":{"rendered":"Workshop 1.1 &#8211; Install Python in Ubuntu"},"content":{"rendered":"<p>version details:<\/p><ul class=\"wp-block-list\"><li>Ubuntu 18.04<\/li><li>Python <del>2.7<\/del> <strong>3.6.7<\/strong><ul><li>library<ul><li>python-bitcoinlib<ul><li>sudo apt-get install libssl-dev<\/li><li><del>pip install python-bitcoinlib<\/del> or or <strong>pip3 <\/strong>install python-bitcoinlib<\/li><\/ul><\/li><li>pycoin<\/li><\/ul><\/li><\/ul><\/li><li>Bitcoin Core 0.16.3<ul><li>code<ul><li>rpc_block.py<\/li><li>rpc_transaction.py<\/li><\/ul><\/li><\/ul><\/li><li>Text Editor<ul><li><del>Nano 2.5.3<\/del> <\/li><li>Leafpad <\/li><li>Sublime or equivalent<\/li><\/ul><\/li><\/ul><p>libssl-dev is needed to handle SSL and TLS cryptographic protocols <\/p><p>The best way to learn coding is to review examples available on the internet and referencing syntax to the official documentation &#8211; <a href=\"https:\/\/media.readthedocs.org\/pdf\/bitcoin-boh\/latest\/bitcoin-boh.pdf\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"python-bitcoinlib Documentation (opens in a new tab)\">python-bitcoinlib Documentation<\/a><\/p><p>Let&#8217;s review 2 methods:<\/p><ul class=\"wp-block-list\"><li> getblockhash(<em>height<\/em>) <ul><li>Return hash of block in best-block-chain at height.<\/li><li>Raises IndexError if height is not valid.<\/li><\/ul><\/li><li>getrawtransaction(txid, verbose=False)<ul><li>Return transaction with hash txid<\/li><li>Raises IndexError if transaction not found.<\/li><li>verbose &#8211; If true a dict is returned instead with additional information on the transaction.<\/li><li> Note that if all txouts are spent and the transaction index is not enabled the transaction may not be available<\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li>Exercise #1:<ul><li>design a GUI allowing for the<ul><li>input of the blockheight<\/li><li>output of the corresponding total output (BTC) <\/li><li>GUI to have Label, grid, messagebox<\/li><\/ul><\/li><li>use tkinter, bitcoin.rpc\/RawProxy<\/li><\/ul><\/li><\/ul><p>The idea is to extract a list of all transaction IDs in the block. Next, to iterate through each transaction ID in the block for txid and drill down to the <em>output<\/em>. <\/p><p>Like so &#8230;<\/p><figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython1-1.png\" alt=\"\" class=\"wp-image-481\" width=\"374\" height=\"395\" srcset=\"https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython1-1.png 499w, https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython1-1-284x300.png 284w, https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython1-1-416x439.png 416w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><\/figure><ul class=\"wp-block-list\"><li> Exercise #2a:<ul><li>design a GUI \/ command line interface (bitcoin-cli) to understand the following methods<ul><li>getblockchaininfo<ul><li>bestblockhash<\/li><\/ul><\/li><li>getwalletinfo<\/li><li>getblockhash<\/li><li>getrawtransaction txid<\/li><li>decoderawtransaction<\/li><\/ul><\/li><li>GUI to have <ul><li>Label, grid, messagebox<\/li><li>tkinter, bitcoin.rpc\/RawPro<\/li><\/ul><\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li> Exercise #2b:<ul><li>design a GUI \/ command line interface (bitcoin-cli) to trace the history of a particular transaction through its <strong>txid<\/strong><\/li><li>determine its blockid  <ul><li><em>run node with txindex=1 in the configuration<\/em><ul><li><em>bitcoind -reindex<\/em><\/li><li>obtain blockhash  <br>(<em>use an example from the internet and verify the data points programmatically for consistency<\/em>) <ul><li>bitcoin-cli getrawtransaction [txid] <strong><del>1<\/del><\/strong><\/li><\/ul><\/li><li><del>alternatively, obtain its hash by manually obtaining blockid from the internet<\/del><ul><li><del>bitcoin-cli getblock<\/del><strong><del>hash<\/del><\/strong><del> <\/del><strong><del>[blockid]<\/del><\/strong><\/li><li> bitcoin-cli getrawtransaction [txid] <strong>1<\/strong> <ul><li>it is equivalent to <em><strong>decoderawtransaction<\/strong><\/em> <\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li>get block details<ul><li> bitcoin-cli [blockhash]<\/li><li>validate \/ search for a  <strong>txid <\/strong>is recorded in the list (<strong>tx<\/strong>) the said block <\/li><li>verify whether the <strong>hash <\/strong>of the said transaction is also its <strong>txid <\/strong><br><\/li><\/ul><\/li><\/ul><\/li><li>obain raw transaction of txid<ul><li> bitcoin-cli getrawtransaction  [txid]<\/li><\/ul><\/li><li>decode the raw transaction<ul><li> bitcoin-cli decoderawtransaction  [ ]<br><\/li><\/ul><\/li><li>view and interpret the details<ul><li>txid<\/li><li>hash<\/li><li>vin<ul><li>txid (previous transaction)<\/li><li>vout<ul><li>can have <strong><em>more than 1 output<\/em><\/strong><\/li><li>for this exercise the <strong>txid <\/strong>example has only 1 <strong><em>previous output<\/em><\/strong><\/li><\/ul><\/li><li><del>scripSig<\/del><\/li><\/ul><\/li><li>vout<ul><li>value<\/li><li>n<\/li><li><del>scripPubKey<\/del><\/li><li>address<\/li><\/ul><\/li><li>tie in the values <ul><li>Input = Outputs + Mining Fees<\/li><\/ul><\/li><\/ul><\/li><li>GUI to have <ul><li>Label, grid, messagebox<br><\/li><li>tkinter, bitcoin.rpc\/RawPro <\/li><\/ul><\/li><\/ul><\/li><\/ul><p>Like so &#8230;<\/p><figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython2b-1.png\" alt=\"\" class=\"wp-image-514\" width=\"708\" height=\"431\" srcset=\"https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython2b-1.png 944w, https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython2b-1-300x182.png 300w, https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython2b-1-768x467.png 768w, https:\/\/www.usesatoshi.com\/wp-content\/uploads\/2019\/03\/workshop-btcpython2b-1-416x253.png 416w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>","protected":false},"excerpt":{"rendered":"<p>version details: Ubuntu 18.04 Python 2.7 3.6.7 library python-bitcoinlib sudo apt-get install libssl-dev pip install python-bitcoinlib or or pip3 install python-bitcoinlib pycoin Bitcoin Core 0.16.3 code rpc_block.py rpc_transaction.py Text Editor Nano 2.5.3 Leafpad Sublime or equivalent libssl-dev is needed to handle SSL and TLS cryptographic protocols The best way to learn coding is to review [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-431","post","type-post","status-publish","format-standard","hentry","category-lab"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/comments?post=431"}],"version-history":[{"count":66,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/431\/revisions"}],"predecessor-version":[{"id":515,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/431\/revisions\/515"}],"wp:attachment":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/media?parent=431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/categories?post=431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/tags?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}