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