/
incremententrygen.go
60 lines (49 loc) · 1.79 KB
/
incremententrygen.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
59
60
package blockgen
import (
"fmt"
"github.com/FactomProject/factomd/common/entryBlock"
"github.com/FactomProject/factomd/common/entryCreditBlock"
"github.com/FactomProject/factomd/common/interfaces"
"github.com/FactomProject/factomd/common/primitives"
)
/********************
* EntryGen Example *
* with a state *
********************/
// IncrementEntryGenerator generates entries of incrementing count
// The count is reset per chain.
type IncrementEntryGenerator struct {
EntryGenCore // Has supporting functions and fields
// The stateful object
currentCount int
}
func NewIncrementEntryGenerator(ecKey primitives.PrivateKey, config EntryGeneratorConfig) *IncrementEntryGenerator {
r := new(IncrementEntryGenerator)
r.ECKey = ecKey
r.Config = config
r.Parent = r
return r
}
func (r *IncrementEntryGenerator) Name() string {
return "IncrementEntryGenerator"
}
func (r *IncrementEntryGenerator) NewChainHead() *entryBlock.Entry {
// Reset the count for the next chain
r.currentCount = 0
return r.EntryGenCore.NewChainHead()
}
func (r *IncrementEntryGenerator) NewEntry(chain interfaces.IHash) *entryBlock.Entry {
ent := entryBlock.NewEntry()
// Putting the ASCII number so you can read in explorer
ent.Content = primitives.ByteSlice{[]byte(fmt.Sprintf("%d", r.currentCount))}
ent.ChainID = chain
r.currentCount++
return ent
}
// Default implementation
func (r *IncrementEntryGenerator) AllEntries(height uint32, time interfaces.Timestamp) ([]*entryBlock.EBlock, []*entryBlock.Entry, []*entryCreditBlock.CommitEntry, int) {
return r.EntryGenCore.AllEntries(height, time)
}
func (r *IncrementEntryGenerator) NewEblock(height uint32, time interfaces.Timestamp) (*entryBlock.EBlock, []*entryBlock.Entry, []*entryCreditBlock.CommitEntry, int) {
return r.EntryGenCore.NewEblock(height, time)
}