mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-05-18 15:29:26 +00:00
Minor improvements.
This commit is contained in:
parent
a291e1cb54
commit
e4e495f9b2
@ -2,6 +2,13 @@ use crate::ffi;
|
||||
|
||||
pub struct Bytes(Vec<u8>);
|
||||
|
||||
impl Bytes {
|
||||
#[must_use]
|
||||
pub fn inner(&self) -> &Vec<u8> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ffi::Bytes> for Bytes {
|
||||
fn from(mut ffi_value: ffi::Bytes) -> Self {
|
||||
let raw = unsafe {
|
||||
|
||||
@ -34,7 +34,7 @@ impl TryFrom<crate::ffi::Status> for () {
|
||||
let error_message = message
|
||||
.map(|inner| DynError::from(inner.to_string_lossy().to_owned()))
|
||||
.unwrap_or_else(|| DynError::from("Unknown error"));
|
||||
Err(Error::Other(error_message))
|
||||
Err(error_message.into())
|
||||
},
|
||||
FfiStatusCode::InvalidInput => Err(Error::InvalidInput),
|
||||
FfiStatusCode::OutOfMemory => Err(Error::OutOfMemory),
|
||||
|
||||
@ -18,9 +18,10 @@ impl WitnessInput {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a guard for managing the lifetime of a WitnessInput in FFI.
|
||||
/// This struct ensures that the memory allocated for the FFI representation of WitnessInput is
|
||||
/// properly released when it goes out of scope.
|
||||
/// Temporary FFI view of a [`WitnessInput`], valid for the lifetime of the source.
|
||||
///
|
||||
/// Owns the C string allocation of `WitnessInput::inputs_json` and ensures it is freed when
|
||||
/// dropped.
|
||||
pub struct WitnessInputFfiGuard<'a> {
|
||||
ffi: ffi::WitnessInput,
|
||||
_lifetime: std::marker::PhantomData<&'a WitnessInput>,
|
||||
@ -28,7 +29,7 @@ pub struct WitnessInputFfiGuard<'a> {
|
||||
|
||||
impl<'a> WitnessInputFfiGuard<'a> {
|
||||
#[must_use]
|
||||
pub fn new(inner: &'a WitnessInput) -> Self {
|
||||
fn new(inner: &'a WitnessInput) -> Self {
|
||||
let dat = ffi::ConstBytes { data: inner.dat.as_ptr(), size: inner.dat.len() };
|
||||
let inputs_json = CString::new(inner.inputs_json.clone()).expect("CString::new failed").into_raw();
|
||||
let ffi = ffi::WitnessInput { dat, inputs_json };
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use std::cmp::PartialEq;
|
||||
use std::ffi::c_char;
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user