-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from 0xPolygonMiden/greenhat/i159-tx-kernel-f…
…unc-11apr [5/x] Add bindings to `remove_asset` and `create_note` Miden SDK `tx-kernel` functions
- Loading branch information
Showing
11 changed files
with
810 additions
and
249 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
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,39 +1,20 @@ | ||
//! Function types and lowering for tx kernel API functions | ||
#![allow(missing_docs)] | ||
|
||
use std::sync::OnceLock; | ||
pub(crate) mod account; | ||
pub(crate) mod note; | ||
pub(crate) mod tx; | ||
|
||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
use std::sync::OnceLock; | ||
|
||
use super::ModuleFunctionTypeMap; | ||
use crate::miden_abi::FunctionTypeMap; | ||
|
||
pub const NOTE_MODULE_NAME: &str = "miden:tx_kernel/note"; | ||
pub const NOTE_GET_INPUTS: &str = "get_inputs"; | ||
|
||
pub const ACCOUNT_MODULE_NAME: &str = "miden:tx_kernel/account"; | ||
pub const ACCOUNT_ADD_ASSET: &str = "add_asset"; | ||
pub const ACCOUNT_GET_ID: &str = "get_id"; | ||
|
||
pub(crate) fn signatures() -> &'static ModuleFunctionTypeMap { | ||
static TYPES: OnceLock<ModuleFunctionTypeMap> = OnceLock::new(); | ||
TYPES.get_or_init(|| { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
|
||
let mut note: FunctionTypeMap = Default::default(); | ||
note.insert(NOTE_GET_INPUTS, FunctionType::new([Felt], [I32, Felt])); | ||
m.insert(NOTE_MODULE_NAME, note); | ||
|
||
let mut account: FunctionTypeMap = Default::default(); | ||
account.insert( | ||
ACCOUNT_ADD_ASSET, | ||
// Accepts and returns word | ||
FunctionType::new([Felt, Felt, Felt, Felt], [Felt, Felt, Felt, Felt]), | ||
); | ||
account.insert(ACCOUNT_GET_ID, FunctionType::new([], [Felt])); | ||
m.insert(ACCOUNT_MODULE_NAME, account); | ||
|
||
m.extend(account::signatures()); | ||
m.extend(note::signatures()); | ||
m.extend(tx::signatures()); | ||
m | ||
}) | ||
} |
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,22 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub const ADD_ASSET: &str = "add_asset"; | ||
pub const REMOVE_ASSET: &str = "remove_asset"; | ||
pub const GET_ID: &str = "get_id"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut account: FunctionTypeMap = Default::default(); | ||
account | ||
.insert(ADD_ASSET, FunctionType::new([Felt, Felt, Felt, Felt], [Felt, Felt, Felt, Felt])); | ||
account.insert( | ||
REMOVE_ASSET, | ||
FunctionType::new([Felt, Felt, Felt, Felt], [Felt, Felt, Felt, Felt]), | ||
); | ||
account.insert(GET_ID, FunctionType::new([], [Felt])); | ||
m.insert("miden:tx_kernel/account", account); | ||
m | ||
} |
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,14 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub const GET_INPUTS: &str = "get_inputs"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut note: FunctionTypeMap = Default::default(); | ||
note.insert(GET_INPUTS, FunctionType::new([Felt], [I32, Felt])); | ||
m.insert("miden:tx_kernel/note", note); | ||
m | ||
} |
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,17 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub const CREATE_NOTE: &str = "create_note"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut note: FunctionTypeMap = Default::default(); | ||
note.insert( | ||
CREATE_NOTE, | ||
FunctionType::new([Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], [Felt]), | ||
); | ||
m.insert("miden:tx_kernel/tx", note); | ||
m | ||
} |
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,36 @@ | ||
use miden_prelude::Felt; | ||
|
||
use crate::{AccountId, CoreAsset, NoteId, NoteType, Tag}; | ||
|
||
#[link(wasm_import_module = "miden:tx_kernel/account")] | ||
extern "C" { | ||
#[link_name = "get_id<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_account_get_id() -> AccountId; | ||
#[link_name = "add_asset<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_account_add_asset(_: Felt, _: Felt, _: Felt, _: Felt, ptr: *mut CoreAsset); | ||
#[link_name = "remove_asset<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_account_remove_asset(_: Felt, _: Felt, _: Felt, _: Felt, ptr: *mut CoreAsset); | ||
} | ||
|
||
#[link(wasm_import_module = "miden:tx_kernel/note")] | ||
extern "C" { | ||
#[link_name = "get_inputs<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_note_get_inputs(ptr: *mut Felt) -> usize; | ||
} | ||
|
||
#[link(wasm_import_module = "miden:tx_kernel/tx")] | ||
extern "C" { | ||
#[link_name = "create_note<0x0000000000000000000000000000000000000000000000000000000000000000>"] | ||
pub fn extern_tx_create_note( | ||
asset_f0: Felt, | ||
asset_f1: Felt, | ||
asset_f2: Felt, | ||
asset_f3: Felt, | ||
tag: Tag, | ||
note_type: NoteType, | ||
recipient_f0: Felt, | ||
recipient_f1: Felt, | ||
recipient_f2: Felt, | ||
recipient_f3: Felt, | ||
) -> NoteId; | ||
} |
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,38 @@ | ||
use miden_prelude::{Felt, Word}; | ||
|
||
#[repr(transparent)] | ||
#[derive(Copy, Clone)] | ||
pub struct AccountId(Felt); | ||
|
||
impl From<AccountId> for Felt { | ||
fn from(account_id: AccountId) -> Felt { | ||
account_id.0 | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct CoreAsset { | ||
pub(crate) inner: Word, | ||
} | ||
|
||
impl CoreAsset { | ||
pub fn new(word: Word) -> Self { | ||
CoreAsset { inner: word } | ||
} | ||
|
||
pub fn as_word(&self) -> Word { | ||
self.inner | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct Recipient(pub(crate) Word); | ||
|
||
#[repr(transparent)] | ||
pub struct Tag(pub(crate) Felt); | ||
|
||
#[repr(transparent)] | ||
pub struct NoteId(pub(crate) Felt); | ||
|
||
#[repr(transparent)] | ||
pub struct NoteType(pub(crate) Felt); |
Oops, something went wrong.