From 69d92808f3095cfc14e4fc9429a4c2481faf9075 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 9 Jan 2024 20:58:17 -0700 Subject: [PATCH 1/3] Add `WalletRead::get_account_ids` function --- .editorconfig | 7 +++++++ zcash_client_backend/CHANGELOG.md | 1 + zcash_client_backend/src/data_api.rs | 7 +++++++ zcash_client_sqlite/src/lib.rs | 4 ++++ zcash_client_sqlite/src/wallet.rs | 28 ++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..12f32366a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +# EditorConfig is awesome:http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*.md] +indent_style = space diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 2ec395ed6..2c98d29a9 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -140,6 +140,7 @@ and this library adheres to Rust's notion of - `get_spendable_sapling_notes`, `select_spendable_sapling_notes`, and `get_unspent_transparent_outputs` have been removed; use `data_api::InputSource` instead. + - Added `get_account_ids` - `wallet::{propose_shielding, shield_transparent_funds}` now takes their `min_confirmations` arguments as `u32` rather than a `NonZeroU32` to permit implmentations to enable zero-conf shielding. diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index b2980a139..b88e479ca 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -560,6 +560,9 @@ pub trait WalletRead { account: AccountId, max_height: BlockHeight, ) -> Result, Self::Error>; + + /// Returns a vector with the IDs of all accounts known to this wallet. + fn get_account_ids(&self) -> Result, Self::Error>; } /// Metadata describing the sizes of the zcash note commitment trees as of a particular block. @@ -1283,6 +1286,10 @@ pub mod testing { ) -> Result, Self::Error> { Ok(HashMap::new()) } + + fn get_account_ids(&self) -> Result, Self::Error> { + Ok(Vec::new()) + } } impl WalletWrite for MockWalletDb { diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index db432183e..0b8d7cd58 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -372,6 +372,10 @@ impl, P: consensus::Parameters> WalletRead for W ) -> Result, Self::Error> { todo!() } + + fn get_account_ids(&self) -> Result, Self::Error> { + wallet::get_account_ids(self.conn.borrow()) + } } impl WalletWrite for WalletDb { diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 013afcd62..881b300bb 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1458,6 +1458,20 @@ pub(crate) fn get_transparent_balances( Ok(res) } +/// Returns a vector with the IDs of all accounts known to this wallet. +pub(crate) fn get_account_ids(conn: &rusqlite::Connection) -> Result, SqliteClientError> { + let mut stmt = conn.prepare("SELECT account FROM accounts")?; + let mut rows = stmt.query([])?; + let mut result = Vec::new(); + while let Some(row) = rows.next()? { + let id: u32 = row.get(0)?; + result.push(AccountId::try_from(id).map_err(|_| { + SqliteClientError::CorruptedData("Account ID out of range".to_string()) + })?); + } + Ok(result) +} + /// Inserts information about a scanned block into the database. pub(crate) fn put_block( conn: &rusqlite::Transaction<'_>, @@ -2128,6 +2142,20 @@ mod tests { assert_matches!(res2, Err(_)); } + #[test] + fn get_account_ids() { + use crate::testing::TestBuilder; + + let st = TestBuilder::new() + .with_test_account(AccountBirthday::from_sapling_activation) + .build(); + + assert_eq!( + vec![AccountId::try_from(0).unwrap()], + st.wallet().get_account_ids().unwrap() + ); + } + #[test] #[cfg(feature = "transparent-inputs")] fn transparent_balance_across_shielding() { From 28ed048c7ea9954a3c69b699c2e752a946b1d4a9 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 11 Jan 2024 12:02:24 -0700 Subject: [PATCH 2/3] Add punctuation to changelog Co-authored-by: Daira Emma Hopwood --- zcash_client_backend/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcash_client_backend/CHANGELOG.md b/zcash_client_backend/CHANGELOG.md index 2c98d29a9..785b72aaa 100644 --- a/zcash_client_backend/CHANGELOG.md +++ b/zcash_client_backend/CHANGELOG.md @@ -140,7 +140,7 @@ and this library adheres to Rust's notion of - `get_spendable_sapling_notes`, `select_spendable_sapling_notes`, and `get_unspent_transparent_outputs` have been removed; use `data_api::InputSource` instead. - - Added `get_account_ids` + - Added `get_account_ids`. - `wallet::{propose_shielding, shield_transparent_funds}` now takes their `min_confirmations` arguments as `u32` rather than a `NonZeroU32` to permit implmentations to enable zero-conf shielding. From 60336714f7a5eb66a62e203c395fe88c15a79306 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 11 Jan 2024 14:31:19 -0700 Subject: [PATCH 3/3] Fix Rust formatting. --- zcash_client_sqlite/src/wallet.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 881b300bb..951d7af64 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -1459,7 +1459,9 @@ pub(crate) fn get_transparent_balances( } /// Returns a vector with the IDs of all accounts known to this wallet. -pub(crate) fn get_account_ids(conn: &rusqlite::Connection) -> Result, SqliteClientError> { +pub(crate) fn get_account_ids( + conn: &rusqlite::Connection, +) -> Result, SqliteClientError> { let mut stmt = conn.prepare("SELECT account FROM accounts")?; let mut rows = stmt.query([])?; let mut result = Vec::new();