Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(wallet): move endpoint defaults into tinywallet

Steven Enamakel274f1b630806
diff --git a/crates/openhuman-core/src/modules/wallet_host.rs b/crates/openhuman-core/src/modules/wallet_host.rs
index f8e6de3546..31953af671 100644
--- a/crates/openhuman-core/src/modules/wallet_host.rs
+++ b/crates/openhuman-core/src/modules/wallet_host.rs
@@ -94,20 +94,8 @@ pub(crate) fn bind_endpoint_references(
let mut resolved = HashMap::new();
for endpoint in references {
- let url = match endpoint.key {
- RpcEndpointKey::Evm { network } => {
- crate::web3::wallet::endpoints::rpc_url_for_evm_network(network)
- }
- RpcEndpointKey::Btc => crate::web3::wallet::endpoints::rpc_url_for_chain(
- crate::web3::wallet::WalletChain::Btc,
- ),
- RpcEndpointKey::Solana => crate::web3::wallet::endpoints::rpc_url_for_chain(
- crate::web3::wallet::WalletChain::Solana,
- ),
- RpcEndpointKey::Tron => crate::web3::wallet::endpoints::rpc_url_for_chain(
- crate::web3::wallet::WalletChain::Tron,
- ),
- };
+ let url = crate::web3::wallet::endpoints::override_for_endpoint(endpoint.key)
+ .ok_or_else(|| "wallet module referenced an endpoint without a host override".to_string())?;
if endpoint.reference.trim().is_empty()
|| resolved
.insert(
diff --git a/crates/openhuman-core/src/modules/wallet_service.rs b/crates/openhuman-core/src/modules/wallet_service.rs
index 324955c728..d9a88a7137 100644
--- a/crates/openhuman-core/src/modules/wallet_service.rs
+++ b/crates/openhuman-core/src/modules/wallet_service.rs
@@ -352,33 +352,18 @@ pub(super) fn native_wallet_config_request() -> NativeWalletConfigRequest {
overridden_endpoints.push(RpcEndpointKey::Evm { network });
}
}
- for (chain, key) in [
- (crate::web3::wallet::WalletChain::Btc, RpcEndpointKey::Btc),
- (
- crate::web3::wallet::WalletChain::Solana,
- RpcEndpointKey::Solana,
- ),
- (crate::web3::wallet::WalletChain::Tron, RpcEndpointKey::Tron),
- ] {
- let name = crate::web3::wallet::endpoints::env_var_for_chain(chain);
- if nonempty_env(name) {
+ for key in [RpcEndpointKey::Btc, RpcEndpointKey::Solana, RpcEndpointKey::Tron] {
+ if crate::web3::wallet::endpoints::override_for_endpoint(key).is_some() {
overridden_endpoints.push(key);
}
}
- let solana_cluster = match crate::web3::wallet::solana_cluster() {
- tinywallet_bus::wire::SolanaCluster::Mainnet => SolanaCluster::Mainnet,
- tinywallet_bus::wire::SolanaCluster::Devnet => SolanaCluster::Devnet,
- };
+ let solana_cluster = crate::web3::wallet::solana_cluster();
NativeWalletConfigRequest {
solana_cluster,
overridden_endpoints,
}
}
-fn nonempty_env(name: &str) -> bool {
- std::env::var(name).is_ok_and(|value| !value.trim().is_empty())
-}
-
#[cfg(test)]
#[path = "wallet_service_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/web3/wallet/endpoints.rs b/crates/openhuman-core/src/web3/wallet/endpoints.rs
index 50d1223a15..77e735fa86 100644
--- a/crates/openhuman-core/src/web3/wallet/endpoints.rs
+++ b/crates/openhuman-core/src/web3/wallet/endpoints.rs
@@ -1,23 +1,12 @@
-//! Endpoint and cluster resolution for the wallet: the `OPENHUMAN_WALLET_RPC_*`
-//! and `OPENHUMAN_SOLANA_CLUSTER` environment handling.
+//! Host configuration for Wallet RPC overrides.
//!
-//! The static half (default URLs, the Solana cluster's RPC and USDC mint) lives
-//! in `tinywallet_web3::crypto::defaults`; what stays here is the part that
-//! depends on this deployment's environment. [`HostEndpoints`] is the
-//! `RpcEndpoints` seam the engine asks, and the free functions are what the
-//! host [`Transport`](super::transport) and the x402 helpers resolve through.
+//! Default endpoints and network metadata are selected by TinyWallet. This
+//! module only reads OpenHuman's environment overrides and exposes their
+//! values to the host transport after the module returns an opaque alias.
-use tinywallet_web3::crypto::defaults::{
- default_rpc_url, EvmNetwork, EvmNetworkReferenceData, RpcSource, SolanaCluster,
-};
-use tinywallet_web3::crypto::seams::RpcEndpoints;
+use tinywallet_bus::wire::{EvmNetwork, RpcEndpointKey, SolanaCluster, WalletChain};
-#[cfg(test)]
-use tinywallet_web3::crypto::defaults::SolanaClusterReferenceData;
-
-use super::ops::WalletChain;
-
-/// The `OPENHUMAN_WALLET_RPC_<NAME>` variable that overrides `network`.
+/// Environment variable used to override one EVM network endpoint.
pub(crate) fn evm_rpc_env_var(network: EvmNetwork) -> &'static str {
match network {
EvmNetwork::EthereumMainnet => "OPENHUMAN_WALLET_RPC_EVM",
@@ -29,8 +18,7 @@ pub(crate) fn evm_rpc_env_var(network: EvmNetwork) -> &'static str {
}
}
-/// The `OPENHUMAN_WALLET_RPC_<NAME>` variable that overrides `chain`'s
-/// endpoint (Ethereum mainnet's, for EVM).
+/// Environment variable used to override a non-EVM chain endpoint.
pub(crate) fn env_var_for_chain(chain: WalletChain) -> &'static str {
match chain {
WalletChain::Evm => evm_rpc_env_var(EvmNetwork::EthereumMainnet),
@@ -40,92 +28,34 @@ pub(crate) fn env_var_for_chain(chain: WalletChain) -> &'static str {
}
}
-/// Trimmed value of `env_var`, or `None` when unset or blank.
-fn env_nonempty(env_var: &str) -> Option<String> {
- std::env::var(env_var)
+/// Read only an explicitly configured endpoint override. Defaults stay inside
+/// the module and are never copied into host configuration or bus payloads.
+pub(crate) fn override_for_endpoint(key: RpcEndpointKey) -> Option<String> {
+ let variable = match key {
+ RpcEndpointKey::Evm { network } => evm_rpc_env_var(network),
+ RpcEndpointKey::Btc => env_var_for_chain(WalletChain::Btc),
+ RpcEndpointKey::Solana => env_var_for_chain(WalletChain::Solana),
+ RpcEndpointKey::Tron => env_var_for_chain(WalletChain::Tron),
+ };
+ std::env::var(variable)
.ok()
- .map(|value| value.trim().to_string())
+ .map(|value| value.trim().to_owned())
.filter(|value| !value.is_empty())
}
-/// Resolve the configured Solana cluster from `OPENHUMAN_SOLANA_CLUSTER`
-/// (case-insensitive `devnet` selects [`SolanaCluster::Devnet`]; anything else
-/// or unset selects [`SolanaCluster::Mainnet`], preserving the default).
+/// Parse OpenHuman's Solana-cluster setting. Unknown and blank values retain
+/// the historical mainnet default; endpoint defaults themselves remain
+/// module-owned.
pub fn solana_cluster() -> SolanaCluster {
- let configured = env_nonempty("OPENHUMAN_SOLANA_CLUSTER").map(|v| v.to_ascii_lowercase());
+ let configured = std::env::var("OPENHUMAN_SOLANA_CLUSTER")
+ .ok()
+ .map(|value| value.trim().to_ascii_lowercase());
match configured.as_deref() {
- Some("devnet") => {
- log::debug!("[wallet] Solana cluster = devnet (via OPENHUMAN_SOLANA_CLUSTER)");
- SolanaCluster::Devnet
- }
+ Some("devnet") => SolanaCluster::Devnet,
_ => SolanaCluster::Mainnet,
}
}
-/// The endpoint serving `network`: its env override, else the built-in default.
-pub(crate) fn rpc_url_for_evm_network(network: EvmNetwork) -> String {
- env_nonempty(evm_rpc_env_var(network)).unwrap_or_else(|| network.default_rpc_url().to_string())
-}
-
-/// Whether `network`'s endpoint is a default or an env override.
-pub(crate) fn rpc_source_for_evm_network(network: EvmNetwork) -> RpcSource {
- if env_nonempty(evm_rpc_env_var(network)).is_some() {
- RpcSource::EnvOverride
- } else {
- RpcSource::Default
- }
-}
-
-/// The endpoint serving `chain` (Ethereum mainnet's for EVM): its env override,
-/// else the built-in default (which follows the Solana cluster for Solana).
-pub(crate) fn rpc_url_for_chain(chain: WalletChain) -> String {
- match chain {
- WalletChain::Evm => rpc_url_for_evm_network(EvmNetwork::EthereumMainnet),
- other => env_nonempty(env_var_for_chain(other))
- .unwrap_or_else(|| default_rpc_url(other, solana_cluster()).to_string()),
- }
-}
-
-/// Whether `chain`'s endpoint is a default or an env override.
-pub(crate) fn rpc_source_for_chain(chain: WalletChain) -> RpcSource {
- match chain {
- WalletChain::Evm => rpc_source_for_evm_network(EvmNetwork::EthereumMainnet),
- other => {
- if env_nonempty(env_var_for_chain(other)).is_some() {
- RpcSource::EnvOverride
- } else {
- RpcSource::Default
- }
- }
- }
-}
-
-/// The host's [`RpcEndpoints`]: environment overrides over the built-in
-/// defaults, resolved on every call so an override applied mid-process (as the
-/// e2e harness does) is picked up without rebuilding the engine.
-#[derive(Debug, Clone, Copy, Default)]
-pub struct HostEndpoints;
-
-impl RpcEndpoints for HostEndpoints {
- fn url(&self, chain: WalletChain, network: Option<EvmNetwork>) -> String {
- match (chain, network) {
- (WalletChain::Evm, Some(network)) => rpc_url_for_evm_network(network),
- (chain, _) => rpc_url_for_chain(chain),
- }
- }
-
- fn source(&self, chain: WalletChain, network: Option<EvmNetwork>) -> RpcSource {
- match (chain, network) {
- (WalletChain::Evm, Some(network)) => rpc_source_for_evm_network(network),
- (chain, _) => rpc_source_for_chain(chain),
- }
- }
-
- fn solana_cluster(&self) -> SolanaCluster {
- solana_cluster()
- }
-}
-
#[cfg(test)]
#[path = "endpoints_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/web3/wallet/endpoints_tests.rs b/crates/openhuman-core/src/web3/wallet/endpoints_tests.rs
index fd351fc6f3..edfa841d56 100644
--- a/crates/openhuman-core/src/web3/wallet/endpoints_tests.rs
+++ b/crates/openhuman-core/src/web3/wallet/endpoints_tests.rs
@@ -1,8 +1,5 @@
use super::*;
-// The variables read here are process-global. Serialise these tests (and the
-// ones that repoint every endpoint) so they do not race each other, and restore
-// what they touched.
use crate::web3::wallet::test_support::RPC_ENV_LOCK as ENDPOINT_ENV_LOCK;
fn with_env<T>(pairs: &[(&str, Option<&str>)], f: impl FnOnce() -> T) -> T {
@@ -15,136 +12,73 @@ fn with_env<T>(pairs: &[(&str, Option<&str>)], f: impl FnOnce() -> T) -> T {
.collect();
for (name, value) in pairs {
match value {
- Some(v) => std::env::set_var(name, v),
+ Some(value) => std::env::set_var(name, value),
None => std::env::remove_var(name),
}
}
- let out = f();
+ let output = f();
for (name, value) in previous {
match value {
- Some(v) => std::env::set_var(name, v),
+ Some(value) => std::env::set_var(name, value),
None => std::env::remove_var(name),
}
}
- out
+ output
}
#[test]
-fn solana_cluster_defaults_to_mainnet() {
+fn solana_cluster_keeps_the_host_environment_compatibility() {
with_env(&[("OPENHUMAN_SOLANA_CLUSTER", None)], || {
assert_eq!(solana_cluster(), SolanaCluster::Mainnet);
- assert_eq!(
- rpc_url_for_chain(WalletChain::Solana),
- SolanaCluster::Mainnet.rpc_url()
- );
});
-}
-
-#[test]
-fn devnet_cluster_is_case_insensitive_and_moves_the_default_endpoint() {
- with_env(
- &[
- ("OPENHUMAN_SOLANA_CLUSTER", Some(" DevNet ")),
- ("OPENHUMAN_WALLET_RPC_SOLANA", None),
- ],
- || {
- assert_eq!(solana_cluster(), SolanaCluster::Devnet);
- assert_eq!(
- rpc_url_for_chain(WalletChain::Solana),
- SolanaCluster::Devnet.rpc_url()
- );
- assert_eq!(HostEndpoints.solana_cluster(), SolanaCluster::Devnet);
- },
- );
-}
-
-#[test]
-fn an_unknown_cluster_value_falls_back_to_mainnet() {
+ with_env(&[("OPENHUMAN_SOLANA_CLUSTER", Some(" DevNet "))], || {
+ assert_eq!(solana_cluster(), SolanaCluster::Devnet);
+ });
with_env(&[("OPENHUMAN_SOLANA_CLUSTER", Some("testnet"))], || {
assert_eq!(solana_cluster(), SolanaCluster::Mainnet);
});
}
#[test]
-fn an_env_override_wins_and_is_reported_as_one() {
+fn only_explicit_nonblank_endpoint_overrides_are_exposed_to_transport() {
with_env(
&[
- ("OPENHUMAN_WALLET_RPC_BTC", Some(" http://btc.test/api ")),
- ("OPENHUMAN_WALLET_RPC_BASE", Some("http://base.test")),
+ ("OPENHUMAN_WALLET_RPC_BTC", Some(" https://btc.example/rpc ")),
+ ("OPENHUMAN_WALLET_RPC_BASE", Some("https://base.example/rpc")),
("OPENHUMAN_WALLET_RPC_TRON", Some(" ")),
],
|| {
- assert_eq!(rpc_url_for_chain(WalletChain::Btc), "http://btc.test/api");
assert_eq!(
- rpc_source_for_chain(WalletChain::Btc),
- RpcSource::EnvOverride
+ override_for_endpoint(RpcEndpointKey::Btc).as_deref(),
+ Some("https://btc.example/rpc")
);
assert_eq!(
- rpc_url_for_evm_network(EvmNetwork::BaseMainnet),
- "http://base.test"
- );
- assert_eq!(
- rpc_source_for_evm_network(EvmNetwork::BaseMainnet),
- RpcSource::EnvOverride
- );
- // A blank override is no override.
- assert_eq!(rpc_source_for_chain(WalletChain::Tron), RpcSource::Default);
- assert_eq!(
- rpc_url_for_chain(WalletChain::Tron),
- default_rpc_url(WalletChain::Tron, SolanaCluster::Mainnet)
+ override_for_endpoint(RpcEndpointKey::Evm {
+ network: EvmNetwork::BaseMainnet,
+ })
+ .as_deref(),
+ Some("https://base.example/rpc")
);
+ assert_eq!(override_for_endpoint(RpcEndpointKey::Tron), None);
},
);
}
#[test]
-fn the_seam_resolves_an_evm_network_or_the_chain() {
- with_env(
- &[
- ("OPENHUMAN_WALLET_RPC_EVM", None),
- ("OPENHUMAN_WALLET_RPC_ARBITRUM", Some("http://arb.test")),
- ],
- || {
- let endpoints = HostEndpoints;
- assert_eq!(
- endpoints.url(WalletChain::Evm, Some(EvmNetwork::ArbitrumOne)),
- "http://arb.test"
- );
- assert_eq!(
- endpoints.source(WalletChain::Evm, Some(EvmNetwork::ArbitrumOne)),
- RpcSource::EnvOverride
- );
- // No network means Ethereum mainnet.
- assert_eq!(
- endpoints.url(WalletChain::Evm, None),
- EvmNetwork::EthereumMainnet.default_rpc_url()
- );
- assert_eq!(endpoints.source(WalletChain::Evm, None), RpcSource::Default);
- assert_eq!(
- endpoints.url(WalletChain::Btc, None),
- rpc_url_for_chain(WalletChain::Btc)
- );
- assert_eq!(
- endpoints.source(WalletChain::Btc, None),
- rpc_source_for_chain(WalletChain::Btc)
- );
- },
- );
-}
-
-#[test]
-fn every_chain_and_network_has_its_own_env_var() {
- let mut names: Vec<&str> = EvmNetwork::ALL
+fn each_wallet_endpoint_has_a_distinct_host_override_name() {
+ let mut names: Vec<_> = EvmNetwork::ALL
.iter()
- .map(|n| evm_rpc_env_var(*n))
+ .map(|network| evm_rpc_env_var(*network))
.collect();
- for chain in [WalletChain::Btc, WalletChain::Solana, WalletChain::Tron] {
- names.push(env_var_for_chain(chain));
- }
+ names.extend([
+ env_var_for_chain(WalletChain::Btc),
+ env_var_for_chain(WalletChain::Solana),
+ env_var_for_chain(WalletChain::Tron),
+ ]);
let count = names.len();
names.sort_unstable();
names.dedup();
- assert_eq!(names.len(), count, "no two endpoints share an override");
+ assert_eq!(names.len(), count);
assert_eq!(
env_var_for_chain(WalletChain::Evm),
"OPENHUMAN_WALLET_RPC_EVM"
diff --git a/crates/openhuman-core/src/web3/wallet/ops/types.rs b/crates/openhuman-core/src/web3/wallet/ops/types.rs
index 7d8c4712f4..976c1a7b5c 100644
--- a/crates/openhuman-core/src/web3/wallet/ops/types.rs
+++ b/crates/openhuman-core/src/web3/wallet/ops/types.rs
@@ -2,16 +2,47 @@
use serde::{Deserialize, Serialize};
-// The wallet's vocabulary lives in `tinywallet-web3`, which the engine and the
-// tools share; the host keeps only the persisted shape and the setup params.
-pub use tinywallet_web3::crypto::wallet::{
- WalletAccount, WalletChain, WalletSetupSource, WalletStatus,
-};
-/// Error message returned when the wallet has not been set up yet. Downstream
-/// boundaries match against it to classify the condition as an expected user
-/// state, so it stays out of Sentry; it is defined once in `tinywallet-web3`
-/// so the producer and any classifier cannot drift apart.
-pub use tinywallet_web3::quote::WALLET_NOT_CONFIGURED_MESSAGE;
+/// Wallet chain identifiers are shared contract vocabulary.
+pub use tinywallet_bus::wire::WalletChain;
+
+/// Error returned when no local wallet has been configured.
+pub const WALLET_NOT_CONFIGURED_MESSAGE: &str =
+ "wallet is not configured; run wallet setup first";
+
+/// How the host's local wallet state was created.
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "snake_case")]
+pub enum WalletSetupSource {
+ Generated,
+ Imported,
+}
+
+/// A public account retained in OpenHuman's wallet setup state.
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+pub struct WalletAccount {
+ pub chain: WalletChain,
+ pub address: String,
+ pub derivation_path: String,
+}
+
+/// Host-owned wallet setup status exposed by the existing RPC surface.
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+#[allow(clippy::struct_excessive_bools)]
+pub struct WalletStatus {
+ pub configured: bool,
+ pub onboarding_completed: bool,
+ pub consent_granted: bool,
+ pub secret_stored: bool,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub source: Option<WalletSetupSource>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub mnemonic_word_count: Option<u8>,
+ pub accounts: Vec<WalletAccount>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub updated_at_ms: Option<u64>,
+}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]