Skip to content

Commit

Permalink
chore: Lints
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed Jan 22, 2025
1 parent 9be9038 commit c7be47e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 113 deletions.
2 changes: 1 addition & 1 deletion crates/rust-client/src/store/web_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};

#[cfg(not(target_arch = "wasm32"))]
compile_error!("The `idxdb` feature is only supported when targeting wasm32.")
compile_error!("The `idxdb` feature is only supported when targeting wasm32.");

pub mod accounts;
pub mod chain_data;
Expand Down
1 change: 1 addition & 0 deletions crates/web-client/js/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
NoteInputs,
NoteMetadata,
NoteRecipient,
NoteScript,
NoteTag,
NoteType,
OutputNote,
Expand Down
116 changes: 4 additions & 112 deletions crates/web-client/test/new_transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,116 +490,8 @@ const customTxWithMultipleNotes = async (
new BigUint64Array([BigInt(5), BigInt(6), BigInt(7), BigInt(8)])
);

const p2id_script = `
use.miden::account
use.miden::note
use.miden::contracts::wallets::basic->wallet
# ERRORS
# =================================================================================================
# P2ID script expects exactly 2 note inputs
const.ERR_P2ID_WRONG_NUMBER_OF_INPUTS=0x00020050
# P2ID's target account address and transaction address do not match
const.ERR_P2ID_TARGET_ACCT_MISMATCH=0x00020051
#! Helper procedure to add all assets of a note to an account.
#!
#! Inputs: []
#! Outputs: []
proc.add_note_assets_to_account
push.0 exec.note::get_assets
# => [num_of_assets, 0 = ptr, ...]
# compute the pointer at which we should stop iterating
dup.1 add
# => [end_ptr, ptr, ...]
# pad the stack and move the pointer to the top
padw movup.5
# => [ptr, 0, 0, 0, 0, end_ptr, ...]
# compute the loop latch
dup dup.6 neq
# => [latch, ptr, 0, 0, 0, 0, end_ptr, ...]
while.true
# => [ptr, 0, 0, 0, 0, end_ptr, ...]
# save the pointer so that we can use it later
dup movdn.5
# => [ptr, 0, 0, 0, 0, ptr, end_ptr, ...]
# load the asset
mem_loadw
# => [ASSET, ptr, end_ptr, ...]
# pad the stack before call
padw swapw padw padw swapdw
# => [ASSET, pad(12), ptr, end_ptr, ...]
# add asset to the account
call.wallet::receive_asset
# => [pad(16), ptr, end_ptr, ...]
# clean the stack after call
dropw dropw dropw
# => [0, 0, 0, 0, ptr, end_ptr, ...]
# increment the pointer and compare it to the end_ptr
movup.4 add.1 dup dup.6 neq
# => [latch, ptr+1, ASSET, end_ptr, ...]
end
# clear the stack
drop dropw drop
end
#! Pay-to-ID script: adds all assets from the note to the account, assuming ID of the account
#! matches target account ID specified by the note inputs.
#!
#! Requires that the account exposes:
#! - miden::contracts::wallets::basic::receive_asset procedure.
#!
#! Inputs: []
#! Outputs: []
#!
#! Note inputs are assumed to be as follows:
#! - target_account_id is the ID of the account for which the note is intended.
#!
#! Panics if:
#! - Account does not expose miden::contracts::wallets::basic::receive_asset procedure.
#! - Account ID of executing account is not equal to the Account ID specified via note inputs.
#! - The same non-fungible asset already exists in the account.
#! - Adding a fungible asset would result in amount overflow, i.e., the total amount would be
#! greater than 2^63.
begin
# store the note inputs to memory starting at address 0
push.0 exec.note::get_inputs
# => [num_inputs, inputs_ptr]
# make sure the number of inputs is 2
eq.2 assert.err=ERR_P2ID_WRONG_NUMBER_OF_INPUTS
# => [inputs_ptr]
# read the target account ID from the note inputs
padw movup.4 mem_loadw drop drop
# => [target_account_id_prefix, target_account_id_suffix]
exec.account::get_id
# => [account_id_prefix, account_id_suffix, target_account_id_prefix, target_account_id_suffix, ...]
# ensure account_id = target_account_id, fails otherwise
exec.account::is_id_equal assert.err=ERR_P2ID_TARGET_ACCT_MISMATCH
# => []
exec.add_note_assets_to_account
# => []
end
`;

let compiledNoteScript = await client.compile_note_script(p2id_script);
const p2idScript = window.NoteScript.p2id();

let noteInputs = new window.NoteInputs(
new window.FeltArray([
targetAccount.id().suffix(),
Expand All @@ -609,12 +501,12 @@ const customTxWithMultipleNotes = async (

let noteRecipient1 = new window.NoteRecipient(
serialNum1,
compiledNoteScript,
p2idScript,
noteInputs
);
let noteRecipient2 = new window.NoteRecipient(
_isSerialNumSame ? serialNum1 : serialNum2,
compiledNoteScript,
p2idScript,
noteInputs
);

Expand Down

0 comments on commit c7be47e

Please sign in to comment.