Skip to content

Commit

Permalink
Make project with bbolt?
Browse files Browse the repository at this point in the history
  • Loading branch information
steadylearner committed Feb 13, 2020
1 parent c55f9ea commit 17032ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions blockchain/golang/part4/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const dbFile = "blockchain.db"
const blocksBucket = "blocks"
const genesisCoinbaseData = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
const genesisCoinbaseData = "genesisCoinbaseData"

// Blockchain implements interactions with a DB
type Blockchain struct {
Expand Down Expand Up @@ -128,6 +128,7 @@ func (bc *Blockchain) FindSpendableOutputs(address string, amount int) (int, map
unspentTXs := bc.FindUnspentTransactions(address)
accumulated := 0

// Give loop name to continue or break
Work:
for _, tx := range unspentTXs {
txID := hex.EncodeToString(tx.ID)
Expand Down Expand Up @@ -183,10 +184,11 @@ func dbExists() bool {
return true
}

// NewBlockchain creates a new Blockchain with genesis Block
// 1. NewBlockchain creates a new Blockchain with genesis Block
func NewBlockchain(address string) *Blockchain {
if dbExists() == false {
fmt.Println("No existing blockchain found. Create one first.")
fmt.Println("No blockchain butil yet. We will create one first.")
// There was some issue which caused the program to exit.
os.Exit(1)
}

Expand All @@ -212,10 +214,10 @@ func NewBlockchain(address string) *Blockchain {
return &bc
}

// CreateBlockchain creates a new blockchain DB
// 2. CreateBlockchain creates a new blockchain DB
func CreateBlockchain(address string) *Blockchain {
if dbExists() {
fmt.Println("Blockchain already exists.")
fmt.Println("Blockchain was already made.")
os.Exit(1)
}

Expand Down
1 change: 1 addition & 0 deletions blockchain/golang/part4/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

// CLI responsible for processing command line arguments
// Use this form just to attach methods to it.
type CLI struct{}

func (cli *CLI) createBlockchain(address string) {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/golang/part4/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module https: //github.com/steadylearner/part4
go 1.13

require (
github.com/boltdb/bolt v1.3.1 // indirect
github.com/boltdb/bolt v1.3.1
go.etcd.io/bbolt v1.3.3
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
)

0 comments on commit 17032ab

Please # to comment.