From c745a4a4d67462cacc6be0fd1bff4a0b4122b999 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Tue, 23 Jul 2024 17:56:47 +0300 Subject: [PATCH] update the `account` template code to basic wallet example add a CI workflow to test the new project build --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ account/template/Cargo.toml | 3 ++- account/template/src/lib.rs | 37 ++++++++++++++++++++----------------- rust-toolchain | 1 + 4 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 rust-toolchain diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8c37eb5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - '*.md' + pull_request: + paths-ignore: + - '*.md' + +env: + ACTIONS_RUNNER_DEBUG: true + ACTIONS_STEP_DEBUG: true + +jobs: + test_new_project_build: + # Create a new project from the template and build it + name: Test new project build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + - name: Install Miden cargo extension + uses: actions-rs/cargo@v1 + with: + command: install + args: --git https://github.com/0xPolygonMiden/compiler --branch main cargo-miden + - name: Run `cargo miden new` command + run: cargo miden new my_account_proj --template-path . + - name: Run `cargo miden build` command + run: cargo miden build --release + working-directory: my_account_proj \ No newline at end of file diff --git a/account/template/Cargo.toml b/account/template/Cargo.toml index d256860..7a97ee1 100644 --- a/account/template/Cargo.toml +++ b/account/template/Cargo.toml @@ -9,7 +9,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -# Miden SDK consists of a Prelude (intrinsic functions for VM opr, stdlib) and transaction kernel API for the Miden rollup +# Miden SDK consists of a stdlib (intrinsic functions for VM ops, stdlib functions and types) +# and transaction kernel API for the Miden rollup {% if compiler_path %} miden-sdk = { path = "{{ compiler_path }}/sdk/sdk" } {% elsif compiler_branch %} diff --git a/account/template/src/lib.rs b/account/template/src/lib.rs index 1e6fb8c..38bf7ad 100644 --- a/account/template/src/lib.rs +++ b/account/template/src/lib.rs @@ -19,22 +19,25 @@ fn my_panic(_info: &core::panic::PanicInfo) -> ! { use miden_sdk::*; -// Marking the function no_mangle ensures that it is exported -// from the compiled binary as `fib`, otherwise it would have -// a mangled name that has no stable form. -// -// You can specify a different name from the library than the -// name in the source code using the `#[export_name = "foo"]` -// attribute, which will make the function callable as `foo` -// externally (in this example) -#[no_mangle] -pub fn fib(n: u32) -> Felt { - let mut a = felt!(0); - let mut b = felt!(1); - for _ in 0..n { - let c = a + b; - a = b; - b = c; +struct Account; + +impl Account { + // Marking the function no_mangle ensures that it is exported + // from the compiled binary as `receive_asset`, otherwise it would have + // a mangled name that has no stable form. + // + // You can specify a different name from the library than the + // name in the source code using the `#[export_name = "foo"]` + // attribute, which will make the function callable as `foo` + // externally (in this example) + #[no_mangle] + fn receive_asset(asset: CoreAsset) { + add_asset(asset); + } + + #[no_mangle] + fn send_asset(asset: CoreAsset, tag: Tag, note_type: NoteType, recipient: Recipient) { + let asset = remove_asset(asset); + create_note(asset, tag, note_type, recipient); } - a } diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..b22e856 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2024-03-10 \ No newline at end of file