Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Introduce top-level module docs for Rust client crate #683

Merged
merged 20 commits into from
Jan 27, 2025

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented Jan 21, 2025

  • Improves top level module documentation. These are kept mostly general to avoid drifting from implementations but in a way that provides guidance as well.
  • Adds inline Rust examples and a CI job to check for correctness
  • Refactors some of the pre-existing docs a bit

Best way to test this might be to pull the branch and cargo doc --features tonic,sqlite and browse the output

Closes #453

@igamigo igamigo changed the title docs: Introduce top-level module docs: Introduce top-level module docs Jan 21, 2025
@igamigo igamigo added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Jan 21, 2025
@igamigo igamigo mentioned this pull request Jan 21, 2025
3 tasks
@igamigo igamigo changed the title docs: Introduce top-level module docs docs: Introduce top-level module docs for Rust client crate Jan 21, 2025
Copy link
Collaborator

@SantiagoPittella SantiagoPittella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, it is really nice to have.

I left some comments about typos.

crates/rust-client/src/accounts.rs Outdated Show resolved Hide resolved
crates/rust-client/src/lib.rs Outdated Show resolved Hide resolved
crates/rust-client/src/lib.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/rpc/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/store/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/sync/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/transactions/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/transactions/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good. Not a full review, but I left some comments inline.

Makefile Outdated Show resolved Hide resolved
.github/workflows/test.yml Outdated Show resolved Hide resolved
crates/rust-client/README.md Outdated Show resolved Hide resolved
crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/lib.rs Outdated Show resolved Hide resolved
crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/account.rs Show resolved Hide resolved
@igamigo igamigo requested a review from bobbinth January 24, 2025 20:41
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left some more comments inline - most are pretty minor.

One other comment: I noticed that assets module is still using plural rather than singular name. We should probably rename it to just asset.

crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/store/sqlite_store/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/lib.rs Outdated Show resolved Hide resolved
crates/rust-client/src/store/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/sync/mod.rs Outdated Show resolved Hide resolved
docs/library.md Outdated Show resolved Hide resolved
crates/rust-client/src/transaction/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/transaction/mod.rs Outdated Show resolved Hide resolved
@igamigo
Copy link
Collaborator Author

igamigo commented Jan 25, 2025

I think I got all suggestions in. One thing (only very marginally related to this) is that currently both web-tonic and tonic features imply most of the same dependencies (tonic, prost, hex). I think this was because of the assumption that one of them would always be enabled. We could take the optional = true so it can be compiled with no features without errors. Otherwise, because the domain module ends up referencing RPC structs and these have prost types, it fails to compile unless one of those features is active (which I think you suggested we might want anyway but I think I'd prefer it to work anyway).

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good. I left a few more comments inline. Also, the comment about asset vs assets from #683 (review) still needs to be addressed.

One thing (only very marginally related to this) is that currently both web-tonic and tonic features imply most of the same dependencies (tonic, prost, hex). I think this was because of the assumption that one of them would always be enabled. We could take the optional = true so it can be compiled with no features without errors. Otherwise, because the domain module ends up referencing RPC structs and these have prost types, it fails to compile unless one of those features is active (which I think you suggested we might want anyway but I think I'd prefer it to work anyway).

This makes sense - but we could also do it in a different PR.

crates/rust-client/src/account.rs Outdated Show resolved Hide resolved
crates/rust-client/src/store/sqlite_store/mod.rs Outdated Show resolved Hide resolved
docs/library.md Outdated Show resolved Hide resolved
docs/library.md Outdated
Comment on lines 28 to 48
let client: Client<RpoRandomCoin> = {
// Create the SQLite store from the client configuration.
let sqlite_store = SqliteStore::new("path/to/store".try_into()?).await?;
let store = Arc::new(sqlite_store);
// Generate a random seed for the RpoRandomCoin.
let mut rng = rand::thread_rng();
let coin_seed: [u64; 4] = rng.gen();
// Initialize the random coin using the generated seed.
let rng = RpoRandomCoin::new(coin_seed.map(Felt::new));
// Create a store authenticator with the store and random coin.
let authenticator = StoreAuthenticator::new_with_rng(store.clone(), rng);
// Instantiate the client using a Tonic RPC client
let endpoint = Endpoint::new("https".into(), "localhost".into(), Some(57291));
Client::new(
Box::new(TonicRpcClient::new(endpoint, 10_000)),
rng,
store,
Arc::new(authenticator),
false, // Set to true for debug mode, if needed.
)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can probably reduce the indentation here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the indentation here can still be reduced.

crates/rust-client/src/accounts.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! I left just one small nit inline.

docs/library.md Outdated
Comment on lines 28 to 48
let client: Client<RpoRandomCoin> = {
// Create the SQLite store from the client configuration.
let sqlite_store = SqliteStore::new("path/to/store".try_into()?).await?;
let store = Arc::new(sqlite_store);
// Generate a random seed for the RpoRandomCoin.
let mut rng = rand::thread_rng();
let coin_seed: [u64; 4] = rng.gen();
// Initialize the random coin using the generated seed.
let rng = RpoRandomCoin::new(coin_seed.map(Felt::new));
// Create a store authenticator with the store and random coin.
let authenticator = StoreAuthenticator::new_with_rng(store.clone(), rng);
// Instantiate the client using a Tonic RPC client
let endpoint = Endpoint::new("https".into(), "localhost".into(), Some(57291));
Client::new(
Box::new(TonicRpcClient::new(endpoint, 10_000)),
rng,
store,
Arc::new(authenticator),
false, // Set to true for debug mode, if needed.
)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the indentation here can still be reduced.

@igamigo igamigo merged commit 55e6508 into next Jan 27, 2025
13 checks passed
@igamigo igamigo deleted the igamigo-top-level-docs branch January 27, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog This PR does not require an entry in the `CHANGELOG.md` file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants