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
743895bfc7
commit
4c0e77d70a
@ -1,6 +1,7 @@
|
||||
use std::ffi::c_char;
|
||||
use crate::ffi::ConstBytes;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct WitnessInput {
|
||||
pub dat: ConstBytes,
|
||||
pub inputs_json: *const c_char,
|
||||
|
||||
@ -4,11 +4,22 @@ pub struct Bytes(Vec<u8>);
|
||||
|
||||
impl Bytes {
|
||||
#[must_use]
|
||||
pub fn inner(&self) -> &Vec<u8> {
|
||||
pub fn into_inner(self) -> Vec<u8> {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for Bytes {
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ffi::Bytes> for Bytes {
|
||||
fn from(mut ffi_value: ffi::Bytes) -> Self {
|
||||
let raw = unsafe {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::ffi::{c_char, CString};
|
||||
use std::ffi::{c_char, CString, NulError};
|
||||
use crate::ffi;
|
||||
|
||||
pub struct WitnessInput {
|
||||
@ -12,8 +12,7 @@ impl WitnessInput {
|
||||
Self { dat, inputs_json }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn as_ffi(&'_ self) -> WitnessInputFfiGuard<'_> {
|
||||
pub fn as_ffi(&'_ self) -> Result<WitnessInputFfiGuard<'_>, NulError> {
|
||||
WitnessInputFfiGuard::new(self)
|
||||
}
|
||||
}
|
||||
@ -28,15 +27,14 @@ pub struct WitnessInputFfiGuard<'a> {
|
||||
}
|
||||
|
||||
impl<'a> WitnessInputFfiGuard<'a> {
|
||||
#[must_use]
|
||||
fn new(inner: &'a WitnessInput) -> Self {
|
||||
fn new(inner: &'a WitnessInput) -> Result<Self, NulError> {
|
||||
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())?.into_raw();
|
||||
let ffi = ffi::WitnessInput { dat, inputs_json };
|
||||
Self {
|
||||
Ok(Self {
|
||||
ffi,
|
||||
_lifetime: std::marker::PhantomData,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,4 +53,3 @@ impl<'a> Drop for WitnessInputFfiGuard<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user