Skip to content

Commit 0191581

Browse files
committed
Adapt lightning-invoice to no_std
1 parent 5655590 commit 0191581

File tree

11 files changed

+369
-158
lines changed

11 files changed

+369
-158
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ jobs:
115115
# check if there is a conflict between no-std and the default std feature
116116
cargo test --verbose --color always --features no-std
117117
cd ..
118+
cd lightning-invoice
119+
cargo test --verbose --color always --no-default-features --features no-std
120+
# check if there is a conflict between no-std and the default std feature
121+
cargo test --verbose --color always --features no-std
122+
cd ..
118123
- name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
119124
if: "matrix.build-no-std && matrix.coverage"
120125
run: |

lightning-invoice/Cargo.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ license = "MIT OR Apache-2.0"
88
keywords = [ "lightning", "bitcoin", "invoice", "BOLT11" ]
99
readme = "README.md"
1010

11+
[features]
12+
default = ["std"]
13+
no-std = ["hashbrown", "lightning/no-std", "core2/alloc"]
14+
std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std"]
15+
1116
[dependencies]
1217
bech32 = "0.8"
13-
lightning = { version = "0.0.104", path = "../lightning" }
14-
secp256k1 = { version = "0.20", features = ["recovery"] }
15-
num-traits = "0.2.8"
16-
bitcoin_hashes = "0.10"
18+
lightning = { version = "0.0.104", path = "../lightning", default-features = false }
19+
secp256k1 = { version = "0.20", default-features = false, features = ["recovery", "alloc"] }
20+
num-traits = { version = "0.2.8", default-features = false }
21+
bitcoin_hashes = { version = "0.10", default-features = false }
22+
hashbrown = { version = "0.11", optional = true }
23+
core2 = { version = "0.3.0", default-features = false, optional = true }
1724

1825
[dev-dependencies]
26+
lightning = { version = "0.0.104", path = "../lightning", default-features = false, features = ["_test_utils"] }
1927
hex = "0.3"
20-
lightning = { version = "0.0.104", path = "../lightning", features = ["_test_utils"] }

lightning-invoice/src/de.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#[cfg(feature = "std")]
12
use std::error;
2-
use std::fmt;
3-
use std::fmt::{Display, Formatter};
4-
use std::num::ParseIntError;
5-
use std::str;
6-
use std::str::FromStr;
3+
use core::fmt;
4+
use core::fmt::{Display, Formatter};
5+
use core::num::ParseIntError;
6+
use core::str;
7+
use core::str::FromStr;
78

89
use bech32;
910
use bech32::{u5, FromBase32};
1011

1112
use bitcoin_hashes::Hash;
1213
use bitcoin_hashes::sha256;
14+
use crate::prelude::*;
1315
use lightning::ln::PaymentSecret;
1416
use lightning::routing::network_graph::RoutingFees;
1517
use lightning::routing::router::{RouteHint, RouteHintHop};
@@ -28,7 +30,7 @@ use self::hrp_sm::parse_hrp;
2830

2931
/// State machine to parse the hrp
3032
mod hrp_sm {
31-
use std::ops::Range;
33+
use core::ops::Range;
3234

3335
#[derive(PartialEq, Eq, Debug)]
3436
enum States {
@@ -723,8 +725,10 @@ impl Display for ParseOrSemanticError {
723725
}
724726
}
725727

728+
#[cfg(feature = "std")]
726729
impl error::Error for ParseError {}
727730

731+
#[cfg(feature = "std")]
728732
impl error::Error for ParseOrSemanticError {}
729733

730734
macro_rules! from_error {

0 commit comments

Comments
 (0)