this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Consolidate CLI Opake construction onto a single builder

Two call sites built `Opake<ReqwestTransport, OsRng, FileStorage>`
with the same five-arg `Opake::for_account` + `OPAKE_INDEXER_URL`
env override: `CommandContext::opake` for user-facing commands and
`daemon::build_opake` for the daemon's per-task builder. When any
construction knob changed (the `now`/`now_micros` collapse; the
priority-chain cleanup's added `accountConfig` seed) both had to be
updated in parallel — bug-prone and nothing enforced the coupling.

Promote `build_opake(storage, did)` to `crate::session` as the one
construction path; `CommandContext::opake` forwards to it; daemon
imports it directly. Shape of the call sites is preserved, so no
behavior change.

+29 -38
+1 -20
apps/cli/src/commands/daemon/mod.rs
··· 17 17 use tokio::task::LocalSet; 18 18 19 19 use crate::config::FileStorage; 20 - use crate::session; 20 + use crate::session::build_opake; 21 21 22 22 /// Shared handle to a CLI-side Opake. Held behind `tokio::sync::Mutex` 23 23 /// so the SSE consumer's token fetcher and the event handler serialize ··· 388 388 }) 389 389 } 390 390 391 - async fn build_opake( 392 - storage: &FileStorage, 393 - did: &str, 394 - ) -> Result<Opake<ReqwestTransport, OsRng, FileStorage>> { 395 - let mut opake = Opake::for_account( 396 - storage.clone(), 397 - Some(did), 398 - ReqwestTransport::new(), 399 - OsRng, 400 - session::chrono_now_micros, 401 - ) 402 - .await?; 403 - 404 - if let Ok(url) = std::env::var("OPAKE_INDEXER_URL") { 405 - opake.set_indexer_url(url); 406 - } 407 - 408 - Ok(opake) 409 - } 410 391 411 392 // --------------------------------------------------------------------------- 412 393 // Shared helpers
+28 -18
apps/cli/src/session.rs
··· 21 21 Utc::now().timestamp_micros() as u64 22 22 } 23 23 24 + /// Build an `Opake` for the given account from a `FileStorage`. 25 + /// 26 + /// The single construction point shared by `CommandContext::opake` (user- 27 + /// facing commands) and the daemon's per-task builder. Reads identity and 28 + /// session from Storage, wires up a reqwest transport, and applies the 29 + /// `OPAKE_INDEXER_URL` runtime override so env tweaks don't require a 30 + /// rebuild. Storage is cloned so the returned Opake owns its own handle 31 + /// for `#[signoff]` auto-persist. 32 + pub async fn build_opake(storage: &FileStorage, did: &str) -> anyhow::Result<CliOpake> { 33 + let mut opake = Opake::for_account( 34 + storage.clone(), 35 + Some(did), 36 + ReqwestTransport::new(), 37 + OsRng, 38 + chrono_now_micros, 39 + ) 40 + .await?; 41 + 42 + if let Ok(url) = std::env::var("OPAKE_INDEXER_URL") { 43 + opake.set_indexer_url(url); 44 + } 45 + 46 + Ok(opake) 47 + } 48 + 24 49 impl CommandContext { 25 50 /// Build an Opake context for this account. 26 51 /// 27 - /// Reads identity and session from Storage, constructs an authenticated 28 - /// XRPC client, and bundles everything into an Opake with Storage for 29 - /// automatic session persistence. 52 + /// Thin forwarder over [`build_opake`] for ergonomics at command 53 + /// callsites (`ctx.opake().await?`). 30 54 pub async fn opake(&self) -> anyhow::Result<CliOpake> { 31 - let mut opake = Opake::for_account( 32 - self.storage.clone(), 33 - Some(&self.did), 34 - ReqwestTransport::new(), 35 - OsRng, 36 - chrono_now_micros, 37 - ) 38 - .await?; 39 - 40 - // Runtime env override (dev/CI convenience — skip recompile). 41 - if let Ok(url) = std::env::var("OPAKE_INDEXER_URL") { 42 - opake.set_indexer_url(url); 43 - } 44 - 45 - Ok(opake) 55 + build_opake(&self.storage, &self.did).await 46 56 } 47 57 } 48 58