-
Notifications
You must be signed in to change notification settings - Fork 0
/
spr.go
52 lines (46 loc) · 1.27 KB
/
spr.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
package node
import (
"context"
"fmt"
"github.com/Factom-Asset-Tokens/factom"
"github.com/pegnet/pegnet/modules/graderStake"
)
// Grade Staking Price Records
func (d *Pegnetd) GradeS(ctx context.Context, block *factom.EBlock) (graderStake.GradedBlock, error) {
if block == nil {
// TODO: Handle the case where there is no opr block.
// Must delay conversions if this- happens
return nil, nil
}
if *block.ChainID != SPRChain {
return nil, fmt.Errorf("trying to grade a non-spr chain")
}
ver := uint8(5)
if block.Height >= V20HeightActivation {
ver = 5
}
if block.Height >= SprSignatureActivation {
ver = 6
}
g, err := graderStake.NewGrader(ver, int32(block.Height))
if err != nil {
return nil, err
}
for _, entry := range block.Entries {
extids := make([][]byte, len(entry.ExtIDs))
for i := range entry.ExtIDs {
extids[i] = entry.ExtIDs[i]
}
// allow only top 100 stake holders submit prices
stakerRCD := extids[1]
if d.Pegnet.IsIncludedTopPEGAddress(stakerRCD) {
// ignore bad opr errors
err = g.AddSPR(entry.Hash[:], extids, entry.Content)
if err != nil {
// This is a noisy debug print
//logrus.WithError(err).WithFields(logrus.Fields{"hash": entry.Hash.String()}).Debug("failed to add spr")
}
}
}
return g.Grade(), nil
}