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.goThe 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.goProvides the structure, creation of the first Genesis block and further blocks.
-
blockchain.goProvides the structure of the blockchain and iterates over it. Used to implement blockchain functions.
-
chain_iter.goProvides a structure for iterating over blockchains.
-
merkle.goProvides a structure for the Merkle tree and its nodes.
-
proof.goProvides structure for proof of block signing and its further mining.
-
transaction.goProvides the structure of transactions and their signatures.
-
tx.goProvides structure for input and output data for transactions.
-
utxo.goProvides logic for reindexing and updating transactions.
The wallet folder is used to store 3 files:
-
utils.goStores functions for base58 encoding and decoding.
-
wallet.goProvides the wallet structure and all its logic.
-
wallets.goProvides a map of all wallets and their storage in a file.
Creating a wallet for further work with blockchain
go run main.go createwalletBlockchain creation, including Genesis
go run main.go createblockchain -address ADDRESSTransactions for token exchange
go run main.go send -from FROM -to TO -amount AMOUNT -mineDisplay blockchain information
go run main.go printchainWallets address output
go run main.go listaddressesCheck balance in the wallet
go run main.go getbalance -address ADDRESSRe-indexing tokens
go run main.go reindexutxoStarting NODE and the miner
go run main.go startnode -miner ADDRESSBelow 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=5000go run main.go createwallet, go run main.go createwallet, go run main.go createwalletgo run main.go createblockchain -address ADDRESScp -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 -minego 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 1go run main.go send -from ADDRESS(NODE_ID=4000) -to ADDRESS(NODE_ID=3000) -amount 1