Skip to content
Open
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
18 changes: 9 additions & 9 deletions docs/src/miden-bank/05-cross-component-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
┌────────────────────────────────────────────────────────────────────────┐
Expand All @@ -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 │
Expand All @@ -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 │
│ │
└────────────────────────────────────────────────────────────────────────┘
```
Expand Down Expand Up @@ -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

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -279,7 +279,7 @@ contracts/bank-account/target/miden/dev/bank-account.masp

</details>

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

Expand All @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions examples/miden-bank/contracts/bank-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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.
///
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/miden-bank/contracts/deposit-note/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}