From b63ff5bfcdae0471a7b07f1b19903db2abd50f30 Mon Sep 17 00:00:00 2001 From: Daira-Emma Hopwood Date: Wed, 3 Jul 2024 17:02:47 +0100 Subject: [PATCH] Rename `get_reserved_ephemeral_addresses` to `get_known_ephemeral_addresses` and change the `TransparentAddressMetadata` in its result map to not be optional. Signed-off-by: Daira-Emma Hopwood --- zcash_client_backend/CHANGELOG.md | 2 +- zcash_client_backend/src/data_api.rs | 19 +++++++++---------- zcash_client_sqlite/src/lib.rs | 6 +++--- .../src/wallet/transparent/ephemeral.rs | 8 ++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index b29f63126..2b4de630f 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -53,7 +53,7 @@ funds to those addresses. See [ZIP 320](https://zips.z.cash/zip-0320) for detail have changed as a consequence of this extraction; please see the `zip321` CHANGELOG for details. - `zcash_client_backend::data_api`: - - `WalletRead` has new `get_reserved_ephemeral_addresses` and + - `WalletRead` has new `get_known_ephemeral_addresses` and `get_transparent_address_metadata` methods. - `WalletWrite` has a new `reserve_next_n_ephemeral_addresses` method. - `error::Error` has a new `Address` variant. diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index bb3b2d589..19ee52bad 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -897,7 +897,7 @@ pub trait WalletRead { /// been derived under this account. Wallets should scan the chain for UTXOs sent to /// these receivers. /// - /// Use [`Self::get_reserved_ephemeral_addresses`] to obtain the ephemeral transparent + /// Use [`Self::get_known_ephemeral_addresses`] to obtain the ephemeral transparent /// receivers. #[cfg(feature = "transparent-inputs")] fn get_transparent_receivers( @@ -929,8 +929,8 @@ pub trait WalletRead { /// if let Some(result) = self.get_transparent_receivers(account)?.get(address) { /// return Ok(result.clone()); /// } - /// if let Some(result) = self.get_reserved_ephemeral_addresses(account, false)?.get(address) { - /// return Ok(result.clone()); + /// if let Some(result) = self.get_known_ephemeral_addresses(account, false)?.get(address) { + /// return Ok(Some(result.clone())); /// } /// Ok(None) /// ``` @@ -948,10 +948,10 @@ pub trait WalletRead { return Ok(result.clone()); } if let Some(result) = self - .get_reserved_ephemeral_addresses(account, false)? + .get_known_ephemeral_addresses(account, false)? .get(address) { - return Ok(result.clone()); + return Ok(Some(result.clone())); } Ok(None) } @@ -991,11 +991,11 @@ pub trait WalletRead { /// In all cases, the wallet should re-shield the unspent outputs, in a separate /// transaction per ephemeral address, before re-spending the funds. #[cfg(feature = "transparent-inputs")] - fn get_reserved_ephemeral_addresses( + fn get_known_ephemeral_addresses( &self, _account: Self::AccountId, _for_detection: bool, - ) -> Result>, Self::Error> { + ) -> Result, Self::Error> { Ok(HashMap::new()) } } @@ -1991,12 +1991,11 @@ pub mod testing { } #[cfg(feature = "transparent-inputs")] - fn get_reserved_ephemeral_addresses( + fn get_known_ephemeral_addresses( &self, _account: Self::AccountId, _for_detection: bool, - ) -> Result>, Self::Error> - { + ) -> Result, Self::Error> { Ok(HashMap::new()) } } diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 1a31ab31a..ad0d03597 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -549,12 +549,12 @@ impl, P: consensus::Parameters> WalletRead for W } #[cfg(feature = "transparent-inputs")] - fn get_reserved_ephemeral_addresses( + fn get_known_ephemeral_addresses( &self, account: Self::AccountId, for_detection: bool, - ) -> Result>, Self::Error> { - wallet::transparent::ephemeral::get_reserved_ephemeral_addresses( + ) -> Result, Self::Error> { + wallet::transparent::ephemeral::get_known_ephemeral_addresses( self.conn.borrow(), &self.params, account, diff --git a/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs b/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs index 445275c76..83fa19ee4 100644 --- a/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs +++ b/zcash_client_sqlite/src/wallet/transparent/ephemeral.rs @@ -119,12 +119,12 @@ pub(crate) fn get_ephemeral_ivk( /// If `for_detection` is false, the result only includes reserved addresses. /// If `for_detection` is true, it includes addresses for an additional /// `GAP_LIMIT` indices, up to the limit. -pub(crate) fn get_reserved_ephemeral_addresses( +pub(crate) fn get_known_ephemeral_addresses( conn: &rusqlite::Connection, params: &P, account_id: AccountId, for_detection: bool, -) -> Result>, SqliteClientError> { +) -> Result, SqliteClientError> { let mut stmt = conn.prepare( "SELECT address, address_index FROM ephemeral_addresses WHERE account_id = :account ORDER BY address_index", )?; @@ -141,7 +141,7 @@ pub(crate) fn get_reserved_ephemeral_addresses( .checked_add(1); let address_index = NonHardenedChildIndex::from_index(raw_index).unwrap(); let address = TransparentAddress::decode(params, &addr_str)?; - result.insert(address, Some(metadata(address_index))); + result.insert(address, metadata(address_index)); } if for_detection { @@ -151,7 +151,7 @@ pub(crate) fn get_reserved_ephemeral_addresses( for raw_index in range_after(first, GAP_LIMIT) { let address_index = NonHardenedChildIndex::from_index(raw_index).unwrap(); let address = ephemeral_ivk.derive_ephemeral_address(address_index)?; - result.insert(address, Some(metadata(address_index))); + result.insert(address, metadata(address_index)); } } }