Skip to content

Commit 6ec82b3

Browse files
committed
Allow protocol tests to run (in no_std)
1 parent 14a6282 commit 6ec82b3

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

protocol/src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ pub mod bincode_impl {
122122

123123
impl TryFrom<&[u8]> for ChainAnchor {
124124
type Error = DecodeError;
125-
fn try_from(value: &[u8]) -> std::result::Result<Self, Self::Error> {
125+
fn try_from(value: &[u8]) -> core::result::Result<Self, Self::Error> {
126126
let (meta, _): (ChainAnchor, _) = bincode::decode_from_slice(value, config::standard())
127-
.expect("could not parse chain anchor");
127+
.map_err(|_| DecodeError::OtherString("could not parse chain anchor".to_owned()))?;
128128
Ok(meta)
129129
}
130130
}

protocol/src/hasher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::alloc::string::ToString;
12
#[cfg(feature = "bincode")]
23
use bincode::{Decode, Encode};
34
use bitcoin::{Amount, OutPoint};

protocol/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ extern crate core;
55

66
pub extern crate bitcoin;
77

8+
use alloc::vec;
9+
use alloc::vec::Vec;
10+
811
#[cfg(feature = "bincode")]
912
use bincode::{Decode, Encode};
1013
use bitcoin::{

protocol/src/prepare.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloc::vec::Vec;
2+
13
use bitcoin::{
24
absolute::LockTime,
35
opcodes::all::OP_RETURN,

protocol/src/script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::collections::btree_map::BTreeMap;
2+
use alloc::vec::Vec;
23

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

protocol/src/sname.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use alloc::{string::String, vec::Vec};
22
use core::{
33
fmt::{Display, Formatter},
4+
result,
45
str::FromStr,
56
};
67

@@ -130,31 +131,31 @@ pub trait NameLike {
130131
impl FromStr for SName {
131132
type Err = crate::errors::Error;
132133

133-
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
134+
fn from_str(s: &str) -> result::Result<Self, Self::Err> {
134135
s.try_into()
135136
}
136137
}
137138

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

141-
fn try_from(value: &[u8; N]) -> std::result::Result<Self, Self::Error> {
142+
fn try_from(value: &[u8; N]) -> result::Result<Self, Self::Error> {
142143
value.as_slice().try_into()
143144
}
144145
}
145146

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

149-
fn try_from(value: &Vec<u8>) -> std::result::Result<Self, Self::Error> {
150+
fn try_from(value: &Vec<u8>) -> result::Result<Self, Self::Error> {
150151
value.as_slice().try_into()
151152
}
152153
}
153154

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

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

196-
fn try_from(value: String) -> std::result::Result<Self, Self::Error> {
197+
fn try_from(value: String) -> result::Result<Self, Self::Error> {
197198
value.as_str().try_into()
198199
}
199200
}
200201

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

204-
fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
205+
fn try_from(value: &str) -> result::Result<Self, Self::Error> {
205206
let (subspace, space) = value
206207
.split_once('@')
207208
.ok_or(Error::Name(NameErrorKind::MalformedName))?;

protocol/src/validate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use alloc::collections::btree_map::BTreeMap;
2+
use alloc::vec;
13
use alloc::vec::Vec;
2-
use std::collections::BTreeMap;
34

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

0 commit comments

Comments
 (0)