github.com/turingchain2020/turingchain@v1.1.21/executor/plugin_stat.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package executor 6 7 import ( 8 "github.com/turingchain2020/turingchain/types" 9 ) 10 11 func init() { 12 RegisterPlugin("stat", &statPlugin{}) 13 } 14 15 type statPlugin struct { 16 pluginBase 17 } 18 19 func (p *statPlugin) CheckEnable(executor *executor, enable bool) (kvs []*types.KeyValue, ok bool, err error) { 20 kvs, ok, err = p.checkFlag(executor, types.StatisticFlag(), enable) 21 if err == types.ErrDBFlag { 22 panic("stat config is enable, it must be synchronized from 0 height ") 23 } 24 return kvs, ok, err 25 } 26 27 func (p *statPlugin) ExecLocal(executor *executor, data *types.BlockDetail) ([]*types.KeyValue, error) { 28 return countInfo(executor, data) 29 } 30 31 func (p *statPlugin) ExecDelLocal(executor *executor, data *types.BlockDetail) ([]*types.KeyValue, error) { 32 return delCountInfo(executor, data) 33 } 34 35 func countInfo(ex *executor, b *types.BlockDetail) ([]*types.KeyValue, error) { 36 var kvset types.LocalDBSet 37 //保存挖矿统计数据 38 ticketkv, err := countTicket(ex, b) 39 if err != nil { 40 return nil, err 41 } 42 if ticketkv == nil { 43 return nil, nil 44 } 45 kvset.KV = ticketkv.KV 46 return kvset.KV, nil 47 } 48 49 func delCountInfo(ex *executor, b *types.BlockDetail) ([]*types.KeyValue, error) { 50 var kvset types.LocalDBSet 51 //删除挖矿统计数据 52 ticketkv, err := delCountTicket(ex, b) 53 if err != nil { 54 return nil, err 55 } 56 if ticketkv == nil { 57 return nil, nil 58 } 59 kvset.KV = ticketkv.KV 60 return kvset.KV, nil 61 } 62 63 //这两个功能需要重构到 ticket 里面去。 64 //有些功能需要开启选项,才会启用功能。并且功能必须从0开始 65 func countTicket(ex *executor, b *types.BlockDetail) (*types.LocalDBSet, error) { 66 return nil, nil 67 } 68 69 func delCountTicket(ex *executor, b *types.BlockDetail) (*types.LocalDBSet, error) { 70 return nil, nil 71 }