Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit b519d2a

Browse files
authored
Merge pull request #5 from benthecarman/bdk-db
2 parents 03a1a5d + de5cdaf commit b519d2a

8 files changed

Lines changed: 1093 additions & 35 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ jobs:
88
name: Browser Tests
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- uses: actions-rs/toolchain@v1
1313
with:
14-
toolchain: stable
14+
toolchain: nightly
15+
components: clippy
1516
target: wasm32-unknown-unknown
1617
override: true
1718
profile: minimal

node-manager/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ cfg-if = "1.0.0"
1111
wasm-bindgen = "0.2.83"
1212
bip39 = { version = "1.0.1" }
1313
bitcoin = "0.29.1"
14+
bdk = { git = "https://github.com/afilini/bdk", branch = "upgrade/rust-bitcoin-29", default-features = false, features = ["keys-bip39"] }
1415
getrandom = { version = "0.2", features = ["js"] }
16+
serde = { version = "^1.0", features = ["derive"] }
17+
serde_json = { version = "^1.0" }
1518
gloo-storage = "0.2.2"
1619

1720
# The `console_error_panic_hook` crate provides better debugging of panics by

node-manager/rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

node-manager/src/error.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
use gloo_storage::errors::StorageError;
2+
use std::fmt;
3+
4+
#[derive(Debug)]
5+
#[allow(dead_code)]
6+
// copied from LDK lite
7+
/// An error that possibly needs to be handled by the user.
8+
pub enum Error {
9+
/// Returned when trying to start Mutiny while it is already running.
10+
AlreadyRunning,
11+
/// Returned when trying to stop Mutiny while it is not running.
12+
NotRunning,
13+
/// The funding transaction could not be created.
14+
FundingTxCreationFailed,
15+
/// A network connection has been closed.
16+
ConnectionFailed,
17+
/// Payment of the given invoice has already been initiated.
18+
NonUniquePaymentHash,
19+
/// The given invoice is invalid.
20+
InvoiceInvalid,
21+
/// Invoice creation failed.
22+
InvoiceCreationFailed,
23+
/// No route for the given target could be found.
24+
RoutingFailed,
25+
/// A given peer info could not be parsed.
26+
PeerInfoParseFailed,
27+
/// A channel could not be opened.
28+
ChannelCreationFailed,
29+
/// A channel could not be closed.
30+
ChannelClosingFailed,
31+
/// Persistence failed.
32+
PersistenceFailed,
33+
/// A wallet operation failed.
34+
WalletOperationFailed,
35+
/// A signing operation failed.
36+
WalletSigningFailed,
37+
/// A chain access operation failed.
38+
ChainAccessFailed,
39+
}
40+
41+
impl fmt::Display for Error {
42+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43+
match *self {
44+
Self::AlreadyRunning => write!(f, "Mutiny is already running."),
45+
Self::NotRunning => write!(f, "Mutiny is not running."),
46+
Self::FundingTxCreationFailed => {
47+
write!(f, "Funding transaction could not be created.")
48+
}
49+
Self::ConnectionFailed => write!(f, "Network connection closed."),
50+
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
51+
Self::InvoiceInvalid => write!(f, "The given invoice is invalid."),
52+
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
53+
Self::RoutingFailed => write!(f, "Failed to find route."),
54+
Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."),
55+
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
56+
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
57+
Self::PersistenceFailed => write!(f, "Failed to persist data."),
58+
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
59+
Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."),
60+
Self::ChainAccessFailed => write!(f, "Failed to conduct chain access operation."),
61+
}
62+
}
63+
}
64+
65+
impl std::error::Error for Error {}
66+
67+
impl From<bdk::Error> for Error {
68+
fn from(e: bdk::Error) -> Self {
69+
match e {
70+
bdk::Error::Signer(_) => Self::WalletSigningFailed,
71+
_ => Self::WalletOperationFailed,
72+
}
73+
}
74+
}
75+
76+
// todo uncomment when we add esplora stuff
77+
// impl From<esplora::EsploraError> for Error {
78+
// fn from(_e: esplora::EsploraError) -> Self {
79+
// Self::ChainAccessFailed
80+
// }
81+
// }
82+
83+
impl From<StorageError> for Error {
84+
fn from(_e: StorageError) -> Self {
85+
Self::PersistenceFailed
86+
}
87+
}

node-manager/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// wasm_bindgen uses improper casing and it needs to be turned off:
33
// https://github.com/rustwasm/wasm-bindgen/issues/2882
44

5+
mod error;
6+
mod localstorage;
57
mod nodemanager;
68
mod seedgen;
7-
mod storage;
89
mod utils;
910

1011
use cfg_if::cfg_if;
@@ -26,3 +27,12 @@ pub async fn main_js() -> Result<(), JsValue> {
2627
debug!("Main function ends");
2728
Ok(())
2829
}
30+
31+
#[cfg(test)]
32+
mod test {
33+
use gloo_storage::{LocalStorage, Storage};
34+
35+
pub(crate) fn cleanup_test() {
36+
LocalStorage::clear();
37+
}
38+
}

0 commit comments

Comments
 (0)