Skip to content

Commit

Permalink
wip on PSBT changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 15, 2023
1 parent db31a8e commit 98706a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
24 changes: 7 additions & 17 deletions psbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod rgb;
use std::collections::HashMap;

use bpstd::secp256k1::serde::{Deserialize, Serialize};
use psbt::Psbt;
use rgbstd::{AnchoredBundle, ContractId, Outpoint, Transition};
use rgbstd::containers::{Batch, Fascia};
use rgbstd::{ContractId, Outpoint};

/// A batch of state transitions under different contracts which are associated
/// with some specific transfer and will be anchored within a single layer 1
/// transaction.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct Batch {
pub transitions: Vec<Transition>,
}

/// Structure exported from a PSBT for merging into the stash. It contains a set
/// of finalized state transitions, packed into bundles, and anchored to a
/// single layer 1 transaction.
#[derive(Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct Fascia {
pub bundles: Vec<AnchoredBundle>,
}
pub use self::rgb::{
ProprietaryKeyRgb, RgbExt, RgbInExt, RgbOutExt, RgbPsbtError, PSBT_GLOBAL_RGB_TRANSITION,
PSBT_IN_RGB_CONSUMED_BY, PSBT_OUT_RGB_VELOCITY_HINT, PSBT_RGB_PREFIX,
};

pub enum EmbedError {}
pub enum ExtractError {}
Expand Down
24 changes: 10 additions & 14 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use std::convert::Infallible;
use std::iter;

use bp::seals::txout::CloseMethod;
use bp::{Sats, Vout};
use bpwallet::{Invoice, PsbtMeta, TxParams};
use bp::Sats;
use bpwallet::{PsbtMeta, TxParams};
use psbt::Psbt;
use rgbstd::containers::{Bindle, BuilderSeal, Transfer};
use rgbstd::interface::{BuilderError, ContractSuppl, FilterIncludeAll, TypedState, VelocityHint};
use rgbstd::interface::{BuilderError, FilterIncludeAll};
use rgbstd::invoice::{Beneficiary, InvoiceState, RgbInvoice};
use rgbstd::persistence::{ConsignerError, Inventory, InventoryError, Stash};
use rgbstd::{
AssignmentType, ContractId, GraphSeal, Operation, Opout, SealDefinition,
RGB_NATIVE_DERIVATION_INDEX, RGB_TAPRET_DERIVATION_INDEX,
};

use crate::Runtime;

Expand Down Expand Up @@ -78,7 +72,7 @@ pub enum PayError {
Consigner(ConsignerError<Infallible, Infallible>),
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[derive(Clone, PartialEq, Debug)]
pub struct TransferParams {
pub tx: TxParams,
pub min_amount: Sats,
Expand Down Expand Up @@ -142,11 +136,13 @@ impl Runtime {
}
_ => return Err(PayError::Unsupported),
};
let inv = match invoice.beneficiary {
Beneficiary::BlindedSeal(_) => Invoice::with_max(self.wallet().next_address()),
Beneficiary::WitnessVoutBitcoin(addr) => Invoice::new(addr, params.min_amount),
let beneficiary = match invoice.beneficiary {
Beneficiary::BlindedSeal(_) => Beneficiary::with_max(self.wallet().next_address()),
Beneficiary::WitnessVoutBitcoin(addr) => Beneficiary::new(addr, params.min_amount),
};
let (mut psbt, meta) = self.wallet().construct_psbt(&outputs, inv, params.tx)?;
let (mut psbt, meta) = self
.wallet()
.construct_psbt(&outputs, beneficiary, params.tx)?;

let batch =
self.compose(&invoice, outputs, method, meta.change_vout, |_, _, _| meta.change_vout)?;
Expand Down

0 comments on commit 98706a6

Please sign in to comment.