Recently looked at the bitcoin source code, initially see the mainstream C + + version, but I have not used C + + for many years, almost equivalent to revisit the grammar, in addition to C + + environment compiled a lot of trouble. Instead of starting with the Golang version, the Golang language is relatively easy to get started, and the BTCD version of the code module design and unit testing is clearer and better than the C + + version of the source.
For Golang Novice But there are other language based people, I recommend "Go language combat" as a Golang primer books. The book is not the same as the traditional teaching materials according to the basic type, cycle this sequence of routines, but directly point out Golang and other languages, and with different small items directly from the code to explain the Golang grammar. For people with other language basics, it's easier to understand a new language through code.
At the same time, you can first see "How to implement Blockchain" this simplified version of the project (https://liuchengxu.gitbooks.io/blockchain-tutorial/content/part-1/ basic-prototype.html), which includes the most basic structure of the blockchain, can help to understand. After the basic work is ready, start experiencing the BTCD code.
First of all to configure the environment, I use the Ubuntu system, install Golang and then set the Goroot and Gopath path. These can be found in the online detailed setup method, simply said Goroot is the Golang source installation path, Gopath is the path to develop code, similar to Java Project workplace.
$ go get -u github.com/Masterminds/glide$ git clone https://github.com/btcsuite/btcd $GOPATH/src/github.com/btcsuite/btcd$ cd $GOPATH/src/github.com/btcsuite/btcd$ glide install$ go install . ./cmd/...
Run Glide install here will encounter wall problems, resulting in the following error:
[ERROR] Update failed for golang.org/x/crypto: Cannot detect VCS
My approach is to configure the image and then re-run glide install.
glide mirror set https://golang.org/x/crypto https://github.com/golang/crypto --vcs git
As simple as this, the BTCD installation is complete.
There are a few basic commands that you can run down
View version
btcd --version
To view available commands
btcd --help
Run BTCD directly started the Bitcoin program, the built-in DNS seeds will let this new node access to the Bitcoin network.
btcd
BTCD start a new node.
In this, you can see a lot of information, that is, the local re-node how to access other nodes in the Bitcoin network, and then download the chunk data to the local, detailed interactive details to be analyzed later. Simply put, the first launch of the program, like a newcomer into the world of Bitcoin, but the new people do not know the world in the others, others do not know him. So the newcomer will first find several authoritative people (DNS Seeds), find the other person's address, then the new person to meet more people, become part of this network, at the same time the ledger data on their hand to download to the local.
In addition, it is necessary to pay attention to this is the main network, this is the January 3, 2009 Nakamoto to create a bitcoin network, the current total chunk data has exceeded 100G. If you just study the code, do not need to download so much data, and there is no way to test directly on the main network, because each transaction to the real gold miner fee, then testnet or become the first choice of local development, the next article will introduce the Bitcoin test network.