web3coach / the-blockchain-bar

The source-code for: "Build a Blockchain from Scratch in Go" eBook.
https://web3.coach
GNU Lesser General Public License v3.0
499 stars 184 forks source link

Error if no tx.db file #7

Closed timdadd closed 4 years ago

timdadd commented 4 years ago

Basically the first state is a genesis file with no transactions, the transactions need adding. So no tx.db file if you use rm database/tx.db

I added this code:

// Now apply the transactions in the transaction file which is a set of json messages
txDbFilePath := filepath.Join(cwd, databaseDir, "tx.db")
// If the file doesn't exist then create it
_, err = os.Stat(txDbFilePath)
if os.IsNotExist(err) {
    _, err = os.Create(txDbFilePath)
}
if err != nil {
    return nil, err
}
web3coach commented 4 years ago

Instead of removing the entire tx.db file, you could also just empty the TXs inside by removing its content.

If you would like to add this support for non existent tx.db file (which should never be missing bc is commited to the repository), can u please create a PR for this? :)

Glad to see you eager to learn and progressing through the book Tim!

timdadd commented 4 years ago

will do and thanks for writing such an entertaining tutorial.

web3coach commented 4 years ago

Glad you are enjoying the book! Gonna close this task. Let me know how is your book progress going, and if you have any other question feel free to reach out on Discord. Happy to help and chat! :)