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

update the account template code to basic wallet example #4

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
push:
branches:
- main
paths-ignore:
- '*.md'
pull_request:
paths-ignore:
- '*.md'

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
Loading