Skip to content

Commit dec3024

Browse files
authored
Merge pull request zcash#1557 from zcash/add_accountid_conversions
zcash_client_sqlite: Add unstable conversions between `AccountId` and `u32`.
2 parents 5eebc0a + cb349f8 commit dec3024

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

zcash_client_sqlite/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this library adheres to Rust's notion of
77

88
## [Unreleased]
99

10+
### Added
11+
- Exposed `AccountId::from_u32` and `AccountId::as_u32` conversions under the
12+
`unstable` feature flag.
13+
1014
## [0.12.0] - 2024-10-04
1115

1216
### Added

zcash_client_sqlite/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ pub(crate) const DEFAULT_UA_REQUEST: UnifiedAddressRequest =
164164
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
165165
pub struct AccountId(u32);
166166

167+
impl AccountId {
168+
/// Constructs an `AccountId` from a bare `u32` value. The resulting identifier is not
169+
/// guaranteed to correspond to any account stored in the database.
170+
#[cfg(feature = "unstable")]
171+
pub fn from_u32(value: u32) -> Self {
172+
AccountId(value)
173+
}
174+
175+
/// Unwraps a raw `accounts` table primary key value from its typesafe wrapper.
176+
///
177+
/// Note that account identifiers are not guaranteed to be stable; if a wallet is restored from
178+
/// seed, the account identifiers of the restored wallet are not likely to correspond to the
179+
/// identifiers for the same accounts in another wallet created or restored from the same seed.
180+
/// These unwrapped identifier values should therefore be treated as ephemeral.
181+
#[cfg(feature = "unstable")]
182+
pub fn as_u32(&self) -> u32 {
183+
self.0
184+
}
185+
}
186+
167187
impl ConditionallySelectable for AccountId {
168188
fn conditional_select(a: &Self, b: &Self, choice: subtle::Choice) -> Self {
169189
AccountId(ConditionallySelectable::conditional_select(

0 commit comments

Comments
 (0)