Skip to content

Commit

Permalink
update FFI
Browse files Browse the repository at this point in the history
update grpc network call
  • Loading branch information
SWvheerden committed Jan 26, 2024
1 parent 69421f5 commit 79b1d82
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions applications/minotari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ message GetNewBlockResult{
// This is the completed block
Block block = 2;
bytes merge_mining_hash =3;
bytes tari_unique_id =4;
}

// This is the message that is returned for a miner after it asks for a new block.
Expand Down
18 changes: 18 additions & 0 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,23 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
))
},
};
let gen_hash = handler
.get_header(0)
.await
.map_err(|s| {
obscure_error_if_true(
report_error_flag,
Status::invalid_argument(format!("Malformed block template provided: {}", s)),
)
})?
.ok_or_else(|| {
obscure_error_if_true(
report_error_flag,
Status::not_found(format!("Tari genesis block not found")),
)
})?
.hash()
.to_vec();
// construct response
let block_hash = new_block.hash().to_vec();
let mining_hash = match new_block.header.pow.pow_algo {
Expand All @@ -651,6 +668,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
block_hash,
block,
merge_mining_hash: mining_hash,
tari_unique_id: gen_hash,
};
debug!(target: LOG_TARGET, "Sending GetNewBlock response to client");
Ok(Response::new(response))
Expand Down
32 changes: 32 additions & 0 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,38 @@ pub unsafe extern "C" fn tari_address_to_emoji_id(
CString::into_raw(result)
}

/// Creates a char array from a TariWalletAddress's network
///
/// ## Arguments
/// `address` - The pointer to a TariWalletAddress
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
/// as an out parameter.
///
/// ## Returns
/// `*mut c_char` - Returns a pointer to a char array. Note that it returns empty
/// if there was an error from TariWalletAddress
///
/// # Safety
/// The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
#[no_mangle]
pub unsafe extern "C" fn tari_address_network(address: *mut TariWalletAddress, error_out: *mut c_int) -> *mut c_char {
let mut error = 0;
let mut result = CString::new("").expect("Blank CString will not fail.");
ptr::swap(error_out, &mut error as *mut c_int);
if address.is_null() {
error = LibWalletError::from(InterfaceError::NullError("address".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return CString::into_raw(result);
}
let network_string = address
.as_ref()
.expect("Address should not be empty")
.network()
.to_string();
result = CString::new(network_string).expect("string will not fail.");
CString::into_raw(result)
}

/// Creates a TariWalletAddress from a char array in emoji format
///
/// ## Arguments
Expand Down
18 changes: 18 additions & 0 deletions base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,24 @@ TariWalletAddress *tari_address_from_hex(const char *address,
char *tari_address_to_emoji_id(TariWalletAddress *address,
int *error_out);

/**
* Creates a char array from a TariWalletAddress's network
*
* ## Arguments
* `address` - The pointer to a TariWalletAddress
* `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
* as an out parameter.
*
* ## Returns
* `*mut c_char` - Returns a pointer to a char array. Note that it returns empty
* if there was an error from TariWalletAddress
*
* # Safety
* The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak
*/
char *tari_address_network(TariWalletAddress *address,
int *error_out);

/**
* Creates a TariWalletAddress from a char array in emoji format
*
Expand Down

0 comments on commit 79b1d82

Please sign in to comment.