-
Notifications
You must be signed in to change notification settings - Fork 1
/
consensus.go
85 lines (74 loc) · 2.32 KB
/
consensus.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package types
import (
"time"
)
type GenesisRow struct {
OneRowID bool `db:"one_row_id"`
Time time.Time `db:"time"`
InitialHeight int64 `db:"initial_height"`
ChainId string `db:"chain_id"`
}
func NewGenesisRow(time time.Time, initialHeight int64, chainId string) GenesisRow {
return GenesisRow{
OneRowID: true,
Time: time,
InitialHeight: initialHeight,
ChainId: chainId,
}
}
func (r GenesisRow) Equal(s GenesisRow) bool {
return r.Time.Equal(s.Time) &&
r.InitialHeight == s.InitialHeight &&
r.ChainId == s.ChainId
}
// -------------------------------------------------------------------------------------------------------------------
// AverageTimeRow is the average block time each minute/hour/day
type AverageTimeRow struct {
OneRowID bool `db:"one_row_id"`
AverageTime float64 `db:"average_time"`
Height int64 `db:"height"`
}
func NewAverageTimeRow(averageTime float64, height int64) AverageTimeRow {
return AverageTimeRow{
OneRowID: true,
AverageTime: averageTime,
Height: height,
}
}
// Equal return true if two AverageTimeRow are true
func (r AverageTimeRow) Equal(s AverageTimeRow) bool {
return r.AverageTime == s.AverageTime &&
r.Height == s.Height
}
// -------------------------------------------------------------------------------------------------------------------
// BlockRow represents a single block row stored inside the database
type BlockRow struct {
Height int64 `db:"height"`
Id string `db:"id"`
ParentId string `db:"parent_id"`
CollectionGuarantees string `db:"collection_guarantees"`
Timestamp time.Time `db:"timestamp"`
}
// Equal tells whether v and w represent the same rows
func (v BlockRow) Equal(w BlockRow) bool {
return v.Height == w.Height &&
v.Id == w.Id &&
v.ParentId == w.ParentId &&
v.CollectionGuarantees == w.CollectionGuarantees &&
v.Timestamp.Equal(w.Timestamp)
}
// BlockRow allows to build a new BlockRow
func NewBlockRow(
height int64,
id string,
parentId string,
collectionGuarantees string,
timestamp time.Time) BlockRow {
return BlockRow{
Height: height,
Id: id,
ParentId: parentId,
CollectionGuarantees: collectionGuarantees,
Timestamp: timestamp,
}
}