Skip to content

Commit

Permalink
Upgrade ZCashOrchardStorage for shard tree purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Nov 13, 2024
1 parent eb888f9 commit eebde04
Show file tree
Hide file tree
Showing 17 changed files with 2,114 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace brave_wallet {
OrchardBlockScanner::Result::Result() = default;

OrchardBlockScanner::Result::Result(std::vector<OrchardNote> discovered_notes,
std::vector<OrchardNullifier> spent_notes)
std::vector<OrchardNoteSpend> spent_notes)
: discovered_notes(std::move(discovered_notes)),
spent_notes(std::move(spent_notes)) {}

Expand All @@ -31,7 +31,7 @@ base::expected<OrchardBlockScanner::Result, OrchardBlockScanner::ErrorCode>
OrchardBlockScanner::ScanBlocks(
std::vector<OrchardNote> known_notes,
std::vector<zcash::mojom::CompactBlockPtr> blocks) {
std::vector<OrchardNullifier> found_nullifiers;
std::vector<OrchardNoteSpend> found_spends;
std::vector<OrchardNote> found_notes;

for (const auto& block : blocks) {
Expand Down Expand Up @@ -64,15 +64,15 @@ OrchardBlockScanner::ScanBlocks(
[&action_nullifier](const auto& v) {
return v.nullifier == action_nullifier;
}) != known_notes.end()) {
OrchardNullifier nullifier;
nullifier.block_id = block->height;
nullifier.nullifier = action_nullifier;
found_nullifiers.push_back(std::move(nullifier));
OrchardNoteSpend spend;
spend.block_id = block->height;
spend.nullifier = action_nullifier;
found_spends.push_back(std::move(spend));
}
}
}
}
return Result({std::move(found_notes), std::move(found_nullifiers)});
return Result({std::move(found_notes), std::move(found_spends)});
}

} // namespace brave_wallet
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class OrchardBlockScanner {
struct Result {
Result();
Result(std::vector<OrchardNote> discovered_notes,
std::vector<OrchardNullifier> spent_notes);
std::vector<OrchardNoteSpend> spent_notes);
Result(const Result&);
Result& operator=(const Result&);
~Result();

// New notes have been discovered
std::vector<OrchardNote> discovered_notes;
// Nullifiers for the previously discovered notes
std::vector<OrchardNullifier> spent_notes;
std::vector<OrchardNoteSpend> spent_notes;
};

explicit OrchardBlockScanner(const OrchardFullViewKey& full_view_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ TEST(OrchardBlockScanner, FoundKnownNullifiers) {
PrefixedHexStringToBytes(
"0x1b32edbbe4d18f28876de262518ad31122701f8c0a52e98047a337876e7eea19")
.value();
OrchardNullifier nf;
OrchardNoteSpend nf;
base::ranges::copy(nullifier_bytes, nf.nullifier.begin());
nf.block_id = 10;

Expand Down
2 changes: 0 additions & 2 deletions components/brave_wallet/browser/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ source_set("brave_wallet_unit_tests") {
"//brave/components/brave_wallet/browser/zcash/zcash_orchard_storage_unittest.cc",
"//brave/components/brave_wallet/browser/zcash/zcash_shield_sync_service_unittest.cc",
]
deps +=
[ "//brave/components/brave_wallet/browser/internal:orchard_bundle" ]
}

if (!is_ios) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ OrchardBlockDecoderImpl::ScanBlock(
::rust::Box<::brave_wallet::orchard::BatchOrchardDecodeBundle>
result_bundle = decode_result->unwrap();
for (size_t i = 0; i < result_bundle->size(); i++) {
result.emplace_back(OrchardNote(
{block->height, result_bundle->note_nullifier(full_view_key_, i),
result_bundle->note_value(i)}));
result.emplace_back(
OrchardNote({{},
block->height,
result_bundle->note_nullifier(full_view_key_, i),
result_bundle->note_value(i),
0,
{},
{}}));
}
} else {
return std::nullopt;
Expand Down
Loading

0 comments on commit eebde04

Please sign in to comment.