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

Differentiate witness txo-based seals from existing utxo-based seals #282

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ ultrasonic = { git = "https://github.com/AluVM/ultrasonic", branch = "master" }
hypersonic = { git = "https://github.com/AluVM/sonic", branch = "master" }
sonic-api = { git = "https://github.com/AluVM/sonic", branch = "master" }
sonic-callreq = { git = "https://github.com/AluVM/sonic", branch = "master" }
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "v0.12" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "v0.12" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "v0.12" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.12" }
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "wtxoseal" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "wtxoseal" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "wtxoseal" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "wtxoseal" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "v0.12" }
bp-derive = { git = "https://github.com/BP-WG/bp-std", branch = "v0.12" }
descriptors = { git = "https://github.com/BP-WG/bp-std", branch = "v0.12" }
psbt = { git = "https://github.com/BP-WG/bp-std", branch = "v0.12" }
bp-std = { git = "https://github.com/BP-WG/bp-std", branch = "v0.12" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "v0.12" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.12" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.12" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.12" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "wtxoseal" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "wtxoseal" }
rgb-invoice = { git = "https://github.com/RGB-WG/rgb-std", branch = "wtxoseal" }
36 changes: 22 additions & 14 deletions cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,27 @@ impl Args {
FsTextStore::new(self.wallet_dir(name)).expect("Broken directory structure")
}

pub fn runtime(&self, name: Option<&str>) -> RgbDirRuntime {
let provider = self.wallet_provider(name);
pub fn runtime(&self, opts: &WalletOpts) -> RgbDirRuntime {
let provider = self.wallet_provider(opts.wallet.as_deref());
let wallet = RgbWallet::load(provider, true).unwrap_or_else(|_| {
panic!("Error: unable to load wallet from path `{}`", self.wallet_dir(name).display())
panic!(
"Error: unable to load wallet from path `{}`",
self.wallet_dir(opts.wallet.as_deref()).display()
)
});
RgbDirRuntime::from(DirBarrow::with(wallet, self.mound()))
// TODO: Sync wallet if needed
let mut runtime = RgbDirRuntime::from(DirBarrow::with(wallet, self.mound()));
if opts.sync {
eprintln!("Synchronizing wallet");
runtime.wallet.update(&self.indexer(&opts.resolver), false);
}
runtime
}

pub fn indexer(&self, resolver: &ResolverOpt) -> AnyIndexer {
let network = self.network.to_string();
match (&resolver.esplora, &resolver.electrum, &resolver.mempool) {
(None, Some(url), None) => AnyIndexer::Electrum(Box::new(
// TODO: Check network match
electrum::Client::new(url).expect("Unable to initialize indexer"),
)),
(Some(url), None, None) => AnyIndexer::Esplora(Box::new(
Expand Down Expand Up @@ -425,7 +433,7 @@ impl Args {
}
}
Cmd::Issue { params: Some(params), wallet } => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
let file = File::open(params).expect("Unable to open parameters file");
let params = serde_yaml::from_reader::<_, CreateParams<Outpoint>>(file)?;
let contract_id = runtime.issue_to_file(params)?;
Expand Down Expand Up @@ -456,7 +464,7 @@ impl Args {
}

Cmd::Fund { wallet } => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
let addr = runtime.wallet.next_address(Keychain::OUTER, true);
println!("{addr}");
}
Expand All @@ -472,7 +480,7 @@ impl Args {
state,
value,
} => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
let beneficiary = if *wout {
let wout = runtime.wout(*nonce);
RgbBeneficiary::WitnessOut(wout)
Expand Down Expand Up @@ -513,7 +521,7 @@ impl Args {
}

Cmd::State { wallet, all, global, owned, contract } => {
let mut runtime = self.runtime(wallet.wallet.as_deref());
let mut runtime = self.runtime(wallet);
if wallet.sync {
let indexer = self.indexer(&wallet.resolver);
runtime.wallet.update(&indexer, false);
Expand Down Expand Up @@ -605,7 +613,7 @@ impl Args {
psbt: psbt_filename,
consignment,
} => {
let mut runtime = self.runtime(wallet.wallet.as_deref());
let mut runtime = self.runtime(wallet);
// TODO: sync wallet if needed
// TODO: Add params and giveway to arguments
let params = TxParams::with(*fee);
Expand All @@ -626,7 +634,7 @@ impl Args {
}

Cmd::Script { wallet, strategy, invoice, output } => {
let mut runtime = self.runtime(wallet.wallet.as_deref());
let mut runtime = self.runtime(wallet);
let giveaway = Some(Sats::from(500u16));
let script = runtime.script(invoice, *strategy, giveaway)?;
let file = File::create_new(output).expect("Unable to open script file");
Expand All @@ -641,7 +649,7 @@ impl Args {
psbt: psbt_filename,
print,
} => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
let src = File::open(script).expect("Unable to open script file");
let script =
serde_yaml::from_reader::<_, OpRequestSet<Option<WoutAssignment>>>(src)?;
Expand Down Expand Up @@ -670,7 +678,7 @@ impl Args {
}

Cmd::Complete { wallet, bundle, psbt: psbt_file } => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
let bundle = PrefabBundle::strict_deserialize_from_file::<{ usize::MAX }>(bundle)?;
let psbt = Psbt::decode(&mut File::open(psbt_file).expect("Unable to open PSBT"))?;

Expand All @@ -693,7 +701,7 @@ impl Args {
}

Cmd::Accept { wallet, input } => {
let mut runtime = self.runtime(wallet.as_deref());
let mut runtime = self.runtime(&WalletOpts::default_with_name(wallet));
runtime.consume_from_file(input)?;
}

Expand Down
10 changes: 10 additions & 0 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ pub struct WalletOpts {
#[clap(flatten)]
pub resolver: ResolverOpt,
}

impl WalletOpts {
pub fn default_with_name(name: &Option<String>) -> Self {
WalletOpts {
wallet: name.clone(),
sync: false,
resolver: ResolverOpt { electrum: None, esplora: None, mempool: None },
}
}
}
6 changes: 3 additions & 3 deletions examples/Transfer.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- contractId: contract:qKpMlzOe-Imn6ysZ-a8JjG2p-WHWvaFm-BWMiPi3-_LvnfRw
- contractId: contract:G2KKVrys-4zQs3fu-yGt_7dH-A~IJUVA-6TURwEs-3fZUy3E
method: transfer
reading: []
using:
- addr: L28_t0y5~n3eYz4hR40Vt3rRaH9PptXJragTHTvZTCU:0
- addr: iX33C_EhQPmp0pRj0VslnKqHTW2SJ53V5SEefJUclpE:0
outpoint: b7116550736fbe5d3e234d0141c6bc8d1825f94da78514a3cede5674e9a5eae9:1
val: 10000
global: []
owned:
- name: owned
seal: at:5WIb5EMY-RCLbO3Wq-hGdddRP4-IeCQzP1y-S5H_UKzd-ViYmlA
seal: at:FWKMBVDc-NBk8dAZA-tYGt2HIP-MtzSRO17-8g3QvRIN-nuPjug
data: 10
- name: owned
seal: null
Expand Down
2 changes: 1 addition & 1 deletion examples/data/bitcoin.testnet/alice.wallet/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ name = ""

[lastUsed]
0 = 2
1 = 68
1 = 75

[layer2]
10 changes: 9 additions & 1 deletion examples/data2/bitcoin.testnet/bob.wallet/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ headers: []
tx:
efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356:
txid: efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356
status: mempool
status: !mined
height: 58373
time: 1734446715
blockHash: 000000003e3bb07f6583add889b2ece51f9ef2c422a02ede87615f22fdadc993
inputs:
- outpoint: d0455f0a1f4f8a699d33c78967d1285102568aaad84ee347787b18271503a400:0
payer: !counterparty tb1q0dzcgv7scppjxsnwlzpkt02vlmc5rtr40wyjgr
Expand Down Expand Up @@ -139,4 +142,9 @@ addr:
used: 0
volume: 0
balance: 0
- terminal: '&1/9'
addr: tb1qld0axaw9urkyjruhel2cvpc0fmj9krkqvhcz03
used: 0
volume: 0
balance: 0
layer2: {}
4 changes: 2 additions & 2 deletions examples/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ $RGB complete -w alice examples/transfer.pfab examples/transfer.psbt || exit 1

rm examples/transfer.rgb
$RGB consign DemoToken -t "$AUTH_TOKEN" examples/transfer.rgb || exit 1
$RGB state -goa -w alice --sync --mempool

$RGB_2 accept -w bob examples/transfer.rgb || exit 1

$RGB_2 state -go -w bob
$RGB state -go -w alice
$RGB_2 state -go -w bob --sync --mempool
1 change: 0 additions & 1 deletion psbt/src/bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl RgbPsbt for Psbt {
let host = self
.insert_output(0, ScriptPubkey::op_return(&[]), Sats::ZERO)
.map_err(|_| RgbPsbtFinalizeError::Unfinalizable)?;
eprintln!("{host:?}");
host.set_opret_host().ok();
}
1 => {}
Expand Down
12 changes: 7 additions & 5 deletions src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::collections::HashMap;

use amplify::{Bytes32, Wrapper, WrapperMut};
use bpstd::dbc::tapret::TapretCommitment;
use bpstd::seals::TxoSeal;
use bpstd::seals::WTxoSeal;
use bpstd::{
Derive, DeriveCompr, DeriveKey, DeriveSet, DeriveXOnly, DerivedScript, Descriptor, KeyOrigin,
Keychain, LegacyKeySig, LegacyPk, NormalIndex, SigScript, SpkClass, StdDescr, TapDerivation,
Expand All @@ -39,14 +39,14 @@ use commit_verify::CommitVerify;
use indexmap::IndexMap;

pub trait DescriptorRgb<K = XpubDerivable, V = ()>: Descriptor<K, V> {
fn add_seal(&self, seal: TxoSeal);
fn add_seal(&self, seal: WTxoSeal);
}

#[derive(Wrapper, WrapperMut, Clone, Eq, PartialEq, Debug, Default, From)]
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))]
pub struct SealDescr(BTreeSet<TxoSeal>);
pub struct SealDescr(BTreeSet<WTxoSeal>);

impl Display for SealDescr {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -269,9 +269,11 @@ impl<K: DeriveSet> RgbDescr<K> {

pub fn noise(&self) -> Bytes32 { self.noise }

pub fn seals(&self) -> impl Iterator<Item = TxoSeal> + use<'_, K> { self.seals.iter().copied() }
pub fn seals(&self) -> impl Iterator<Item = WTxoSeal> + use<'_, K> {
self.seals.iter().copied()
}

pub fn add_seal(&mut self, seal: TxoSeal) { self.seals.insert(seal); }
pub fn add_seal(&mut self, seal: WTxoSeal) { self.seals.insert(seal); }

pub fn add_tweak(&mut self, terminal: Terminal, tweak: TapretCommitment) {
match &mut self.deriver {
Expand Down
24 changes: 15 additions & 9 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,43 @@
use std::ops::{Deref, DerefMut};

use bpstd::psbt::{ConstructionError, DbcPsbtError, TxParams};
use bpstd::seals::TxoSeal;
use bpstd::seals::{TxoSeal, WTxoSeal};
use bpstd::{Psbt, Sats};
use rgb::invoice::{RgbBeneficiary, RgbInvoice};
use rgb::popls::bp::{
Barrow, BundleError, FulfillError, IncludeError, OpRequestSet, PaymentScript, PrefabBundle,
};
use rgb::{AuthToken, ContractId, Excavate, Pile, SealAuthToken, Supply};
use rgb::{AuthToken, ContractId, Excavate, Pile, RgbSealDef, Supply};
use rgpsbt::{RgbPsbt, RgbPsbtCsvError, RgbPsbtFinalizeError, ScriptResolver};

use crate::wallet::RgbWallet;
use crate::CoinselectStrategy;

pub struct RgbRuntime<S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>>(
pub struct RgbRuntime<S: Supply, P: Pile<SealDef = WTxoSeal, SealSrc = TxoSeal>, X: Excavate<S, P>>(
Barrow<RgbWallet, S, P, X>,
);

impl<S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>> From<Barrow<RgbWallet, S, P, X>>
for RgbRuntime<S, P, X>
impl<S: Supply, P: Pile<SealDef = WTxoSeal, SealSrc = TxoSeal>, X: Excavate<S, P>>
From<Barrow<RgbWallet, S, P, X>> for RgbRuntime<S, P, X>
{
fn from(barrow: Barrow<RgbWallet, S, P, X>) -> Self { Self(barrow) }
}

impl<S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>> Deref for RgbRuntime<S, P, X> {
impl<S: Supply, P: Pile<SealDef = WTxoSeal, SealSrc = TxoSeal>, X: Excavate<S, P>> Deref
for RgbRuntime<S, P, X>
{
type Target = Barrow<RgbWallet, S, P, X>;
fn deref(&self) -> &Self::Target { &self.0 }
}
impl<S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>> DerefMut for RgbRuntime<S, P, X> {
impl<S: Supply, P: Pile<SealDef = WTxoSeal, SealSrc = TxoSeal>, X: Excavate<S, P>> DerefMut
for RgbRuntime<S, P, X>
{
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
}

impl<S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>> RgbRuntime<S, P, X> {
impl<S: Supply, P: Pile<SealDef = WTxoSeal, SealSrc = TxoSeal>, X: Excavate<S, P>>
RgbRuntime<S, P, X>
{
/// Pay an invoice producing PSBT ready to be signed.
///
/// Should not be used in multi-party protocols like coinjoins, when a PSBT may needs to be
Expand Down Expand Up @@ -190,7 +196,7 @@ pub mod file {

use super::*;

pub type RgbDirRuntime = RgbRuntime<FileSupply, FilePile<TxoSeal>, DirExcavator<TxoSeal>>;
pub type RgbDirRuntime = RgbRuntime<FileSupply, FilePile<WTxoSeal>, DirExcavator<WTxoSeal>>;

pub trait ConsignmentStream {
fn write(self, writer: impl io::Write) -> io::Result<()>;
Expand Down
Loading