@@ -318,7 +318,8 @@ pub struct TariUtxo {
318318 pub lock_height: u64,
319319 pub status: u8,
320320 pub coinbase_extra: *const c_char,
321- pub payment_id: *const c_char,
321+ pub raw_payment_id: *const c_char,
322+ pub user_payment_id: *const c_char,
322323 pub mined_in_block: *const c_char,
323324}
324325
@@ -351,7 +352,10 @@ impl From<DbWalletOutput> for TariUtxo {
351352 coinbase_extra: CString::new(x.wallet_output.features.coinbase_extra.to_hex())
352353 .expect("failed to obtain hex from a commitment")
353354 .into_raw(),
354- payment_id: CString::new(format!("{}", x.payment_id))
355+ raw_payment_id: CString::new(format!("{}", x.payment_id))
356+ .expect("failed to obtain string from a payment id")
357+ .into_raw(),
358+ user_payment_id: CString::new(format!("{}", x.payment_id.user_data_as_string()))
355359 .expect("failed to obtain string from a payment id")
356360 .into_raw(),
357361 mined_in_block: CString::new(x.mined_in_block.unwrap_or_default().to_hex())
@@ -868,7 +872,44 @@ pub unsafe extern "C" fn tari_utxo_get_coinbase_extra(utxo: *const TariUtxo, err
868872 CString::into_raw(result)
869873}
870874
871- /// Get the payment id from a TariUtxo
875+ /// Get the raw payment id from a TariUtxo
876+ ///
877+ /// ## Arguments
878+ /// `utxo` - The pointer to a TariUtxo.
879+ /// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
880+ /// as an out parameter. Returns a null pointer if any pointer argument is null.
881+ ///
882+ /// ## Returns
883+ /// `*mut c_char` - Returns a pointer to a char array (that contains the payment id). Note that it returns empty if
884+ /// there was an error
885+ ///
886+ /// # Safety
887+ /// The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
888+ #[no_mangle]
889+ pub unsafe extern "C" fn tari_utxo_get_raw_payment_id(utxo: *const TariUtxo, error_out: *mut c_int) -> *mut c_char {
890+ if error_out.is_null() {
891+ return ptr::null_mut();
892+ }
893+ *error_out = 0;
894+
895+ let result = CString::new("").expect("Blank CString will not fail.");
896+ if utxo.is_null() {
897+ *error_out = LibWalletError::from(InterfaceError::NullError("utxo".to_string())).code;
898+ return ptr::null_mut();
899+ }
900+
901+ let payment_id_str = match CStr::from_ptr((*utxo).raw_payment_id).to_str() {
902+ Ok(s) => s,
903+ Err(_) => {
904+ *error_out = LibWalletError::from(InterfaceError::PointerError("payment_id".to_string())).code;
905+ return CString::into_raw(result);
906+ },
907+ };
908+ let result = CString::new(payment_id_str).expect("Commitment will not fail.");
909+ CString::into_raw(result)
910+ }
911+
912+ /// Get the user payment id from a TariUtxo
872913///
873914/// ## Arguments
874915/// `utxo` - The pointer to a TariUtxo.
@@ -882,7 +923,7 @@ pub unsafe extern "C" fn tari_utxo_get_coinbase_extra(utxo: *const TariUtxo, err
882923/// # Safety
883924/// The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
884925#[no_mangle]
885- pub unsafe extern "C" fn tari_utxo_get_payment_id (utxo: *const TariUtxo, error_out: *mut c_int) -> *mut c_char {
926+ pub unsafe extern "C" fn tari_utxo_get_user_payment_id (utxo: *const TariUtxo, error_out: *mut c_int) -> *mut c_char {
886927 if error_out.is_null() {
887928 return ptr::null_mut();
888929 }
@@ -894,7 +935,7 @@ pub unsafe extern "C" fn tari_utxo_get_payment_id(utxo: *const TariUtxo, error_o
894935 return ptr::null_mut();
895936 }
896937
897- let payment_id_str = match CStr::from_ptr((*utxo).payment_id ).to_str() {
938+ let payment_id_str = match CStr::from_ptr((*utxo).user_payment_id ).to_str() {
898939 Ok(s) => s,
899940 Err(_) => {
900941 *error_out = LibWalletError::from(InterfaceError::PointerError("payment_id".to_string())).code;
0 commit comments