@@ -464,19 +464,57 @@ pub unsafe extern "C" fn wallet_free_const(wallet: *const FFIWallet) {
464464/// The caller must ensure that:
465465/// - The wallet pointer is either null or points to a valid FFIWallet
466466/// - The FFIWallet remains valid for the duration of this call
467+ ///
468+ /// # Note
469+ ///
470+ /// This function does NOT support the following account types:
471+ /// - `PlatformPayment`: Use `wallet_add_platform_payment_account()` instead
472+ /// - `DashpayReceivingFunds`: Use `wallet_add_dashpay_receiving_account()` instead
473+ /// - `DashpayExternalAccount`: Use `wallet_add_dashpay_external_account_with_xpub_bytes()` instead
467474#[ no_mangle]
468475pub unsafe extern "C" fn wallet_add_account (
469476 wallet : * mut FFIWallet ,
470477 account_type : crate :: types:: FFIAccountType ,
471478 account_index : c_uint ,
472479) -> crate :: types:: FFIAccountResult {
480+ use crate :: types:: FFIAccountType ;
481+
473482 if wallet. is_null ( ) {
474483 return crate :: types:: FFIAccountResult :: error (
475484 FFIErrorCode :: InvalidInput ,
476485 "Wallet is null" . to_string ( ) ,
477486 ) ;
478487 }
479488
489+ // Check for account types that require special handling
490+ match account_type {
491+ FFIAccountType :: PlatformPayment => {
492+ return crate :: types:: FFIAccountResult :: error (
493+ FFIErrorCode :: InvalidInput ,
494+ "PlatformPayment accounts require account and key_class indices. \
495+ Use wallet_add_platform_payment_account() instead."
496+ . to_string ( ) ,
497+ ) ;
498+ }
499+ FFIAccountType :: DashpayReceivingFunds => {
500+ return crate :: types:: FFIAccountResult :: error (
501+ FFIErrorCode :: InvalidInput ,
502+ "DashpayReceivingFunds accounts require identity IDs. \
503+ Use wallet_add_dashpay_receiving_account() instead."
504+ . to_string ( ) ,
505+ ) ;
506+ }
507+ FFIAccountType :: DashpayExternalAccount => {
508+ return crate :: types:: FFIAccountResult :: error (
509+ FFIErrorCode :: InvalidInput ,
510+ "DashpayExternalAccount accounts require identity IDs. \
511+ Use wallet_add_dashpay_external_account_with_xpub_bytes() instead."
512+ . to_string ( ) ,
513+ ) ;
514+ }
515+ _ => { } // Other types are supported
516+ }
517+
480518 let wallet = & mut * wallet;
481519
482520 let account_type_rust = account_type. to_account_type ( account_index) ;
@@ -644,6 +682,13 @@ pub unsafe extern "C" fn wallet_add_dashpay_external_account_with_xpub_bytes(
644682/// - The wallet pointer is either null or points to a valid FFIWallet
645683/// - The xpub_bytes pointer is either null or points to at least xpub_len bytes
646684/// - The FFIWallet remains valid for the duration of this call
685+ ///
686+ /// # Note
687+ ///
688+ /// This function does NOT support the following account types:
689+ /// - `PlatformPayment`: Use `wallet_add_platform_payment_account()` instead
690+ /// - `DashpayReceivingFunds`: Use `wallet_add_dashpay_receiving_account()` instead
691+ /// - `DashpayExternalAccount`: Use `wallet_add_dashpay_external_account_with_xpub_bytes()` instead
647692#[ no_mangle]
648693pub unsafe extern "C" fn wallet_add_account_with_xpub_bytes (
649694 wallet : * mut FFIWallet ,
@@ -652,6 +697,8 @@ pub unsafe extern "C" fn wallet_add_account_with_xpub_bytes(
652697 xpub_bytes : * const u8 ,
653698 xpub_len : usize ,
654699) -> crate :: types:: FFIAccountResult {
700+ use crate :: types:: FFIAccountType ;
701+
655702 if wallet. is_null ( ) {
656703 return crate :: types:: FFIAccountResult :: error (
657704 FFIErrorCode :: InvalidInput ,
@@ -666,6 +713,35 @@ pub unsafe extern "C" fn wallet_add_account_with_xpub_bytes(
666713 ) ;
667714 }
668715
716+ // Check for account types that require special handling
717+ match account_type {
718+ FFIAccountType :: PlatformPayment => {
719+ return crate :: types:: FFIAccountResult :: error (
720+ FFIErrorCode :: InvalidInput ,
721+ "PlatformPayment accounts require account and key_class indices. \
722+ Use wallet_add_platform_payment_account() instead."
723+ . to_string ( ) ,
724+ ) ;
725+ }
726+ FFIAccountType :: DashpayReceivingFunds => {
727+ return crate :: types:: FFIAccountResult :: error (
728+ FFIErrorCode :: InvalidInput ,
729+ "DashpayReceivingFunds accounts require identity IDs. \
730+ Use wallet_add_dashpay_receiving_account() instead."
731+ . to_string ( ) ,
732+ ) ;
733+ }
734+ FFIAccountType :: DashpayExternalAccount => {
735+ return crate :: types:: FFIAccountResult :: error (
736+ FFIErrorCode :: InvalidInput ,
737+ "DashpayExternalAccount accounts require identity IDs. \
738+ Use wallet_add_dashpay_external_account_with_xpub_bytes() instead."
739+ . to_string ( ) ,
740+ ) ;
741+ }
742+ _ => { } // Other types are supported
743+ }
744+
669745 let wallet = & mut * wallet;
670746
671747 use key_wallet:: ExtendedPubKey ;
@@ -730,13 +806,22 @@ pub unsafe extern "C" fn wallet_add_account_with_xpub_bytes(
730806/// - The wallet pointer is either null or points to a valid FFIWallet
731807/// - The xpub_string pointer is either null or points to a valid null-terminated C string
732808/// - The FFIWallet remains valid for the duration of this call
809+ ///
810+ /// # Note
811+ ///
812+ /// This function does NOT support the following account types:
813+ /// - `PlatformPayment`: Use `wallet_add_platform_payment_account()` instead
814+ /// - `DashpayReceivingFunds`: Use `wallet_add_dashpay_receiving_account()` instead
815+ /// - `DashpayExternalAccount`: Use `wallet_add_dashpay_external_account_with_xpub_bytes()` instead
733816#[ no_mangle]
734817pub unsafe extern "C" fn wallet_add_account_with_string_xpub (
735818 wallet : * mut FFIWallet ,
736819 account_type : crate :: types:: FFIAccountType ,
737820 account_index : c_uint ,
738821 xpub_string : * const c_char ,
739822) -> crate :: types:: FFIAccountResult {
823+ use crate :: types:: FFIAccountType ;
824+
740825 if wallet. is_null ( ) {
741826 return crate :: types:: FFIAccountResult :: error (
742827 FFIErrorCode :: InvalidInput ,
@@ -751,6 +836,35 @@ pub unsafe extern "C" fn wallet_add_account_with_string_xpub(
751836 ) ;
752837 }
753838
839+ // Check for account types that require special handling
840+ match account_type {
841+ FFIAccountType :: PlatformPayment => {
842+ return crate :: types:: FFIAccountResult :: error (
843+ FFIErrorCode :: InvalidInput ,
844+ "PlatformPayment accounts require account and key_class indices. \
845+ Use wallet_add_platform_payment_account() instead."
846+ . to_string ( ) ,
847+ ) ;
848+ }
849+ FFIAccountType :: DashpayReceivingFunds => {
850+ return crate :: types:: FFIAccountResult :: error (
851+ FFIErrorCode :: InvalidInput ,
852+ "DashpayReceivingFunds accounts require identity IDs. \
853+ Use wallet_add_dashpay_receiving_account() instead."
854+ . to_string ( ) ,
855+ ) ;
856+ }
857+ FFIAccountType :: DashpayExternalAccount => {
858+ return crate :: types:: FFIAccountResult :: error (
859+ FFIErrorCode :: InvalidInput ,
860+ "DashpayExternalAccount accounts require identity IDs. \
861+ Use wallet_add_dashpay_external_account_with_xpub_bytes() instead."
862+ . to_string ( ) ,
863+ ) ;
864+ }
865+ _ => { } // Other types are supported
866+ }
867+
754868 let wallet = & mut * wallet;
755869
756870 use key_wallet:: ExtendedPubKey ;
@@ -804,3 +918,71 @@ pub unsafe extern "C" fn wallet_add_account_with_string_xpub(
804918 ) ,
805919 }
806920}
921+
922+ /// Add a Platform Payment account (DIP-17) to the wallet
923+ ///
924+ /// Platform Payment accounts use the derivation path:
925+ /// `m/9'/coin_type'/17'/account'/key_class'/index`
926+ ///
927+ /// # Arguments
928+ /// * `wallet` - Pointer to the wallet
929+ /// * `account_index` - The account index (hardened) in the derivation path
930+ /// * `key_class` - The key class (hardened) - typically 0' for main addresses
931+ ///
932+ /// # Safety
933+ ///
934+ /// This function dereferences a raw pointer to FFIWallet.
935+ /// The caller must ensure that:
936+ /// - The wallet pointer is either null or points to a valid FFIWallet
937+ /// - The FFIWallet remains valid for the duration of this call
938+ #[ no_mangle]
939+ pub unsafe extern "C" fn wallet_add_platform_payment_account (
940+ wallet : * mut FFIWallet ,
941+ account_index : c_uint ,
942+ key_class : c_uint ,
943+ ) -> crate :: types:: FFIAccountResult {
944+ use key_wallet:: account:: AccountType ;
945+
946+ if wallet. is_null ( ) {
947+ return crate :: types:: FFIAccountResult :: error (
948+ FFIErrorCode :: InvalidInput ,
949+ "Wallet is null" . to_string ( ) ,
950+ ) ;
951+ }
952+
953+ let wallet = & mut * wallet;
954+
955+ let account_type = AccountType :: PlatformPayment {
956+ account : account_index,
957+ key_class,
958+ } ;
959+
960+ match wallet. inner_mut ( ) {
961+ Some ( w) => {
962+ // Use the proper add_account method
963+ match w. add_account ( account_type, None ) {
964+ Ok ( ( ) ) => {
965+ // Get the account we just added
966+ if let Some ( account) = w. accounts . account_of_type ( account_type) {
967+ let ffi_account = crate :: types:: FFIAccount :: new ( account) ;
968+ return crate :: types:: FFIAccountResult :: success ( Box :: into_raw ( Box :: new (
969+ ffi_account,
970+ ) ) ) ;
971+ }
972+ crate :: types:: FFIAccountResult :: error (
973+ FFIErrorCode :: WalletError ,
974+ "Failed to retrieve account after adding" . to_string ( ) ,
975+ )
976+ }
977+ Err ( e) => crate :: types:: FFIAccountResult :: error (
978+ FFIErrorCode :: WalletError ,
979+ format ! ( "Failed to add platform payment account: {}" , e) ,
980+ ) ,
981+ }
982+ }
983+ None => crate :: types:: FFIAccountResult :: error (
984+ FFIErrorCode :: InvalidState ,
985+ "Cannot modify wallet" . to_string ( ) ,
986+ ) ,
987+ }
988+ }
0 commit comments