Skip to content

Commit

Permalink
containers: automatically use ConsignmentResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 5, 2024
1 parent a8ca960 commit 09eabe1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "resolvers" }
8 changes: 6 additions & 2 deletions src/containers/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use super::{
};
use crate::containers::anchors::ToWitnessId;
use crate::interface::{Iface, IfaceImpl};
use crate::resolvers::ResolveHeight;
use crate::resolvers::{ConsignmentResolver, ResolveHeight};
use crate::{BundleExt, SecretSeal, LIB_NAME_RGB_STD};

pub type Transfer = Consignment<true>;
Expand Down Expand Up @@ -349,7 +349,11 @@ impl<const TRANSFER: bool> Consignment<TRANSFER> {
testnet: bool,
) -> Result<ValidConsignment<TRANSFER>, (validation::Status, Consignment<TRANSFER>)> {
let index = IndexedConsignment::new(&self);
let mut status = Validator::validate(&index, resolver, testnet);
let resolver = ConsignmentResolver {
consignment: &index,
fallback: resolver,
};
let mut status = Validator::validate(&index, &resolver, testnet);

let validity = status.validity();

Expand Down
12 changes: 2 additions & 10 deletions src/resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,12 @@ pub trait ResolveHeight {
fn resolve_height(&mut self, witness_id: XWitnessId) -> Result<WitnessAnchor, String>;
}

pub struct ConsignmentResolver<'cons, R: ResolveWitness + ResolveHeight, const TRANSFER: bool> {
pub(crate) struct ConsignmentResolver<'cons, R: ResolveWitness, const TRANSFER: bool> {
pub consignment: &'cons IndexedConsignment<'cons, TRANSFER>,
pub fallback: R,
}

impl<'cons, R: ResolveWitness + ResolveHeight, const TRANSFER: bool> ResolveHeight
for ConsignmentResolver<'cons, R, TRANSFER>
{
fn resolve_height(&mut self, witness_id: XWitnessId) -> Result<WitnessAnchor, String> {
self.fallback.resolve_height(witness_id)
}
}

impl<'cons, R: ResolveWitness + ResolveHeight, const TRANSFER: bool> ResolveWitness
impl<'cons, R: ResolveWitness, const TRANSFER: bool> ResolveWitness
for ConsignmentResolver<'cons, R, TRANSFER>
{
fn resolve_pub_witness(
Expand Down

0 comments on commit 09eabe1

Please sign in to comment.