Skip to content

Commit

Permalink
resolve seals on consignment consume
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 23, 2024
1 parent 50ad8cd commit eec5e16
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
14 changes: 6 additions & 8 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ amplify = "4.8.0"
strict_encoding = "2.8.1"
commit_verify = "0.12.0-beta.1"
nonasync = "0.1.2"
hypersonic = "0.12.0-beta.1"
bp-std = { version = "0.12.0-alpha.1", features = ["client-side-validation"] }
bp-electrum = "0.12.0-beta.1"
bp-esplora = { version = "0.12.0-beta.1", default-features = false }
Expand Down Expand Up @@ -51,7 +50,6 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
amplify = { workspace = true }
hypersonic = { workspace = true }
commit_verify = { workspace = true }
nonasync = { workspace = true }
bp-std = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ name = "rgb"
[dependencies]
amplify.workspace = true
strict_encoding.workspace = true
hypersonic = { workspace = true, features = ["persist-file"] }
bp-wallet = { workspace = true, features = ["fs", "serde", "cli"] }
bp-electrum = { workspace = true }
bp-esplora = { workspace = true }
Expand Down
22 changes: 8 additions & 14 deletions cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ use bpwallet::indexers::esplora;
use bpwallet::psbt::TxParams;
use bpwallet::{AnyIndexer, Keychain, Network, Psbt, Sats, Vout, Wpkh, XpubDerivable};
use clap::ValueHint;
use hypersonic::{AuthToken, ContractId};
use rgb::popls::bp::file::{DirBarrow, DirMound};
use rgb::popls::bp::{PrefabBundle, PrefabParams};
use rgb::{CreateParams, Outpoint, SealType};
use rgb::{AuthToken, ContractId, CreateParams, Outpoint, SealType};
use rgbp::descriptor::{Opret, Tapret};
use rgbp::wallet::file::DirRuntime;
use rgbp::wallet::{OpretWallet, TapretWallet};
Expand Down Expand Up @@ -258,6 +257,10 @@ pub enum Cmd {
/// Verify and accept a consignment
#[clap(alias = "a")]
Accept {
/// Wallet to use
#[clap(short, long, global = true, env = RGB_WALLET_ENV)]
wallet: Option<String>,

/// File with consignment to accept
#[clap(value_hint = ValueHint::FilePath)]
input: PathBuf,
Expand Down Expand Up @@ -570,18 +573,9 @@ impl Args {
.expect("Unable to consign contract");
}

Cmd::Accept { input } => {
let mut mound = self.mound();
match self.seal {
SealType::BitcoinOpret => mound
.bc_opret
.consume_from_file(input)
.unwrap_or_else(|err| panic!("Unable to accept a consignment: {err}")),
SealType::BitcoinTapret => mound
.bc_tapret
.consume_from_file(input)
.unwrap_or_else(|err| panic!("Unable to accept a consignment: {err}")),
};
Cmd::Accept { wallet, input } => {
let mut runtime = self.runtime(wallet.as_deref());
runtime.consume_from_file(input)?;
}

_ => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion examples/data/bcor/alice/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ name = ""

[lastUsed]
0 = 2
1 = 52
1 = 55

[layer2]
2 changes: 1 addition & 1 deletion examples/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ $RGB --seal bcor complete -w alice examples/transfer.pfab examples/transfer.psbt
rm examples/transfer.rgb
$RGB --seal bcor consign yxrQaqAE-W4F5io~-pU4nVOB-yo7028N-JXCESWT-1abvQk8 -t 5WIb5EMY-RCLbO3Wq-hGdddRP4-IeCQzP1y-S5H_UKzd-XJ6ejw examples/transfer.rgb

$RGB_2 --seal bcor accept examples/transfer.rgb
$RGB_2 --seal bcor accept -w bob examples/transfer.rgb
Binary file modified examples/transfer.psbt
Binary file not shown.
Binary file modified examples/transfer.rgb
Binary file not shown.
31 changes: 31 additions & 0 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use bpstd::{Network, Outpoint, XpubDerivable};
use bpwallet::{Layer2Empty, NoLayer2, Wallet, WalletCache, WalletData, WalletDescr};
use nonasync::persistence::{PersistenceError, PersistenceProvider};
use rgb::popls::bp::{OpretProvider, TapretProvider, WalletProvider};
use rgb::{AuthToken, SealAuthToken};

use crate::descriptor::{Opret, Tapret};

Expand All @@ -55,6 +56,21 @@ impl WalletProvider for OpretWallet {
})
});
}

fn resolve_seals(
&self,
seals: impl Iterator<Item = AuthToken>,
) -> impl Iterator<Item = TxoSealDef> {
seals
.flat_map(|auth| {
self.0
.descriptor()
.seals
.iter()
.filter(move |seal| seal.auth_token() == auth)
})
.copied()
}
}
impl OpretProvider for OpretWallet {}

Expand Down Expand Up @@ -109,6 +125,21 @@ impl WalletProvider for TapretWallet {
})
});
}

fn resolve_seals(
&self,
seals: impl Iterator<Item = AuthToken>,
) -> impl Iterator<Item = TxoSealDef> {
seals
.flat_map(|auth| {
self.0
.descriptor()
.seals
.iter()
.filter(move |seal| seal.auth_token() == auth)
})
.copied()
}
}
impl TapretProvider for TapretWallet {}

Expand Down

0 comments on commit eec5e16

Please sign in to comment.