-
Notifications
You must be signed in to change notification settings - Fork 14
/
proof.go
46 lines (37 loc) · 971 Bytes
/
proof.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
package pow
import (
"bytes"
"go.dedis.ch/dela/core/store/hashtree"
"golang.org/x/xerrors"
)
// Proof is a proof that the chain of blocks has or has not the key in the
// store. If the key exists, the proof also contains the value.
//
// - implements ordering.Proof
type Proof struct {
blocks []Block
path hashtree.Path
}
// NewProof creates a new valid proof.
func NewProof(blocks []Block, path hashtree.Path) (Proof, error) {
pr := Proof{
blocks: blocks,
path: path,
}
if len(blocks) == 0 {
return pr, xerrors.New("empty list of blocks")
}
last := blocks[len(blocks)-1]
if !bytes.Equal(last.root, path.GetRoot()) {
return pr, xerrors.Errorf("mismatch block and share store root %#x != %#x", last.root, path.GetRoot())
}
return pr, nil
}
// GetKey implements ordering.Proof.
func (p Proof) GetKey() []byte {
return p.path.GetKey()
}
// GetValue implements ordering.Proof.
func (p Proof) GetValue() []byte {
return p.path.GetValue()
}