From 09eabe169c4f2dc50b70f9ec9494d153f14f9df9 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 5 Jul 2024 10:37:08 +0200 Subject: [PATCH] containers: automatically use ConsignmentResolver --- Cargo.lock | 3 +-- Cargo.toml | 3 +++ src/containers/consignment.rs | 8 ++++++-- src/resolvers.rs | 12 ++---------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1ed51e3..5ef01a10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,8 +663,7 @@ dependencies = [ [[package]] name = "rgb-core" version = "0.11.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd852c74f2b91711ef730a4aa5149442e2488425b3db811c6a55b72eb6db41d4" +source = "git+https://github.com/RGB-WG/rgb-core?branch=resolvers#b6657a434df9db2882cc50aeb1f40f8e1c138654" dependencies = [ "aluvm", "amplify", diff --git a/Cargo.toml b/Cargo.toml index 5c113d8f..98618cc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/containers/consignment.rs b/src/containers/consignment.rs index c31b7c6e..baab7f4f 100644 --- a/src/containers/consignment.rs +++ b/src/containers/consignment.rs @@ -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; @@ -349,7 +349,11 @@ impl Consignment { testnet: bool, ) -> Result, (validation::Status, Consignment)> { 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(); diff --git a/src/resolvers.rs b/src/resolvers.rs index e94286e2..eb560d65 100644 --- a/src/resolvers.rs +++ b/src/resolvers.rs @@ -28,20 +28,12 @@ pub trait ResolveHeight { fn resolve_height(&mut self, witness_id: XWitnessId) -> Result; } -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 { - 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(