|
4 | 4 |
|
5 | 5 | use crate::bip32::{ChildNumber, DerivationPath}; |
6 | 6 | use crate::dip9::DerivationPathReference; |
7 | | -use crate::transaction_checking::transaction_router::AccountTypeToCheck; |
| 7 | +use crate::transaction_checking::transaction_router::{ |
| 8 | + AccountTypeToCheck, PlatformAccountConversionError, |
| 9 | +}; |
8 | 10 | use crate::Network; |
9 | 11 | #[cfg(feature = "bincode")] |
10 | 12 | use bincode_derive::{Decode, Encode}; |
@@ -94,40 +96,45 @@ pub enum AccountType { |
94 | 96 | }, |
95 | 97 | } |
96 | 98 |
|
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> { |
99 | 103 | match value { |
100 | 104 | AccountType::Standard { |
101 | 105 | standard_account_type, |
102 | 106 | .. |
103 | 107 | } => 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), |
106 | 110 | }, |
107 | 111 | AccountType::CoinJoin { |
108 | 112 | .. |
109 | | - } => AccountTypeToCheck::CoinJoin, |
110 | | - AccountType::IdentityRegistration => AccountTypeToCheck::IdentityRegistration, |
| 113 | + } => Ok(AccountTypeToCheck::CoinJoin), |
| 114 | + AccountType::IdentityRegistration => Ok(AccountTypeToCheck::IdentityRegistration), |
111 | 115 | AccountType::IdentityTopUp { |
112 | 116 | .. |
113 | | - } => AccountTypeToCheck::IdentityTopUp, |
| 117 | + } => Ok(AccountTypeToCheck::IdentityTopUp), |
114 | 118 | AccountType::IdentityTopUpNotBoundToIdentity => { |
115 | | - AccountTypeToCheck::IdentityTopUpNotBound |
| 119 | + Ok(AccountTypeToCheck::IdentityTopUpNotBound) |
116 | 120 | } |
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), |
122 | 126 | AccountType::DashpayReceivingFunds { |
123 | 127 | .. |
124 | | - } => AccountTypeToCheck::DashpayReceivingFunds, |
| 128 | + } => Ok(AccountTypeToCheck::DashpayReceivingFunds), |
125 | 129 | AccountType::DashpayExternalAccount { |
126 | 130 | .. |
127 | | - } => AccountTypeToCheck::DashpayExternalAccount, |
| 131 | + } => Ok(AccountTypeToCheck::DashpayExternalAccount), |
128 | 132 | AccountType::PlatformPayment { |
129 | 133 | .. |
130 | | - } => AccountTypeToCheck::PlatformPayment, |
| 134 | + } => { |
| 135 | + // Platform Payment accounts (DIP-17) operate on Dash Platform, not Core chain. |
| 136 | + Err(PlatformAccountConversionError) |
| 137 | + } |
131 | 138 | } |
132 | 139 | } |
133 | 140 | } |
|
0 commit comments