Skip to content

Commit

Permalink
Merge pull request #50 from dashpay/fix/null-address-check
Browse files Browse the repository at this point in the history
fix: Crash while sending tx
  • Loading branch information
pankcuf authored Sep 12, 2023
2 parents d48063b + b49e684 commit 12d5a12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dash-spv-apple-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dash_spv_apple_bindings"
version = "0.4.10"
version = "0.4.11"
description = "C-bindings for using and interoperating with Dash SPV"
readme = "README.md"
edition = "2021"
Expand Down
24 changes: 16 additions & 8 deletions dash-spv-masternode-processor/src/bindings/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@ pub extern "C" fn address_from_hash160(hash: *const u8, chain_type: ChainType) -
/// # Safety
#[no_mangle]
pub extern "C" fn address_with_script_pubkey(script: *const u8, script_len: usize, chain_type: ChainType) -> *mut c_char {
let script = unsafe { slice::from_raw_parts(script, script_len) };
let script_map = chain_type.script_map();
address::with_script_pub_key(&script.to_vec(), &script_map)
.to_c_string_ptr()
if script.is_null() {
std::ptr::null_mut()
} else {
let script = unsafe { slice::from_raw_parts(script, script_len) };
let script_map = chain_type.script_map();
address::with_script_pub_key(&script.to_vec(), &script_map)
.to_c_string_ptr()
}
}

/// # Safety
#[no_mangle]
pub extern "C" fn address_with_script_sig(script: *const u8, script_len: usize, chain_type: ChainType) -> *mut c_char {
let script = unsafe { slice::from_raw_parts(script, script_len) };
let script_map = chain_type.script_map();
address::with_script_sig(&script.to_vec(), &script_map)
.to_c_string_ptr()
if script.is_null() {
std::ptr::null_mut()
} else {
let script = unsafe { slice::from_raw_parts(script, script_len) };
let script_map = chain_type.script_map();
address::with_script_sig(&script.to_vec(), &script_map)
.to_c_string_ptr()
}
}

/// # Safety
Expand Down

0 comments on commit 12d5a12

Please sign in to comment.