Skip to content

Commit

Permalink
feat: Integrate newer changes (#321)
Browse files Browse the repository at this point in the history
* feat: Integrate next changes

* fix: Back to next

* Fix conflicts

* Use node next

* fix: Tetss

* refactor: reuse function to create mocked client

* fix: update swap note script root

* fix: Generalize Authenticator

* Merge fixes and refactors

* Lints

* docs: update docs from changes to CLI (#336)

* feat: Utilize expected notes from `ExecutedTransaction` (#329)

* feat: Use expected notes from TransactionResult

* fix: Re-add output note check

* Remove unused code

* Lints

* Fix tests

* fix: Tetss

* Stash

* fix: Address reviews

* fix: Tests

* fix: Lints

* fix: Lints

* Try fix test

* fix: Merge conflicts

* Fix tests

* docs: Address reviews

* Lints

* fix: New script root

* Use 0.3

* fix: Correct genesis toml file

* fix: test fix con cargo make start-node

* fix: temp fix to rename config paths

* fix: Correct miden-node toml

* fix: Ship our own node config files

* Migrate to node 0.3

* feat: Use incoming MMR proof to add block authentications for notes created in past blocks (#337)

* test: Integration tests run with main node

* fix: Remove std::cmp::max

* refactor: git-like usage commands (#338)

* Move new account creation to command

* Flatten account command

* Refactor `default` option

* Separate new account commands

* Refactor `notes` command

* Refactor import comand to infer type

* Remove intermediate sucommand for export

* Flatten tags command

* Separate tx new commands

* Fix documentation

* Join p2id and p2idr to send command

* Remove trait

* Change comment suggestions

* Clarify new account help comments

* Ask for storage path if not specified

* Fixed problem with listing notes with no filter

* Added a message for default account updates

* Change suggestions

* Remove prompt for store path

* Added all NotesFilter

* Fix merge

* feat: enable swap notes (#324)

* feature: add swap tx request and store swap payback note

* feature: insert input note record from payback note details

* feature: show message to user on how to track payback notes

* fix: integration test compilation

* make swap tx send the offered asset

* fix: temporary fix for partial output notes

* test: add skeleton for integration test

* fix: lint issues

* test: add test for onchain swap flow

* test: add test for offchain swap flow

* test: fix note minting for swap tests

* test: fix compilation errors

* fix: use all committed note ids to check transactions to commit

* fix: fix tests checks

* address review comments

* docs: update CHANGELOG

* docs: update CLI reference

* address remaining comment

* fix: clippy issues

* fix: remove wrong check

* refactor: store partial notes in relevant notes of transaction result

* rephrase doc comment

Co-authored-by: igamigo <[email protected]>

* address review comments

* fix: fix offchain swap test

---------

Co-authored-by: igamigo <[email protected]>

* docs: fix doc comments for swap clap command

* feat: update cli-reference with new command structure (#342)

* Update cli-reference with new command structure

* Fix merge

* Fix merge

* Update cli-reference.md

---------

Co-authored-by: igamigo <[email protected]>

* Update README.md

* CLI config.md

---------

Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Tomas Rodriguez Dala <[email protected]>
  • Loading branch information
4 people authored May 15, 2024
1 parent 5d5a268 commit f6f747d
Show file tree
Hide file tree
Showing 53 changed files with 2,543 additions and 1,454 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

* Added swap transactions and example flows on integration tests.
* Flatten the CLI subcommand tree.
* Added a mechanism to retrieve MMR data whenever a note created on a past block is imported.
* Changed the way notes are added to the database based on `ExecutedTransaction`.
* Added more feedback information to commands `info`, `notes list`, `notes show`, `account new`, `notes import`, `tx new` and `sync`.
* Add `consumer_account_id` to `InputNoteRecord` with an implementation for sqlite store.
* Renamed the cli `input-notes` command to `notes`. Now we only export notes that were created on this client as the result of a transaction.
* Renamed the CLI `input-notes` command to `notes`. Now we only export notes that were created on this client as the result of a transaction.
* Added validation using the `NoteScreener` to see if a block has relevant notes.
* Added flags to `init` command for non-interactive environments
* Added an option to verify note existence in the chain before importing.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ clap = { version = "4.3", features = ["derive"] }
comfy-table = "7.1.0"
figment = { version = "0.10", features = ["toml", "env"] }
lazy_static = "1.4.0"
miden-lib = { version = "0.2", default-features = false }
miden-node-proto = { version = "0.2", default-features = false }
miden-tx = { version = "0.2", default-features = false }
miden-objects = { version = "0.2", features = ["serde"] }
miden-lib = { version = "0.3", default-features = false }
miden-node-proto = { version = "0.3", default-features = false }
miden-tx = { version = "0.3", default-features = false }
miden-objects = { version = "0.3", default-features = false, features = ["serde"] }
rand = { version = "0.8.5" }
rusqlite = { version = "0.30.0", features = ["vtab", "array", "bundled"] }
rusqlite_migration = { version = "1.0" }
Expand Down
10 changes: 5 additions & 5 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ args = ["-rf", "miden-node"]
description = "Clone or update miden-node repository and clean up files"
script_runner = "bash"
script = [
'if [ -d miden-node ]; then cd miden-node && git checkout main; else git clone https://github.com/0xPolygonMiden/miden-node.git && cd miden-node && git checkout main; fi',
'if [ -d miden-node ]; then cd miden-node ; else git clone https://github.com/0xPolygonMiden/miden-node.git && cd miden-node; fi',
'git checkout main && git pull origin main && cargo update',
'rm -rf miden-store.sqlite3 miden-store.sqlite3-wal miden-store.sqlite3-shm',
'cd bin/node',
'cargo run --features $NODE_FEATURES_TESTING -- make-genesis --force'
'cargo run --bin miden-node --features $NODE_FEATURES_TESTING -- make-genesis --inputs-path ../tests/config/genesis.toml --force',
]

[tasks.start-node]
description = "Start the miden-node"
script_runner = "bash"
cwd = "./miden-node/bin/node"
script = "cargo run --features ${NODE_FEATURES_TESTING} -- start node"
cwd = "./miden-node"
script = "cargo run --bin miden-node --features $NODE_FEATURES_TESTING -- start --config ../tests/config/miden-node.toml node"

[tasks.docs-deps]
description = "Install documentation dependencies"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/0xPolygonMiden/miden-client/blob/main/LICENSE)
[![CI](https://github.com/0xPolygonMiden/miden-client/actions/workflows/ci.yml/badge.svg)](https://github.com/0xPolygonMiden/miden-clinet/actions/workflows/ci.yml)
[![RUST_VERSION](https://img.shields.io/badge/rustc-1.77+-lightgray.svg)]()
[![RUST_VERSION](https://img.shields.io/badge/rustc-1.78+-lightgray.svg)]()
[![crates.io](https://img.shields.io/crates/v/miden-client)](https://crates.io/crates/miden-client)

This repository contains the Miden client, which provides a way to execute and prove transactions, facilitating the interaction with the Miden rollup.
Expand Down Expand Up @@ -31,14 +31,14 @@ For more info check:

Before you can use the Miden client, you'll need to make sure you have both
[Rust](https://www.rust-lang.org/tools/install) and sqlite3 installed. Miden
client v0.2 requires rust version **1.77** or higher.
client requires rust version **1.78** or higher.

### Adding miden-client as a dependency

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.2" }
miden-client = { version = "0.3" }
````

#### Features
Expand Down
10 changes: 8 additions & 2 deletions docs/cli-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ transactions against it when the account flag is not provided.
By default none is set, but you can set and unset it with:
```sh
miden account default set <ACCOUNT_ID>`
miden account default unset
miden account --default <ACCOUNT_ID> #Sets default account
miden account --default none #Unsets default account
```
You can also see the current default account ID with:
```sh
miden account --default
```
### Environment variables
Expand Down
166 changes: 105 additions & 61 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
comments: true
---

The following document lists the commands that the CLI currently supports.
The following document lists the commands that the CLI currently supports.

!!! note
Use `--help` as a flag on any command for more information.
Expand All @@ -12,13 +12,13 @@ The following document lists the commands that the CLI currently supports.
Call a command on the `miden-client` like this:

```sh
miden <command> <sub-command>
miden <command> <flags> <arguments>
```

Optionally, you can include the `--debug` flag to run the command with debug mode, which enables debug output logs from scripts that were compiled in this mode:

```sh
miden --debug <command> <sub-command>
miden --debug <flags> <arguments>
```

Note that the debug flag overrides the `MIDEN_DEBUG` environment variable.
Expand Down Expand Up @@ -51,131 +51,165 @@ miden init --rpc testnet.miden.io --store_path db/store.sqlite3

### `account`

Create accounts and inspect account details.
Inspect account details.

#### Sub-commands
#### Action Flags

| Sub-command | Description | Aliases |
|---------|-----------------------------------------------------|---------|
| `list` | List all accounts monitored by this client | -l |
| `show` | Show details of the account for the specified ID | -s |
| `new <ACCOUNT TYPE>` | Create new account and store it locally | -n |
| `import` | Import accounts from binary files | -i |
| `default` | Manage the setting for the default account | -d |
| Flags | Description | Short Flag|
|-----------------|-----------------------------------------------------|-----------|
|`--list` | List all accounts monitored by this client | `-l` |
|`--show <ID>` | Show details of the account for the specified ID | `-s` |
|`--default <ID>` | Manage the setting for the default account | `-d` |

After creating an account with the `new` command, it is automatically stored and tracked by the client. This means the client can execute transactions that modify the state of accounts and track related changes by synchronizing with the Miden node.

The `show` subcommand also accepts a partial ID instead of the full ID. For example, instead of:
The `--show` flag also accepts a partial ID instead of the full ID. For example, instead of:

```sh
miden account show 0x8fd4b86a6387f8d8
miden account --show 0x8fd4b86a6387f8d8
```

You can call:

```sh
miden account show 0x8fd4b86
miden account --show 0x8fd4b86
```

For the `--default` flag, if `<ID>` is "none" then the previous default account is cleared. If no `<ID>` is specified then the default account is shown.

### `new-wallet`

Creates a new wallet account.

This command has two optional flags:
- `--storage-type <TYPE>`: Used to select the storage type of the account (off-chain if not specified). It may receive "off-chain" or "on-chain".
- `--mutable`: Makes the account code mutable (it's immutable by default).

After creating an account with the `new-wallet` command, it is automatically stored and tracked by the client. This means the client can execute transactions that modify the state of accounts and track related changes by synchronizing with the Miden node.

### `new-faucet`

Creates a new faucet account.

This command has two optional flags:
- `--storage-type <type>`: Used to select the storage type of the account (off-chain if not specified). It may receive "off-chain" or "on-chain".
- `--non-fungible`: Makes the faucet asset non-fungible (it's fungible by default).

After creating an account with the `new-faucet` command, it is automatically stored and tracked by the client. This means the client can execute transactions that modify the state of accounts and track related changes by synchronizing with the Miden node.

### `info`

View a summary of the current client state.

### `input-notes`
### `notes`

View and manage input notes.
View and manage notes.

#### Sub-commands
#### Action Flags

| Command | Description | Aliases |
|-------------------|-------------------------------------------------------------|---------|
| `list` | List input notes | -l |
| `show` | Show details of the input note for the specified note ID | -s |
| `export` | Export input note data to a binary file | -e |
| `import` | Import input note data from a binary file | -i |
| `list-consumables`| List consumable notes by tracked accounts | -c |
| Flags | Description | Short Flag |
|-------------------|-------------------------------------------------------------|------------|
|`--list [<filter>]`| List input notes | `-l` |
| `--show <ID>` | Show details of the input note for the specified note ID | `-s` |

The `show` subcommand also accepts a partial ID instead of the full ID. For example, instead of:
The `--list` flag receives an optional filter:
- pending: Only lists pending notes.
- commited: Only lists commited notes.
- consumed: Only lists consumed notes.
- consumable: Only lists consumable notes. An additional `--account-id <ID>` flag may be added to only show notes consumable by the specified account.
If no filter is specified then all notes are listed.

The `--show` flag also accepts a partial ID instead of the full ID. For example, instead of:

```sh
miden input-notes show 0x70b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0
miden notes --show 0x70b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0
```

You can call:

```sh
miden input-notes show 0x70b7ec
miden notes --show 0x70b7ec
```

The `import` subcommand verifies that the note that is about to be imported exists on chain. The user can add an optional flag `--no-verify` that skips this verification.

### `sync`

Sync the client with the latest state of the Miden network.
Sync the client with the latest state of the Miden network. Shows a brief summary at the end.

### `tags`

View and add tags.

#### Sub-commands
#### Action Flags

| Command | Description | Aliases |
|---------|----------------------------------------------------------|---------|
| `list` | List all tags monitored by this client | -l |
| `add` | Add a new tag to the list of tags monitored by this client | -a |
| `remove` | Remove a tag from the list of tags monitored by this client | -r |
| Flag | Description | Aliases |
|-----------------|-------------------------------------------------------------|---------|
| `--list` | List all tags monitored by this client | `-l` |
| `--add <tag>` | Add a new tag to the list of tags monitored by this client | `-a` |
| `--remove <tag>`| Remove a tag from the list of tags monitored by this client | `-r` |

### `tx` or `transaction`
### `tx`

Execute and view transactions.
View transactions.

#### Sub-commands
#### Action Flags

| Command | Description | Aliases |
|---------|----------------------------------------------------------|---------|
| `list` | List tracked transactions | -l |
| `new <TX TYPE>` | Execute a transaction, prove and submit it to the node. Once submitted, it gets tracked by the client. | -n |
| `--list`| List tracked transactions | -l |

After a transaction gets executed, two entities start being tracked:

- The transaction itself: It follows a lifecycle from `pending` (initial state) and `committed` (after the node receives it).
- Output notes that might have been created as part of the transaction (for example, when executing a pay-to-id transaction).

#### Types of transaction
### Transaction creation commands
#### `mint`

Creates a note that contains a specific amount tokens minted by a faucet, that the target Account ID can consume.

| Command | Explanation |
|-----------------|-------------------------------------------------------------------------------------------------------------------|
| `p2id --sender <SENDER ACCOUNT ID> --target <TARGET ACCOUNT ID> --faucet <FAUCET ID> <AMOUNT> --note-type <NOTE_TYPE>` | Pay-to-id transaction. Sender Account creates a note that a target Account ID can consume. The asset is identifed by the tuple `(FAUCET ID, AMOUNT)`. |
| `p2idr --sender <SENDER ACCOUNT ID> --target <TARGET ACCOUNT ID> --faucet <FAUCET ID> <AMOUNT> <RECALL_HEIGHT> --note-type <NOTE_TYPE>` | Pay-to-id With Recall transaction. Sender Account creates a note that a target Account ID can consume, but the Sender will also be able to consume it after `<RECALL_HEIGHT>` is reached. The asset is identifed by the tuple `(FAUCET ID, AMOUNT)`. |
| `mint --target <TARGET ACCOUNT ID> --faucet <FAUCET ID> <AMOUNT> --note-type <NOTE_TYPE>` | Creates a note that contains a specific amount tokens minted by a faucet, that the target Account ID can consume|
| `consume-notes --account <ACCOUNT ID> [NOTES]` | Account ID consumes a list of notes, specified by their Note ID |
Usage: `miden mint --target <TARGET ACCOUNT ID> --faucet <FAUCET ID> <AMOUNT> --note-type <NOTE_TYPE>`

`<NOTE_TYPE>` can be either `public` or `private`.
#### `consume-notes`

For `consume-notes` subcommand, you can also provide a partial ID instead of the full ID for each note. So instead of
Account ID consumes a list of notes, specified by their Note ID.

Usage: `miden consume-notes --account <ACCOUNT ID> [NOTES]`

For this command, you can also provide a partial ID instead of the full ID for each note. So instead of

```sh
miden tx new consume-notes --account <some-account-id> 0x70b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0 0x80b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0
```
miden consume-notes --account <some-account-id> 0x70b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0 0x80b7ecba1db44c3aa75e87a3394de95463cc094d7794b706e02a9228342faeb0
```

You can do:
You can do:

```sh
miden tx new consume-notes --account <some-account-id> 0x70b7ecb 0x80b7ecb
miden consume-notes --account <some-account-id> 0x70b7ecb 0x80b7ecb
```

Also, for `p2id`, `p2idr` and `consume-notes`, you can omit the `--sender` and `--account` flags to use the default account defined in the [config](./cli-config.md). If you omit the flag but have no default account defined in the config, you'll get an error instead.
#### `send`

Sends assets to another account. Sender Account creates a note that a target Account ID can consume. The asset is identifed by the tuple `(FAUCET ID, AMOUNT)`. The note can be configured to be recallable making the sender able to consume it after a height is reached.

Usage: `miden send --sender <SENDER ACCOUNT ID> --target <TARGET ACCOUNT ID> --faucet <FAUCET ID> --note-type <NOTE_TYPE> <AMOUNT> <RECALL_HEIGHT>`

#### `swap`

The source account creates a Swap note that offers some asset in exchange for some other asset. When another account consumes that note, it'll receive the offered amount and it'll have the requested amount removed from its assets (and put into a new note which the first account can then consume). Consuming the note will fail if the account doesn't have enough of the requested asset.

Usage: `miden swap --source <SOURCE ACCOUNT ID> --offered_faucet <OFFERED FAUCET ID> --offered_amount <OFFERED AMOUNT> --requested_faucet <REQUESTED FAUCET ID> --requested_amount <REQUESTED AMOUNT> --note-type <NOTE_TYPE>`

#### Tips
For `send` and `consume-notes`, you can omit the `--sender` and `--account` flags to use the default account defined in the [config](./cli-config.md). If you omit the flag but have no default account defined in the config, you'll get an error instead.

For every command which needs an account ID (either wallet or faucet), you can also provide a partial ID instead of the full ID for each account. So instead of

```sh
miden tx new p2id --sender 0x80519a1c5e3680fc --target 0x8fd4b86a6387f8d8 --faucet 0xa99c5c8764d4e011 100
miden send --sender 0x80519a1c5e3680fc --target 0x8fd4b86a6387f8d8 --faucet 0xa99c5c8764d4e011 100
```

You can do:

```sh
miden tx new p2id --sender 0x80519 --target 0x8fd4b --faucet 0xa99c5 100
miden send --sender 0x80519 --target 0x8fd4b --faucet 0xa99c5 100
```

#### Transaction confirmation
Expand All @@ -192,4 +226,14 @@ TX Summary:
Continue with proving and submission? Changes will be irreversible once the proof is finalized on the rollup (Y/N)
```

This confirmation can be skipped in non-interactive environments by providing the `--force` flag (`miden tx new --force ...`):
This confirmation can be skipped in non-interactive environments by providing the `--force` flag (`miden send --force ...`):

### `import`

Import entities managed by the client, such as accounts and notes. The type of entitie is inferred.

When importing notes the CLI verifies that they exist on chain. The user can add an optional flag `--no-verify` that skips this verification.

### `export`

Export input note data to a binary file .
2 changes: 1 addition & 1 deletion docs/install-and-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ comments: true

## Software prerequisites

- [Rust installation](https://www.rust-lang.org/tools/install) minimum version 1.77.
- [Rust installation](https://www.rust-lang.org/tools/install) minimum version 1.78.

## Install the client

Expand Down
22 changes: 13 additions & 9 deletions docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ The current supported store is the `SqliteDataStore`, which is a SQLite implemen
```rust
let client: Client<TonicRpcClient, SqliteDataStore> = {

let store = Store::new((&client_config).into()).map_err(ClientError::StoreError)?;

Client::new(

client_config,
TonicRpcClient::new(&rpc_endpoint),
SqliteDataStore::new(store),

)?
let store = SqliteStore::new((&client_config).into()).map_err(ClientError::StoreError)?;
let store = Rc::new(store);

let rng = miden_client::get_random_coin();
let authenticator = StoreAuthenticator::new_with_rng(store.clone(), rng);

let client = Client::new(
TonicRpcClient::new(&client_config.rpc),
rng,
store,
authenticator,
false, // set to true if you want a client with debug mode
)
};
```

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.77
1.78
Loading

0 comments on commit f6f747d

Please sign in to comment.