Skip to content

Commit 87a8d43

Browse files
committed
fix tari address
1 parent d292cec commit 87a8d43

File tree

2 files changed

+22
-10
lines changed
  • base_layer

2 files changed

+22
-10
lines changed

โ€Žbase_layer/common_types/src/tari_address/mod.rsโ€Ž

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,6 @@ impl TariAddress {
259259

260260
/// helper function to convert emojis to u8
261261
fn emoji_to_bytes(emoji: &str) -> Result<Vec<u8>, TariAddressError> {
262-
// The string must be the correct size, including the checksum
263-
if !(emoji.chars().count() == TARI_ADDRESS_INTERNAL_SINGLE_SIZE ||
264-
emoji.chars().count() == TARI_ADDRESS_INTERNAL_DUAL_SIZE)
265-
{
266-
return Err(TariAddressError::InvalidSize);
267-
}
268262
if emoji.chars().count() == TARI_ADDRESS_INTERNAL_SINGLE_SIZE {
269263
SingleAddress::emoji_to_bytes(emoji)
270264
} else {

โ€Žbase_layer/wallet_ffi/src/lib.rsโ€Ž

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,13 +1968,14 @@ pub unsafe extern "C" fn emoji_id_to_tari_address(
19681968
return ptr::null_mut();
19691969
}
19701970

1971-
match CStr::from_ptr(emoji)
1971+
let cstring = CStr::from_ptr(emoji)
19721972
.to_str()
19731973
.map_err(|_| TariAddressError::InvalidEmoji)
1974-
.and_then(TariAddress::from_emoji_string)
1975-
{
1974+
.unwrap();
1975+
match TariAddress::from_emoji_string(cstring) {
19761976
Ok(address) => Box::into_raw(Box::new(address)),
1977-
Err(_) => {
1977+
Err(e) => {
1978+
dbg!(e);
19781979
*error_out = LibWalletError::from(InterfaceError::InvalidEmojiId).code;
19791980
ptr::null_mut()
19801981
},
@@ -10924,6 +10925,23 @@ mod test {
1092410925
}
1092510926
}
1092610927

10928+
#[test]
10929+
fn test_emoji_string() {
10930+
unsafe {
10931+
let mut error = 0;
10932+
let error_ptr = &mut error as *mut c_int;
10933+
let emoji_string = "๐Ÿข๐Ÿ‹๐Ÿฆ๐Ÿ’ค๐Ÿฃ๐Ÿ‘ฃ๐Ÿ“ฑ๐Ÿšœ๐Ÿ๐Ÿ‰๐ŸŽบ๐ŸฅŠ๐Ÿ“–๐Ÿ”ฆ๐Ÿ˜ท๐Ÿ‘พ๐Ÿบ๐Ÿฌ๐Ÿ‘—๐Ÿ”ฑ๐ŸŒป๐Ÿ’๐ŸŽข๐ŸŽช๐Ÿ›ต๐Ÿ‹๐ŸŠ๐Ÿ‘ž๐Ÿฅ๐Ÿ๐ŸŒธ๐Ÿ“ท๐Ÿ”ง๐ŸŽญ๐Ÿฎโฐ๐Ÿ‡๐Ÿ’ฏ๐Ÿ›๐ŸŒด๐Ÿ’จ๐Ÿ”Œ๐Ÿช๐Ÿ“Ÿ๐ŸŽฒ๐Ÿ๐Ÿคข๐ŸŽ‰๐Ÿ”‘๐ŸŒต๐Ÿš’๐Ÿ™๐Ÿ˜๐Ÿ๐Ÿ‘๐Ÿœ๐Ÿ‘‚๐Ÿงฉโฐ๐ŸŽ€๐Ÿš€๐Ÿต๐Ÿ‘‘๐Ÿ’๐ŸŽฎ๐ŸŽฎ๐ŸŽฃ๐ŸŽ’๐Ÿฌ๐Ÿณ๐Ÿธ๐Ÿท๐Ÿถ๐Ÿฏ๐Ÿต๐Ÿฅ„๐Ÿญ๐Ÿฅ๐Ÿ’ฃ";
10934+
10935+
let _tari_address = TariAddress::from_emoji_string(emoji_string).unwrap();
10936+
10937+
let cstring = CString::new(emoji_string).unwrap();
10938+
let cstring_ptr: *const c_char = CString::into_raw(cstring) as *const c_char;
10939+
10940+
let _result = emoji_id_to_tari_address(cstring_ptr, error_ptr);
10941+
assert_eq!(*error_ptr, 0, "No error expected");
10942+
}
10943+
}
10944+
1092710945
#[test]
1092810946
fn test_emoji_convert() {
1092910947
unsafe {

0 commit comments

Comments
ย (0)
โšก