This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade.go
94 lines (78 loc) · 2.25 KB
/
grade.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
86
87
88
89
90
91
92
93
94
package OracleMiner
import (
"fmt"
"github.com/FactomProject/factom"
"github.com/pegnet/OracleRecord"
)
func GradeLastBlock(mstate *MinerState, opr *oprecord.OraclePriceRecord, dbht int64, miner *Mine) {
var oprs []*oprecord.OraclePriceRecord
oprChainID := mstate.GetOraclePriceRecordChain()
var eb *factom.EBlock
// Get the last DirectoryBlock Merkle Root
ebMR, err := factom.GetChainHead(oprChainID)
check(err)
// Get the last DirectoryBlock
eb, err = factom.GetEBlock(ebMR)
if err != nil || eb == nil {
fmt.Println(err)
fmt.Printf("%s\n", ebMR)
}
for i, ebentry := range eb.EntryList {
entry, err := factom.GetEntry(ebentry.EntryHash)
if err != nil {
fmt.Println(i, "Error Entry Nil")
continue
}
if len(entry.ExtIDs) != 1 {
fmt.Println(i, "skipping ExtIDs not 1")
continue
}
newOpr := new(oprecord.OraclePriceRecord)
err = newOpr.UnmarshalBinary(entry.Content)
if err != nil {
fmt.Println(i, "Error Unmarshalling OPR")
continue
}
if newOpr.Dbht != int32(dbht) {
//continue
}
newOpr.Entry = entry
copy(newOpr.Nonce[:], entry.ExtIDs[0])
if newOpr.ComputeDifficulty() == 0 {
fmt.Println(i, "Error Difficulty is zero!")
continue
}
oprs = append(oprs, newOpr)
}
tobepaid, oprlist := oprecord.GradeBlock(oprs)
_, _ = tobepaid, oprlist
if len(tobepaid) > 0 {
copy(opr.WinningPreviousOPR[:], tobepaid[0].GetEntry(mstate.GetOraclePriceRecordChain()).Hash())
//h := tobepaid[0].FactomDigitalID[:6]
//fmt.Printf("OPRs %3d tobepaid %3d winner %x\n", len(oprs), len(tobepaid), h)
if mstate.MinerNumber == 1 {
for i, op := range tobepaid {
fmt.Printf("%3d %s\n", i+1, op.ShortString())
}
fmt.Println("==================")
for i, op := range oprlist {
fmt.Printf("%3d %s\n", i+1, op.ShortString())
}
}
if mstate.MinerNumber == 1 {
fmt.Println(tobepaid[0].String())
}
}
}
func NewEntry(chainID string, extIDs [][]byte, content []byte) *factom.Entry {
e := factom.Entry{ChainID: chainID, ExtIDs: extIDs, Content: content}
return &e
}
func NewEntryStr(chainID string, extIDs []string, content string) *factom.Entry {
var b [][]byte
for _, str := range extIDs {
b = append(b, []byte(str))
}
e := factom.Entry{ChainID: chainID, ExtIDs: b, Content: []byte(content)}
return &e
}