From 5a0d3f48fae0998e4bb74f886f5437634318e070 Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 1 Jul 2024 18:20:56 +0800 Subject: [PATCH] collect signatures from the stash --- src/persistence/stash.rs | 9 ++++++++ src/persistence/stock.rs | 48 +++++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/persistence/stash.rs b/src/persistence/stash.rs index 242b39ca..45becb2a 100644 --- a/src/persistence/stash.rs +++ b/src/persistence/stash.rs @@ -255,6 +255,15 @@ impl Stash

{ .map_err(StashError::ReadProvider) } + pub(super) fn sigs_for( + &self, + content_id: &ContentId, + ) -> Result, StashError

> { + self.provider + .sigs_for(content_id) + .map_err(StashError::ReadProvider) + } + pub(super) fn supplement( &self, content_ref: ContentRef, diff --git a/src/persistence/stock.rs b/src/persistence/stock.rs index 67bde242..ff479cfc 100644 --- a/src/persistence/stock.rs +++ b/src/persistence/stock.rs @@ -48,9 +48,9 @@ use super::{ }; use crate::containers::{ AnchorSet, AnchoredBundles, Batch, BuilderSeal, BundledWitness, Consignment, ContainerVer, - ContentRef, Contract, Fascia, Kit, SealWitness, SupplItem, SupplSub, Terminal, TerminalSeal, - Transfer, TransitionInfo, TransitionInfoError, ValidConsignment, ValidContract, ValidKit, - ValidTransfer, VelocityHint, SUPPL_ANNOT_VELOCITY, + ContentId, ContentRef, Contract, Fascia, Kit, SealWitness, SupplItem, SupplSub, Terminal, + TerminalSeal, Transfer, TransitionInfo, TransitionInfoError, ValidConsignment, ValidContract, + ValidKit, ValidTransfer, VelocityHint, SUPPL_ANNOT_VELOCITY, }; use crate::info::{ContractInfo, IfaceInfo, SchemaInfo}; use crate::interface::resolver::DumbResolver; @@ -148,6 +148,8 @@ impl #[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)] #[display(doc_comments)] pub enum ConsignError { + /// unable to construct consignment: too many signatures provided. + TooManySignatures, /// unable to construct consignment: too many supplements provided. TooManySupplements, @@ -656,10 +658,17 @@ impl Stock { let outputs = outputs.as_ref(); let secret_seals = secret_seals.as_ref(); - // initialize supplyments with btree set + // Initialize supplements with btree set let mut supplements = bset![]; - - // get genesis supplyment by contract id + // Initialize signatures with btree map + let mut signatures = bmap! {}; + // Get genesis signature by contract id + self.stash + .sigs_for(&ContentId::Genesis(contract_id))? + .map(|genesis_sig| { + signatures.insert(ContentId::Genesis(contract_id), genesis_sig.clone()) + }); + // Get genesis supplement by contract id self.stash .supplement(ContentRef::Genesis(contract_id))? .map(|genesis_suppl| supplements.insert(genesis_suppl.clone())); @@ -743,7 +752,13 @@ impl Stock { } let genesis = self.stash.genesis(contract_id)?.clone(); - // get schema supplyment by schema id + // Get schema signature by schema id + self.stash + .sigs_for(&ContentId::Schema(genesis.schema_id))? + .map(|schema_signature| { + signatures.insert(ContentId::Schema(genesis.schema_id), schema_signature.clone()) + }); + // Get schema supplement by schema id self.stash .supplement(ContentRef::Schema(genesis.schema_id))? .map(|schema_suppl| supplements.insert(schema_suppl.clone())); @@ -752,7 +767,19 @@ impl Stock { let mut ifaces = BTreeMap::new(); for (iface_id, iimpl) in schema_ifaces.iimpls { let iface = self.stash.iface(iface_id)?; - // get iface and iimpl supplyment by iface id and iimpl id + // Get iface and iimpl signatures by iface id and iimpl id + self.stash + .sigs_for(&ContentId::Iface(iface.iface_id()))? + .map(|iface_signature| { + signatures.insert(ContentId::Iface(iface.iface_id()), iface_signature.clone()) + }); + self.stash + .sigs_for(&ContentId::IfaceImpl(iimpl.impl_id()))? + .map(|iimpl_signature| { + signatures + .insert(ContentId::IfaceImpl(iimpl.impl_id()), iimpl_signature.clone()) + }); + // Get iface and iimpl supplement by iface id and iimpl id self.stash .supplement(ContentRef::Iface(iface.iface_id()))? .map(|iface_suppl| supplements.insert(iface_suppl.clone())); @@ -786,7 +813,8 @@ impl Stock { let scripts = Confined::from_iter_unsafe(scripts.into_values()); let supplements = Confined::try_from(supplements).map_err(|_| ConsignError::TooManySupplements)?; - + let signatures = + Confined::try_from(signatures).map_err(|_| ConsignError::TooManySignatures)?; // TODO: Conceal everything we do not need // TODO: Add known sigs to the consignment @@ -802,7 +830,7 @@ impl Stock { extensions: none!(), attachments: none!(), - signatures: none!(), // TODO: Collect signatures + signatures, supplements, types, scripts,