Skip to content

Commit

Permalink
Build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Sep 12, 2024
1 parent de3799c commit 2e91873
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/keyring_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2505,12 +2505,14 @@ mojom::ZCashAccountInfoPtr KeyringService::GetZCashAccountInfo(
derived_account_info.zcash_account_birthday->second);
}

#if BUILDFLAG(ENABLE_ORCHARD)
auto unified_address = zcash_keyring->GetUnifiedAddress(
*receive_key_id,
*mojom::ZCashKeyId::New(account_id->account_index, 0, 0));
if (unified_address) {
result->unified_address = *unified_address;
}
#endif // BUILDFLAG(ENABLE_ORCHARD)

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ namespace brave_wallet {

namespace {

#if BUILDFLAG(ENABLE_ORCHARD)
std::unique_ptr<OrchardBundleManager> ApplyOrchardSignatures(
std::unique_ptr<OrchardBundleManager> orchard_bundle_manager,
std::array<uint8_t, kZCashDigestSize> sighash) {
// Heavy CPU operation, should be executed on background thread
return orchard_bundle_manager->ApplySignature(sighash);
}
#endif // BUILDFLAG(ENABLE_ORCHARD)

} // namespace

Expand Down Expand Up @@ -72,6 +74,7 @@ void ZCashTransactionCompleteManager::OnGetLatestBlockHeight(
params.transaction.set_expiry_height(result.value()->height +
kDefaultZCashBlockHeightDelta);

#if BUILDFLAG(ENABLE_ORCHARD)
if (params.transaction.orchard_part().outputs.empty()) {
SignTransparentPart(std::move(params));
return;
Expand All @@ -81,8 +84,13 @@ void ZCashTransactionCompleteManager::OnGetLatestBlockHeight(
chain_id,
base::BindOnce(&ZCashTransactionCompleteManager::OnGetTreeState,
weak_ptr_factory_.GetWeakPtr(), std::move(params)));
#else
SignTransparentPart(std::move(params));
#endif // BUILDFLAG(ENABLE_ORCHARD)
}

#if BUILDFLAG(ENABLE_ORCHARD)

void ZCashTransactionCompleteManager::OnGetTreeState(
ParamsBundle params,
base::expected<zcash::mojom::TreeStatePtr, std::string> result) {
Expand Down Expand Up @@ -130,33 +138,35 @@ void ZCashTransactionCompleteManager::OnGetTreeState(
weak_ptr_factory_.GetWeakPtr(), std::move(params)));
}

void ZCashTransactionCompleteManager::SignTransparentPart(ParamsBundle params) {
// Sign transparent part
if (!ZCashSerializer::SignTransparentPart(
zcash_wallet_service_->keyring_service(), params.account_id,
params.transaction)) {
void ZCashTransactionCompleteManager::OnSignOrchardPartComplete(
ParamsBundle params,
std::unique_ptr<OrchardBundleManager> orchard_bundle_manager) {
if (!orchard_bundle_manager) {
std::move(params.callback)
.Run(base::unexpected(
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
return;
}
params.transaction.orchard_part().raw_tx =
orchard_bundle_manager->GetRawTxBytes();

std::move(params.callback).Run(std::move(params.transaction));
SignTransparentPart(std::move(params));
}

void ZCashTransactionCompleteManager::OnSignOrchardPartComplete(
ParamsBundle params,
std::unique_ptr<OrchardBundleManager> orchard_bundle_manager) {
if (!orchard_bundle_manager) {
#endif // BUILDFLAG(ENABLE_ORCHARD)

void ZCashTransactionCompleteManager::SignTransparentPart(ParamsBundle params) {
// Sign transparent part
if (!ZCashSerializer::SignTransparentPart(
zcash_wallet_service_->keyring_service(), params.account_id,
params.transaction)) {
std::move(params.callback)
.Run(base::unexpected(
l10n_util::GetStringUTF8(IDS_WALLET_INTERNAL_ERROR)));
return;
}
params.transaction.orchard_part().raw_tx =
orchard_bundle_manager->GetRawTxBytes();

SignTransparentPart(std::move(params));
std::move(params.callback).Run(std::move(params.transaction));
}

} // namespace brave_wallet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/brave_wallet/browser/zcash/zcash_rpc.h"
#include "brave/components/brave_wallet/browser/zcash/zcash_transaction.h"
#include "brave/components/brave_wallet/common/buildflags.h"

namespace brave_wallet {

Expand Down Expand Up @@ -52,12 +53,14 @@ class ZCashTransactionCompleteManager {
void OnGetLatestBlockHeight(
ParamsBundle params,
base::expected<zcash::mojom::BlockIDPtr, std::string> result);
#if BUILDFLAG(ENABLE_ORCHARD)
void OnGetTreeState(
ParamsBundle params,
base::expected<zcash::mojom::TreeStatePtr, std::string> result);
void OnSignOrchardPartComplete(
ParamsBundle params,
std::unique_ptr<OrchardBundleManager> orchard_bundle_manager);
#endif // BUILDFLAG(ENABLE_ORCHARD)

raw_ptr<ZCashWalletService> zcash_wallet_service_; // Owns `this`.
base::WeakPtrFactory<ZCashTransactionCompleteManager> weak_ptr_factory_{this};
Expand Down
4 changes: 4 additions & 0 deletions components/brave_wallet/browser/zcash/zcash_wallet_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ inline constexpr char kOrchardDatabaseName[] = "orchard.db";

namespace {

#if BUILDFLAG(ENABLE_ORCHARD)
// Creates address key id for receiving funds on internal orchard address
mojom::ZCashKeyIdPtr CreateOrchardInternalKeyId(
const mojom::AccountIdPtr& accoint_id) {
return mojom::ZCashKeyId::New(accoint_id->account_index, 1 /* internal */, 0);
}
#endif // BUILDFLAG(ENABLE_ORCHARD)

} // namespace

Expand Down Expand Up @@ -702,11 +704,13 @@ void ZCashWalletService::CreateTransactionTaskDone(
[task](auto& item) { return item.get() == task; }));
}

#if BUILDFLAG(ENABLE_ORCHARD)
void ZCashWalletService::CreateTransactionTaskDone(
ZCashCreateShieldTransactionTask* task) {
CHECK(create_shield_transaction_tasks_.remove_if(
[task](auto& item) { return item.get() == task; }));
}
#endif // BUILDFLAG(ENABLE_ORCHARD)

ZCashRpc* ZCashWalletService::zcash_rpc() {
return zcash_rpc_.get();
Expand Down

0 comments on commit 2e91873

Please sign in to comment.