Skip to content

Commit 1fd5212

Browse files
shumkovclaude
andcommitted
feat: adapt to platform-wallet2 API (WalletManager two-map, event handler trait)
Adapt evo-tool to the new platform-wallet2 API: - WalletManager two-map design (wallet + wallet_info separate maps) - Sub-wallets access state through wallet_manager + wallet_id - SpvEventBridge implements PlatformEventHandler directly (no broadcast channel) - Remove subscribe_events / broadcast run-loop wiring - Remove WalletCreationOptions (use WalletAccountCreationOptions directly) - Remove reset_filter_committed_height usage - Simplify changeset/sqlite (remove wallet sub-changeset) - Update all backend tasks, UI screens, and E2E harness for new API Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4ca8b52 commit 1fd5212

25 files changed

Lines changed: 180 additions & 428 deletions

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend_task/core/mod.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl AppContext {
157157

158158
if let Some(pw) = platform_wallet {
159159
let info = pw.state().await;
160-
let first_addr = crate::platform_wallet_bridge::CoreAddressInfo::all_from_wallet_info(info.managed_state.wallet_info())
160+
let first_addr = crate::platform_wallet_bridge::CoreAddressInfo::all_from_wallet_info(&info.core_wallet)
161161
.into_iter()
162162
.next()
163163
.map(|a| a.address);
@@ -602,19 +602,14 @@ impl AppContext {
602602
let pw = self.require_platform_wallet(&seed_hash)?;
603603

604604
let tx = {
605-
let info_guard =
606-
pw
607-
.try_state()
608-
.ok_or_else(|| TaskError::WalletPaymentFailed {
609-
detail: "Wallet info unavailable".to_string(),
610-
})?;
605+
let info_guard = pw.state().await;
611606
let unsigned = self.build_spv_unsigned_transaction_multi_pw(
612-
info_guard.managed_state.wallet_info(),
613-
info_guard.managed_state.wallet(),
607+
&info_guard.core_wallet,
608+
info_guard.wallet(),
614609
&parsed_recipients,
615610
&request,
616611
)?;
617-
self.sign_spv_transaction_pw(info_guard.managed_state.wallet_info(), info_guard.managed_state.wallet(), unsigned)?
612+
self.sign_spv_transaction_pw(&info_guard.core_wallet, info_guard.wallet(), unsigned)?
618613
};
619614

620615
self.wallet_manager
@@ -725,7 +720,7 @@ impl AppContext {
725720
// Get UTXOs and change address from the wallet account
726721
let (utxos, change_index) = {
727722
let account = managed_info
728-
.accounts()
723+
.accounts
729724
.standard_bip44_accounts
730725
.get(&DEFAULT_BIP44_ACCOUNT_INDEX)
731726
.ok_or_else(|| TaskError::WalletPaymentFailed {
@@ -816,7 +811,7 @@ impl AppContext {
816811
account_index: u32,
817812
current_height: u32,
818813
) -> Result<u64, TaskError> {
819-
let collection = managed_info.accounts();
814+
let collection = &managed_info.accounts;
820815
let account = collection
821816
.standard_bip44_accounts
822817
.get(&account_index)
@@ -854,7 +849,7 @@ impl AppContext {
854849
change_address: &Address,
855850
) -> Result<Transaction, WalletError> {
856851
// Get spendable UTXOs from the managed wallet info
857-
let collection = managed_info.accounts();
852+
let collection = &managed_info.accounts;
858853
let account = collection
859854
.standard_bip44_accounts
860855
.get(&account_index)
@@ -900,7 +895,7 @@ impl AppContext {
900895
wallet: &dash_sdk::dpp::key_wallet::wallet::Wallet,
901896
tx: Transaction,
902897
) -> Result<Transaction, TaskError> {
903-
let accounts = managed_info.accounts();
898+
let accounts = &managed_info.accounts;
904899
let account = accounts
905900
.standard_bip44_accounts
906901
.get(&DEFAULT_BIP44_ACCOUNT_INDEX)

src/backend_task/core/recover_asset_locks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl AppContext {
5050
// Locked wallets (no PlatformWallet) have no addresses — return empty.
5151
let addresses: Vec<Address> = if let Some(pw) = wallet_guard.platform_wallet.as_ref() {
5252
let info = pw.state_blocking();
53-
CoreAddressInfo::all_from_wallet_info(info.managed_state.wallet_info())
53+
CoreAddressInfo::all_from_wallet_info(&info.core_wallet)
5454
.into_iter()
5555
.map(|a| a.address)
5656
.collect()

src/backend_task/core/refresh_wallet_info.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl AppContext {
2929
// Exclude platform payment addresses since those are not tracked by Core.
3030
let addrs = if let Some(pw) = wallet_guard.platform_wallet.as_ref() {
3131
let info = pw.state_blocking();
32-
CoreAddressInfo::all_from_wallet_info(info.managed_state.wallet_info())
32+
CoreAddressInfo::all_from_wallet_info(&info.core_wallet)
3333
.into_iter()
3434
.filter(|a| !a.derivation_path.is_platform_payment(self.network))
3535
.map(|a| a.address)
@@ -283,17 +283,20 @@ impl AppContext {
283283
// current and can serve as the canonical read source.
284284
// Uses try_state_mut() because we are in a blocking context
285285
// (spawn_blocking) where awaiting is not possible.
286-
if let Some(pw) = self.get_platform_wallet(&seed_hash)
287-
&& let Some(mut pw_info) = pw.try_state_mut()
288-
{
289-
pw_info.managed_state.wallet_info_mut().balance = WalletCoreBalance::new(
290-
total_balance, // spendable
291-
0, // unconfirmed
292-
0, // immature
293-
0, // locked
294-
);
295-
// Wallet changes are auto-flushed via FlushStrategy::Immediate
296-
// when queued by the platform wallet.
286+
if let Some(pw) = self.get_platform_wallet(&seed_hash) {
287+
if let Ok(mut wm_guard) = pw.wallet_manager().try_write() {
288+
let wallet_id = pw.wallet_id();
289+
if let Some(info) = wm_guard.get_wallet_info_mut(&wallet_id) {
290+
info.core_wallet.balance = WalletCoreBalance::new(
291+
total_balance, // spendable
292+
0, // unconfirmed
293+
0, // immature
294+
0, // locked
295+
);
296+
}
297+
// Wallet changes are auto-flushed via FlushStrategy::Immediate
298+
// when queued by the platform wallet.
299+
}
297300
}
298301

299302
let warning = if tx_truncated {

src/backend_task/dashpay/contact_requests.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,11 @@ pub async fn send_contact_request_with_proof(
290290
source: Box::new(e),
291291
})?;
292292

293-
// Step 5: Stage a PlatformWalletChangeSet capturing the sent contact request
294-
// and the new DashPay contact account, then persist so the delta is
295-
// durably stored.
296-
//
297-
// `register_contact_account()` (called inside `send_contact_request`)
298-
// creates a DashpayReceivingFunds managed account in memory. Record
299-
// its initial `last_revealed` index so the key-wallet changeset
300-
// reflects the full delta.
301-
let kw_account_cs = dash_sdk::dpp::key_wallet::changeset::AccountChangeSet {
302-
last_revealed: BTreeMap::from([(0u32, 0u32)]),
303-
..Default::default()
304-
};
293+
// Step 5: Stage a PlatformWalletChangeSet capturing the sent contact request.
294+
// TODO: re-wire persistence after changeset migration
295+
// key_wallet::changeset (AccountChangeSet, WalletChangeSet) was removed from dashcore.
296+
// The `wallet` field no longer exists on PlatformWalletChangeSet.
305297
let changeset = PlatformWalletChangeSet {
306-
wallet: Some(dash_sdk::dpp::key_wallet::changeset::WalletChangeSet {
307-
accounts: Some(kw_account_cs),
308-
..Default::default()
309-
}),
310298
contacts: Some(ContactChangeSet {
311299
sent_requests: BTreeMap::from([(
312300
(sender_id, to_identity_id),
@@ -454,24 +442,14 @@ pub async fn accept_contact_request(
454442
source: Box::new(e),
455443
})?;
456444

457-
// Stage a PlatformWalletChangeSet capturing the reciprocal sent request,
458-
// the newly established contact, and the new DashPay contact account.
459-
//
460-
// `register_contact_account()` (called inside `send_contact_request`) creates
461-
// a DashpayReceivingFunds managed account in memory. Record its initial
462-
// `last_revealed` index so the key-wallet changeset reflects the full delta.
445+
// Stage a PlatformWalletChangeSet capturing the reciprocal sent request and the newly established contact.
446+
// TODO: re-wire persistence after changeset migration
447+
// key_wallet::changeset (AccountChangeSet, WalletChangeSet) was removed from dashcore.
448+
// The `wallet` field no longer exists on PlatformWalletChangeSet.
463449
let mut established = BTreeSet::new();
464450
established.insert((our_identity_id, from_identity_id));
465451

466-
let kw_account_cs = dash_sdk::dpp::key_wallet::changeset::AccountChangeSet {
467-
last_revealed: BTreeMap::from([(0u32, 0u32)]),
468-
..Default::default()
469-
};
470452
let changeset = PlatformWalletChangeSet {
471-
wallet: Some(dash_sdk::dpp::key_wallet::changeset::WalletChangeSet {
472-
accounts: Some(kw_account_cs),
473-
..Default::default()
474-
}),
475453
contacts: Some(ContactChangeSet {
476454
sent_requests: BTreeMap::from([(
477455
(our_identity_id, from_identity_id),

src/backend_task/dashpay/incoming_payments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub async fn register_dashpay_addresses_for_identity(
128128

129129
// Acquire the key-wallet read guard for derivation
130130
let info_guard = platform_wallet_arc.state().await;
131-
let key_wallet_guard = info_guard.managed_state.wallet();
131+
let key_wallet_guard = info_guard.wallet();
132132

133133
for contact in contacts {
134134
let contact_id = match Identifier::from_bytes(&contact.contact_identity_id) {

src/backend_task/identity/discover_identities.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl AppContext {
7979
);
8080

8181
// Read back the managed identity data from the identity manager.
82-
let manager = identity_wallet.state().await;
82+
let manager = platform_wallet.state().await;
8383

8484
let mut found_count = 0;
8585
for identity in &discovered {
@@ -117,7 +117,7 @@ impl AppContext {
117117
let private_keys_map: std::collections::BTreeMap<_, _> = managed
118118
.key_storage
119119
.iter()
120-
.map(|(key_id, (pub_key, pk_data))| {
120+
.map(|(key_id, (pub_key, pk_data)): (&dash_sdk::dpp::identity::KeyID, &(dash_sdk::dpp::identity::IdentityPublicKey, platform_wallet::PrivateKeyData))| {
121121
let (evo_pk_data, wallet_path) = match pk_data {
122122
platform_wallet::PrivateKeyData::AtWalletDerivationPath {
123123
wallet_seed_hash,
@@ -135,10 +135,7 @@ impl AppContext {
135135
)
136136
}
137137
platform_wallet::PrivateKeyData::Clear(key_bytes) => {
138-
{
139-
let bytes: &[u8; 32] = key_bytes;
140-
(PrivateKeyData::Clear(*bytes), None)
141-
}
138+
(PrivateKeyData::Clear(**key_bytes), None)
142139
}
143140
};
144141

src/backend_task/identity/load_identity_from_wallet.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl AppContext {
8181
let identity_id = identity.id();
8282

8383
// Read the enriched ManagedIdentity from the identity manager.
84-
let manager = identity_wallet.state().await;
84+
let manager = platform_wallet.state().await;
8585
let managed = manager.identity_manager.managed_identity(&identity_id).ok_or_else(|| {
8686
TaskError::WalletIdentityNotFound {
8787
identity_index,
@@ -93,7 +93,7 @@ impl AppContext {
9393
let private_keys_map: BTreeMap<_, _> = managed
9494
.key_storage
9595
.iter()
96-
.map(|(key_id, (pub_key, pk_data))| {
96+
.map(|(key_id, (pub_key, pk_data)): (&dash_sdk::dpp::identity::KeyID, &(dash_sdk::dpp::identity::IdentityPublicKey, platform_wallet::PrivateKeyData))| {
9797
let (evo_pk_data, wallet_path) = match pk_data {
9898
platform_wallet::PrivateKeyData::AtWalletDerivationPath {
9999
wallet_seed_hash,
@@ -109,8 +109,7 @@ impl AppContext {
109109
)
110110
}
111111
platform_wallet::PrivateKeyData::Clear(key_bytes) => {
112-
let bytes: &[u8; 32] = key_bytes;
113-
(PrivateKeyData::Clear(*bytes), None)
112+
(PrivateKeyData::Clear(**key_bytes), None)
114113
}
115114
};
116115

src/backend_task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl AppContext {
550550
WalletTask::LoadAddressInfo { seed_hash } => {
551551
let platform_wallet = self.require_platform_wallet(&seed_hash)?;
552552
let wallet_info = platform_wallet.state().await;
553-
let info = CoreAddressInfo::all_from_wallet_info(wallet_info.managed_state.wallet_info());
553+
let info = CoreAddressInfo::all_from_wallet_info(&wallet_info.core_wallet);
554554
Ok(BackendTaskSuccessResult::AddressInfo(info))
555555
}
556556
}

src/backend_task/wallet/generate_receive_address.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ impl AppContext {
2929

3030
// Register the address in DET's address table so it shows in the UI.
3131
// Read derivation path from the ManagedWalletInfo accounts.
32-
if let Some(wallet_info) = platform_wallet.try_state() {
33-
for acc in wallet_info.managed_state.wallet_info().accounts.all_accounts() {
32+
{
33+
let wallet_info = platform_wallet.state().await;
34+
for acc in wallet_info.core_wallet.accounts.all_accounts() {
3435
if let Some(ai) = acc.get_address_info(&address) {
3536
let _ = self.register_spv_address(
3637
&wallet_arc,

0 commit comments

Comments
 (0)