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 …

Posted on

Let’s Get Started

A place to get your hands dirty. So let’s roll up our sleeves and get underway. It will be messy and we are likely to be all over the shop and hoping to find a path of least resistance. Before going wild like kids in a candy store, a little order is good to have – to serve as a check to our progress.

There is this SMART objective – Specific – Measurable – Attainable – Realistic – Timely. Instead of viewing this as stifling creativity, we should embrace it as our friend keeping us stay focus and ensuring the sustainability of the initiative(s).

We will for a start keep to a general goal ( oxymoron – yes/no?) – how to get to writing the first code that resembles some form of lightning network application (LApp).

First, we need to find the resources and ingredients to get us there …

Next, we can proceed to the installation stage.

We are making the assumptions that we have installed the following resources: i.e. Linux on Raspberry Pi 3 B (Debian)

  • is 16 GB SD card space adequate?
  • is hard disk storage space required?

We will install:

  • Go – lnd is written in Go
    • set$GOPATH environment variable – represents the path to the workspace
  • LND –
    • specify a chain backend
    • pruned or full node

Please proceed to Workshop 1 – Lightning Node Setup on the how to install.

We will also document (with continuous updating) what constitutes key success factors:

  • a site to hold domain know-how
  • gathering a team of collaborators
    • in social interactions, shared values are crucial as well as communication skill
    • documentation is part of communication skill – solving a byzantine general problem i.e. how do we trust the signal so that when we execute it will not be in vain
    • it is good to be up-front on beliefs and behaviors
    • win-win is underpinned by game theory and it is about growing the economic pie first before sharing
    • values such as care and empathy are little understood and less so, practiced
      • individuals that are inherently sad, characterless and or lacking wisdom will have a huge wall to climb before been able to have positive impacts in the community
      • a special category of not invented here personalities will be challenged to have shared values – such self centricity can point to a possible single point of failure
        • do not be blind sided – be aware of the “unknown, unknown” and defer to the expert on site to take the lead
        • be generous in sharing with such like minded experts
    • [ifpaid 0.00001 BTC text=”Please pay 0.00001 BTC to continue reading.” button=”Click here to pay using the Lightning Network”]
    • timely completion of realistic milestones (including return on investment) ensures sustainability of the project
      • monetary measurement being the lowest common denominator and for now the most objective tool, for bringing individuals together to collaborate for the common good, weed out free loaders and rent seekers
      • zero tolerance and speed
        • first mover advantage means leveraging on whatever few competitive advantages a start-up may have and move forward speedily and this means collaborate-collaborate-collaborate, document-document-document
          • financial incentives (game theory)
          • solving byzantine general problems
      • self-assessment helps to stake claim that would otherwise be claimed by free loaders, rent seekers etc – everyone will claim credit, and accountability & transparency will surface double spend problem
      • there must be financial dis-incentives to deter double spending / free loading / value extraction e.g. Hashed Timelock Contracts (HTLCs) – only a fair exchange of value will ensure the sustainability of the collaboration
      • workarounds in the block-chain space can mitigate the double spend problem
      • mitigate 2 key concerns – byzantine general problem and tragedy of the common
      • be careful of fragmentation … When things get difficult, people become more insular in their thinking and they start magnifying differences instead of focusing on commonalities” ~ Andreas Antonopoulos
    • workarounds are the norm in bleeding edge projects with no right or wrong path – it is about trial & error and sussing out the path of least resistance, testing traction and gaining adoption. It is always a work in progress. Therefore in such venture, long-term commitment is necessary and it predicated on one’s beliefs and behaviors towards the mission (purpose) and vision
  • co-working space to assemble the pieces of work

Posted on

Workshop 1 – Lightning Node Setup

Learning objectives:

  • to be able to setup a sandbox to learn more about LND
    • what is LND?
    • what is c-lightning?
      • why the need to install this on top of LND
    • what are the commands (cli) use for?
    • what are the use cases for the commands?
    • how to do up a simple smart contract?
  • understand what is meant by programmable money
    • give 1 to 2 examples how layer 2 BTC can be used this way
    • roll out a project to illustrate how layer 2 BTC is used this way

Resource materials:

Exercises: assuming that the setup is completed

  • Running
    • bitcoind or
    • bitcoin-qt
      can run either one (bitcoind , bitcoin-qt) not both
  • Test whether bitcoind is running
    • bitcoin-cli getblockchaininfo
    • ps|grep bitcoind
  • shutdown and power up
  • controlling services
    • Start: sudo systemctl start
    • Restart: sudo systemctl restart
    • The services names are: bitcoind,lightningd,btc-rpc-explorer,eps and spark-wallet

Questions:

  • Node address – does the TOR hide the full node address?
  • Tor Hidden Services and other – how to remote access the node and wallet in order to test out cli commands e.g.
  • Node address does not accept incoming connections – do we need to open port and expose IP? –
    • what abt TOR – what purpose does it serve?
  • Test drive commands
    • start lightningd
      • lightning/lightningd/lightningd
        • ~/lightning/cli$ ./lightning-cli []
    • lightning-cli help
      • lightning-cli newaddr
        • pay via any segwit HD (hierarchical deterministic) wallet
      • lightning-cli connect id [host] [port]
      • lightning-cli getinfo
    • hands-on example: how to send lightning payments using the terminal?
      • lightning-cli newaddr
        • Layer 1 BTC transaction
        • Bech32 – a segwit address format specified by BIP 0173)
          • bc1 format
      • lightning-cli listfunds
      • lightning-cli connect 03e5f9d1935c67a029bf0a26af5f63109f4f4c45993a8f45177a8f2f39bcb46144 77.58.162.148 9735
        • nodeId@host:port
      • lightning-cli list peers
      • lightning-cli fundchannel
      • lightning-cli listpeers
      • lightning-cli decodepay
      • lightning-cli pay
      • lightning-cli listpayments
  • Down the rabbit hole … and took a detour
    • need to take a look into bitcoin-cli and bitcoind, together with chapter 3 of Andreas Antonopoulos’ book Mastering Bitcoin
      • elliptic curve cryptography – generating the public key in Python
      • bitcoin scripts
    • using python to test drive the command-line interface (cli)

[ifpaid 0.00001 BTC text=”Please pay 0.00001 BTC to continue reading.” button=”Click here to pay using the Lightning Network”]

  • what is:
    • sudo ufw allow from 192.168.1.0/24 to any port 50002,3002,9737,22 proto tcp