-
Notifications
You must be signed in to change notification settings - Fork 2
/
proof.go
57 lines (50 loc) · 1.74 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
package exported
import (
"fmt"
ics23 "github.com/confio/ics23/go"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/tendermint/tendermint/proto/tendermint/crypto"
)
func GetCommitmentProof(proof *crypto.ProofOps, getMultiStoreEp bool) ([]byte, *ics23.ExistenceProof, *ics23.ExistenceProof, error) {
if proof == nil {
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("Proof not found")
}
ops := proof.GetOps()
if ops == nil {
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("Proof ops not found")
}
// Extract iavl proof and multistore existence proof
var iavlEp *ics23.ExistenceProof
var multiStoreEp *ics23.ExistenceProof
for _, op := range ops {
switch op.GetType() {
case storetypes.ProofOpIAVLCommitment:
proof := &ics23.CommitmentProof{}
err := proof.Unmarshal(op.Data)
if err != nil {
panic(err)
}
iavlOps := storetypes.NewIavlCommitmentOp(op.Key, proof)
iavlEp = iavlOps.Proof.GetExist()
if iavlEp == nil {
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("IAVL existence proof not found")
}
case storetypes.ProofOpSimpleMerkleCommitment:
if getMultiStoreEp {
proof := &ics23.CommitmentProof{}
err := proof.Unmarshal(op.Data)
if err != nil {
panic(err)
}
multiStoreOps := storetypes.NewSimpleMerkleCommitmentOp(op.Key, proof)
multiStoreEp = multiStoreOps.Proof.GetExist()
if multiStoreEp == nil {
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("MultiStore existence proof not found")
}
}
default:
return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("Unknown proof ops found")
}
}
return nil, iavlEp, multiStoreEp, nil
}