-
Notifications
You must be signed in to change notification settings - Fork 0
/
everybroadcastseed.go
58 lines (47 loc) · 1.66 KB
/
everybroadcastseed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2018 The MATRIX Authors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php
package everybroadcastseed
import (
"math/big"
"github.com/MatrixAINetwork/go-matrix/baseinterface"
"github.com/MatrixAINetwork/go-matrix/common"
"github.com/MatrixAINetwork/go-matrix/params/manparams"
)
var (
ModuleEveryBroadcastSeed = "广播区块种子"
mapEveryBroadcastSeedPlugs = make(map[string]preBroadcastSeedPlug)
)
func init() {
baseinterface.RegRandom(manparams.EveryBroadcastSeed, newSubService)
}
type preBroadcastSeedPlug interface {
CalcSeed(data common.Hash, support baseinterface.RandomChainSupport) (*big.Int, error)
Prepare(uint64, common.Hash) error
}
func newSubService(plug string, support baseinterface.RandomChainSupport) (baseinterface.RandomSubService, error) {
everyBroadcastSeed := &preBroadcastSeed{
plug: plug,
support: support,
}
return everyBroadcastSeed, nil
}
type preBroadcastSeed struct {
plug string
support baseinterface.RandomChainSupport
}
func (self *preBroadcastSeed) SetValue(plug string, support baseinterface.RandomChainSupport) error {
self.plug = plug
self.support = support
return nil
}
func RegisterEveryBlockSeedPlugs(name string, plug preBroadcastSeedPlug) {
mapEveryBroadcastSeedPlugs[name] = plug
}
func (self *preBroadcastSeed) Prepare(height uint64, hash common.Hash) error {
err := mapEveryBroadcastSeedPlugs[self.plug].Prepare(height, hash)
return err
}
func (self *preBroadcastSeed) CalcData(calcData common.Hash) (*big.Int, error) {
return mapEveryBroadcastSeedPlugs[self.plug].CalcSeed(calcData, self.support)
}