Skip to content

Commit

Permalink
chore: slight reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Apr 17, 2024
1 parent be41f7a commit 5f0725f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 9 additions & 8 deletions crates/da-rpc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ pub extern "C" fn get_error() -> *mut c_char {
}
}

/// # Safety
/// we check if the pointer is null before attempting to free it
#[no_mangle]
pub extern "C" fn free_error(error: *mut c_char) {
if !error.is_null() {
unsafe {
let _ = CString::from_raw(error);
}
pub unsafe extern "C" fn free_error(error: *mut c_char) {
null_pointer_check!(error);
unsafe {
let _ = CString::from_raw(error);
}
}

Expand Down Expand Up @@ -293,7 +294,7 @@ pub unsafe extern "C" fn submit_batch(
let blob = Blob::new_v0(tx_data.to_vec());
match RUNTIME.block_on(client.submit(&[blob])) {
Ok(result) => {
let blob_ref: BlobRef = result.0.into();
let blob_ref: BlobRef = result.0;

RustSafeArray::new((*blob_ref).to_vec())
}
Expand Down Expand Up @@ -332,7 +333,7 @@ pub mod test {
let secret = env::var("TEST_NEAR_SECRET").unwrap();
let config = Config {
key: config::KeyType::SecretKey(account, secret),
contract: "throwawaykey.testnet".to_string().into(),
contract: "throwawaykey.testnet".to_string(),
network: Network::Testnet,
namespace: None,
};
Expand Down Expand Up @@ -362,7 +363,7 @@ pub mod test {
fn c_submit() {
let blobs: Vec<BlobSafe> = vec![Blob::new_v0(vec![0x01, 0x02, 0x03]).into()];
let (client, _) = test_get_client();
let res = unsafe { submit(&client, blobs.as_ptr(), blobs.len().into()) };
let res = unsafe { submit(&client, blobs.as_ptr(), blobs.len()) };
assert!(!res.is_null());
let binding = unsafe { CString::from_raw(res) };
let str = binding.to_str().unwrap();
Expand Down
8 changes: 2 additions & 6 deletions crates/da-rpc/src/near/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Network {
fn parse_customnet(s: &str) -> Result<Network, String> {
s.parse::<Url>()
.map_err(|err| err.to_string())
.and_then(|_| Ok(Network::Custom(s.into())))
.map(|_| Network::Custom(s.into()))
}
}

Expand All @@ -50,11 +50,7 @@ impl<'de> Deserialize<'de> for Network {
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(deserializer)?;
match s.to_lowercase().as_str() {
"mainnet" => Ok(Network::Mainnet),
"testnet" => Ok(Network::Testnet),
url => Self::parse_customnet(url).map_err(serde::de::Error::custom),
}
s.try_into().map_err(serde::de::Error::custom)
}
}

Expand Down

0 comments on commit 5f0725f

Please sign in to comment.