Operating System:
In this Golang video tutorial, we take our first steps into building a full featured blockchain with the Go programming language. We also take a look at the new Go module system which was added to the language as of Go version 1.11 and how it simplifies package management in Go.
When Go was first released, the language was built with a somewhat unorthodox system called the GOPATH. To develop Go applications, a user needed to define a directory on their computer as your GOPATH. This GOPATH environment variable tells the compiler where to find directories that contain Go source code outside of the installation directory. The old module system is derived off of this concept and there was no first party package manager included in the Go tool chain.
With the release of Go version 1.11, this module system was reworked so that the GOPATH is no longer a requirement. A new command called go mod was added to the tool chain. This command allows the user to define a go module inside of any directory on their computer. This module system also enables package management with version control. The above image shows a go.sum file which is similar to a yarn.lock or package-lock.json file.
In general terms, a blockchain can be defined as a distributed peer to peer database. The blockchain itself is like a linked list made of hashes. Each block contains its own hash and a hash that points at the proceeding block in the chain. The block also contains the data which is being stored on the chain. This data is used to derive the block's hash through a proof of x hashing algorithm.
In this example, we implement this basic generalization with Go. A block type is defined with a hash, a previous hash reference and a data field. The hash for each block is derived using a SHA256 algorithm which doesn't require much work. This algorithm acts as a placeholder for the hashcash proof of work algorithm that will be implemented in future videos. When the data changes, the block's hash changes which makes it easy to verify that the data is corrupted.
The Source Code for this video may be found here: https://github.com/tensor-programming/golang-blockchain