Skip to content

Commit 0179dd4

Browse files
more work
1 parent b1ebc57 commit 0179dd4

File tree

13 files changed

+290
-351
lines changed

13 files changed

+290
-351
lines changed

Cargo.lock

Lines changed: 42 additions & 247 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rs-dapi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ prometheus = "0.14"
8585
once_cell = "1.19"
8686

8787
# Dash Core RPC client
88-
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "e44b1fb2086ad57c8884995f9f93f14de91bf964" }
89-
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "e44b1fb2086ad57c8884995f9f93f14de91bf964" }
88+
dashcore-rpc = { path = "../../../rust-dashcore/rpc-client" }
89+
dash-spv = { path = "../../../rust-dashcore/dash-spv" }
9090

9191
rs-dash-event-bus = { path = "../rs-dash-event-bus" }
9292

packages/rs-platform-wallet/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Platform wallet with identity management support"
99
[dependencies]
1010
# Dash Platform packages
1111
dpp = { path = "../rs-dpp" }
12-
dash-sdk = { path = "../rs-sdk", optional = true }
12+
dash-sdk = { path = "../rs-sdk", default-features = false, features = ["dashpay-contract", "dpns-contract"] }
1313
platform-encryption = { path = "../rs-platform-encryption" }
1414

1515
# Key wallet dependencies (from rust-dashcore)
@@ -22,6 +22,7 @@ dashcore = { path = "../../../rust-dashcore/dash" }
2222
# Standard dependencies
2323
serde = { version = "1.0", features = ["derive"] }
2424
thiserror = "1.0"
25+
async-trait = "0.1"
2526

2627
# Collections
2728
indexmap = "2.0"
@@ -31,8 +32,7 @@ rand = "0.8"
3132

3233

3334
[features]
34-
default = ["bls", "eddsa", "manager", "sdk"]
35+
default = ["bls", "eddsa", "manager"]
3536
bls = ["key-wallet/bls"]
3637
eddsa = ["key-wallet/eddsa"]
3738
manager = ["key-wallet-manager"]
38-
sdk = ["dep:dash-sdk"]

packages/rs-platform-wallet/src/established_contact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module provides the `EstablishedContact` struct representing a bidirectional
44
//! relationship (friendship) between two identities where both have sent contact requests.
55
6-
use crate::ContactRequest;
6+
#[allow(unused_imports)] use crate::ContactRequest;
77
use dpp::prelude::Identifier;
88

99
/// An established contact represents a bidirectional relationship between two identities

packages/rs-platform-wallet/src/identity_manager/initializers.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ impl IdentityManager {
1414
}
1515

1616
/// Create a new identity manager with an SDK instance
17-
#[cfg(feature = "sdk")]
1817
pub fn new_with_sdk(sdk: std::sync::Arc<dash_sdk::Sdk>) -> Self {
1918
Self {
2019
identities: indexmap::IndexMap::new(),
@@ -24,13 +23,11 @@ impl IdentityManager {
2423
}
2524

2625
/// Set the SDK instance
27-
#[cfg(feature = "sdk")]
2826
pub fn set_sdk(&mut self, sdk: std::sync::Arc<dash_sdk::Sdk>) {
2927
self.sdk = Some(sdk);
3028
}
3129

3230
/// Get a reference to the SDK instance
33-
#[cfg(feature = "sdk")]
3431
pub fn sdk(&self) -> Option<&std::sync::Arc<dash_sdk::Sdk>> {
3532
self.sdk.as_ref()
3633
}

packages/rs-platform-wallet/src/identity_manager/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::managed_identity::ManagedIdentity;
77
use dpp::prelude::Identifier;
88
use indexmap::IndexMap;
99

10-
#[cfg(feature = "sdk")]
1110
use std::sync::Arc;
1211

1312
// Import implementation modules
@@ -24,7 +23,6 @@ pub struct IdentityManager {
2423
pub primary_identity_id: Option<Identifier>,
2524

2625
/// SDK instance for platform operations (optional, available with 'sdk' feature)
27-
#[cfg(feature = "sdk")]
2826
pub sdk: Option<Arc<dash_sdk::Sdk>>,
2927
}
3028

@@ -33,7 +31,6 @@ impl Default for IdentityManager {
3331
Self {
3432
identities: IndexMap::new(),
3533
primary_identity_id: None,
36-
#[cfg(feature = "sdk")]
3734
sdk: None,
3835
}
3936
}

packages/rs-platform-wallet/src/platform_wallet_info/contact_requests.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ use key_wallet::wallet::managed_wallet_info::ManagedAccountOperations;
1919
use key_wallet::Network;
2020
use key_wallet::Wallet;
2121

22-
#[cfg(feature = "sdk")]
2322
use dpp::document::DocumentV0Getters;
24-
#[cfg(feature = "sdk")]
2523
use dpp::identity::signer::Signer;
26-
#[cfg(feature = "sdk")]
2724
use dpp::identity::IdentityPublicKey;
2825

2926
impl PlatformWalletInfo {
@@ -323,7 +320,6 @@ impl PlatformWalletInfo {
323320
/// # Returns
324321
///
325322
/// Returns the document ID and recipient ID on success
326-
#[cfg(feature = "sdk")]
327323
pub async fn send_contact_request<S, F, Fut, G, Gut>(
328324
&mut self,
329325
wallet: &mut Wallet,

packages/rs-platform-wallet/src/platform_wallet_info/matured_transactions.rs

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Processing matured transactions for identity registration detection
1+
//! Processing asset lock transactions for identity registration detection
22
//!
33
//! This module handles the detection and fetching of identities created from
4-
//! matured asset lock transactions.
4+
//! asset lock transactions.
55
66
use super::PlatformWalletInfo;
77
use crate::error::PlatformWalletError;
@@ -10,34 +10,79 @@ use dpp::prelude::Identifier;
1010
use key_wallet::wallet::immature_transaction::ImmatureTransaction;
1111
use key_wallet::Network;
1212

13-
#[cfg(feature = "sdk")]
14-
use crate::ContactRequest;
13+
#[allow(unused_imports)] use crate::ContactRequest;
1514

16-
#[cfg(feature = "sdk")]
1715
use dpp::identity::accessors::IdentityGettersV0;
1816

1917
impl PlatformWalletInfo {
20-
/// Discover identities and fetch contact requests after matured asset locks
18+
/// Discover identity and fetch contact requests for a single asset lock transaction
2119
///
22-
/// When asset lock transactions mature, identities may have been registered.
20+
/// This is called automatically when an asset lock transaction is detected.
21+
///
22+
/// # Arguments
23+
///
24+
/// * `wallet` - The wallet to derive authentication keys from
25+
/// * `network` - The network to operate on
26+
/// * `tx` - The asset lock transaction
27+
///
28+
/// # Returns
29+
///
30+
/// Returns Ok(Some(identity_id)) if found, Ok(None) if not found
31+
pub async fn fetch_identity_and_contacts_for_asset_lock(
32+
&mut self,
33+
wallet: &key_wallet::Wallet,
34+
network: Network,
35+
tx: &dashcore::Transaction,
36+
) -> Result<Option<Identifier>, PlatformWalletError> {
37+
use dashcore::hashes::Hash;
38+
use key_wallet::wallet::immature_transaction::AffectedAccounts;
39+
40+
// Create an ImmatureTransaction wrapper
41+
// Note: For asset locks detected in check_transaction, we don't have full block info yet
42+
// We use placeholder values for height/block_hash since we only need the transaction
43+
// for identity discovery
44+
let immature_tx = ImmatureTransaction {
45+
transaction: tx.clone(),
46+
txid: tx.txid(),
47+
height: 0, // Placeholder - not used for identity discovery
48+
block_hash: dashcore::BlockHash::all_zeros(),
49+
timestamp: std::time::SystemTime::now()
50+
.duration_since(std::time::UNIX_EPOCH)
51+
.unwrap_or_default()
52+
.as_secs(),
53+
maturity_confirmations: 0,
54+
affected_accounts: AffectedAccounts::new(),
55+
total_received: 0,
56+
is_coinbase: false,
57+
};
58+
59+
let result = self
60+
.fetch_contact_requests_for_identities_after_asset_locks(wallet, network, &[immature_tx])
61+
.await?;
62+
63+
Ok(result.first().copied())
64+
}
65+
66+
/// Discover identities and fetch contact requests after asset locks
67+
///
68+
/// When asset lock transactions are seen (added as immature), identities may have been registered.
2369
/// This searches for the first identity key to discover newly registered identities
2470
/// and fetches their DashPay contact requests.
2571
///
2672
/// # Arguments
2773
///
2874
/// * `wallet` - The wallet to derive authentication keys from
2975
/// * `network` - The network to operate on
30-
/// * `matured_transactions` - List of matured transactions from process_matured_transactions
76+
/// * `asset_lock_transactions` - List of asset lock transactions from pending_asset_locks
3177
///
3278
/// # Returns
3379
///
3480
/// Returns a list of identity IDs for which contact requests were fetched
35-
#[cfg(feature = "sdk")]
36-
pub async fn fetch_contact_requests_for_identities_after_matured_asset_locks(
81+
pub async fn fetch_contact_requests_for_identities_after_asset_locks(
3782
&mut self,
3883
wallet: &key_wallet::Wallet,
3984
network: Network,
40-
matured_transactions: &[ImmatureTransaction],
85+
asset_lock_transactions: &[ImmatureTransaction],
4186
) -> Result<Vec<Identifier>, PlatformWalletError> {
4287
use dash_sdk::platform::types::identity::PublicKeyHash;
4388
use dash_sdk::platform::Fetch;
@@ -46,14 +91,7 @@ impl PlatformWalletInfo {
4691
let mut identities_processed = Vec::new();
4792

4893
// Early return if no asset lock transactions
49-
let has_asset_locks = matured_transactions.iter().any(|tx| {
50-
matches!(
51-
&tx.transaction.special_transaction_payload,
52-
Some(TransactionPayload::AssetLockPayloadType(_))
53-
)
54-
});
55-
56-
if !has_asset_locks {
94+
if asset_lock_transactions.is_empty() {
5795
return Ok(identities_processed);
5896
}
5997

@@ -197,7 +235,6 @@ impl PlatformWalletInfo {
197235
}
198236

199237
/// Parse a contact request document into a ContactRequest struct
200-
#[cfg(feature = "sdk")]
201238
fn parse_contact_request_document(
202239
doc: &dpp::document::Document,
203240
) -> Result<ContactRequest, PlatformWalletError> {
@@ -283,16 +320,4 @@ fn parse_contact_request_document(
283320
created_at_core_block_height,
284321
created_at,
285322
))
286-
}
287-
288-
#[cfg(test)]
289-
mod tests {
290-
use super::*;
291-
292-
#[test]
293-
fn test_parse_contact_request_document_basic() {
294-
// This is a basic compilation test
295-
// Full testing would require creating mock Document instances
296-
assert!(true);
297-
}
298-
}
323+
}

packages/rs-platform-wallet/src/platform_wallet_info/wallet_info_interface.rs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,38 +110,12 @@ impl WalletInfoInterface for PlatformWalletInfo {
110110
network: Network,
111111
current_height: u32,
112112
) -> Vec<ImmatureTransaction> {
113-
let matured = self
114-
.wallet_info
115-
.process_matured_transactions(network, current_height);
116-
117-
// Process each matured transaction to check for identity registrations
118-
#[cfg(feature = "sdk")]
119-
{
120-
use dashcore::transaction::special_transaction::TransactionPayload;
121-
122-
for immature_tx in &matured {
123-
// Check if this is an asset lock transaction (identity registration)
124-
if let Some(TransactionPayload::AssetLockPayloadType(_asset_lock)) =
125-
&immature_tx.transaction.special_transaction_payload
126-
{
127-
// This is an asset lock transaction - we need to find the identity
128-
// The identity would have been registered using credits from this asset lock
129-
// We'll need to query the platform for identities created from this transaction
130-
131-
// Note: This is a synchronous context, so we can't make async SDK calls here
132-
// The actual fetching will need to be done by the caller after this returns
133-
// by calling a separate method to fetch identities for matured asset locks
134-
135-
// For now, we just detect it and log (or mark it for processing)
136-
// The caller should call fetch_identities_for_asset_lock() after this
137-
}
138-
}
139-
}
140-
141-
matured
113+
self.wallet_info
114+
.process_matured_transactions(network, current_height)
142115
}
143116

144117
fn add_immature_transaction(&mut self, network: Network, tx: ImmatureTransaction) {
118+
// Delegate to the underlying wallet_info
145119
self.wallet_info.add_immature_transaction(network, tx)
146120
}
147121

@@ -173,4 +147,9 @@ impl WalletInfoInterface for PlatformWalletInfo {
173147
current_block_height,
174148
)
175149
}
150+
151+
fn update_chain_height(&mut self, network: Network, current_height: u32) {
152+
// Delegate to the underlying wallet_info
153+
self.wallet_info.update_chain_height(network, current_height)
154+
}
176155
}
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
use crate::platform_wallet_info::PlatformWalletInfo;
2+
use async_trait::async_trait;
23
use dashcore::{Network, Transaction};
34
use key_wallet::transaction_checking::{
45
TransactionCheckResult, TransactionContext, WalletTransactionChecker,
56
};
67
use key_wallet::Wallet;
78

8-
/// Implement WalletTransactionChecker by delegating to ManagedWalletInfo
9+
/// Implement WalletTransactionChecker for PlatformWalletInfo
10+
#[async_trait]
911
impl WalletTransactionChecker for PlatformWalletInfo {
10-
fn check_transaction(
12+
async fn check_transaction(
1113
&mut self,
1214
tx: &Transaction,
1315
network: Network,
1416
context: TransactionContext,
15-
update_state_with_wallet_if_found: Option<&Wallet>,
17+
wallet: &mut Wallet,
18+
update_state: bool,
1619
) -> TransactionCheckResult {
17-
// Delegate to the underlying wallet info
18-
self.wallet_info
19-
.check_transaction(tx, network, context, update_state_with_wallet_if_found)
20+
// Check transaction with underlying wallet info
21+
let result = self
22+
.wallet_info
23+
.check_transaction(tx, network, context, wallet, update_state)
24+
.await;
25+
26+
// If the transaction is relevant, and it's an asset lock, automatically fetch identities
27+
if result.is_relevant {
28+
use dashcore::transaction::special_transaction::TransactionPayload;
29+
30+
if matches!(
31+
&tx.special_transaction_payload,
32+
Some(TransactionPayload::AssetLockPayloadType(_))
33+
) {
34+
// Check if we have an SDK configured for this network
35+
if let Some(identity_manager) = self.identity_managers.get(&network) {
36+
if identity_manager.sdk.is_some() {
37+
// Call the identity fetching logic
38+
if let Err(e) = self
39+
.fetch_identity_and_contacts_for_asset_lock(wallet, network, tx)
40+
.await
41+
{
42+
eprintln!("Failed to fetch identity for asset lock: {}", e);
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
result
2050
}
2151
}

0 commit comments

Comments
 (0)