ipld-eth-server/pkg/observers/blockchain_logging_observer.go

33 lines
673 B
Go
Raw Normal View History

package observers
import (
"os"
"text/template"
"time"
2017-11-06 18:53:43 +00:00
"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)
}