diff --git a/docs/src/miden-bank/05-cross-component-calls.md b/docs/src/miden-bank/05-cross-component-calls.md index d09850c..5192da6 100644 --- a/docs/src/miden-bank/05-cross-component-calls.md +++ b/docs/src/miden-bank/05-cross-component-calls.md @@ -19,7 +19,7 @@ By the end of this section, you will have: ## Building on Part 4 -In Part 4, you wrote `account.deposit(depositor, asset)` in the deposit note. But how does that call actually work? This part explains the binding system: +In Part 4, you wrote `account.bank_deposit(depositor, asset)` in the deposit note. But how does that call actually work? This part explains the binding system: ```text ┌────────────────────────────────────────────────────────────────────────┐ @@ -29,7 +29,7 @@ In Part 4, you wrote `account.deposit(depositor, asset)` in the deposit note. Bu │ bank-account/ │ │ └── src/lib.rs │ │ #[component] trait Bank │ -│ ├── deposit(...) │ +│ ├── bank_deposit(...) │ │ └── withdraw(...) │ │ │ │ │ │ miden build │ @@ -45,7 +45,7 @@ In Part 4, you wrote `account.deposit(depositor, asset)` in the deposit note. Bu │ └── src/lib.rs │ │ #[account(bank_account::Bank)] │ │ pub struct Wallet; │ -│ account.deposit(...) ──▶ generated binding ──▶ Bank::deposit │ +│ account.deposit(...) ──▶ generated binding ──▶ Bank::bank_deposit │ │ │ └────────────────────────────────────────────────────────────────────────┘ ``` @@ -101,7 +101,7 @@ For our bank: - `bank_account` - The package name (derived from `bank-account` with underscores) - `Bank` - The component trait whose methods are exposed on the wrapper -The macro reads the bank account's generated WIT and generates a `Wallet` type whose methods (`deposit`, `withdraw`, `initialize`, `get_depositor_balance`) call into the bank component across the component boundary. +The macro reads the bank account's generated WIT and generates a `Wallet` type whose methods (`bank_deposit`, `withdraw`, `initialize`, `get_depositor_balance`) call into the bank component across the component boundary. ## Calling Account Methods @@ -123,7 +123,7 @@ impl DepositNote { // Deposit each asset into the bank for asset in assets { - account.deposit(depositor, asset); + account.bank_deposit(depositor, asset); } } } @@ -196,7 +196,7 @@ trait Bank { #[account_procedure] fn get_depositor_balance(&self, depositor: AccountId, asset: Asset) -> Felt; #[account_procedure] - fn deposit(&mut self, depositor: AccountId, deposit_asset: Asset); + fn bank_deposit(&mut self, depositor: AccountId, deposit_asset: Asset); #[account_procedure] fn withdraw(&mut self, withdraw_asset: Asset, serial_num: Word, tag: Felt, note_type: Felt); } @@ -231,7 +231,7 @@ interface bank { initialize: func(); get-depositor-balance: func(depositor: account-id, asset: asset) -> felt; - deposit: func(depositor: account-id, deposit-asset: asset); + bank-deposit: func(depositor: account-id, deposit-asset: asset); withdraw: func(withdraw-asset: asset, serial-num: word, tag: felt, note-type: felt); } @@ -279,7 +279,7 @@ contracts/bank-account/target/miden/dev/bank-account.masp -The embedded interface enables the deposit note's `#[account(bank_account::Bank)]` wrapper to call `account.deposit()`. +The embedded interface enables the deposit note's `#[account(bank_account::Bank)]` wrapper to call `account.bank_deposit()`. ## Common Issues @@ -299,7 +299,7 @@ error: cannot find module `bindings` ### "Method not found" Error ``` -error: no method named `deposit` found +error: no method named `bank_deposit` found ``` **Cause**: The method isn't declared on the `#[component] trait Bank`. Only trait methods are exported through bindings. diff --git a/examples/miden-bank/contracts/bank-account/src/lib.rs b/examples/miden-bank/contracts/bank-account/src/lib.rs index 8e3ca71..c86aee2 100644 --- a/examples/miden-bank/contracts/bank-account/src/lib.rs +++ b/examples/miden-bank/contracts/bank-account/src/lib.rs @@ -93,6 +93,9 @@ trait Bank { /// Deposit an asset into the bank for a specific depositor. /// + /// Named `bank_deposit` to avoid colliding with the built-in wallet `deposit` + /// method when FPI bindings are generated. + /// /// The asset is added to the bank's vault and the depositor's /// balance is updated in the mapping. /// @@ -106,7 +109,7 @@ trait Bank { /// Panics if the resulting balance would exceed `MAX_BALANCE` (u64 overflow). /// Panics if the bank has not been initialized. #[account_procedure] - fn deposit(&mut self, depositor: AccountId, deposit_asset: Asset); + fn bank_deposit(&mut self, depositor: AccountId, deposit_asset: Asset); /// Withdraw assets back to the depositor. /// @@ -157,7 +160,7 @@ impl Bank for BankStorage { self.balances.get(key) } - fn deposit(&mut self, depositor: AccountId, deposit_asset: Asset) { + fn bank_deposit(&mut self, depositor: AccountId, deposit_asset: Asset) { // Ensure the bank is initialized before accepting deposits self.require_initialized(); @@ -221,7 +224,7 @@ impl Bank for BankStorage { // bound to the note metadata, so it cannot be spoofed by a malicious caller. let depositor = active_note::get_sender(); - // Verify this is a fungible asset — see `deposit()` for the rationale. + // Verify this is a fungible asset — see `bank_deposit()` for the rationale. assert!( withdraw_asset.is_fungible(), "Only fungible assets are supported" diff --git a/examples/miden-bank/contracts/deposit-note/src/lib.rs b/examples/miden-bank/contracts/deposit-note/src/lib.rs index 31e7b82..4365bf1 100644 --- a/examples/miden-bank/contracts/deposit-note/src/lib.rs +++ b/examples/miden-bank/contracts/deposit-note/src/lib.rs @@ -18,7 +18,7 @@ pub struct Wallet; /// 1. Note is created by a user with fungible assets attached /// 2. Bank account consumes this note /// 3. Note script reads the sender (depositor) and assets -/// 4. For each asset, calls `account.deposit(depositor, asset)` +/// 4. For each asset, calls `account.bank_deposit(depositor, asset)` /// 5. Bank receives the asset and updates the depositor's balance /// /// # Note Inputs @@ -38,7 +38,7 @@ impl DepositNote { // Deposit each asset into the bank for asset in assets { - account.deposit(depositor, asset); + account.bank_deposit(depositor, asset); } } }