Skip to content

Commit

Permalink
chore: update to refactored witness-related types in RGB Core
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 30, 2024
1 parent a2ff52c commit f0a85cd
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ features = ["all"]
[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "master" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std.git", branch = "master" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "mining" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "movearound" }
8 changes: 7 additions & 1 deletion src/containers/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use super::{
ASCII_ARMOR_SCHEMA, ASCII_ARMOR_TERMINAL, ASCII_ARMOR_VERSION,
};
use crate::interface::{Iface, IfaceImpl};
use crate::persistence::MemContract;
use crate::resolvers::ConsignmentResolver;
use crate::{BundleExt, SecretSeal, LIB_NAME_RGB_STD};

Expand Down Expand Up @@ -348,7 +349,12 @@ impl<const TRANSFER: bool> Consignment<TRANSFER> {
consignment: &index,
fallback: resolver,
};
let mut status = Validator::validate(&index, &resolver, testnet);
let mut status = Validator::<MemContract, _, _>::validate(
&index,
&resolver,
testnet,
(&self.schema, self.contract_id()),
);

let validity = status.validity();

Expand Down
21 changes: 4 additions & 17 deletions src/containers/indexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@
use std::collections::{BTreeMap, BTreeSet};
use std::ops::Deref;

use amplify::confinement::Collection;
use commit_verify::Conceal;
use rgb::validation::{ConsignmentApi, EAnchor, Scripts};
use rgb::vm::OpRef;
use rgb::{
BundleId, Extension, Genesis, OpId, OpRef, Operation, Schema, Transition, TransitionBundle,
XChain, XWitnessId,
BundleId, Extension, Genesis, OpId, Operation, Schema, Transition, TransitionBundle, XWitnessId,
};
use strict_types::TypeSystem;

use super::{Consignment, XPubWitness};
use crate::containers::anchors::ToWitnessId;
use crate::SecretSeal;

// TODO: Transform consignment into this type instead of composing over it
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -122,22 +119,12 @@ impl<'c, const TRANSFER: bool> ConsignmentApi for IndexedConsignment<'c, TRANSFE
return Some(OpRef::Genesis(&self.genesis));
}
self.transition(opid)
.map(OpRef::from)
.or_else(|| self.extension(opid).map(OpRef::from))
.map(OpRef::Transition)
.or_else(|| self.extension(opid).map(OpRef::Extension))
}

fn genesis(&self) -> &Genesis { &self.genesis }

fn terminals<'iter>(&self) -> impl Iterator<Item = (BundleId, XChain<SecretSeal>)> + 'iter {
let mut set = BTreeSet::new();
for (bundle_id, terminal) in &self.terminals {
for seal in &terminal.seals {
set.push((*bundle_id, seal.conceal()));
}
}
set.into_iter()
}

fn bundle_ids<'iter>(&self) -> impl Iterator<Item = BundleId> + 'iter {
self.bundle_idx
.keys()
Expand Down
16 changes: 7 additions & 9 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ use std::fmt::Debug;
use amplify::confinement::SmallVec;
use commit_verify::Conceal;
use invoice::Amount;
use rgb::vm::AssignmentWitness;
use rgb::vm::TxOrd;
use rgb::{
Assign, AssignAttach, AssignData, AssignFungible, AssignRights, AssignmentType, AttachState,
DataState, ExposedSeal, ExposedState, OpId, Opout, RevealedAttach, RevealedData, RevealedValue,
TypedAssigns, VoidState, WitnessOrd, XChain, XOutputSeal, XWitnessId,
TypedAssigns, VoidState, XChain, XOutputSeal, XWitnessId,
};
use strict_encoding::{StrictDecode, StrictDumb, StrictEncode};

Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct OutputAssignment<State: KnownState> {
pub opout: Opout,
pub seal: XOutputSeal,
pub state: State,
pub witness: AssignmentWitness,
pub witness: Option<XWitnessId>,
}

impl<State: KnownState> PartialEq for OutputAssignment<State> {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<State: KnownState> OutputAssignment<State> {
information since it comes from genesis or extension",
),
state,
witness: AssignmentWitness::Absent,
witness: None,
}
}

Expand All @@ -153,12 +153,10 @@ impl<State: KnownState> OutputAssignment<State> {
}
}

pub fn check_witness(&self, filter: &HashMap<XWitnessId, WitnessOrd>) -> bool {
pub fn check_witness(&self, filter: &HashMap<XWitnessId, TxOrd>) -> bool {
match self.witness {
AssignmentWitness::Absent => true,
AssignmentWitness::Present(witness_id) => {
!matches!(filter.get(&witness_id), None | Some(WitnessOrd::Archived))
}
None => true,
Some(witness_id) => !matches!(filter.get(&witness_id), None | Some(TxOrd::Archived)),
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ mod merge_reveal;
pub use assignments::{KnownState, OutputAssignment, TypedAssignsExt};
pub use bundle::{BundleExt, RevealError};
pub use merge_reveal::{MergeReveal, MergeRevealError};
use rgb::vm::AssignmentWitness;
use rgb::OpId;
use rgb::{OpId, XWitnessId};

use crate::LIB_NAME_RGB_STD;

Expand All @@ -40,9 +39,9 @@ use crate::LIB_NAME_RGB_STD;
pub struct OpEl {
pub op: OpId,
pub no: u16,
pub witness: AssignmentWitness,
pub witness: Option<XWitnessId>,
}

impl OpEl {
pub fn new(op: OpId, no: u16, witness: AssignmentWitness) -> OpEl { OpEl { op, no, witness } }
pub fn new(op: OpId, no: u16, witness: Option<XWitnessId>) -> OpEl { OpEl { op, no, witness } }
}
5 changes: 2 additions & 3 deletions src/interface/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::collections::HashMap;

use amplify::confinement::SmallOrdSet;
use invoice::{Allocation, Amount};
use rgb::vm::AssignmentWitness;
use rgb::{
AttachState, ContractId, DataState, OpId, RevealedAttach, RevealedData, RevealedValue, Schema,
VoidState, XOutpoint, XOutputSeal, XWitnessId,
Expand Down Expand Up @@ -396,7 +395,7 @@ impl<S: ContractStateRead> ContractIface<S> {
let spent = f::<_, C::State>(state).map(OutputAssignment::from);
let mut ops = HashMap::<XWitnessId, IfaceOp<C>>::new();
for alloc in spent {
let AssignmentWitness::Present(witness_id) = alloc.witness else {
let Some(witness_id) = alloc.witness else {
continue;
};
if let Some(op) = ops.get_mut(&witness_id) {
Expand All @@ -407,7 +406,7 @@ impl<S: ContractStateRead> ContractIface<S> {
}

for alloc in allocations {
let AssignmentWitness::Present(witness_id) = alloc.witness else {
let Some(witness_id) = alloc.witness else {
continue;
};
if let Some(op) = ops.get_mut(&witness_id) {
Expand Down
10 changes: 3 additions & 7 deletions src/interface/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
// limitations under the License.

use rgb::validation::{ResolveWitness, WitnessResolverError};
use rgb::vm::WitnessAnchor;
use rgb::XWitnessTx;
use rgb::vm::{TxOrd, XWitnessTx};
use strict_encoding::StrictDumb;

use crate::resolvers::ResolveWitnessAnchor;
use crate::XWitnessId;

pub(crate) struct DumbResolver;
Expand All @@ -33,10 +31,8 @@ impl ResolveWitness for DumbResolver {
fn resolve_pub_witness(&self, _: XWitnessId) -> Result<XWitnessTx, WitnessResolverError> {
Ok(XWitnessTx::strict_dumb())
}
}

impl ResolveWitnessAnchor for DumbResolver {
fn resolve_witness_anchor(&mut self, _: XWitnessId) -> Result<WitnessAnchor, String> {
Ok(WitnessAnchor::strict_dumb())
fn resolve_pub_witness_ord(&self, _: XWitnessId) -> Result<TxOrd, WitnessResolverError> {
Ok(TxOrd::strict_dumb())
}
}
Loading

0 comments on commit f0a85cd

Please sign in to comment.