From 0f2632494d59cfdf8b4b40ee7a13ce6572d5c291 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 14 Nov 2023 15:10:02 +0100 Subject: [PATCH] iface: add AllocationWitness type --- src/interface/contract.rs | 21 +++++++++++++++++++-- src/interface/mod.rs | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/interface/contract.rs b/src/interface/contract.rs index f9e6f1a0..73da76d4 100644 --- a/src/interface/contract.rs +++ b/src/interface/contract.rs @@ -74,11 +74,28 @@ impl From for AttachedState { } } +#[derive(Copy, Clone, Eq, PartialEq, Debug, Display)] +pub enum AllocationWitness { + #[display("~")] + Absent, + #[display(inner)] + Present(WitnessId), +} + +impl From> for AllocationWitness { + fn from(value: Option) -> Self { + match value { + None => AllocationWitness::Absent, + Some(id) => AllocationWitness::Present(id), + } + } +} + // TODO: Consider removing type in favour of `FungibleOutput` #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub struct FungibleAllocation { pub owner: Output, - pub witness: Option, + pub witness: AllocationWitness, pub value: u64, } @@ -90,7 +107,7 @@ impl From<&FungibleOutput> for FungibleAllocation { fn from(out: &FungibleOutput) -> Self { FungibleAllocation { owner: out.output, - witness: out.witness, + witness: out.witness.into(), value: out.state.value.as_u64(), } } diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 362e9ce0..8ec4554a 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -34,8 +34,8 @@ mod suppl; pub use builder::{BuilderError, ContractBuilder, TransitionBuilder}; pub use contract::{ - ContractIface, FilterExclude, FilterIncludeAll, FungibleAllocation, IfaceWrapper, - OutpointFilter, TypedState, + AllocationWitness, ContractIface, FilterExclude, FilterIncludeAll, FungibleAllocation, + IfaceWrapper, OutpointFilter, TypedState, }; pub use iface::{ ArgMap, ArgSpec, AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceId,