2017-11-02 19:37:07 +00:00
|
|
|
package observers
|
2017-10-23 15:56:29 +00:00
|
|
|
|
2017-10-25 22:24:38 +00:00
|
|
|
import (
|
2017-12-19 20:14:41 +00:00
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2017-10-25 22:24:38 +00:00
|
|
|
"time"
|
2017-11-02 19:37:07 +00:00
|
|
|
|
2017-11-06 18:53:43 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
2017-10-25 22:24:38 +00:00
|
|
|
)
|
2017-10-23 15:56:29 +00:00
|
|
|
|
2017-12-19 20:14:41 +00:00
|
|
|
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))
|
|
|
|
|
2017-10-23 15:56:29 +00:00
|
|
|
type BlockchainLoggingObserver struct{}
|
|
|
|
|
2017-11-02 19:37:07 +00:00
|
|
|
func (blockchainObserver BlockchainLoggingObserver) NotifyBlockAdded(block core.Block) {
|
2017-12-19 20:14:41 +00:00
|
|
|
tmp.Execute(os.Stdout, block)
|
2017-10-23 15:56:29 +00:00
|
|
|
}
|