No. A linked list is only required to have a reference to the previous element,
a block must have an identifier depending on the previous block’s identifier,
meaning that you cannot replace a block without recomputing every single block that comes after.
In this implementation that happens as the previous digest is input in the calc_hash method.

Trivia: Designed by the National Security Agency (NSA) of the United States of America (USA).

Secure == Random e.g. Change one Letter and the Hash will Change Completely

Making (Hash) Mining a Lottery - Find the Lucky Number

Find a hash that starts with ten leading zeros e.g.

0000000000069645c82795c96e4715cea0f5558be514b5096d853a5b9899154a

Hard to compute! Easy to check / validate.

Find the Lucky Number (Nonce == Number Used Once)

Making (Hash) Mining a Lottery

defcompute_hash_with_proof_of_work(difficulty="00")nonce=0loopdohash=calc_hash_with_nonce(nonce)ifhash.start_with?(difficulty)return[nonce,hash]## bingo! proof of work if hash starts with leading zeros (00)elsenonce+=1## keep trying (and trying and trying)endendenddefcalc_hash_with_nonce(nonce=0)sha=Digest::SHA256.newsha.update(nonce.to_s+@index.to_s+@timestamp.to_s+@data+@previous_hash)sha.hexdigestend

See the difference?
All hashes now start with leading zeros (00)
and the nonce is the random “lucky number” that makes it happen.
That’s the magic behind the proof of work.

3. Adding Transactions

Contents

The World's Worst Database - Bitcoin Blockchain Mining

Tulips on the Blockchain! Adding Transactions

The World’s Worst Database - Bitcoin Blockchain Mining

Uses approximately the same amount of electricity as could power an average American household
for a day per transaction

Supports 3 transactions / second across a global network with millions of CPUs/purpose-built ASICs

Takes over 10 minutes to “commit” a transaction

Doesn’t acknowledge accepted writes: requires you read your writes,
but at any given time you may be on a blockchain fork, meaning your write might not actually
make it into the “winning” fork of the blockchain (and no, just making it into the mempool doesn’t count).
In other words: “blockchain technology” cannot by definition tell you if a given write is ever
accepted/committed except by reading it out of the blockchain itself (and even then)

Can only be used as a transaction ledger denominated in a single currency,
or to store/timestamp a maximum of 80 bytes per transaction

No. A linked list is only required to have a reference to the previous element, a block must
have an identifier depending on the previous block’s identifier, meaning that you cannot
replace a block without recomputing every single block that comes after.
In this implementation that happens as the previous digest is input in the calc_hash method.

Proof-of-Work

classBlockattr_reader:indexattr_reader:timestampattr_reader:dataattr_reader:previous_hashattr_reader:nonce## proof of work if hash starts with leading zeros (00)attr_reader:hashdefinitialize(index,data,previous_hash)@index=index@timestamp=Time.now.utc## note: use coordinated universal time (utc)@data=data@previous_hash=previous_hash@nonce,@hash=compute_hash_with_proof_of_workend...end

Let’s add a proof of work to the blockchain.
In the classic blockchain you have to compute a block hash that starts with leading zeros (00). The more leading zeros the harder (more difficult) to compute. Let’s keep it easy to compute with two leading zeros (00), that is, 16^2 = 256 possibilites (^1,2). Three leading zeros (000) would be 16^3 = 4_096 possibilites and four zeros (0000) would be 16^4 = 65_536 and so on.

(^2): A random secure hash algorithm needs on average 256 tries (might be lets say 305 tries, for example, because it’s NOT a perfect statistic distribution of possibilities).

Example:

defcompute_hash_with_proof_of_work(difficulty="00")nonce=0loopdohash=calc_hash_with_nonce(nonce)ifhash.start_with?(difficulty)return[nonce,hash]## bingo! proof of work if hash starts with leading zeros (00)elsenonce+=1## keep trying (and trying and trying)endendenddefcalc_hash_with_nonce(nonce=0)sha=Digest::SHA256.newsha.update(nonce.to_s+@index.to_s+@timestamp.to_s+@data+@previous_hash)sha.hexdigestend

Let’s rerun the sample with the proof of work machinery added.
Now the sample will pretty print (pp) something like:

What’s a Merkle Tree?

A Merkle tree or hash tree is a tree in which every leaf node is labelled with
the hash of a data block and every non-leaf node is labelled with the
cryptographic hash of the labels of its child nodes.
Hash trees allow efficient and secure verification of the
contents of large data structures. […]

The concept of hash trees is named after Ralph Merkle
who patented it in 1979.

So the code adds a “COINBASE” transaction (tx) to the pending pool
(of unconfirmed transactions).
For mining a new block you will get a
mining reward (e.g. $5). That’s the magic moment of printing new money
on the blockchain.
Next all pending (unconfirmed but validated) transactions
get added to the blockchain (chain) as a new block.
Done! Block mined! Let’s clear out the pending pool
and update all wallet balances, that is, update the ledger book.
Let’s dive into the << method for the blockchain (chain) machinery:

Central Bank (gem: centralbank, github: openblockchains/centralbank) - command line tool to print your own money / cryptocurrency; run your own federated central bank nodes on the blockchain peer-to-peer over HTTP; revolutionize the world one block at a time

Blockchain has unlocked the magic of digital scarcity, and combining that with the power of
making the digital goods persistent gives them a potential value that is only limited by how much
prestige a wealthy person might place on ownership of the item.

Awesome CryptoKitties (and CryptoCopycats)

A collection about Awesome CryptoKitties (Yes, Cute Little Cartoon Cats) on the Blockchain! and CryptoCopycats - digital collectibles secured on a distributed public databases w/ crypto hashes. Are CryptoPuppies the new CryptoKitties? Learn by Example from the Real World (Anno 2017) - Buy! Sell! Hodl!

A3. Resources

Blockchain Articles

Reflections on the Blockchain by Rufus Pollock (Open Knowledge Foundation), July 2016 –
The DAO: Code is not Law – and It’s Dangerous to Think So ++
The Internet changed the world - surely the Blockchain will too? ++
Gold-rush or Internet-rush? ++
Governance Matters in Bitcoin ++
The Myth of a Costless, Ownerless Network ++
Lessons from History

Blockchain Books

Attack of the 50 Foot Blockchain: Bitcoin, Blockchain, Ethereum & Smart Contracts by David Gerard, London, 2017 –
What is a bitcoin? ++
The Bitcoin ideology ++
The incredible promises of Bitcoin! ++
Early Bitcoin: the rise to the first bubble ++
How Bitcoin mining centralised ++
Who is Satoshi Nakamoto? ++
Spending bitcoins in 2017 ++
Trading bitcoins in 2017: the second crypto bubble ++
Altcoins ++
Smart contracts, stupid humans ++
Business bafflegab, but on the Blockchain ++
Case study: Why you can’t put the music industry on a blockchain