Posted on

Workshop 1.1 – Install Python in Ubuntu

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 examples available on the internet and referencing syntax to the official documentation – python-bitcoinlib Documentation

Let’s review 2 methods:

  • getblockhash(height)
    • Return hash of block in best-block-chain at height.
    • Raises IndexError if height is not valid.
  • getrawtransaction(txid, verbose=False)
    • Return transaction with hash txid
    • Raises IndexError if transaction not found.
    • verbose – If true a dict is returned instead with additional information on the transaction.
    • Note that if all txouts are spent and the transaction index is not enabled the transaction may not be available
  • Exercise #1:
    • design a GUI allowing for the
      • input of the blockheight
      • output of the corresponding total output (BTC)
      • GUI to have Label, grid, messagebox
    • use tkinter, bitcoin.rpc/RawProxy

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 output.

Like so …

  • Exercise #2a:
    • design a GUI / command line interface (bitcoin-cli) to understand the following methods
      • getblockchaininfo
        • bestblockhash
      • getwalletinfo
      • getblockhash
      • getrawtransaction txid
      • decoderawtransaction
    • GUI to have
      • Label, grid, messagebox
      • tkinter, bitcoin.rpc/RawPro
  • Exercise #2b:
    • design a GUI / command line interface (bitcoin-cli) to trace the history of a particular transaction through its txid
    • determine its blockid
      • run node with txindex=1 in the configuration
        • bitcoind -reindex
        • obtain blockhash
          (use an example from the internet and verify the data points programmatically for consistency)
          • bitcoin-cli getrawtransaction [txid] 1
        • alternatively, obtain its hash by manually obtaining blockid from the internet
          • bitcoin-cli getblockhash [blockid]
          • bitcoin-cli getrawtransaction [txid] 1
            • it is equivalent to decoderawtransaction
      • get block details
        • bitcoin-cli [blockhash]
        • validate / search for a txid is recorded in the list (tx) the said block
        • verify whether the hash of the said transaction is also its txid
    • obain raw transaction of txid
      • bitcoin-cli getrawtransaction [txid]
    • decode the raw transaction
      • bitcoin-cli decoderawtransaction [ ]
    • view and interpret the details
      • txid
      • hash
      • vin
        • txid (previous transaction)
        • vout
          • can have more than 1 output
          • for this exercise the txid example has only 1 previous output
        • scripSig
      • vout
        • value
        • n
        • scripPubKey
        • address
      • tie in the values
        • Input = Outputs + Mining Fees
    • GUI to have
      • Label, grid, messagebox
      • tkinter, bitcoin.rpc/RawPro

Like so …