Skip to content

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

refactor(web3): thread dispatch context into web3 and x402 services

Steven Enamakel98412cd28bd1
diff --git a/crates/openhuman-core/src/tools/impl/network/host.rs b/crates/openhuman-core/src/tools/impl/network/host.rs
index 5404b8b005..8bbd4fcc9a 100644
--- a/crates/openhuman-core/src/tools/impl/network/host.rs
+++ b/crates/openhuman-core/src/tools/impl/network/host.rs
@@ -316,7 +316,7 @@ mod x402 {
client_id: context.client_id.clone(),
});
let (service, payment) =
- x402_service::prepare_payment(&config, url.to_owned(), challenge.to_owned(), owner)
+ x402_service::prepare_payment(&self.ctx, &config, url.to_owned(), challenge.to_owned(), owner)
.await
.map_err(|error| format!("x402 payment failed: {error}"))?;
diff --git a/crates/openhuman-core/src/web3/bridge/schemas.rs b/crates/openhuman-core/src/web3/bridge/schemas.rs
index 6a14566d19..c42df30431 100644
--- a/crates/openhuman-core/src/web3/bridge/schemas.rs
+++ b/crates/openhuman-core/src/web3/bridge/schemas.rs
@@ -96,6 +96,7 @@ fn handle_quote(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFutur
Box::pin(async move {
let config = ctx.load_config().await?;
let quote = web3_service::quote(
+ &ctx,
&config,
None,
methods::WEB3_BRIDGE_QUOTE,
@@ -112,7 +113,7 @@ fn handle_execute(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFut
let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
let config = ctx.load_config().await?;
- let result = web3_service::execute(&config, None, parsed.quote_id, parsed.confirmed)
+ let result = web3_service::execute(&ctx, &config, None, parsed.quote_id, parsed.confirmed)
.await
.map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
diff --git a/crates/openhuman-core/src/web3/dapp/schemas.rs b/crates/openhuman-core/src/web3/dapp/schemas.rs
index 918fb2cc48..6367292526 100644
--- a/crates/openhuman-core/src/web3/dapp/schemas.rs
+++ b/crates/openhuman-core/src/web3/dapp/schemas.rs
@@ -79,6 +79,7 @@ fn handle_call(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture
Box::pin(async move {
let config = ctx.load_config().await?;
let quote = web3_service::quote(
+ &ctx,
&config,
None,
methods::WEB3_DAPP_QUOTE,
@@ -95,7 +96,7 @@ fn handle_execute(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFut
let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
let config = ctx.load_config().await?;
- let result = web3_service::execute(&config, None, parsed.quote_id, parsed.confirmed)
+ let result = web3_service::execute(&ctx, &config, None, parsed.quote_id, parsed.confirmed)
.await
.map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
diff --git a/crates/openhuman-core/src/web3/module_tools.rs b/crates/openhuman-core/src/web3/module_tools.rs
index 362cdbb189..82d5d9ecae 100644
--- a/crates/openhuman-core/src/web3/module_tools.rs
+++ b/crates/openhuman-core/src/web3/module_tools.rs
@@ -74,6 +74,7 @@ impl Web3ModuleTool {
};
let result: anyhow::Result<Value> = match self.name() {
"web3_swap_quote" => crate::modules::web3_service::quote(
+ ctx,
&config,
owner.clone(),
tinywallet_bus::names::methods::WEB3_SWAP_QUOTE,
@@ -83,6 +84,7 @@ impl Web3ModuleTool {
.map_err(|error| anyhow::anyhow!(error.to_string()))
.and_then(|value| serde_json::to_value(value).map_err(Into::into)),
"web3_bridge_quote" => crate::modules::web3_service::quote(
+ ctx,
&config,
owner.clone(),
tinywallet_bus::names::methods::WEB3_BRIDGE_QUOTE,
@@ -92,6 +94,7 @@ impl Web3ModuleTool {
.map_err(|error| anyhow::anyhow!(error.to_string()))
.and_then(|value| serde_json::to_value(value).map_err(Into::into)),
"web3_dapp_call" => crate::modules::web3_service::quote(
+ ctx,
&config,
owner.clone(),
tinywallet_bus::names::methods::WEB3_DAPP_QUOTE,
@@ -100,12 +103,13 @@ impl Web3ModuleTool {
.await
.map_err(|error| anyhow::anyhow!(error.to_string()))
.and_then(|value| serde_json::to_value(value).map_err(Into::into)),
- "web3_swap_routes" => crate::modules::web3_service::routes(&config)
+ "web3_swap_routes" => crate::modules::web3_service::routes(ctx, &config)
.await
.map_err(|error| anyhow::anyhow!(error.to_string())),
"web3_swap_execute" | "web3_bridge_execute" | "web3_dapp_execute" => {
match serde_json::from_value::<crate::modules::web3_service::ExecuteParams>(args) {
Ok(params) => crate::modules::web3_service::execute(
+ ctx,
&config,
owner,
params.quote_id,
diff --git a/crates/openhuman-core/src/web3/swap/schemas.rs b/crates/openhuman-core/src/web3/swap/schemas.rs
index f594b9a096..4f079578a4 100644
--- a/crates/openhuman-core/src/web3/swap/schemas.rs
+++ b/crates/openhuman-core/src/web3/swap/schemas.rs
@@ -107,6 +107,7 @@ fn handle_quote(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFutur
Box::pin(async move {
let config = ctx.load_config().await?;
let quote = web3_service::quote(
+ &ctx,
&config,
None,
methods::WEB3_SWAP_QUOTE,
@@ -123,7 +124,7 @@ fn handle_execute(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFut
let parsed: web3_service::ExecuteParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
let config = ctx.load_config().await?;
- let result = web3_service::execute(&config, None, parsed.quote_id, parsed.confirmed)
+ let result = web3_service::execute(&ctx, &config, None, parsed.quote_id, parsed.confirmed)
.await
.map_err(|error| error.to_string())?;
Outcome::new(result, vec!["web3 transaction broadcast".to_string()])
@@ -134,7 +135,7 @@ fn handle_execute(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFut
fn handle_routes(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let config = ctx.load_config().await?;
- let routes = web3_service::routes(&config)
+ let routes = web3_service::routes(&ctx, &config)
.await
.map_err(|error| error.to_string())?;
Outcome::new(routes, vec!["web3 supported routes listed".to_string()])
diff --git a/crates/openhuman-core/src/web3/x402/schemas.rs b/crates/openhuman-core/src/web3/x402/schemas.rs
index 506a7858ab..3f1bb01faf 100644
--- a/crates/openhuman-core/src/web3/x402/schemas.rs
+++ b/crates/openhuman-core/src/web3/x402/schemas.rs
@@ -115,7 +115,7 @@ fn handle_get_summary(ctx: DispatchCtx, _params: Map<String, Value>) -> Controll
.load_config()
.await
.map_err(|error| format!("x402 get_summary: {error}"))?;
- let summary = crate::modules::x402_service::summary(&config)
+ let summary = crate::modules::x402_service::summary(&ctx, &config)
.await
.map_err(|error| format!("x402 get_summary: {error}"))?;
Ok(summary_value(summary))
@@ -139,7 +139,7 @@ fn handle_list_payments(ctx: DispatchCtx, params: Map<String, Value>) -> Control
.await
.map_err(|error| format!("x402 list_payments: {error}"))?;
let limit = p.limit.unwrap_or(50).min(500);
- let response = crate::modules::x402_service::list_payments(&config, limit)
+ let response = crate::modules::x402_service::list_payments(&ctx, &config, limit)
.await
.map_err(|error| format!("x402 list_payments: {error}"))?;
Ok(payments_value(response.payments))
@@ -171,6 +171,7 @@ fn handle_update_budget(ctx: DispatchCtx, params: Map<String, Value>) -> Control
.await
.map_err(|error| format!("x402 update_budget: {error}"))?;
let summary = crate::modules::x402_service::update_budget(
+ &ctx,
&config,
p.per_request_max,
p.daily_max,