forked from 0xPolygonMiden/miden-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lambda-main' into pretty-table
- Loading branch information
Showing
13 changed files
with
695 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, repoened, synchronize] | ||
|
||
jobs: | ||
test: | ||
name: Test Rust ${{matrix.toolchain}} on ${{matrix.os}} | ||
runs-on: ${{matrix.os}}-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [stable, nightly] | ||
os: [ubuntu] | ||
steps: | ||
- uses: actions/checkout@main | ||
- name: Install rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{matrix.toolchain}} | ||
override: true | ||
- name: Test | ||
uses: actions-rs/cargo@v1 | ||
env: | ||
RUSTFLAGS: -C debug-assertions | ||
with: | ||
command: test | ||
args: --release | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@main | ||
- name: Install minimal stable with clippy | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: nightly | ||
components: clippy | ||
override: true | ||
|
||
- name: Clippy | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: --all --all-targets -- -D clippy::all -D warnings | ||
|
||
rustfmt: | ||
name: rustfmt | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@main | ||
- name: Install minimal stable with rustfmt | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
components: rustfmt | ||
override: true | ||
|
||
- name: rustfmt | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --all -- --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-json | ||
- id: check-toml | ||
- id: pretty-format-json | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-merge-conflict | ||
- id: detect-private-key | ||
- repo: https://github.com/hackaugusto/pre-commit-cargo | ||
rev: v1.0.0 | ||
hooks: | ||
# Allows cargo fmt to modify the source code prior to the commit | ||
- id: cargo | ||
name: Cargo fmt | ||
args: ["+stable", "fmt", "--all"] | ||
stages: [commit] | ||
# Requires code to be properly formatted prior to pushing upstream | ||
- id: cargo | ||
name: Cargo fmt --check | ||
args: ["+stable", "fmt", "--all", "--check"] | ||
stages: [push, manual] | ||
- id: cargo | ||
name: Cargo check --all-targets | ||
args: ["+stable", "check", "--all-targets"] | ||
- id: cargo | ||
name: Cargo check --all-targets --no-default-features | ||
args: ["+stable", "check", "--all-targets", "--no-default-features"] | ||
- id: cargo | ||
name: Cargo check --all-targets --all-features | ||
args: ["+stable", "check", "--all-targets", "--all-features"] | ||
# Unlike fmt, clippy will not be automatically applied | ||
- id: cargo | ||
name: Cargo clippy | ||
args: ["+nightly", "clippy", "--workspace", "--", "--deny", "clippy::all", "--deny", "warnings"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# miden-client | ||
# miden-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
use super::Client; | ||
use super::Parser; | ||
|
||
use objects::notes::RecordedNote; | ||
use objects::Digest; | ||
|
||
#[derive(Debug, Parser, Clone)] | ||
#[clap(about = "View input notes")] | ||
pub enum InputNotes { | ||
/// List input notes | ||
#[clap(short_flag = 'l')] | ||
List, | ||
|
||
/// Show details of the input note for the specified note hash | ||
#[clap(short_flag = 's')] | ||
Show { | ||
/// Hash of the input note to show | ||
#[clap()] | ||
hash: String, | ||
|
||
/// Show note script | ||
#[clap(short, long, default_value = "false")] | ||
script: bool, | ||
|
||
/// Show note vault | ||
#[clap(short, long, default_value = "false")] | ||
vault: bool, | ||
|
||
/// Show note inputs | ||
#[clap(short, long, default_value = "false")] | ||
inputs: bool, | ||
}, | ||
} | ||
|
||
impl InputNotes { | ||
pub fn execute(&self, client: Client) -> Result<(), String> { | ||
match self { | ||
InputNotes::List => { | ||
list_input_notes(client)?; | ||
} | ||
InputNotes::Show { | ||
hash, | ||
script, | ||
vault, | ||
inputs, | ||
} => { | ||
show_input_note(client, hash.clone(), *script, *vault, *inputs)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
// LIST INPUT NOTES | ||
// ================================================================================================ | ||
fn list_input_notes(client: Client) -> Result<(), String> { | ||
let notes = client.get_input_notes().map_err(|err| err.to_string())?; | ||
print_notes_summary(¬es); | ||
Ok(()) | ||
} | ||
|
||
fn show_input_note( | ||
client: Client, | ||
hash: String, | ||
show_script: bool, | ||
show_vault: bool, | ||
show_inputs: bool, | ||
) -> Result<(), String> { | ||
let hash = Digest::try_from(hash) | ||
.map_err(|err| format!("Failed to parse input note hash: {}", err))?; | ||
|
||
let note = client | ||
.store() | ||
.get_input_note_by_hash(hash) | ||
.map_err(|err| err.to_string())?; | ||
|
||
// print note summary | ||
print_notes_summary(core::iter::once(¬e)); | ||
|
||
// print note script | ||
if show_script { | ||
println!("{}", "-".repeat(240)); | ||
println!("Note script hash: {}", note.note().script().hash()); | ||
println!("{}", "-".repeat(240)); | ||
println!("Note Script:"); | ||
println!("{}", "-".repeat(240)); | ||
println!("{}", note.note().script().code()); | ||
}; | ||
|
||
// print note vault | ||
if show_vault { | ||
println!("{}", "-".repeat(240)); | ||
println!("Note vault hash: {}", note.note().vault().hash()); | ||
println!("{}", "-".repeat(240)); | ||
println!("Note Vault:"); | ||
println!("{}", "-".repeat(240)); | ||
for asset in note.note().vault().iter() { | ||
// To do print this nicely | ||
println!("{:?}", asset); | ||
} | ||
}; | ||
|
||
if show_inputs { | ||
println!("{}", "-".repeat(240)); | ||
println!("Note inputs hash: {}", note.note().inputs().hash()); | ||
println!("{}", "-".repeat(240)); | ||
println!("Note Inputs:"); | ||
println!("{}", "-".repeat(240)); | ||
for (idx, input) in note.note().inputs().inputs().iter().enumerate() { | ||
// To do print this nicely | ||
println!("{idx}: {input}"); | ||
} | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
// HELPERS | ||
// ================================================================================================ | ||
fn print_notes_summary<'a, I>(notes: I) | ||
where | ||
I: IntoIterator<Item = &'a RecordedNote>, | ||
{ | ||
println!("{}", "-".repeat(240)); | ||
println!( | ||
"{0: <66} | {1: <66} | {2: <66} | {3: <66} | {4: <15}", | ||
"hash", "script hash", "vault hash", "inputs hash", "serial num", | ||
); | ||
println!("{}", "-".repeat(240)); | ||
|
||
for note in notes { | ||
println!( | ||
"{0: <66} | {1: <66} | {2: <66} | {3: <66} | {4: <15}", | ||
note.note().hash(), | ||
note.note().script().hash(), | ||
note.note().vault().hash(), | ||
note.note().inputs().hash(), | ||
Digest::new(note.note().serial_num()), | ||
); | ||
} | ||
println!("{}", "-".repeat(240)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.