Canonical blocks (#108)

* Update Block w/ newest Block

* Add cascading delete to blocks and transactions tables

* Add handling for new conflicting blocks

* Command line version of sliding window n behind HEAD
This commit is contained in:
Matt K
2017-12-19 14:14:41 -06:00
committed by GitHub
parent 84e77f259d
commit 266c9587c8
19 changed files with 352 additions and 70 deletions
+1 -1
View File
@@ -14,5 +14,5 @@ func NewBlockchainDbObserver(repository repositories.Repository) BlockchainDbObs
}
func (observer BlockchainDbObserver) NotifyBlockAdded(block core.Block) {
observer.repository.CreateBlock(block)
observer.repository.CreateOrUpdateBlock(block)
}
+20 -6
View File
@@ -1,18 +1,32 @@
package observers
import (
"fmt"
"os"
"text/template"
"time"
"github.com/8thlight/vulcanizedb/pkg/core"
)
const blockAddedTemplate = `
New block was added: {{.Number}}
Time: {{.Time | unix_time}}
Gas Limit: {{.GasLimit}}
Gas Used: {{.GasUsed}}
Number of Transactions {{.Transactions | len}}
`
var funcMap = template.FuncMap{
"unix_time": func(n int64) time.Time {
return time.Unix(n, 0)
},
}
var tmp = template.Must(template.New("window").Funcs(funcMap).Parse(blockAddedTemplate))
type BlockchainLoggingObserver struct{}
func (blockchainObserver BlockchainLoggingObserver) NotifyBlockAdded(block core.Block) {
fmt.Printf("New block was added: %d\n"+
"\tTime: %v\n"+
"\tGas Limit: %d\n"+
"\tGas Used: %d\n"+
"\tNumber of Transactions %d\n", block.Number, time.Unix(block.Time, 0), block.GasLimit, block.GasUsed, len(block.Transactions))
tmp.Execute(os.Stdout, block)
}