Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Oct 21, 2024
1 parent 24d9a2a commit f2536f3
Show file tree
Hide file tree
Showing 57 changed files with 1,118 additions and 483 deletions.
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ static_library("browser") {
"zcash/zcash_get_transparent_utxos_context.h",
"zcash/zcash_grpc_utils.cc",
"zcash/zcash_grpc_utils.h",
"zcash/zcash_resolve_balance_task.cc",
"zcash/zcash_resolve_balance_task.h",
"zcash/zcash_rpc.cc",
"zcash/zcash_rpc.h",
"zcash/zcash_serializer.cc",
Expand Down
6 changes: 6 additions & 0 deletions components/brave_wallet/browser/brave_wallet_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,19 @@ void BraveWalletService::GetUserAssets(const std::string& chain_id,
}
}

if (coin == mojom::CoinType::ZEC) {
result.push_back(GetZcashNativeShieldedToken(chain_id));
}

std::move(callback).Run(
EnsureNativeTokens(chain_id, coin, std::move(result)));
}

void BraveWalletService::GetAllUserAssets(GetUserAssetsCallback callback) {
std::vector<mojom::BlockchainTokenPtr> result =
::brave_wallet::GetAllUserAssets(profile_prefs_);
result.push_back(GetZcashNativeShieldedToken(mojom::kZCashMainnet));
result.push_back(GetZcashNativeShieldedToken(mojom::kZCashTestnet));
std::move(callback).Run(std::move(result));
}

Expand Down
14 changes: 14 additions & 0 deletions components/brave_wallet/browser/brave_wallet_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,20 @@ mojom::BlockchainTokenPtr GetZcashNativeToken(const std::string& chain_id) {
return result;
}

mojom::BlockchainTokenPtr GetZcashNativeShieldedToken(const std::string& chain_id) {
auto network = NetworkManager::GetKnownChain(chain_id, mojom::CoinType::ZEC);
CHECK(network);

auto result = NetworkToNativeToken(*network);
result->logo = "zec.png";
result->coingecko_id = "zec";
result->is_shielded = true;
result->name = "Zcash(Shielded)";

return result;
}


mojom::BlowfishOptInStatus GetTransactionSimulationOptInStatus(
PrefService* prefs) {
return static_cast<mojom::BlowfishOptInStatus>(
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/browser/brave_wallet_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ std::string WalletInternalErrorMessage();

mojom::BlockchainTokenPtr GetBitcoinNativeToken(const std::string& chain_id);
mojom::BlockchainTokenPtr GetZcashNativeToken(const std::string& chain_id);
mojom::BlockchainTokenPtr GetZcashNativeShieldedToken(const std::string& chain_id);

mojom::BlowfishOptInStatus GetTransactionSimulationOptInStatus(
PrefService* prefs);
Expand Down
4 changes: 4 additions & 0 deletions components/brave_wallet/browser/internal/hd_key_zip32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ OrchardFullViewKey HDKeyZip32::GetFullViewKey() {
return extended_spending_key_->GetFullViewKey();
}

OrchardSpendingKey HDKeyZip32::GetSpendingKey() {
return extended_spending_key_->GetSpendingKey();
}

} // namespace brave_wallet
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/internal/hd_key_zip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class HDKeyZip32 {
// Full view key(fvk) is used to decode incoming transactions
OrchardFullViewKey GetFullViewKey();

OrchardSpendingKey GetSpendingKey();

private:
explicit HDKeyZip32(std::unique_ptr<orchard::ExtendedSpendingKey> key);
// Extended spending key is a root key of an account, all other keys can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ base::expected<OrchardBlockScanner::Result, OrchardBlockScanner::ErrorCode>
OrchardBlockScanner::ScanBlocks(
FrontierChainState chain_state,
std::vector<zcash::mojom::CompactBlockPtr> blocks) {
LOG(ERROR) << "XXXZZZ 1";
std::unique_ptr<orchard::OrchardDecodedBlocksBundle> result =
decoder_->ScanBlocks(chain_state, blocks);
if (!result) {
return base::unexpected(ErrorCode::kInputError);
}
LOG(ERROR) << "XXXZZZ 2";

if (!result->GetDiscoveredNotes()) {
return base::unexpected(ErrorCode::kInputError);
}
LOG(ERROR) << "XXXZZZ 3";

std::vector<OrchardNoteSpend> found_spends;
std::vector<OrchardNote> found_notes = result->GetDiscoveredNotes().value();
LOG(ERROR) << "XXXZZZ 4";

for (const auto& block : blocks) {
for (const auto& tx : block->vtx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ std::unique_ptr<OrchardShardTreeManager> OrchardShardTreeManager::Create(
}

// static
std::unique_ptr<OrchardShardTreeManager> OrchardShardTreeManager::CreateForTesting(
std::unique_ptr<OrchardShardTreeManager>
OrchardShardTreeManager::CreateForTesting(
std::unique_ptr<OrchardShardTreeDelegate> delegate) {
auto shard_tree =
orchard::OrchardShardTree::CreateForTesting(std::move(delegate));
Expand Down Expand Up @@ -57,4 +58,8 @@ OrchardShardTreeManager::CalculateWitness(std::vector<OrchardInput> notes,
return notes;
}

bool OrchardShardTreeManager::Truncate(uint32_t checkpoint) {
return orchard_shard_tree_->TruncateToCheckpoint(checkpoint);
}

} // namespace brave_wallet
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class OrchardShardTreeManager {
base::expected<std::vector<OrchardInput>, std::string> CalculateWitness(
std::vector<OrchardInput> notes,
uint32_t checkpoint_position);
bool Truncate(uint32_t checkpoint);
base::expected<bool, std::string> VerifyCheckpoint();

static std::unique_ptr<OrchardShardTreeManager> Create(
std::unique_ptr<OrchardShardTreeDelegate> delegate);
Expand Down
16 changes: 16 additions & 0 deletions components/brave_wallet/browser/keyring_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,17 @@ std::optional<OrchardFullViewKey> KeyringService::GetOrchardFullViewKey(

return zcash_keyring->GetOrchardFullViewKey(account_id->account_index);
}

std::optional<OrchardSpendingKey> KeyringService::GetOrchardSpendingKey(
const mojom::AccountIdPtr& account_id) {
auto* zcash_keyring = GetZCashKeyringById(account_id->keyring_id);
if (!zcash_keyring) {
return std::nullopt;
}

return zcash_keyring->GetOrchardSpendingKey(account_id->account_index);
}

#endif

void KeyringService::UpdateNextUnusedAddressForBitcoinAccount(
Expand Down Expand Up @@ -2512,6 +2523,11 @@ mojom::ZCashAccountInfoPtr KeyringService::GetZCashAccountInfo(
if (unified_address) {
result->unified_address = *unified_address;
}
auto orchard_address = zcash_keyring->GetShieldedAddress(
*mojom::ZCashKeyId::New(account_id->account_index, 0, 0));
if (orchard_address) {
result->orchard_address = orchard_address->address_string;
}
#endif // BUILDFLAG(ENABLE_ORCHARD)

return result;
Expand Down
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/keyring_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ class KeyringService : public mojom::KeyringService {
const mojom::ZCashKeyIdPtr& key_id);
std::optional<OrchardFullViewKey> GetOrchardFullViewKey(
const mojom::AccountIdPtr& account_id);
std::optional<OrchardSpendingKey> GetOrchardSpendingKey(
const mojom::AccountIdPtr& account_id);
#endif

const std::vector<mojom::AccountInfoPtr>& GetAllAccountInfos();
Expand Down
Loading

0 comments on commit f2536f3

Please sign in to comment.