Skip to content
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

Add electrum support #131

Merged
merged 11 commits into from
Feb 26, 2024
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
fail-fast: false
matrix:
feature:
- esplora
- esplora_blocking
- log
- serde
steps:
Expand Down
53 changes: 52 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ license = "Apache-2.0"
[workspace.dependencies]
amplify = "4.5.0"
baid58 = "0.4.4"
bitcoin = "0.31.1"
commit_verify = "0.11.0-beta.3"
strict_encoding = "2.6.2"
strict_types = "1.6.3"
Expand All @@ -36,6 +37,7 @@ bp-wallet = "0.11.0-beta.4"
bp-util = "0.11.0-beta.4"
bp-esplora = "0.11.0-beta.2"
descriptors = "0.11.0-beta.3"
electrum-client = "0.19.0"
psbt = { version = "0.11.0-beta.3", features = ["client-side-validation"] }
rgb-std = { version = "0.11.0-beta.3", features = ["fs"] }
rgb-psbt = { version = "0.11.0-beta.3", path = "psbt" }
Expand Down Expand Up @@ -66,13 +68,15 @@ name = "rgb_rt"
[dependencies]
amplify = { workspace = true }
baid58 = { workspace = true }
bitcoin = { workspace = true, optional = true }
commit_verify = { workspace = true }
strict_types = { workspace = true }
bp-core = { workspace = true }
bp-std = { workspace = true }
bp-wallet = { workspace = true, features = ["fs"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zoedberg,

Please set default-features=false, to avoid load bp-esplora blocking client along wasm compilation.

Suggested change
bp-wallet = { workspace = true, features = ["fs"] }
bp-wallet = { workspace = true, default-features = false, features = ["fs"] }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @crisdut, sorry for the late answer but I've somehow missed this. Thanks for the tip, unfortunately though I'm still receiving the previously reported errors.

bp-esplora = { workspace = true, optional = true }
descriptors = { workspace = true }
electrum-client = { workspace = true, optional = true }
rgb-std = { workspace = true }
rgb-psbt = { workspace = true }
rgb-persist-fs = { version = "0.11.0", path = "fs" }
Expand All @@ -84,9 +88,10 @@ serde_with = { workspace = true, optional = true }
log = { workspace = true, optional = true }

[features]
default = ["esplora"]
all = ["esplora", "serde", "log"]
esplora = ["bp-esplora", "bp-wallet/esplora"]
default = ["esplora_blocking"]
all = ["esplora_blocking", "electrum", "serde", "log"]
esplora_blocking = ["bp-esplora", "bp-wallet/esplora"]
electrum = ["electrum-client", "bitcoin"]
serde = ["serde_crate", "serde_with", "serde_yaml", "bp-std/serde", "bp-wallet/serde", "descriptors/serde", "rgb-psbt/serde"]

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bp-wallet = { workspace = true }
bp-util = { workspace = true }
psbt = { workspace = true }
rgb-std = { workspace = true, features = ["serde"] }
rgb-runtime = { version = "0.11.0-beta.1", path = "..", features = ["esplora", "log", "serde"] }
rgb-runtime = { version = "0.11.0-beta.1", path = "..", features = ["esplora_blocking", "log", "serde"] }
log = { workspace = true }
env_logger = "0.10.1"
clap = { version = "4.4.8", features = ["derive", "env"] }
Expand Down
3 changes: 2 additions & 1 deletion cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

use bp_util::{Config, DescriptorOpts};
use bpstd::{Wpkh, XpubDerivable};
use rgb_rt::{Resolver, ResolverError, RgbDescr, Runtime, RuntimeError, TapretKey};
use rgb_rt::esplora_blocking::{Resolver, ResolverError};
use rgb_rt::{RgbDescr, Runtime, RuntimeError, TapretKey};

use crate::Command;

Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ extern crate serde_with;
mod runtime;
mod descriptor;
mod pay;
#[cfg(feature = "esplora")]
mod resolver;
mod resolvers;

pub use descriptor::{DescriptorRgb, RgbDescr, RgbKeychain, TapTweakAlreadyAssigned, TapretKey};
pub use pay::{CompletionError, CompositionError, PayError, TransferParams};
#[cfg(feature = "esplora")]
pub use resolver::{AnchorResolverError, Resolver, ResolverError};
pub use resolvers::*;
pub use runtime::{ContractOutpointsFilter, Runtime, RuntimeError};
84 changes: 84 additions & 0 deletions src/resolvers/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// RGB smart contracts for Bitcoin & Lightning
//
// SPDX-License-Identifier: Apache-2.0
//
// Written in 2024 by
// Zoe Faltibà <[email protected]>
//
// Copyright (C) 2024 LNP/BP Standards Association. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use rgbstd::resolvers::ResolveHeight;
use rgbstd::validation::{ResolveWitness, WitnessResolverError};
use rgbstd::{WitnessAnchor, WitnessId, XAnchor, XPubWitness};

#[cfg(feature = "electrum")]
use crate::electrum;
#[cfg(feature = "esplora_blocking")]
use crate::esplora_blocking;

/// Type that contains any of the [`Resolver`] types defined by the library
#[derive(From)]
#[non_exhaustive]
pub enum AnyResolver {
#[cfg(feature = "electrum")]
#[from]
/// Electrum resolver
Electrum(Box<electrum::Resolver>),
#[cfg(feature = "esplora_blocking")]
#[from]
/// Esplora resolver
Esplora(Box<esplora_blocking::Resolver>),
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum AnyAnchorResolverError {
#[cfg(feature = "electrum")]
#[from]
#[display(inner)]
Electrum(electrum::AnchorResolverError),
#[cfg(feature = "esplora_blocking")]
#[from]
#[display(inner)]
Esplora(esplora_blocking::AnchorResolverError),
}

impl ResolveHeight for AnyResolver {
type Error = AnyAnchorResolverError;

fn resolve_anchor(&mut self, anchor: &XAnchor) -> Result<WitnessAnchor, Self::Error> {
match self {
#[cfg(feature = "electrum")]
AnyResolver::Electrum(inner) => inner.resolve_anchor(anchor).map_err(|e| e.into()),
#[cfg(feature = "esplora_blocking")]
AnyResolver::Esplora(inner) => inner.resolve_anchor(anchor).map_err(|e| e.into()),
}
}
}

impl ResolveWitness for AnyResolver {
fn resolve_pub_witness(
&self,
witness_id: WitnessId,
) -> Result<XPubWitness, WitnessResolverError> {
match self {
#[cfg(feature = "electrum")]
AnyResolver::Electrum(inner) => inner.resolve_pub_witness(witness_id),
#[cfg(feature = "esplora_blocking")]
AnyResolver::Esplora(inner) => inner.resolve_pub_witness(witness_id),
}
}
}
Loading
Loading