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

refactor: library api reorganization #367

Merged
merged 106 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
6365fd8
feat: point to miden base's next and fix errors
mFragaBA May 24, 2024
fc276bf
fix: point node to custom branch on integration tests also
mFragaBA May 24, 2024
215908e
fix: filter out partial notes
mFragaBA May 24, 2024
a062bae
fix: only store in scripts table if output note record has a script
mFragaBA May 24, 2024
dd002d1
fix: add new storage type to node config file from #365
mFragaBA May 29, 2024
50b9d49
fix: pull from custom branch instead of main
mFragaBA May 29, 2024
58f3dd1
Update the `TransactionAuthenticator` imports
tomyrd May 31, 2024
5a4091c
Remove duplicate `get_falcon_signature`
tomyrd May 31, 2024
c1c301e
fix: update note script root hashes
mFragaBA Jun 3, 2024
32417cc
refactor: flatten refactors
mFragaBA May 28, 2024
143e1d4
refactor: make `StoreConfig` an associated type of the `Store` trait.
mFragaBA May 28, 2024
0dbb8d4
refactor: put sqlite store behind feature flag
mFragaBA May 28, 2024
56bd328
refactor: put tonic rpc client behind a feature flag
mFragaBA May 28, 2024
72b5f8d
refactor: make concurrent feature imply std
mFragaBA May 28, 2024
1c9df97
refactor: remove tests in cli module files
mFragaBA May 29, 2024
aa2d7d0
refactor: invert dependency between ClientConfig and CliConfig and mo…
mFragaBA May 29, 2024
2ffbb2a
refactor: stop exposing optional dependencies as features
mFragaBA May 30, 2024
4b6ca9d
fix: fix compilation errors after rebase
mFragaBA May 31, 2024
5dabd8a
fix CHANGELOG
mFragaBA May 31, 2024
d29652f
address some review comments
mFragaBA Jun 1, 2024
e979b0d
refactor: rename error types
mFragaBA Jun 3, 2024
9563888
refactor: remove old client config struct
mFragaBA Jun 3, 2024
14086c5
feat: point to miden base's next and fix errors
mFragaBA May 24, 2024
96374a5
fix: point node to custom branch on integration tests also
mFragaBA May 24, 2024
5a55246
fix: filter out partial notes
mFragaBA May 24, 2024
0123246
fix: only store in scripts table if output note record has a script
mFragaBA May 24, 2024
a1aeaac
fix: add new storage type to node config file from #365
mFragaBA May 29, 2024
74f1af5
fix: pull from custom branch instead of main
mFragaBA May 29, 2024
9649afa
Update the `TransactionAuthenticator` imports
tomyrd May 31, 2024
c2e0d8c
Remove duplicate `get_falcon_signature`
tomyrd May 31, 2024
2d7e68a
fix: update note script root hashes
mFragaBA Jun 3, 2024
35f7c8c
Use `&mut rng` for note creation in transactions
tomyrd Jun 6, 2024
2286e8d
Fix usage of new `InputNote`
tomyrd Jun 6, 2024
352d62b
fix: fix after rebase
mFragaBA Jun 6, 2024
b26e21c
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 6, 2024
4d6cbce
feat: point to miden base's next and fix errors
mFragaBA May 24, 2024
30899cf
fix: filter out partial notes
mFragaBA May 24, 2024
879d80f
fix: only store in scripts table if output note record has a script
mFragaBA May 24, 2024
d598e9d
fix: add new storage type to node config file from #365
mFragaBA May 29, 2024
68e1fe3
Update the `TransactionAuthenticator` imports
tomyrd May 31, 2024
6d7cee6
Remove duplicate `get_falcon_signature`
tomyrd May 31, 2024
5702529
fix: update note script root hashes
mFragaBA Jun 3, 2024
cd17166
Use `&mut rng` for note creation in transactions
tomyrd Jun 6, 2024
79163bf
Fix usage of new `InputNote`
tomyrd Jun 6, 2024
e5e8319
fix: fix after rebase
mFragaBA Jun 6, 2024
479f169
cargo: point to node's next branch
mFragaBA Jun 7, 2024
820cc0c
Change node ref
igamigo Jun 7, 2024
0908283
test: avoid reruns on genesis cli tests
mFragaBA Jun 7, 2024
e12bbdc
add looser sleep times to ensure blocks are included
mFragaBA Jun 7, 2024
00d9215
test: add helper to wait until notes get committed/consumed
mFragaBA Jun 10, 2024
11526b3
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 10, 2024
18fea55
test: add helper to wait until notes get committed/consumed
mFragaBA Jun 10, 2024
cd11167
deps: point to miden-node's next branch and fix compilation errors
mFragaBA Jun 10, 2024
3a59096
Test transaction ordering
igamigo Jun 11, 2024
f864310
make: remove dependency for node to avoid duplication on CI
mFragaBA Jun 11, 2024
0c212ef
Rollback node branch
igamigo Jun 11, 2024
9ce2308
Merge branch 'mFragaBA-next-0.4' of https://github.com/0xPolygonMiden…
igamigo Jun 11, 2024
1b18a70
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 12, 2024
b0ed0b6
fix: fix breaking change from base
mFragaBA Jun 12, 2024
61cc33c
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 12, 2024
d27be2f
fix: update swap note script root
mFragaBA Jun 12, 2024
50ef57e
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 12, 2024
85bc53a
feat: point to miden base's next and fix errors
mFragaBA May 24, 2024
e9a0679
fix: filter out partial notes
mFragaBA May 24, 2024
ab89603
fix: only store in scripts table if output note record has a script
mFragaBA May 24, 2024
5f0d673
fix: add new storage type to node config file from #365
mFragaBA May 29, 2024
b5f715a
Update the `TransactionAuthenticator` imports
tomyrd May 31, 2024
84b77d4
Remove duplicate `get_falcon_signature`
tomyrd May 31, 2024
a7c4531
fix: update note script root hashes
mFragaBA Jun 3, 2024
825e7ea
Use `&mut rng` for note creation in transactions
tomyrd Jun 6, 2024
96b7222
Fix usage of new `InputNote`
tomyrd Jun 6, 2024
6b9cc58
fix: fix after rebase
mFragaBA Jun 6, 2024
8d6e896
cargo: point to node's next branch
mFragaBA Jun 7, 2024
e01726f
Change node ref
igamigo Jun 7, 2024
0ae6ce2
test: avoid reruns on genesis cli tests
mFragaBA Jun 7, 2024
7357d12
add looser sleep times to ensure blocks are included
mFragaBA Jun 7, 2024
d6f1d83
test: add helper to wait until notes get committed/consumed
mFragaBA Jun 10, 2024
75ce560
deps: point to miden-node's next branch and fix compilation errors
mFragaBA Jun 10, 2024
b8e5ddb
Test transaction ordering
igamigo Jun 11, 2024
43414e1
Rollback node branch
igamigo Jun 11, 2024
cd261de
make: remove dependency for node to avoid duplication on CI
mFragaBA Jun 11, 2024
5d4c826
fix: fix breaking change from base
mFragaBA Jun 12, 2024
a409605
fix: update swap note script root
mFragaBA Jun 12, 2024
46c8738
fix: add new aux field to updated note creation functions from base
mFragaBA Jun 14, 2024
7b5a85d
chore: increment crate version to v0.3.1
bobbinth May 22, 2024
e4a2565
Handle aux parameter
igamigo Jun 14, 2024
fba5d06
MASM fix
igamigo Jun 14, 2024
7c89d5c
Correct script root
igamigo Jun 14, 2024
cdee736
Update CHANGELOG.md for WASM changes
igamigo Jun 14, 2024
9374d22
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 14, 2024
51aff68
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 14, 2024
6d978e3
Aux param on custom note
igamigo Jun 14, 2024
2edb6ff
Merge branch 'mFragaBA-next-0.4' of https://github.com/0xPolygonMiden…
igamigo Jun 14, 2024
d9db35d
Merge branch 'mFragaBA-next-0.4' of github.com:0xPolygonMiden/miden-c…
mFragaBA Jun 14, 2024
3395840
Merge branch 'next' into mFragaBA-library-api-reorganization
igamigo Jun 14, 2024
9638b5d
Remove wasm feature in favor of being compatible by default
igamigo Jun 16, 2024
88f37c8
Clean up testing targets
igamigo Jun 16, 2024
6319335
Clean up lint targets
igamigo Jun 16, 2024
e8baba0
Fix typo
igamigo Jun 16, 2024
79a190d
Undo async call in CLI
igamigo Jun 17, 2024
168a5af
Update Cargo.toml
igamigo Jun 17, 2024
7559fb9
Undo async call in CLI
igamigo Jun 17, 2024
bb80a83
Cargo fmt
igamigo Jun 17, 2024
13489b1
Remove getrandom
igamigo Jun 17, 2024
9d1f2d0
Re-add getrandom, but under asyhnc
igamigo Jun 17, 2024
81c8519
Reviews
igamigo Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

* [BREAKING] Library API reorganization (#367).
* Added `wasm` and `async` feature to make the code compatible with WASM-32 target (#378).
* Changed `cargo-make` usage for `make` and `Makefile.toml` for a regular `Makefile` (#359).
* Added integration tests using the CLI (#353).
Expand Down
32 changes: 17 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ crate-type = ["lib"]
[[bin]]
name = "miden"
path = "src/main.rs"
required-features = ["executable"]
igamigo marked this conversation as resolved.
Show resolved Hide resolved

[[test]]
name = "integration"
Expand All @@ -26,20 +27,19 @@ required-features = ["integration"]

[features]
async = ["miden-tx/async"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent"]
default = ["std", "clap", "comfy-table", "figment", "lazy_static", "miden-node-proto", "rusqlite", "rusqlite_migration", "tokio", "tonic", "toml"]
integration = ["testing", "concurrent", "uuid", "assert_cmd"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"]
default = ["std", "dep:hex", "dep:thiserror", "dep:prost"]
executable = ["std", "sqlite", "tonic", "dep:clap", "dep:comfy-table", "dep:figment", "dep:tokio", "dep:toml"]
integration = ["concurrent", "executable", "testing"]
sqlite = ["dep:rusqlite", "dep:rusqlite_migration", "dep:lazy_static"]
std = ["miden-objects/std"]
testing = ["miden-objects/testing", "miden-lib/testing"]
test_utils = ["miden-objects/testing"]
wasm = ["std", "async", "getrandom", "hex", "thiserror", "prost"]
tonic = ["dep:tonic", "dep:miden-node-proto"]

[dependencies]
assert_cmd = { version = "2.0", optional = true }
clap = { version = "4.3", features = ["derive"], optional = true }
comfy-table = { version = "7.1.0", optional = true }
figment = { version = "0.10", features = ["toml", "env"], optional = true }
getrandom = { version = "0.2", features = ["js"], optional = true }
hex = { version = "0.4", optional = true }
lazy_static = { version = "1.4.0", optional = true }
miden-lib = { package = "miden-lib", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false }
Expand All @@ -52,18 +52,20 @@ rusqlite = { version = "0.30.0", features = ["vtab", "array", "bundled"], option
rusqlite_migration = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
thiserror = { version = "1.0", optional = true }
tokio = { version = "1.29", features = ["rt-multi-thread", "net", "macros"], optional = true }
toml = { version = "0.8", optional = true }
tonic = { version = "0.11", optional = true }
toml = { version = "0.8", optional = true }
thiserror = { version = "1.0", optional = true }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3" }
uuid = { version = "1.6.1", features = ["serde", "v4"], optional = true }
winter-maybe-async = "0.10.0"

[target.'wasm32-unknown-unknown'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
# needed for tests to run always with the test utils feature
miden_client = { package = "miden-client", path = ".", features = [
"test_utils",
"uuid",
] }
# To enable testing feature during tests
miden-lib = { package = "miden-lib", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["testing"] }
miden-objects = { package = "miden-objects", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["serde", "testing"] }
uuid = { version = "1.6.1", features = ["serde", "v4"] }
assert_cmd = { version = "2.0" }
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ help: ## Show description of all commands
# --- Variables -----------------------------------------------------------------------------------

FEATURES_INTEGRATION_TESTING="integration"
FEATURES_CLI="testing,concurrent"
FEATURES_CLI="testing, executable, concurrent"
NODE_FEATURES_TESTING="testing"
WARNINGS=RUSTDOCFLAGS="-D warnings"
NODE_BRANCH="next"
Expand All @@ -16,11 +16,11 @@ NODE_BRANCH="next"

.PHONY: clippy
clippy: ## Runs clippy on all targets with config
cargo +nightly clippy --workspace --tests --all-targets --all-features -- -D clippy::all -D warnings
cargo +nightly clippy --workspace --tests --all-targets --features executable -- -D clippy::all -D warnings
bobbinth marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: fix
fix: ## Runs Fix with configs
cargo +nightly fix --allow-staged --allow-dirty --all-targets --all-features
cargo +nightly fix --allow-staged --allow-dirty --all-targets --features executable

.PHONY: format
format: ## Runs format using nightly toolchain
Expand Down Expand Up @@ -57,13 +57,13 @@ doc: ## Generates & checks rust documentation

.PHONY: test
test: ## Run tests
cargo nextest run --release --workspace
cargo nextest run --release --workspace --features $(FEATURES_CLI)

# --- Integration testing -------------------------------------------------------------------------

.PHONY: integration-test
integration-test: ## Run integration tests
cargo nextest run --no-capture --release --test=integration --features $(FEATURES_INTEGRATION_TESTING)
cargo nextest run --no-capture --release --test=integration --features $(FEATURES_INTEGRATION_TESTING) --no-default-features

.PHONY: integration-test-full
integration-test-full: ## Run the integration test binary with ignored tests included
Expand Down Expand Up @@ -98,3 +98,6 @@ install: ## Installs the CLI binary using the current dir

build: ## Builds the CLI binary and client library in release mode
cargo build --release --features $(FEATURES_CLI)

build-wasm: ## Builds the CLI binary for wasm32
cargo build --target wasm32-unknown-unknown --features async
bobbinth marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ client requires rust version **1.78** or higher.
In order to utilize the `miden-client` library, you can add the dependency to your project's `Cargo.toml` file:

````toml
miden-client = { version = "0.3" }
miden-client = { version = "0.3.1" }
````

By default, the library is `no_std` compatible.

#### Features

- `concurrent`: used to enable concurrent proofs generation
- `testing`: useful feature that lowers PoW difficulty when enabled. Only use this during development and not on production.
- `concurrent`: used to enable concurrency during execution and proof generation.
- `testing`: useful feature that lowers PoW difficulty when enabled, meant to be used during development and not on production.
- `sqlite`: includes `SqliteStore`, a SQLite implementation of the `Store` trait that can be used as a component of `Client`.
- `async`: enables async traits. Disabled by default.
- `tonic`: includes `TonicRpcClient`, a Tonic client to communicate with Miden node, that can be used as a component of `Client`.
- `executable`: builds the CLI, based on `SqliteStore` and `TonicRpcClient`.

### Running `miden-client`'s CLI

Expand Down Expand Up @@ -74,10 +80,9 @@ make

To test the project's code, we provide both unit tests (which can be run with `cargo test`) and integration tests. For more info on integration tests, refer to the [integration testing document](./tests/README.md)

The crate also comes with 2 feature flags that are used exclusively on tests:
The crate also comes with one feature flag that is used exclusively on tests:

- `test_utils`: used on unit tests to use the mocked RPC API.
- `integration`: only used to run integration tests and separate them from unit tests
- `integration`: only used to run integration tests and separate them from unit tests.

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion docs/install-and-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ We currently recommend installing and running the client with the [`testing`](#t
Run the following command to install the miden-client:

```sh
cargo install miden-client --features testing,concurrent
cargo install miden-client --features concurrent,executable,testing
```

This installs the `miden` binary (at `~/.cargo/bin/miden`) with the [`testing`](#testing-feature) and [`concurrent`](#concurrent-feature) features.
Expand Down
5 changes: 4 additions & 1 deletion docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ let client: Client<TonicRpcClient, SqliteDataStore> = {
let store = SqliteStore::new((&client_config).into()).map_err(ClientError::StoreError)?;
let store = Rc::new(store);

let rng = miden_client::get_random_coin();
let mut rng = rand::thread_rng();
let coin_seed: [u64; 4] = rng.gen();

let rng = RpoRandomCoin::new(coin_seed.map(Felt::new));
let authenticator = StoreAuthenticator::new_with_rng(store.clone(), rng);

let client = Client::new(
Expand Down
26 changes: 10 additions & 16 deletions src/cli/account.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use clap::Parser;
use comfy_table::{presets, Attribute, Cell, ContentArrangement, Table};
use miden_client::{
client::{rpc::NodeRpcClient, Client},
config::{CliConfig, ClientConfig},
store::Store,
};
use miden_client::{rpc::NodeRpcClient, store::Store, Client};
use miden_objects::{
accounts::{AccountId, AccountStorage, AccountType, AuthSecretKey, StorageSlotType},
assets::Asset,
Expand All @@ -16,7 +12,10 @@ use miden_tx::{
utils::{bytes_to_hex_string, Serializable},
};

use super::utils::{load_config_file, parse_account_id, update_config};
use super::{
config::CliConfig,
utils::{load_config_file, parse_account_id, update_config},
};
use crate::cli::{create_dynamic_table, CLIENT_BINARY_NAME};

// ACCOUNT COMMAND
Expand Down Expand Up @@ -272,10 +271,7 @@ fn storage_type_display_name(account: &AccountId) -> String {

/// Loads config file and displays current default account ID
fn display_default_account_id() -> Result<(), String> {
let (miden_client_config, _) = load_config_file()?;
let cli_config = miden_client_config
.cli
.ok_or("No CLI options found in the client config file".to_string())?;
let (cli_config, _) = load_config_file()?;

let default_account = cli_config.default_account_id.ok_or(
"No default account found in the CLI options from the client config file.".to_string(),
Expand All @@ -291,27 +287,25 @@ pub(crate) fn set_default_account(account_id: Option<AccountId>) -> Result<(), S
let (mut current_config, config_path) = load_config_file()?;

// set default account
current_config.cli = Some(CliConfig {
default_account_id: account_id.map(|id| id.to_hex()),
});
current_config.default_account_id = account_id.map(|id| id.to_hex());

update_config(&config_path, current_config)
}

/// Sets the provided account ID as the default account and updates the config file, if not set already.
pub(crate) fn maybe_set_default_account(
current_config: &mut ClientConfig,
current_config: &mut CliConfig,
account_id: AccountId,
) -> Result<(), String> {
if let Some(CliConfig { default_account_id: Some(_) }) = current_config.cli {
if current_config.default_account_id.is_some() {
return Ok(());
}

set_default_account(Some(account_id))?;
let account_id = account_id.to_hex();
println!("Setting account {account_id} as the default account ID.");
println!("You can unset it with `{CLIENT_BINARY_NAME} account --default none`.");
current_config.cli = Some(CliConfig { default_account_id: Some(account_id) });
current_config.default_account_id = Some(account_id);

Ok(())
}
37 changes: 37 additions & 0 deletions src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use core::fmt::Debug;

use figment::{
value::{Dict, Map},
Metadata, Profile, Provider,
};
use miden_client::{config::RpcConfig, store::sqlite_store::config::SqliteStoreConfig};
use serde::{Deserialize, Serialize};

// CLI CONFIG
// ================================================================================================

#[derive(Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct CliConfig {
/// Describes settings related to the RPC endpoint
pub rpc: RpcConfig,
/// Describes settings related to the store.
pub store: SqliteStoreConfig,
/// Address of the Miden node to connect to.
pub default_account_id: Option<String>,
}

// Make `ClientConfig` a provider itself for composability.
impl Provider for CliConfig {
fn metadata(&self) -> Metadata {
Metadata::named("CLI Config")
}

fn data(&self) -> Result<Map<Profile, Dict>, figment::Error> {
figment::providers::Serialized::defaults(CliConfig::default()).data()
}

fn profile(&self) -> Option<Profile> {
// Optionally, a profile that's selected by default.
None
}
}
4 changes: 3 additions & 1 deletion src/cli/export.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{fs::File, io::Write, path::PathBuf};

use miden_client::{
client::{rpc::NodeRpcClient, Client},
rpc::NodeRpcClient,
store::{InputNoteRecord, Store},
Client,
};
use miden_objects::crypto::rand::FeltRng;
use miden_tx::{auth::TransactionAuthenticator, utils::Serializable};
Expand Down Expand Up @@ -35,6 +36,7 @@ impl ExportCmd {

// EXPORT NOTE
// ================================================================================================

pub fn export_note<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator>(
client: &Client<N, R, S, A>,
note_id: &str,
Expand Down
Loading