Skip to content

Commit 788e3ee

Browse files
committed
review and more info from ffi
1 parent 418589b commit 788e3ee

File tree

3 files changed

+243
-12
lines changed

3 files changed

+243
-12
lines changed

applications/minotari_app_grpc/proto/wallet.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ message PaymentRecipient {
10651065
}
10661066
// The type of payment to perform.
10671067
PaymentType payment_type = 5;
1068+
// Reserve the old payment_id tag to prevent future reuse.
1069+
reserved 6;
10681070
// Optional encrypted payment ID for reference (max 256 bytes).
10691071
UserPaymentId user_payment_id = 7;
10701072
}

base_layer/wallet_ffi/src/lib.rs

Lines changed: 218 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4719,7 +4719,7 @@ pub unsafe extern "C" fn completed_transaction_get_mined_in_block(
47194719
CString::into_raw(result)
47204720
}
47214721

4722-
/// Gets the payment ID of a TariCompletedTransaction
4722+
/// Gets the user payment ID of a TariCompletedTransaction in string format
47234723
///
47244724
/// ## Arguments
47254725
/// `transaction` - The pointer to a TariCompletedTransaction
@@ -4733,7 +4733,7 @@ pub unsafe extern "C" fn completed_transaction_get_mined_in_block(
47334733
/// # Safety
47344734
/// The ```string_destroy``` method must be called when finished with string coming from rust to prevent a memory leak
47354735
#[no_mangle]
4736-
pub unsafe extern "C" fn completed_transaction_get_payment_id(
4736+
pub unsafe extern "C" fn completed_transaction_user_get_payment_id(
47374737
transaction: *mut TariCompletedTransaction,
47384738
error_out: *mut c_int,
47394739
) -> *mut c_char {
@@ -4750,14 +4750,84 @@ pub unsafe extern "C" fn completed_transaction_get_payment_id(
47504750
}
47514751
match CString::new(payment_id.user_data_as_string()) {
47524752
Ok(v) => result = v,
4753-
_ => {
4754-
*error_out = LibWalletError::from(InterfaceError::PointerError("payment id".to_string())).code;
4753+
Err(e) => {
4754+
*error_out = LibWalletError::from(InterfaceError::InternalError(e.to_string())).code;
47554755
},
47564756
}
47574757

47584758
result.into_raw()
47594759
}
47604760

4761+
/// Gets the user payment ID of a TariCompletedTransaction as bytes
4762+
///
4763+
/// ## Arguments
4764+
/// `transaction` - The pointer to a TariCompletedTransaction
4765+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
4766+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
4767+
///
4768+
/// ## Returns
4769+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
4770+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
4771+
/// element_count when it is created
4772+
///
4773+
/// # Safety
4774+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
4775+
#[no_mangle]
4776+
pub unsafe extern "C" fn completed_transaction_user_get_payment_id_as_bytes(
4777+
transaction: *mut TariCompletedTransaction,
4778+
error_out: *mut c_int,
4779+
) -> *mut ByteVector {
4780+
if error_out.is_null() {
4781+
return ptr::null_mut();
4782+
}
4783+
*error_out = 0;
4784+
4785+
let payment_id = (*transaction).payment_id.clone();
4786+
if transaction.is_null() {
4787+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
4788+
return ptr::null_mut();
4789+
}
4790+
let mut bytes = ByteVector(Vec::new());
4791+
bytes.0 = payment_id.user_data_as_bytes();
4792+
4793+
Box::into_raw(Box::new(bytes))
4794+
}
4795+
4796+
/// Gets the payment ID of a TariCompletedTransaction as bytes
4797+
///
4798+
/// ## Arguments
4799+
/// `transaction` - The pointer to a TariCompletedTransaction
4800+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
4801+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
4802+
///
4803+
/// ## Returns
4804+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
4805+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
4806+
/// element_count when it is created
4807+
///
4808+
/// # Safety
4809+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
4810+
#[no_mangle]
4811+
pub unsafe extern "C" fn completed_transaction_get_payment_id_as_bytes(
4812+
transaction: *mut TariCompletedTransaction,
4813+
error_out: *mut c_int,
4814+
) -> *mut ByteVector {
4815+
if error_out.is_null() {
4816+
return ptr::null_mut();
4817+
}
4818+
*error_out = 0;
4819+
4820+
let payment_id = (*transaction).payment_id.clone();
4821+
if transaction.is_null() {
4822+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
4823+
return ptr::null_mut();
4824+
}
4825+
let mut bytes = ByteVector(Vec::new());
4826+
bytes.0 = payment_id.to_bytes();
4827+
4828+
Box::into_raw(Box::new(bytes))
4829+
}
4830+
47614831
/// Extract the transaction type from a TariCompletedTransaction
47624832
///
47634833
/// ## Arguments
@@ -5209,14 +5279,84 @@ pub unsafe extern "C" fn pending_outbound_transaction_get_payment_id(
52095279

52105280
match CString::new(payment_id.user_data_as_string()) {
52115281
Ok(v) => result = v,
5212-
_ => {
5213-
*error_out = LibWalletError::from(InterfaceError::PointerError("message".to_string())).code;
5282+
Err(e) => {
5283+
*error_out = LibWalletError::from(InterfaceError::InternalError(e.to_string())).code;
52145284
},
52155285
}
52165286

52175287
result.into_raw()
52185288
}
52195289

5290+
/// Gets the user payment ID of a TariPendingOutboundTransaction as bytes
5291+
///
5292+
/// ## Arguments
5293+
/// `transaction` - The pointer to a TariPendingOutboundTransaction
5294+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
5295+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
5296+
///
5297+
/// ## Returns
5298+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
5299+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
5300+
/// element_count when it is created
5301+
///
5302+
/// # Safety
5303+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
5304+
#[no_mangle]
5305+
pub unsafe extern "C" fn pending_outbound_transaction_user_get_payment_id_as_bytes(
5306+
transaction: *mut TariPendingOutboundTransaction,
5307+
error_out: *mut c_int,
5308+
) -> *mut ByteVector {
5309+
if error_out.is_null() {
5310+
return ptr::null_mut();
5311+
}
5312+
*error_out = 0;
5313+
5314+
let payment_id = (*transaction).payment_id.clone();
5315+
if transaction.is_null() {
5316+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
5317+
return ptr::null_mut();
5318+
}
5319+
let mut bytes = ByteVector(Vec::new());
5320+
bytes.0 = payment_id.user_data_as_bytes();
5321+
5322+
Box::into_raw(Box::new(bytes))
5323+
}
5324+
5325+
/// Gets the payment ID of a TariPendingOutboundTransaction as bytes
5326+
///
5327+
/// ## Arguments
5328+
/// `transaction` - The pointer to a TariPendingOutboundTransaction
5329+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
5330+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
5331+
///
5332+
/// ## Returns
5333+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
5334+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
5335+
/// element_count when it is created
5336+
///
5337+
/// # Safety
5338+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
5339+
#[no_mangle]
5340+
pub unsafe extern "C" fn pending_outbound_transaction_get_payment_id_as_bytes(
5341+
transaction: *mut TariPendingOutboundTransaction,
5342+
error_out: *mut c_int,
5343+
) -> *mut ByteVector {
5344+
if error_out.is_null() {
5345+
return ptr::null_mut();
5346+
}
5347+
*error_out = 0;
5348+
5349+
let payment_id = (*transaction).payment_id.clone();
5350+
if transaction.is_null() {
5351+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
5352+
return ptr::null_mut();
5353+
}
5354+
let mut bytes = ByteVector(Vec::new());
5355+
bytes.0 = payment_id.to_bytes();
5356+
5357+
Box::into_raw(Box::new(bytes))
5358+
}
5359+
52205360
/// Gets the status of a TariPendingOutboundTransaction
52215361
///
52225362
/// ## Arguments
@@ -5427,14 +5567,84 @@ pub unsafe extern "C" fn pending_inbound_transaction_get_payment_id(
54275567

54285568
match CString::new(payment_id.user_data_as_string()) {
54295569
Ok(v) => result = v,
5430-
_ => {
5431-
*error_out = LibWalletError::from(InterfaceError::PointerError("message".to_string())).code;
5570+
Err(e) => {
5571+
*error_out = LibWalletError::from(InterfaceError::InternalError(e.to_string())).code;
54325572
},
54335573
}
54345574

54355575
result.into_raw()
54365576
}
54375577

5578+
/// Gets the user payment ID of a TariPendingInboundTransaction as bytes
5579+
///
5580+
/// ## Arguments
5581+
/// `transaction` - The pointer to a TariPendingInboundTransaction
5582+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
5583+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
5584+
///
5585+
/// ## Returns
5586+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
5587+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
5588+
/// element_count when it is created
5589+
///
5590+
/// # Safety
5591+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
5592+
#[no_mangle]
5593+
pub unsafe extern "C" fn pending_inbound_transaction_user_get_payment_id_as_bytes(
5594+
transaction: *mut TariPendingInboundTransaction,
5595+
error_out: *mut c_int,
5596+
) -> *mut ByteVector {
5597+
if error_out.is_null() {
5598+
return ptr::null_mut();
5599+
}
5600+
*error_out = 0;
5601+
5602+
let payment_id = (*transaction).payment_id.clone();
5603+
if transaction.is_null() {
5604+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
5605+
return ptr::null_mut();
5606+
}
5607+
let mut bytes = ByteVector(Vec::new());
5608+
bytes.0 = payment_id.user_data_as_bytes();
5609+
5610+
Box::into_raw(Box::new(bytes))
5611+
}
5612+
5613+
/// Gets the payment ID of a TariPendingInboundTransaction as bytes
5614+
///
5615+
/// ## Arguments
5616+
/// `transaction` - The pointer to a TariPendingInboundTransaction
5617+
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
5618+
/// as an out parameter. Returns a null pointer if any pointer argument is null.
5619+
///
5620+
/// ## Returns
5621+
/// `*mut ByteVector` - Pointer to the created ByteVector. Note that it will be ptr::null_mut()
5622+
/// if the byte_array pointer was null or if the elements in the byte_vector don't match
5623+
/// element_count when it is created
5624+
///
5625+
/// # Safety
5626+
/// The ```byte_vector_destroy``` function must be called when finished with a ByteVector to prevent a memory leak
5627+
#[no_mangle]
5628+
pub unsafe extern "C" fn pending_inbound_transaction_get_payment_id_as_bytes(
5629+
transaction: *mut TariPendingInboundTransaction,
5630+
error_out: *mut c_int,
5631+
) -> *mut ByteVector {
5632+
if error_out.is_null() {
5633+
return ptr::null_mut();
5634+
}
5635+
*error_out = 0;
5636+
5637+
let payment_id = (*transaction).payment_id.clone();
5638+
if transaction.is_null() {
5639+
*error_out = LibWalletError::from(InterfaceError::NullError("transaction".to_string())).code;
5640+
return ptr::null_mut();
5641+
}
5642+
let mut bytes = ByteVector(Vec::new());
5643+
bytes.0 = payment_id.to_bytes();
5644+
5645+
Box::into_raw(Box::new(bytes))
5646+
}
5647+
54385648
/// Gets the status of a TariPendingInboundTransaction
54395649
///
54405650
/// ## Arguments

base_layer/wallet_ffi/wallet.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ struct TariUtxo {
173173
uint64_t lock_height;
174174
uint8_t status;
175175
const char *coinbase_extra;
176-
const char *payment_id;
176+
const char *raw_payment_id;
177+
const char *user_payment_id;
177178
const char *mined_in_block;
178179
};
179180

@@ -453,7 +454,7 @@ char *tari_utxo_get_coinbase_extra(const struct TariUtxo *utxo,
453454
int *error_out);
454455

455456
/**
456-
* Get the payment id from a TariUtxo
457+
* Get the raw payment id from a TariUtxo
457458
*
458459
* ## Arguments
459460
* `utxo` - The pointer to a TariUtxo.
@@ -467,8 +468,26 @@ char *tari_utxo_get_coinbase_extra(const struct TariUtxo *utxo,
467468
* # Safety
468469
* The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
469470
*/
470-
char *tari_utxo_get_payment_id(const struct TariUtxo *utxo,
471-
int *error_out);
471+
char *tari_utxo_get_raw_payment_id(const struct TariUtxo *utxo,
472+
int *error_out);
473+
474+
/**
475+
* Get the user payment id from a TariUtxo
476+
*
477+
* ## Arguments
478+
* `utxo` - The pointer to a TariUtxo.
479+
* `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
480+
* as an out parameter. Returns a null pointer if any pointer argument is null.
481+
*
482+
* ## Returns
483+
* `*mut c_char` - Returns a pointer to a char array (that contains the payment id). Note that it returns empty if
484+
* there was an error
485+
*
486+
* # Safety
487+
* The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
488+
*/
489+
char *tari_utxo_get_user_payment_id(const struct TariUtxo *utxo,
490+
int *error_out);
472491

473492
/**
474493
* Get the mined in block hash from a TariUtxo

0 commit comments

Comments
 (0)