Skip to content

Commit e34d162

Browse files
authored
feat(web-client): expose account storage & vault delta in web-client (0xMiden#1098)
1 parent 7f2cc39 commit e34d162

13 files changed

+331
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
* [BREAKING] Updated `toBech32` AccountID method: it now expects a parameter to specify the NetworkID ([#1043](https://github.com/0xMiden/miden-client/pull/1043)).
99
* Introduced enums instead of booleans for public APIs ([#1042](https://github.com/0xMiden/miden-client/pull/1042)).
1010
* [BREAKING] Made authenticator optional for `ClientBuilder` and `Client::new`. The authenticator parameter is now optional, allowing clients to be created without authentication capabilities ([#1056](https://github.com/0xMiden/miden-client/pull/1056)).
11-
* [BREAKING] Updated `applyStateSync` to receive a single object and then write the changes in a single transaction ([#1050](https://github.com/0xMiden/miden-client/pull/1050))
11+
* [BREAKING] Updated `applyStateSync` to receive a single object and then write the changes in a single transaction ([#1050](https://github.com/0xMiden/miden-client/pull/1050)).
1212
* [BREAKING] Refactored `OnNoteReceived` callback to return enum with update action ([#1051](https://github.com/0xMiden/miden-client/pull/1051)).
13-
* [BREAKING] Changed `OnNoteReceived` from closure to trait object (#1080)
14-
* `NoteScript` now has a `toString` method that prints its own MAST source [(#1082)](https://github.com/0xMiden/miden-client/pull/1082).
15-
13+
* [BREAKING] Changed `OnNoteReceived` from closure to trait object ([#1080](https://github.com/0xMiden/miden-client/pull/1080)).
14+
* `NoteScript` now has a `toString` method that prints its own MAST source ([#1082](https://github.com/0xMiden/miden-client/pull/1082)).
1615

1716
### Features
1817

@@ -23,7 +22,8 @@
2322
* Added `TokenSymbol` type to Web Client ([#1046](https://github.com/0xMiden/miden-client/pull/1046)).
2423
* [BREAKING] Added genesis commitment header to `TonicRpcClient` requests (#1045).
2524
* Added authentication arguments support to `TransactionRequest` ([#1121](https://github.com/0xMiden/miden-client/pull/1121)).
26-
25+
* Added bindings for retrieving storage `AccountDelta` in the web client ([#1098](https://github.com/0xMiden/miden-client/pull/1098)).
26+
2727
## 0.10.1 (2025-07-26)
2828

2929
* Avoid passing unneeded nodes to `PartialMmr::from_parts` (#1081).

crates/web-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@demox-labs/miden-sdk",
3-
"version": "0.11.0-next.9",
3+
"version": "0.11.0-next.10",
44
"description": "Miden Wasm SDK",
55
"collaborators": [
66
"Miden",

crates/web-client/src/models/account_delta.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use miden_objects::account::AccountDelta as NativeAccountDelta;
22
use wasm_bindgen::prelude::*;
33

44
use super::{
5-
// account_storage_delta::AccountStorageDelta,
6-
// account_vault_delta::AccountVaultDelta,
7-
felt::Felt,
5+
account_storage_delta::AccountStorageDelta, account_vault_delta::AccountVaultDelta, felt::Felt,
86
};
97

108
#[derive(Clone)]
@@ -18,15 +16,13 @@ impl AccountDelta {
1816
self.0.is_empty()
1917
}
2018

21-
// TODO: storage
22-
// pub fn storage(&self) -> AccountStorageDelta {
23-
// self.0.storage().into()
24-
// }
19+
pub fn storage(&self) -> AccountStorageDelta {
20+
self.0.storage().into()
21+
}
2522

26-
// TODO: vault
27-
// pub fn vault(&self) -> AccountVaultDelta {
28-
// self.0.vault().into()
29-
// }
23+
pub fn vault(&self) -> AccountVaultDelta {
24+
self.0.vault().into()
25+
}
3026

3127
#[wasm_bindgen(js_name = "nonceDelta")]
3228
pub fn nonce_delta(&self) -> Felt {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use miden_objects::account::AccountStorageDelta as NativeAccountStorageDelta;
2+
use wasm_bindgen::prelude::*;
3+
4+
use super::word::Word;
5+
6+
#[derive(Clone)]
7+
#[wasm_bindgen]
8+
pub struct AccountStorageDelta(NativeAccountStorageDelta);
9+
10+
#[wasm_bindgen]
11+
impl AccountStorageDelta {
12+
#[wasm_bindgen(js_name = "isEmpty")]
13+
pub fn is_empty(&self) -> bool {
14+
self.0.is_empty()
15+
}
16+
17+
pub fn values(&self) -> Vec<Word> {
18+
self.0.values().values().copied().map(Into::into).collect()
19+
}
20+
}
21+
22+
// CONVERSIONS
23+
// ================================================================================================
24+
25+
impl From<NativeAccountStorageDelta> for AccountStorageDelta {
26+
fn from(native_account_storage_delta: NativeAccountStorageDelta) -> Self {
27+
AccountStorageDelta(native_account_storage_delta)
28+
}
29+
}
30+
31+
impl From<&NativeAccountStorageDelta> for AccountStorageDelta {
32+
fn from(native_account_storage_delta: &NativeAccountStorageDelta) -> Self {
33+
AccountStorageDelta(native_account_storage_delta.clone())
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use miden_objects::account::AccountVaultDelta as NativeAccountVaultDelta;
2+
use wasm_bindgen::prelude::*;
3+
4+
use super::fungible_asset_delta::FungibleAssetDelta;
5+
6+
#[derive(Clone)]
7+
#[wasm_bindgen]
8+
pub struct AccountVaultDelta(NativeAccountVaultDelta);
9+
10+
#[wasm_bindgen]
11+
impl AccountVaultDelta {
12+
#[wasm_bindgen(js_name = "isEmpty")]
13+
pub fn is_empty(&self) -> bool {
14+
self.0.is_empty()
15+
}
16+
17+
pub fn fungible(&self) -> FungibleAssetDelta {
18+
self.0.fungible().into()
19+
}
20+
}
21+
22+
// CONVERSIONS
23+
// ================================================================================================
24+
25+
impl From<NativeAccountVaultDelta> for AccountVaultDelta {
26+
fn from(native_account_vault_delta: NativeAccountVaultDelta) -> Self {
27+
AccountVaultDelta(native_account_vault_delta)
28+
}
29+
}
30+
31+
impl From<&NativeAccountVaultDelta> for AccountVaultDelta {
32+
fn from(native_account_vault_delta: &NativeAccountVaultDelta) -> Self {
33+
AccountVaultDelta(native_account_vault_delta.clone())
34+
}
35+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use miden_objects::account::{
2+
AccountId as NativeAccountId, FungibleAssetDelta as NativeFungibleAssetDelta,
3+
};
4+
use wasm_bindgen::prelude::*;
5+
6+
use super::account_id::AccountId;
7+
8+
#[derive(Clone)]
9+
#[wasm_bindgen]
10+
pub struct FungibleAssetDeltaItem {
11+
faucet_id: AccountId,
12+
amount: i64,
13+
}
14+
15+
#[wasm_bindgen]
16+
impl FungibleAssetDeltaItem {
17+
#[wasm_bindgen(getter, js_name = "faucetId")]
18+
pub fn faucet_id(&self) -> AccountId {
19+
self.faucet_id
20+
}
21+
22+
#[wasm_bindgen(getter)]
23+
pub fn amount(&self) -> i64 {
24+
self.amount
25+
}
26+
}
27+
28+
impl From<(&NativeAccountId, &i64)> for FungibleAssetDeltaItem {
29+
fn from(native_fungible_asset_delta_item: (&NativeAccountId, &i64)) -> Self {
30+
Self {
31+
faucet_id: (*native_fungible_asset_delta_item.0).into(),
32+
amount: *native_fungible_asset_delta_item.1,
33+
}
34+
}
35+
}
36+
37+
#[derive(Clone)]
38+
#[wasm_bindgen]
39+
pub struct FungibleAssetDelta(NativeFungibleAssetDelta);
40+
41+
#[wasm_bindgen]
42+
impl FungibleAssetDelta {
43+
#[wasm_bindgen(js_name = "numAssets")]
44+
pub fn num_assets(&self) -> usize {
45+
self.0.num_assets()
46+
}
47+
48+
#[wasm_bindgen(js_name = "isEmpty")]
49+
pub fn is_empty(&self) -> bool {
50+
self.0.is_empty()
51+
}
52+
53+
pub fn assets(&self) -> Vec<FungibleAssetDeltaItem> {
54+
self.0.iter().map(Into::into).collect()
55+
}
56+
}
57+
58+
// CONVERSIONS
59+
// ================================================================================================
60+
61+
impl From<NativeFungibleAssetDelta> for FungibleAssetDelta {
62+
fn from(native_fungible_asset_delta: NativeFungibleAssetDelta) -> Self {
63+
FungibleAssetDelta(native_fungible_asset_delta)
64+
}
65+
}
66+
67+
impl From<&NativeFungibleAssetDelta> for FungibleAssetDelta {
68+
fn from(native_fungible_asset_delta: &NativeFungibleAssetDelta) -> Self {
69+
FungibleAssetDelta(native_fungible_asset_delta.clone())
70+
}
71+
}

crates/web-client/src/models/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ pub mod account_delta;
3535
pub mod account_header;
3636
pub mod account_id;
3737
pub mod account_storage;
38+
pub mod account_storage_delta;
3839
pub mod account_storage_mode;
3940
pub mod account_storage_requirements;
4041
pub mod account_type;
42+
pub mod account_vault_delta;
4143
pub mod advice_inputs;
4244
pub mod advice_map;
4345
pub mod assembler;
@@ -49,6 +51,7 @@ pub mod executed_transaction;
4951
pub mod felt;
5052
pub mod foreign_account;
5153
pub mod fungible_asset;
54+
pub mod fungible_asset_delta;
5255
pub mod input_note;
5356
pub mod input_note_record;
5457
pub mod input_note_state;

docs/src/web-client/api/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
- [AccountHeader](classes/AccountHeader.md)
2323
- [AccountId](classes/AccountId.md)
2424
- [AccountStorage](classes/AccountStorage.md)
25+
- [AccountStorageDelta](classes/AccountStorageDelta.md)
2526
- [AccountStorageMode](classes/AccountStorageMode.md)
2627
- [AccountStorageRequirements](classes/AccountStorageRequirements.md)
28+
- [AccountVaultDelta](classes/AccountVaultDelta.md)
2729
- [AdviceInputs](classes/AdviceInputs.md)
2830
- [AdviceMap](classes/AdviceMap.md)
2931
- [Assembler](classes/Assembler.md)
@@ -38,6 +40,8 @@
3840
- [FlattenedU8Vec](classes/FlattenedU8Vec.md)
3941
- [ForeignAccount](classes/ForeignAccount.md)
4042
- [FungibleAsset](classes/FungibleAsset.md)
43+
- [FungibleAssetDelta](classes/FungibleAssetDelta.md)
44+
- [FungibleAssetDeltaItem](classes/FungibleAssetDeltaItem.md)
4145
- [InputNote](classes/InputNote.md)
4246
- [InputNoteRecord](classes/InputNoteRecord.md)
4347
- [InputNotes](classes/InputNotes.md)

docs/src/web-client/api/classes/AccountDelta.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,23 @@
3535
#### Returns
3636

3737
[`Felt`](Felt.md)
38+
39+
***
40+
41+
### storage()
42+
43+
> **storage**(): [`AccountStorageDelta`](AccountStorageDelta.md)
44+
45+
#### Returns
46+
47+
[`AccountStorageDelta`](AccountStorageDelta.md)
48+
49+
***
50+
51+
### vault()
52+
53+
> **vault**(): [`AccountVaultDelta`](AccountVaultDelta.md)
54+
55+
#### Returns
56+
57+
[`AccountVaultDelta`](AccountVaultDelta.md)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[**@demox-labs/miden-sdk**](../README.md)
2+
3+
***
4+
5+
[@demox-labs/miden-sdk](../README.md) / AccountStorageDelta
6+
7+
# Class: AccountStorageDelta
8+
9+
## Methods
10+
11+
### free()
12+
13+
> **free**(): `void`
14+
15+
#### Returns
16+
17+
`void`
18+
19+
***
20+
21+
### isEmpty()
22+
23+
> **isEmpty**(): `boolean`
24+
25+
#### Returns
26+
27+
`boolean`
28+
29+
***
30+
31+
### values()
32+
33+
> **values**(): [`Word`](Word.md)[]
34+
35+
#### Returns
36+
37+
[`Word`](Word.md)[]

0 commit comments

Comments
 (0)