Skip to content

Commit 2f6ad2e

Browse files
committed
Added query_account entrypoint using soroban-rs in WASI component
1 parent ee98d5a commit 2f6ad2e

8 files changed

Lines changed: 1233 additions & 41 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/wasi/STELLAR.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Stellar RPC in WASI: jsonrpsee version mismatch
2+
3+
## Problem
4+
5+
`soroban-rs` (0.2.6) depends on `stellar-rpc-client` which requires `jsonrpsee-http-client ^0.20.1`.
6+
Even the latest `stellar-rpc-client` (25.1.0) still pins jsonrpsee 0.20.
7+
8+
Our wasip2 fork is based on jsonrpsee 0.26 (hyper 1.x). `[patch.crates-io]` cannot substitute
9+
0.26 for a `^0.20.1` requirement — semver mismatch.
10+
11+
## Options
12+
13+
### 1. Fork jsonrpsee 0.20 with wasip2 changes
14+
15+
Port the `WasiConnector` and `DirectResolver` changes to jsonrpsee 0.20, which uses hyper 0.14
16+
(completely different client API from hyper 1.x). The connector and TLS plumbing would need to be
17+
rewritten for the older hyper API. More work, but soroban-rs and stellar-rpc-client stay unchanged.
18+
19+
**Pros:** No other forks needed, `[patch.crates-io]` works directly.
20+
**Cons:** Maintaining wasip2 patches across two major jsonrpsee versions (0.20 and 0.26).
21+
22+
### 2. Raw JSON-RPC calls via existing hyper client
23+
24+
Skip soroban-rs in the wasi component entirely. Use our working `http.rs` helper (hyper 1.x +
25+
tokio TcpStream + std::net DNS) to make raw JSON-RPC POST requests. The Stellar RPC methods
26+
(`getHealth`, `getLedgerEntries`, `getAccount`) are simple JSON-RPC — just POST JSON and parse
27+
the response. XDR decoding can use `stellar-xdr` directly (pure Rust, no networking).
28+
29+
**Pros:** No additional forks. Uses the stack we already proved works. Minimal dependencies.
30+
**Cons:** No type-safe RPC client. Must manually construct JSON-RPC request/response envelopes.
31+
Duplicates some logic from stellar-rpc-client.
32+
33+
### 3. Fork soroban-rs + stellar-rpc-client to use jsonrpsee 0.26
34+
35+
Fork both crates to upgrade their jsonrpsee dependency from 0.20 to 0.26. This involves updating
36+
all jsonrpsee API call sites in stellar-rpc-client (the API changed significantly between 0.20 and
37+
0.26). Then use `[patch.crates-io]` to point jsonrpsee 0.26 at our wasip2-tls fork.
38+
39+
**Pros:** Full type-safe client. Uses our existing jsonrpsee 0.26 wasip2 fork.
40+
**Cons:** Most forks to maintain (soroban-rs, stellar-rpc-client, jsonrpsee). Breaking API changes
41+
between jsonrpsee 0.20 and 0.26 make the stellar-rpc-client port non-trivial.

client/wasi/wasi-runner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2024"
77
wasmtime = { version = "29", features = ["component-model"] }
88
wasmtime-wasi = "29"
99
anyhow = "1"
10+
dotenv = "0.15"

client/wasi/wasi-runner/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ impl WasiView for State {
2323
}
2424

2525
fn main() -> Result<()> {
26+
dotenv::dotenv().ok();
27+
2628
let arg = std::env::args().nth(1).unwrap_or_default();
2729

2830
let mut config = Config::new();
@@ -52,8 +54,15 @@ fn main() -> Result<()> {
5254

5355
let result = match arg.as_str() {
5456
"health" | "" => instance.call_get_health(&mut store)?,
57+
"account" => {
58+
let rpc_url = std::env::var("XLM_RPC_URL")
59+
.expect("XLM_RPC_URL must be set in .env or environment");
60+
let account_id = std::env::var("XLM_ACCOUNT")
61+
.expect("XLM_ACCOUNT must be set in .env or environment");
62+
instance.call_query_account(&mut store, &rpc_url, &account_id)?
63+
}
5564
id => {
56-
let id: u32 = id.parse().expect("argument must be a number or 'health'");
65+
let id: u32 = id.parse().expect("argument must be a number, 'health', or 'account'");
5766
instance.call_get_data(&mut store, id)?
5867
}
5968
};

0 commit comments

Comments
 (0)