Skip to main content

bee/
dev.rs

1//! Bee dev-mode wrapper. The dev-mode endpoint surface is a strict
2//! subset of production Bee, so this is mostly a documentation /
3//! discovery signal: callers can `let bee = DevClient::new(url)?;`
4//! and use the same accessors they already know from [`Client`].
5//!
6//! Mirrors bee-js `BeeDev`. The endpoints currently exposed
7//! (`addresses`, `topology`) accept a slimmer payload in dev mode but
8//! the same accessors work; bee-rs avoids splitting the type system
9//! here and reuses the regular debug handles.
10//!
11//! # Endpoints that work
12//!
13//! - Health / readiness / addresses / topology / node-info / status
14//!   (dev-shaped, simpler JSON — the existing parsers tolerate the
15//!   missing fields).
16//! - File upload / download (`/bytes`, `/bzz`, `/chunks`, `/soc`,
17//!   `/feeds`).
18//! - PSS send / subscribe; GSOC send / subscribe.
19//! - Tags, pins, stewardship, grantees, envelopes.
20//! - The `/stamps` endpoints behave as no-ops in dev mode but do not
21//!   404.
22//!
23//! # Endpoints that return 404
24//!
25//! - Chequebook lifecycle: `chequebook_balance`, `deposit_tokens`,
26//!   `withdraw_tokens`, `last_cheques`, `get_last_cheques_for_peer`,
27//!   `get_last_cashout_action`, `cashout_last_cheque`.
28//! - Settlements: `settlements`, `peer_settlement`.
29//! - Stake: `get_stake`, `stake`, `deposit_stake`,
30//!   `withdraw_surplus_stake`, `migrate_stake`,
31//!   `get_withdrawable_stake`.
32//! - Pending transactions: list, get, rebroadcast, cancel.
33//! - Chain-state reads: `chain_state`, `reserve_state`,
34//!   `redistribution_state`, `rc_hash`.
35//! - Per-peer accounting and balances.
36//! - High-level helpers that internally call any of the above —
37//!   [`crate::storage::buy_storage`], `extend_storage_*`,
38//!   `get_storage_cost`.
39
40use crate::Client;
41use crate::swarm::Error;
42
43/// Thin newtype around [`Client`] for use against Bee in dev mode.
44/// Cheap to clone.
45#[derive(Clone, Debug)]
46pub struct DevClient {
47    inner: Client,
48}
49
50impl DevClient {
51    /// Construct a dev-mode client from a base URL. Same shape as
52    /// [`Client::new`].
53    pub fn new(url: &str) -> Result<Self, Error> {
54        Ok(Self {
55            inner: Client::new(url)?,
56        })
57    }
58
59    /// Construct a dev-mode client with a caller-provided HTTP client.
60    pub fn with_http_client(url: &str, http: reqwest::Client) -> Result<Self, Error> {
61        Ok(Self {
62            inner: Client::with_http_client(url, http)?,
63        })
64    }
65
66    /// Borrow the wrapped [`Client`] for full API access.
67    pub fn client(&self) -> &Client {
68        &self.inner
69    }
70
71    /// Convert into the wrapped [`Client`].
72    pub fn into_client(self) -> Client {
73        self.inner
74    }
75}
76
77impl std::ops::Deref for DevClient {
78    type Target = Client;
79
80    fn deref(&self) -> &Self::Target {
81        &self.inner
82    }
83}