beekeeper/options.rs
1//! Construction options for [`BeekeeperApi`](crate::api::BeekeeperApi).
2
3/// Default [`BeekeeperOptions::storage_root`].
4///
5/// Matches the web default of the `@hiveio/beekeeper` npm package, so both
6/// bindings resolve the same path out of the box.
7pub const DEFAULT_STORAGE_ROOT: &str = "/storage_root";
8
9/// Configuration consumed by [`BeekeeperApi::new`](crate::api::BeekeeperApi::new).
10///
11/// Built with [`BeekeeperOptions::new`] and a chain of setters. All fields
12/// are public so that callers can also construct the struct directly when
13/// that reads more clearly than the builder.
14pub struct BeekeeperOptions {
15 /// Parent directory of the `.beekeeper` wallet directory used by the
16 /// filesystem-backed storage. Ignored when [`Self::in_memory`] is `true`.
17 pub storage_root: String,
18
19 /// Inactivity timeout in **seconds** after which unlocked wallets are
20 /// auto-locked. A value of `0` disables the timeout. Defaults to `900`
21 /// (15 minutes).
22 pub unlock_timeout: u32,
23
24 /// When `true`, no filesystem storage is created and wallets live only
25 /// in process memory. Useful for one-shot operations (e.g. import key
26 /// + sign + drop). Defaults to `false`.
27 pub in_memory: bool,
28}
29
30impl Default for BeekeeperOptions {
31 /// [`DEFAULT_STORAGE_ROOT`], a 900-second unlock timeout, persistent
32 /// mode.
33 fn default() -> Self {
34 Self::new(DEFAULT_STORAGE_ROOT)
35 }
36}
37
38impl BeekeeperOptions {
39 /// Start a new options builder pinned to the given wallet storage root.
40 ///
41 /// The directory is created lazily by
42 /// [`new_rust_storage_protocol`](crate::new_rust_storage_protocol) when
43 /// the [`BeekeeperApi`](crate::api::BeekeeperApi) is constructed in
44 /// persistent mode.
45 pub fn new(storage_root: impl Into<String>) -> Self {
46 Self {
47 storage_root: storage_root.into(),
48 unlock_timeout: 900,
49 in_memory: false,
50 }
51 }
52
53 /// Override the inactivity timeout (seconds). Pass `0` to disable.
54 pub fn unlock_timeout(mut self, seconds: u32) -> Self {
55 self.unlock_timeout = seconds;
56 self
57 }
58
59 /// Toggle in-memory mode. When `true` the `storage_root` value is
60 /// retained for symmetry but is never used.
61 pub fn in_memory(mut self, in_memory: bool) -> Self {
62 self.in_memory = in_memory;
63 self
64 }
65}