forked from cerc-io/ipld-eth-server
266c9587c8
* 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
33 lines
673 B
Go
33 lines
673 B
Go
package observers
|
|
|
|
import (
|
|
"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) {
|
|
tmp.Execute(os.Stdout, block)
|
|
}
|