Merge pull request #1112 from nuttycom/get_accounts
Add WalletRead::get_account_ids (subsumes #1106 to fix formatting issues)
This commit is contained in:
commit
47d432820a
|
@ -0,0 +1,7 @@
|
|||
# EditorConfig is awesome:http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*.md]
|
||||
indent_style = space
|
|
@ -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.
|
||||
|
|
|
@ -560,6 +560,9 @@ pub trait WalletRead {
|
|||
account: AccountId,
|
||||
max_height: BlockHeight,
|
||||
) -> Result<HashMap<TransparentAddress, Amount>, Self::Error>;
|
||||
|
||||
/// Returns a vector with the IDs of all accounts known to this wallet.
|
||||
fn get_account_ids(&self) -> Result<Vec<AccountId>, 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<HashMap<TransparentAddress, Amount>, Self::Error> {
|
||||
Ok(HashMap::new())
|
||||
}
|
||||
|
||||
fn get_account_ids(&self) -> Result<Vec<AccountId>, Self::Error> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl WalletWrite for MockWalletDb {
|
||||
|
|
|
@ -372,6 +372,10 @@ impl<C: Borrow<rusqlite::Connection>, P: consensus::Parameters> WalletRead for W
|
|||
) -> Result<Vec<(AccountId, orchard::note::Nullifier)>, Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_account_ids(&self) -> Result<Vec<AccountId>, Self::Error> {
|
||||
wallet::get_account_ids(self.conn.borrow())
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P> {
|
||||
|
|
|
@ -1458,6 +1458,22 @@ pub(crate) fn get_transparent_balances<P: consensus::Parameters>(
|
|||
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<Vec<AccountId>, 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 +2144,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() {
|
||||
|
|
Loading…
Reference in New Issue