Assignment on distributed software systems at the university.
- Make sure Golang 1.16+ is installed.
- Make sure calling the go command works in the terminal.
To start the project, clone the project and navigate to the golang-blockchain
folder in the terminal.
cd $GOPATH/src/golang-blockchain
Install all dependencies in the go.mod
file using go get
.
To invoke the helper on the command line, simply run the main project file main.go
.
go run main.go
The main executable file of the project is main.go
, where the command line is called to interact with the user.
The go.mod
and go.sum
files are used to store project requirements. For example, the query to the required database and its version.
The file cli/cli.go
represents the command line logic, it provides instructions for the program to work to the user.
The tmp
folder and the blocks folder inside it are needed for the badger database.
The network folder and inside it the network.go
file realizes network communication in the application.
There are 7 files inside the blockchain folder:
-
block.go
Provides the structure, creation of the first Genesis block and further blocks.
-
blockchain.go
Provides the structure of the blockchain and iterates over it. Used to implement blockchain functions.
-
chain_iter.go
Provides a structure for iterating over blockchains.
-
merkle.go
Provides a structure for the Merkle tree and its nodes.
-
proof.go
Provides structure for proof of block signing and its further mining.
-
transaction.go
Provides the structure of transactions and their signatures.
-
tx.go
Provides structure for input and output data for transactions.
-
utxo.go
Provides logic for reindexing and updating transactions.
The wallet folder is used to store 3 files:
-
utils.go
Stores functions for base58 encoding and decoding.
-
wallet.go
Provides the wallet structure and all its logic.
-
wallets.go
Provides a map of all wallets and their storage in a file.
Creating a wallet for further work with blockchain
go run main.go createwallet
Blockchain creation, including Genesis
go run main.go createblockchain -address ADDRESS
Transactions for token exchange
go run main.go send -from FROM -to TO -amount AMOUNT -mine
Display blockchain information
go run main.go printchain
Wallets address output
go run main.go listaddresses
Check balance in the wallet
go run main.go getbalance -address ADDRESS
Re-indexing tokens
go run main.go reindexutxo
Starting NODE and the miner
go run main.go startnode -miner ADDRESS
Below is a test example of using commands to work with the program in the terminal.
I advise to open several tabs in the terminal to work with NODE_ID
and further work with them.
export set NODE_ID=3000
export set NODE_ID=4000
export set NODE_ID=5000
go run main.go createwallet, go run main.go createwallet, go run main.go createwallet
go run main.go createblockchain -address ADDRESS
cp -R blocks_3000/ blocks_4000/
cp -R blocks_3000/ blocks_5000/
cp -R blocks_3000/ blocks_gen/
go run main.go send -from ADDRESS(NODE_ID=3000) -to ADDRESS(NODE_ID=5000) -amount 10 -mine
go run main.go startnode(NODE_ID=3000)
go run main.go startnode(NODE_ID=4000)
go run main.go startnode(NODE_ID=5000) -miner ADDRESS(NODE_ID=5000)
Exit NODE_ID=4000
go run main.go send -from ADDRESS(NODE_ID=5000) -to ADDRESS(NODE_ID=4000) -amount 1
go run main.go send -from ADDRESS(NODE_ID=4000) -to ADDRESS(NODE_ID=3000) -amount 1