Skip to content

Commit 7cf9ef9

Browse files
committed
Have Builder::set_entropy_seed_bytes take [u8; 64] for non-uniffi
Historically, we aligned `uniffi` and non-`uniffi` APIs as much as possible (mostly because there are no rendered docs available for the latter). As the APIs have diverged a bit by now anyways, we here have `Builder::set_entropy_seed_bytes` take a `[u8; 64]`, which makes for a better API in Rust.
1 parent 22cb1df commit 7cf9ef9

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/builder.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,11 @@ impl NodeBuilder {
245245
self
246246
}
247247

248-
/// Configures the [`Node`] instance to source its wallet entropy from the given 64 seed bytes.
249-
pub fn set_entropy_seed_bytes(&mut self, seed_bytes: Vec<u8>) -> Result<&mut Self, BuildError> {
250-
if seed_bytes.len() != WALLET_KEYS_SEED_LEN {
251-
return Err(BuildError::InvalidSeedBytes);
252-
}
253-
let mut bytes = [0u8; WALLET_KEYS_SEED_LEN];
254-
bytes.copy_from_slice(&seed_bytes);
255-
self.entropy_source_config = Some(EntropySourceConfig::SeedBytes(bytes));
256-
Ok(self)
248+
/// Configures the [`Node`] instance to source its wallet entropy from the given
249+
/// [`WALLET_KEYS_SEED_LEN`] seed bytes.
250+
pub fn set_entropy_seed_bytes(&mut self, seed_bytes: [u8; WALLET_KEYS_SEED_LEN]) -> &mut Self {
251+
self.entropy_source_config = Some(EntropySourceConfig::SeedBytes(seed_bytes));
252+
self
257253
}
258254

259255
/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.
@@ -637,11 +633,20 @@ impl ArcedNodeBuilder {
637633
self.inner.write().unwrap().set_entropy_seed_path(seed_path);
638634
}
639635

640-
/// Configures the [`Node`] instance to source its wallet entropy from the given 64 seed bytes.
636+
/// Configures the [`Node`] instance to source its wallet entropy from the given
637+
/// [`WALLET_KEYS_SEED_LEN`] seed bytes.
641638
///
642-
/// **Note:** Panics if the length of the given `seed_bytes` differs from 64.
639+
/// **Note:** Will return an error if the length of the given `seed_bytes` differs from
640+
/// [`WALLET_KEYS_SEED_LEN`].
643641
pub fn set_entropy_seed_bytes(&self, seed_bytes: Vec<u8>) -> Result<(), BuildError> {
644-
self.inner.write().unwrap().set_entropy_seed_bytes(seed_bytes).map(|_| ())
642+
if seed_bytes.len() != WALLET_KEYS_SEED_LEN {
643+
return Err(BuildError::InvalidSeedBytes);
644+
}
645+
let mut bytes = [0u8; WALLET_KEYS_SEED_LEN];
646+
bytes.copy_from_slice(&seed_bytes);
647+
648+
self.inner.write().unwrap().set_entropy_seed_bytes(bytes);
649+
Ok(())
645650
}
646651

647652
/// Configures the [`Node`] instance to source its wallet entropy from a [BIP 39] mnemonic.

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ pub(crate) const TX_BROADCAST_TIMEOUT_SECS: u64 = 5;
7878
// The timeout after which we abort a RGS sync operation.
7979
pub(crate) const RGS_SYNC_TIMEOUT_SECS: u64 = 5;
8080

81-
// The length in bytes of our wallets' keys seed.
82-
pub(crate) const WALLET_KEYS_SEED_LEN: usize = 64;
81+
/// The length in bytes of our wallets' keys seed.
82+
pub const WALLET_KEYS_SEED_LEN: usize = 64;
8383

8484
#[derive(Debug, Clone)]
8585
/// Represents the configuration of an [`Node`] instance.

tests/common/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,16 @@ pub(crate) fn setup_node(
338338
}
339339

340340
if let Some(seed) = seed_bytes {
341-
builder.set_entropy_seed_bytes(seed).unwrap();
341+
#[cfg(feature = "uniffi")]
342+
{
343+
builder.set_entropy_seed_bytes(seed).unwrap();
344+
}
345+
#[cfg(not(feature = "uniffi"))]
346+
{
347+
let mut bytes = [0u8; 64];
348+
bytes.copy_from_slice(&seed);
349+
builder.set_entropy_seed_bytes(bytes);
350+
}
342351
}
343352

344353
let test_sync_store = Arc::new(TestSyncStore::new(config.node_config.storage_dir_path.into()));

0 commit comments

Comments
 (0)