Skip to content

Commit 190bf44

Browse files
feat(key-wallet): add platform accounts and core tx split
1 parent 8a3e0ba commit 190bf44

File tree

21 files changed

+1790
-359
lines changed

21 files changed

+1790
-359
lines changed

key-wallet-manager/src/wallet_manager/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use key_wallet::wallet::managed_wallet_info::{ManagedWalletInfo, TransactionReco
2222
use key_wallet::wallet::WalletType;
2323
use key_wallet::Utxo;
2424
use key_wallet::{Account, AccountType, Address, ExtendedPrivKey, Mnemonic, Network, Wallet};
25-
use key_wallet::{ExtendedPubKey, WalletBalance};
25+
use key_wallet::{ExtendedPubKey, WalletCoreBalance};
2626
use std::collections::BTreeSet;
2727
use std::str::FromStr;
2828
use zeroize::Zeroize;
@@ -483,8 +483,9 @@ impl<T: WalletInfoInterface> WalletManager<T> {
483483
let wallet_info_opt = self.wallet_infos.get_mut(&wallet_id);
484484

485485
if let (Some(wallet), Some(wallet_info)) = (wallet_opt, wallet_info_opt) {
486-
let check_result =
487-
wallet_info.check_transaction(tx, context, wallet, update_state_if_found).await;
486+
let check_result = wallet_info
487+
.check_core_transaction(tx, context, wallet, update_state_if_found)
488+
.await;
488489

489490
// If the transaction is relevant
490491
if check_result.is_relevant {
@@ -904,7 +905,10 @@ impl<T: WalletInfoInterface> WalletManager<T> {
904905
}
905906

906907
/// Get balance for a specific wallet
907-
pub fn get_wallet_balance(&self, wallet_id: &WalletId) -> Result<WalletBalance, WalletError> {
908+
pub fn get_wallet_balance(
909+
&self,
910+
wallet_id: &WalletId,
911+
) -> Result<WalletCoreBalance, WalletError> {
908912
// Get the wallet info
909913
let wallet_info =
910914
self.wallet_infos.get(wallet_id).ok_or(WalletError::WalletNotFound(*wallet_id))?;

key-wallet/src/account/account_type.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
55
use crate::bip32::{ChildNumber, DerivationPath};
66
use crate::dip9::DerivationPathReference;
7-
use crate::transaction_checking::transaction_router::AccountTypeToCheck;
7+
use crate::transaction_checking::transaction_router::{
8+
AccountTypeToCheck, PlatformAccountConversionError,
9+
};
810
use crate::Network;
911
#[cfg(feature = "bincode")]
1012
use bincode_derive::{Decode, Encode};
@@ -94,40 +96,45 @@ pub enum AccountType {
9496
},
9597
}
9698

97-
impl From<AccountType> for AccountTypeToCheck {
98-
fn from(value: AccountType) -> Self {
99+
impl TryFrom<AccountType> for AccountTypeToCheck {
100+
type Error = PlatformAccountConversionError;
101+
102+
fn try_from(value: AccountType) -> Result<Self, Self::Error> {
99103
match value {
100104
AccountType::Standard {
101105
standard_account_type,
102106
..
103107
} => match standard_account_type {
104-
StandardAccountType::BIP44Account => AccountTypeToCheck::StandardBIP44,
105-
StandardAccountType::BIP32Account => AccountTypeToCheck::StandardBIP32,
108+
StandardAccountType::BIP44Account => Ok(AccountTypeToCheck::StandardBIP44),
109+
StandardAccountType::BIP32Account => Ok(AccountTypeToCheck::StandardBIP32),
106110
},
107111
AccountType::CoinJoin {
108112
..
109-
} => AccountTypeToCheck::CoinJoin,
110-
AccountType::IdentityRegistration => AccountTypeToCheck::IdentityRegistration,
113+
} => Ok(AccountTypeToCheck::CoinJoin),
114+
AccountType::IdentityRegistration => Ok(AccountTypeToCheck::IdentityRegistration),
111115
AccountType::IdentityTopUp {
112116
..
113-
} => AccountTypeToCheck::IdentityTopUp,
117+
} => Ok(AccountTypeToCheck::IdentityTopUp),
114118
AccountType::IdentityTopUpNotBoundToIdentity => {
115-
AccountTypeToCheck::IdentityTopUpNotBound
119+
Ok(AccountTypeToCheck::IdentityTopUpNotBound)
116120
}
117-
AccountType::IdentityInvitation => AccountTypeToCheck::IdentityInvitation,
118-
AccountType::ProviderVotingKeys => AccountTypeToCheck::ProviderVotingKeys,
119-
AccountType::ProviderOwnerKeys => AccountTypeToCheck::ProviderOwnerKeys,
120-
AccountType::ProviderOperatorKeys => AccountTypeToCheck::ProviderOperatorKeys,
121-
AccountType::ProviderPlatformKeys => AccountTypeToCheck::ProviderPlatformKeys,
121+
AccountType::IdentityInvitation => Ok(AccountTypeToCheck::IdentityInvitation),
122+
AccountType::ProviderVotingKeys => Ok(AccountTypeToCheck::ProviderVotingKeys),
123+
AccountType::ProviderOwnerKeys => Ok(AccountTypeToCheck::ProviderOwnerKeys),
124+
AccountType::ProviderOperatorKeys => Ok(AccountTypeToCheck::ProviderOperatorKeys),
125+
AccountType::ProviderPlatformKeys => Ok(AccountTypeToCheck::ProviderPlatformKeys),
122126
AccountType::DashpayReceivingFunds {
123127
..
124-
} => AccountTypeToCheck::DashpayReceivingFunds,
128+
} => Ok(AccountTypeToCheck::DashpayReceivingFunds),
125129
AccountType::DashpayExternalAccount {
126130
..
127-
} => AccountTypeToCheck::DashpayExternalAccount,
131+
} => Ok(AccountTypeToCheck::DashpayExternalAccount),
128132
AccountType::PlatformPayment {
129133
..
130-
} => AccountTypeToCheck::PlatformPayment,
134+
} => {
135+
// Platform Payment accounts (DIP-17) operate on Dash Platform, not Core chain.
136+
Err(PlatformAccountConversionError)
137+
}
131138
}
132139
}
133140
}

key-wallet/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ pub use error::{Error, Result};
6565
pub use gap_limit::{GapLimit, GapLimitManager, GapLimitStage};
6666
pub use managed_account::address_pool::{AddressInfo, AddressPool, KeySource, PoolStats};
6767
pub use managed_account::managed_account_type::ManagedAccountType;
68+
pub use managed_account::managed_platform_account::ManagedPlatformAccount;
69+
pub use managed_account::platform_address::PlatformP2PKHAddress;
6870
pub use mnemonic::Mnemonic;
6971
pub use seed::Seed;
7072
pub use utxo::{Utxo, UtxoSet};
71-
pub use wallet::{balance::WalletBalance, Wallet};
73+
pub use wallet::{balance::WalletCoreBalance, Wallet};
7274

7375
/// Re-export commonly used types
7476
pub mod prelude {

0 commit comments

Comments
 (0)