Skip to content

Commit a2f99cb

Browse files
authored
Wasm compatibility (#16)
* Wasm compatibility * Fix warnings * Implement wasm compatible methods * Revert sh scripts * Fix fmt * Fix fmt * Clean unused code
1 parent 34d2476 commit a2f99cb

35 files changed

Lines changed: 2190 additions & 578 deletions

File tree

.github/workflows/build.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ jobs:
3939
shell: bash # Default on Winblows is powershell
4040
run: cargo check --workspace --verbose --color always
4141

42+
wasm:
43+
runs-on: ubuntu-latest
44+
env:
45+
TOOLCHAIN: stable
46+
steps:
47+
- name: Checkout source code
48+
uses: actions/checkout@v4
49+
- name: Install Rust ${{ env.TOOLCHAIN }} toolchain
50+
run: |
51+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ env.TOOLCHAIN }}
52+
- name: Install wasm32 target
53+
run: rustup target add wasm32-unknown-unknown
54+
- name: Build lightning for wasm32 (rgb-wasm backend)
55+
run: cargo check -p lightning --target wasm32-unknown-unknown --no-default-features --features std,grind_signatures,rgb-wasm --verbose --color always
56+
- name: Build lightning-transaction-sync for wasm32 (rgb-wasm backend)
57+
run: cargo check --manifest-path lightning-transaction-sync/Cargo.toml --target wasm32-unknown-unknown --no-default-features --features time,esplora-async,rgb-wasm --verbose --color always
58+
4259
linting:
4360
runs-on: ubuntu-latest
4461
env:

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ std = ["lightning/std", "lightning-liquidity/std", "bitcoin-io/std", "bitcoin_ha
2323
bitcoin = { version = "0.32.2", default-features = false }
2424
bitcoin_hashes = { version = "0.14.0", default-features = false }
2525
bitcoin-io = { version = "0.1.2", default-features = false }
26-
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
26+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["rgb-native"] }
2727
lightning-rapid-gossip-sync = { version = "0.2.0", path = "../lightning-rapid-gossip-sync", default-features = false }
2828
lightning-liquidity = { version = "0.2.0", path = "../lightning-liquidity", default-features = false }
2929
possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false }

lightning-dns-resolver/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "A crate which implements DNSSEC resolution for lightning clients
99
edition = "2021"
1010

1111
[dependencies]
12-
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
12+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["rgb-native"] }
1313
lightning-types = { version = "0.3.0", path = "../lightning-types", default-features = false }
1414
dnssec-prover = { version = "0.6", default-features = false, features = [ "std", "tokio" ] }
1515
tokio = { version = "1.0", default-features = false, features = ["rt"] }

lightning-invoice/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ rustdoc-args = ["--cfg", "docsrs"]
1717
[features]
1818
std = []
1919

20+
default = []
21+
2022
[dependencies]
2123
bech32 = { version = "0.11.0", default-features = false }
2224
lightning-types = { version = "0.3.0", path = "../lightning-types", default-features = false }
2325
serde = { version = "1.0", optional = true, default-features = false, features = ["alloc"] }
2426
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
2527

26-
# RGB and related
27-
rgb-lib = { git = "https://github.com/UTEXO-Protocol/rgb-lib.git", tag = "v0.3.0-beta.24", features = [
28-
"electrum",
29-
"esplora",
30-
] }
28+
# RGB protocol types
29+
rgb-ops = { version = "=0.11.1-rc.10", default-features = false }
3130

3231
[dev-dependencies]
3332
serde_json = { version = "1"}

lightning-invoice/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use lightning_types::routing::{RouteHint, RouteHintHop, RoutingFees};
2222
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
2323
use bitcoin::secp256k1::PublicKey;
2424

25-
use rgb_lib::ContractId;
25+
use crate::ContractId;
2626

2727
use super::{
2828
constants, Bolt11Invoice, Bolt11InvoiceFeatures, Bolt11InvoiceSignature, Bolt11ParseError,

lightning-invoice/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
4040
use bitcoin::secp256k1::PublicKey;
4141
use bitcoin::secp256k1::{Message, Secp256k1};
4242

43-
use rgb_lib::ContractId;
43+
pub use rgbstd::ContractId;
4444

4545
use alloc::boxed::Box;
4646
use alloc::string;
@@ -1682,7 +1682,7 @@ impl Bolt11Invoice {
16821682

16831683
/// Returns the invoice's `rgb_contract_id` if present
16841684
pub fn rgb_contract_id(&self) -> Option<ContractId> {
1685-
self.signed_invoice.rgb_contract_id().map(|x| x.0)
1685+
self.signed_invoice.rgb_contract_id().map(|x| x.0.clone())
16861686
}
16871687
}
16881688

lightning-liquidity/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ backtrace = ["dep:backtrace"]
2121
_test_utils = []
2222

2323
[dependencies]
24-
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
24+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["rgb-native"] }
2525
lightning-types = { version = "0.3.0", path = "../lightning-types", default-features = false }
2626
lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false, features = ["serde"] }
2727
lightning-macros = { version = "0.2.0", path = "../lightning-macros" }
@@ -34,7 +34,7 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
3434
backtrace = { version = "0.3", optional = true }
3535

3636
[dev-dependencies]
37-
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["_test_utils"] }
37+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["_test_utils", "rgb-native"] }
3838
lightning-invoice = { version = "0.34.0", path = "../lightning-invoice", default-features = false, features = ["serde", "std"] }
3939
lightning-persister = { version = "0.2.0", path = "../lightning-persister", default-features = false }
4040

lightning-rapid-gossip-sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default = ["std"]
1414
std = ["bitcoin-io/std", "bitcoin_hashes/std"]
1515

1616
[dependencies]
17-
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
17+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["rgb-native"] }
1818
bitcoin = { version = "0.32.2", default-features = false }
1919
bitcoin_hashes = { version = "0.14.0", default-features = false }
2020
bitcoin-io = { version = "0.1.2", default-features = false }

lightning-transaction-sync/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ all-features = true
1515
rustdoc-args = ["--cfg", "docsrs"]
1616

1717
[features]
18-
default = ["time"]
19-
time = []
18+
default = ["time", "rgb-native"]
19+
time = ["dep:web-time"]
20+
rgb-native = ["lightning/rgb-native"]
21+
rgb-wasm = ["lightning/rgb-wasm"]
2022
esplora-async = ["async-interface", "esplora-client/async", "esplora-client/tokio", "futures"]
2123
esplora-async-https = ["esplora-async", "esplora-client/async-https-rustls"]
2224
esplora-blocking = ["esplora-client/blocking"]
@@ -38,9 +40,10 @@ bitcoin = { version = "0.32.2", default-features = false }
3840
futures = { version = "0.3", optional = true }
3941
esplora-client = { version = "0.12", default-features = false, optional = true }
4042
electrum-client = { version = "0.24.0", optional = true, default-features = false, features = ["proxy"] }
43+
web-time = { version = "1.1", optional = true }
4144

4245
[dev-dependencies]
43-
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["std", "_test_utils"] }
46+
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["std", "_test_utils", "rgb-native"] }
4447
tokio = { version = "1.35.0", features = ["macros"] }
4548

4649
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]

lightning-transaction-sync/src/electrum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bitcoin::{BlockHash, Script, Transaction, Txid};
2323
use std::collections::HashSet;
2424
use std::ops::Deref;
2525
use std::sync::{Arc, Mutex};
26-
use std::time::Instant;
26+
use web_time::Instant;
2727

2828
/// Synchronizes LDK with a given Electrum server.
2929
///

0 commit comments

Comments
 (0)