Skip to content

Allow protocol tests to run (in no_std) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions protocol/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ pub mod bincode_impl {

impl TryFrom<&[u8]> for ChainAnchor {
type Error = DecodeError;
fn try_from(value: &[u8]) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &[u8]) -> core::result::Result<Self, Self::Error> {
let (meta, _): (ChainAnchor, _) = bincode::decode_from_slice(value, config::standard())
.expect("could not parse chain anchor");
.map_err(|_| DecodeError::OtherString("could not parse chain anchor".to_owned()))?;
Ok(meta)
}
}
Expand Down
1 change: 1 addition & 0 deletions protocol/src/hasher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::alloc::string::ToString;
#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
use bitcoin::{Amount, OutPoint};
Expand Down
3 changes: 3 additions & 0 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ extern crate core;

pub extern crate bitcoin;

use alloc::vec;
use alloc::vec::Vec;

#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
use bitcoin::{
Expand Down
2 changes: 2 additions & 0 deletions protocol/src/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

use bitcoin::{
absolute::LockTime,
opcodes::all::OP_RETURN,
Expand Down
1 change: 1 addition & 0 deletions protocol/src/script.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::collections::btree_map::BTreeMap;
use alloc::vec::Vec;

#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
Expand Down
13 changes: 7 additions & 6 deletions protocol/src/sname.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::{string::String, vec::Vec};
use core::{
fmt::{Display, Formatter},
result,
str::FromStr,
};

Expand Down Expand Up @@ -130,31 +131,31 @@ pub trait NameLike {
impl FromStr for SName {
type Err = crate::errors::Error;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
fn from_str(s: &str) -> result::Result<Self, Self::Err> {
s.try_into()
}
}

impl<const N: usize> TryFrom<&[u8; N]> for SName {
type Error = crate::errors::Error;

fn try_from(value: &[u8; N]) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &[u8; N]) -> result::Result<Self, Self::Error> {
value.as_slice().try_into()
}
}

impl TryFrom<&Vec<u8>> for SName {
type Error = crate::errors::Error;

fn try_from(value: &Vec<u8>) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &Vec<u8>) -> result::Result<Self, Self::Error> {
value.as_slice().try_into()
}
}

impl core::convert::TryFrom<&[u8]> for SName {
type Error = crate::errors::Error;

fn try_from(value: &[u8]) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &[u8]) -> result::Result<Self, Self::Error> {
let name_ref: SNameRef = value.try_into()?;
Ok(name_ref.to_owned())
}
Expand Down Expand Up @@ -193,15 +194,15 @@ impl<'a> core::convert::TryFrom<&'a [u8]> for SNameRef<'a> {
impl TryFrom<String> for SName {
type Error = crate::errors::Error;

fn try_from(value: String) -> std::result::Result<Self, Self::Error> {
fn try_from(value: String) -> result::Result<Self, Self::Error> {
value.as_str().try_into()
}
}

impl TryFrom<&str> for SName {
type Error = crate::errors::Error;

fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &str) -> result::Result<Self, Self::Error> {
let (subspace, space) = value
.split_once('@')
.ok_or(Error::Name(NameErrorKind::MalformedName))?;
Expand Down
3 changes: 2 additions & 1 deletion protocol/src/validate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::collections::btree_map::BTreeMap;
use alloc::vec;
use alloc::vec::Vec;
use std::collections::BTreeMap;

#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
Expand Down