Skip to content

Commit

Permalink
update the account template code to basic wallet example
Browse files Browse the repository at this point in the history
add a CI workflow to test the new project build
  • Loading branch information
greenhat committed Jul 24, 2024
1 parent 7e1cf59 commit c745a4a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion account/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
37 changes: 20 additions & 17 deletions account/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2024-03-10

0 comments on commit c745a4a

Please sign in to comment.