Skip to content

Commit 720b7a5

Browse files
chris124567ChrisSchinnerl
authored andcommitted
retrieve merkle proof for outputs, v2 contracts
1 parent 9816b73 commit 720b7a5

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

persist/sqlite/addresses.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func (s *Store) SiacoinElements(ids []types.SiacoinOutputID) (result []explorer.
173173
if err != nil {
174174
return fmt.Errorf("failed to scan siacoin output: %w", err)
175175
}
176+
sco.StateElement.MerkleProof, err = s.MerkleProof(sco.StateElement.LeafIndex)
177+
if err != nil {
178+
return fmt.Errorf("failed to get output merkle proof: %w", err)
179+
}
180+
176181
result = append(result, sco)
177182
}
178183
return nil
@@ -199,6 +204,10 @@ func (s *Store) SiafundElements(ids []types.SiafundOutputID) (result []explorer.
199204
if err != nil {
200205
return fmt.Errorf("failed to scan siafund output: %w", err)
201206
}
207+
sfo.StateElement.MerkleProof, err = s.MerkleProof(sfo.StateElement.LeafIndex)
208+
if err != nil {
209+
return fmt.Errorf("failed to get output merkle proof: %w", err)
210+
}
202211
result = append(result, sfo)
203212
}
204213
return nil

persist/sqlite/v2consensus_test.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@ func getSCE(t *testing.T, db explorer.Store, scid types.SiacoinOutputID) types.S
2323
} else if len(sces) == 0 {
2424
t.Fatal("can't find sce")
2525
}
26-
sce := sces[0]
27-
28-
sce.SiacoinElement.StateElement.MerkleProof, err = db.MerkleProof(sce.StateElement.LeafIndex)
29-
if err != nil {
30-
t.Fatal(err)
31-
}
32-
33-
return sce.SiacoinElement
26+
return sces[0].SiacoinElement
3427
}
3528

3629
func getSFE(t *testing.T, db explorer.Store, sfid types.SiafundOutputID) types.SiafundElement {
@@ -42,14 +35,7 @@ func getSFE(t *testing.T, db explorer.Store, sfid types.SiafundOutputID) types.S
4235
} else if len(sfes) == 0 {
4336
t.Fatal("can't find sfe")
4437
}
45-
sfe := sfes[0]
46-
47-
sfe.SiafundElement.StateElement.MerkleProof, err = db.MerkleProof(sfe.StateElement.LeafIndex)
48-
if err != nil {
49-
t.Fatal(err)
50-
}
51-
52-
return sfe.SiafundElement
38+
return sfes[0].SiafundElement
5339
}
5440

5541
func getFCE(t *testing.T, db explorer.Store, fcid types.FileContractID) types.V2FileContractElement {
@@ -61,14 +47,7 @@ func getFCE(t *testing.T, db explorer.Store, fcid types.FileContractID) types.V2
6147
} else if len(fces) == 0 {
6248
t.Fatal("can't find fces")
6349
}
64-
fce := fces[0]
65-
66-
fce.V2FileContractElement.StateElement.MerkleProof, err = db.MerkleProof(fce.V2FileContractElement.StateElement.LeafIndex)
67-
if err != nil {
68-
t.Fatal(err)
69-
}
70-
71-
return fce.V2FileContractElement
50+
return fces[0].V2FileContractElement
7251
}
7352

7453
func getCIE(t *testing.T, db explorer.Store, bid types.BlockID) types.ChainIndexElement {

persist/sqlite/v2contracts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ WHERE rev.contract_id = ?
5050
if err != nil && !errors.Is(err, sql.ErrNoRows) {
5151
return fmt.Errorf("failed to scan file contract: %w", err)
5252
} else if err == nil {
53+
fc.V2FileContractElement.StateElement.MerkleProof, err = s.MerkleProof(fc.V2FileContractElement.StateElement.LeafIndex)
54+
if err != nil {
55+
return fmt.Errorf("failed to get contract merkle proof: %w", err)
56+
}
5357
result = append(result, fc)
5458
}
5559
}

0 commit comments

Comments
 (0)