Expand crate docs, add examples, and LLM-friendly docs#11
Conversation
- Enrich lib.rs rustdoc with Features, Custom Configuration, Currency, Error Handling, and API Overview sections (6 doc tests pass) - Add 6 runnable examples: send_payment, stake_delegation, node_monitoring, custom_query, error_handling, currency_operations - Add llms.txt / llms-full.txt for LLM consumers - Cargo.toml: add web3 keyword, cryptography::cryptocurrencies category, docs.rs metadata block - README: document available examples and llms.txt files Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
master introduced a fluent builder API for send_payment/send_delegation; the new examples still used the old positional-args signature. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2714fc7 to
b6e4c88
Compare
- Add a "Run examples" step in integration.yml that loops over every example and runs `cargo run --example` against the lightnet daemon, so we catch runtime regressions — not just compile errors. - Examples that need real unlocked accounts (basic_usage, send_payment, stake_delegation) now read MINA_TEST_SENDER_KEY / MINA_TEST_RECEIVER_KEY from env and short-circuit cleanly when unset. Keeps them usable as standalone docs and runnable in CI with acquired keys. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| println!("Nonce: {}", account.nonce); | ||
| // Query an account. Set MINA_TEST_SENDER_KEY to a valid public key to run; | ||
| // otherwise skip this section. | ||
| if let Ok(public_key) = std::env::var("MINA_TEST_SENDER_KEY") { |
There was a problem hiding this comment.
remove that nesting also show example format of this key
There was a problem hiding this comment.
Flattened to a let-else early return and added a real B62q… key in the comment so readers see the format. Fixed in a7e157d.
| println!("Node version: {}", data["version"]); | ||
|
|
||
| // Example 2: Query with variables | ||
| let query = r#"query ($maxLength: Int) { |
There was a problem hiding this comment.
Shouldn't this query be in sdk? That's the very purpose of this project to encapsulate those graphql calls
There was a problem hiding this comment.
Agreed — bestChain is already wrapped by get_best_chain, so this demo was misleading. Replaced with genesisConstants (genuinely not in the SDK) plus a variables-based pooledUserCommands example. Fixed in a7e157d.
|
|
||
| if let Some(chain) = data["bestChain"].as_array() { | ||
| for block in chain { | ||
| let consensus = &block["protocolState"]["consensusState"]; |
There was a problem hiding this comment.
Why not produce nice wrapper around block? and consensus too , user should not be force to use response as array
There was a problem hiding this comment.
Resolved by dropping the raw bestChain demo entirely — the SDK's typed get_best_chain returns Vec<BlockInfo>. The example now uses genesisConstants, which returns scalar fields (coinbase, genesisTimestamp), so no array-indexing gymnastics. Fixed in a7e157d.
|
|
||
| // Example 3: The built-in query constants are also available | ||
| let data = client | ||
| .execute_query(mina_sdk::queries::DAEMON_STATUS, None, "daemon_status") |
There was a problem hiding this comment.
It's good to have execute_query but all others parameters should be names . maybe builder type (I already forgot what argument None is referring to
There was a problem hiding this comment.
Added a MinaClient::query("...") builder that returns QueryBuilder with opt-in .variables(json) and .name("…") — no more bare None. The low-level execute_query stays so existing downstream crates (mina-perf-testing) don't break. Fixed in a7e157d.
|
|
||
| #[tokio::main] | ||
| async fn main() { | ||
| let client = MinaClient::new("http://127.0.0.1:3085/graphql"); |
There was a problem hiding this comment.
Maybe let's introduce default() for this and it will automatically connect to this url ? also some helper method like from URI or inet or host_and_port() erc
There was a problem hiding this comment.
Added impl Default for MinaClient (connects to http://127.0.0.1:3085/graphql with default retries/timeout) and MinaClient::from_host_and_port(host, port). All examples now use MinaClient::default(). Fixed in a7e157d.
| // Set MINA_TEST_SENDER_KEY to an unlocked account and MINA_TEST_RECEIVER_KEY | ||
| // to any account to run. Without them, this example short-circuits. | ||
| let (Ok(sender), Ok(receiver)) = ( | ||
| std::env::var("MINA_TEST_SENDER_KEY"), |
There was a problem hiding this comment.
Document what those variables are , how to generated them etc.
There was a problem hiding this comment.
Added a doc section at the top of the example explaining both env vars, what a B62q… key looks like, and two ways to generate/unlock one (mina advanced generate-keypair for a fresh key, or curl …/acquire-account?unlockAccount=true on a lightnet node). Fixed in a7e157d.
|
|
||
| // Send with an explicit nonce (useful for sending multiple transactions) | ||
| let result2 = client | ||
| .send_payment( |
There was a problem hiding this comment.
I think it would be more clear would be in this example to first define paymnet and then pass it to .send_payment()
There was a problem hiding this comment.
Refactored to build the Payment as a named variable first, then pass it to client.send_payment(payment).await?. Same pattern applied to stake_delegation. Fixed in a7e157d.
| @@ -0,0 +1,374 @@ | |||
| # mina-sdk — Complete API Reference | |||
There was a problem hiding this comment.
Is there any way to autogenerate those ? so we won't allow them to drift?
There was a problem hiding this comment.
Drift is a real concern and I don't want hand-maintained API summaries rotting silently. Proper autogeneration needs either nightly rustdoc --output-format=json or a syn-based generator — both meaningful work. For this PR I removed llms.txt / llms-full.txt so there's nothing to drift; docs.rs remains the always-current reference. Happy to open a follow-up issue if you want the LLM-friendly format back with a real generator behind it. Fixed in a7e157d.
Client ergonomics: - MinaClient::default() returns a client connected to the local daemon. - MinaClient::from_host_and_port(host, port) as a convenience constructor. - New MinaClient::query(&str) returns a QueryBuilder with opt-in variables/name, so callers don't pass bare None sentinels. The low-level execute_query(query, vars, name) stays for downstream crates. Examples: - basic_usage: flatten env-key nesting with let-else; show a real B62q... key format in the comment. - send_payment / stake_delegation: document MINA_TEST_SENDER_KEY and MINA_TEST_RECEIVER_KEY (how to generate/unlock via mina CLI or lightnet acquire-account). Build the Payment/Delegation as a named variable first, then submit. - custom_query: rewritten to use the new query builder. Drop the bestChain demo (redundant with the typed get_best_chain) — instead query genesisConstants, which is not wrapped by the SDK. Add a variables-based pooledUserCommands query as the multi-argument demo. - error_handling / node_monitoring: use MinaClient::default() / from_host_and_port for clarity. llms.txt: - Remove llms.txt / llms-full.txt. Drift risk outweighs their value until we have proper autogeneration (nightly rustdoc-json or syn-based). docs.rs remains the always-current reference; follow-up issue can track a generator if we want the LLM-friendly format back. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
lib.rsrustdoc with Features, Custom Configuration, Currency, Error Handling, and API Overview sectionssend_payment,stake_delegation,node_monitoring,custom_query,error_handling,currency_operationsllms.txt/llms-full.txtfor LLM consumersCargo.toml: addweb3keyword,cryptography::cryptocurrenciescategory, and[package.metadata.docs.rs]blockllms.txtfilesTest plan
cargo build --examples— all examples compilecargo test --doc— 6 doc tests passRUSTDOCFLAGS="-D warnings" cargo doc --no-deps— clean, no broken intra-doc links🤖 Generated with Claude Code