lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit bce54e685b87af3c9f8e3ffba99114488ff2b27b
parent c79337d8851ee6da0b18aa7d7e97bc5b83d537ce
Author: triesap <tyson@radroots.org>
Date:   Sun, 25 Oct 2026 06:53:13 +0000

storage: retain authenticated observed listing heads

- Preserve original bounded signed revisions and historical bytes.
- Select protected observed heads before profile interpretation.
- Bind current access and independently acknowledged source progress.
- Verify retained formats, atomic failures and provider races.

Diffstat:
Mcontracts/api_baselines/radroots_storage.txt | 9+++++++++
Mcontracts/api_baselines/radroots_storage_sqlite.txt | 33+++++++++++++++++++++++++++++++++
Mcontracts/architecture/decisions/shared_sdk_refactor.v1.json | 25++++++++++++++++++++++---
Mcrates/storage/src/workspace/seller_stock.rs | 2+-
Mcrates/storage/src/workspace/seller_stock/source.rs | 33+++++++++++++++++++++++++++++++++
Mcrates/storage_sqlite/Cargo.toml | 2+-
Mcrates/storage_sqlite/src/workspace/crypto.rs | 28++++++++++++++++++++++------
Mcrates/storage_sqlite/src/workspace/mod.rs | 3++-
Mcrates/storage_sqlite/src/workspace/stock.rs | 136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mcrates/storage_sqlite/src/workspace/stock/consent.rs | 6+++---
Mcrates/storage_sqlite/src/workspace/stock/consent/test_provider.rs | 2+-
Mcrates/storage_sqlite/src/workspace/stock/consent/tests.rs | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mcrates/storage_sqlite/src/workspace/stock/grants.rs | 2+-
Mcrates/storage_sqlite/src/workspace/stock/inventory.rs | 4++--
Mcrates/storage_sqlite/src/workspace/stock/inventory/checkpoint.rs | 6+++---
Mcrates/storage_sqlite/src/workspace/stock/inventory/codec.rs | 4++--
Mcrates/storage_sqlite/src/workspace/stock/inventory/mapping.rs | 2+-
Mcrates/storage_sqlite/src/workspace/stock/inventory/plan.rs | 2+-
Acrates/storage_sqlite/src/workspace/stock/public_source.rs | 250+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/src/workspace/stock/public_source/checkpoint.rs | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/src/workspace/stock/public_source/record.rs | 477+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/src/workspace/stock/public_source/test_provider.rs | 321+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/src/workspace/stock/public_source/tests.rs | 966+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/src/workspace/stock/public_source/transaction.rs | 482+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrates/storage_sqlite/src/workspace/stock/schema.rs | 28+++++++++++++++++++++++-----
Mcrates/storage_sqlite/src/workspace/stock/source/transaction.rs | 2+-
Mcrates/storage_sqlite/src/workspace/stock/tests.rs | 33++++++++++++++++++++++-----------
Mcrates/storage_sqlite/src/workspace/worker.rs | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/tests/fixtures/stock_public_sources.v1.json | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/storage_sqlite/tests/fixtures/stock_public_sources.v1.provenance.json | 11+++++++++++
Mcrates/storage_sqlite/tests/support/stock_authority.rs | 2+-
Mtools/xtask/src/architecture/decision_package.rs | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
32 files changed, 3444 insertions(+), 71 deletions(-)

diff --git a/contracts/api_baselines/radroots_storage.txt b/contracts/api_baselines/radroots_storage.txt @@ -2439,6 +2439,15 @@ impl serde_core::ser::Serialize for radroots_storage::workspace::seller_stock::S pub fn radroots_storage::workspace::seller_stock::StockGrantScope::serialize<S: serde_core::ser::Serializer>(&self, S) -> core::result::Result<<S as serde_core::ser::Serializer>::Ok, <S as serde_core::ser::Serializer>::Error> impl<'de> serde_core::de::Deserialize<'de> for radroots_storage::workspace::seller_stock::StockGrantScope pub fn radroots_storage::workspace::seller_stock::StockGrantScope::deserialize<D: serde_core::de::Deserializer<'de>>(D) -> core::result::Result<Self, <D as serde_core::de::Deserializer>::Error> +pub struct radroots_storage::workspace::seller_stock::StockListingCheckpointRef(_) +impl radroots_storage::workspace::seller_stock::StockListingCheckpointRef +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::authority(self) -> radroots_domain::context::AuthorityRef +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::authorization(self) -> core::option::Option<radroots_storage::workspace::seller_stock::StockAuthorizationRef> +pub fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::from_host_metadata(radroots_domain::context::AuthorityRef, radroots_domain::context::Sequence, core::option::Option<radroots_domain::identifier::CheckpointDigest>) -> core::result::Result<Self, radroots_storage::workspace::WorkspaceError> +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::head(self) -> core::option::Option<radroots_domain::identifier::CheckpointDigest> +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::revision(self) -> radroots_domain::context::Sequence +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::with_authorization(self, radroots_storage::workspace::seller_stock::StockAuthorizationRef) -> Self +pub const fn radroots_storage::workspace::seller_stock::StockListingCheckpointRef::with_optional_authorization(self, core::option::Option<radroots_storage::workspace::seller_stock::StockAuthorizationRef>) -> Self pub struct radroots_storage::workspace::seller_stock::StockResources(_) impl radroots_storage::workspace::seller_stock::StockResources pub const fn radroots_storage::workspace::seller_stock::StockResources::all_pools() -> Self diff --git a/contracts/api_baselines/radroots_storage_sqlite.txt b/contracts/api_baselines/radroots_storage_sqlite.txt @@ -381,6 +381,11 @@ pub radroots_storage_sqlite::workspace::StockConsentOutcome::Unknown::transactio pub enum radroots_storage_sqlite::workspace::StockGrantOutcome pub radroots_storage_sqlite::workspace::StockGrantOutcome::Committed(radroots_storage_sqlite::workspace::StockGrantReceipt) pub radroots_storage_sqlite::workspace::StockGrantOutcome::Unknown(radroots_domain::identifier::TransactionId) +pub enum radroots_storage_sqlite::workspace::StockListingOutcome +pub radroots_storage_sqlite::workspace::StockListingOutcome::Committed(alloc::boxed::Box<radroots_storage_sqlite::workspace::StockListingReceipt>) +pub radroots_storage_sqlite::workspace::StockListingOutcome::Unknown +pub radroots_storage_sqlite::workspace::StockListingOutcome::Unknown::listing: radroots_domain::listing::reference::ListingRevision +pub radroots_storage_sqlite::workspace::StockListingOutcome::Unknown::transaction: radroots_domain::identifier::TransactionId pub enum radroots_storage_sqlite::workspace::StockSourceOutcome pub radroots_storage_sqlite::workspace::StockSourceOutcome::Committed(radroots_storage_sqlite::workspace::StockSourceReceipt) pub radroots_storage_sqlite::workspace::StockSourceOutcome::Unknown @@ -408,6 +413,10 @@ impl radroots_storage_sqlite::workspace::NativeWorkspace pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::issue_stock_consent(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, &radroots_storage_sqlite::workspace::StockConsentCapture, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockConsentOutcome, radroots_storage::command::OperationError> pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_consent(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, radroots_domain::identifier::GrantId, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockConsentReceipt>, radroots_storage::command::OperationError> impl radroots_storage_sqlite::workspace::NativeWorkspace +pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::retain_stock_listing(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef, &radroots_storage_sqlite::workspace::StockListingCapture, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockListingOutcome, radroots_storage::command::OperationError> +pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_listing_head(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef, radroots_domain::listing::reference::ListingCoordinate, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockListingSnapshot>, radroots_storage::command::OperationError> +pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_listing_source(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef, radroots_domain::listing::reference::ListingRevision, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockListingSnapshot>, radroots_storage::command::OperationError> +impl radroots_storage_sqlite::workspace::NativeWorkspace pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::retain_stock_source(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::workspace::seller_stock::source::StockSourceCheckpointRef, &radroots_storage_sqlite::workspace::StockSourceCapture, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockSourceOutcome, radroots_storage::command::OperationError> pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_source(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::workspace::seller_stock::source::StockSourceCheckpointRef, radroots_domain::identifier::EnvelopeEventId, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockSourceSnapshot>, radroots_storage::command::OperationError> impl core::fmt::Debug for radroots_storage_sqlite::workspace::NativeWorkspace @@ -440,6 +449,7 @@ pub struct radroots_storage_sqlite::workspace::StockAuthorityReceipt impl radroots_storage_sqlite::workspace::StockAuthorityReceipt pub fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::input(&self) -> &radroots_storage::workspace::AttachmentInput pub const fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::inventory_checkpoint(&self) -> core::option::Option<radroots_storage::inventory::InventoryCheckpointRef> +pub const fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::listing_checkpoint(&self) -> core::option::Option<radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef> pub const fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::revocation_generation(&self) -> radroots_domain::context::Sequence pub const fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::source_checkpoint(&self) -> core::option::Option<radroots_storage::workspace::seller_stock::source::StockSourceCheckpointRef> pub const fn radroots_storage_sqlite::workspace::StockAuthorityReceipt::transaction_id(&self) -> radroots_domain::identifier::TransactionId @@ -488,6 +498,29 @@ impl radroots_storage_sqlite::workspace::StockGrantReceipt pub const fn radroots_storage_sqlite::workspace::StockGrantReceipt::authorization(&self) -> radroots_storage::workspace::seller_stock::authorization::StockAuthorizationRef pub const fn radroots_storage_sqlite::workspace::StockGrantReceipt::grant_id(&self) -> radroots_domain::identifier::GrantId pub const fn radroots_storage_sqlite::workspace::StockGrantReceipt::transaction_id(&self) -> radroots_domain::identifier::TransactionId +pub struct radroots_storage_sqlite::workspace::StockListingCapture +impl radroots_storage_sqlite::workspace::StockListingCapture +pub const fn radroots_storage_sqlite::workspace::StockListingCapture::listing_revision(&self) -> radroots_domain::listing::reference::ListingRevision +pub fn radroots_storage_sqlite::workspace::StockListingCapture::prepare(radroots_storage::workspace::seller_stock::selection::SellerAuthoritySelection, &radroots_nostr::public_ingress::ObservedHead) -> core::result::Result<Self, radroots_storage::workspace::WorkspaceError> +pub const fn radroots_storage_sqlite::workspace::StockListingCapture::transaction_id(&self) -> radroots_domain::identifier::TransactionId +impl core::fmt::Debug for radroots_storage_sqlite::workspace::StockListingCapture +pub fn radroots_storage_sqlite::workspace::StockListingCapture::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result +pub struct radroots_storage_sqlite::workspace::StockListingReceipt +impl radroots_storage_sqlite::workspace::StockListingReceipt +pub const fn radroots_storage_sqlite::workspace::StockListingReceipt::checkpoint(&self) -> radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef +pub const fn radroots_storage_sqlite::workspace::StockListingReceipt::listing_revision(&self) -> radroots_domain::listing::reference::ListingRevision +pub const fn radroots_storage_sqlite::workspace::StockListingReceipt::selected_at_retention(&self) -> bool +pub const fn radroots_storage_sqlite::workspace::StockListingReceipt::transaction_id(&self) -> radroots_domain::identifier::TransactionId +pub struct radroots_storage_sqlite::workspace::StockListingSnapshot +impl radroots_storage_sqlite::workspace::StockListingSnapshot +pub fn radroots_storage_sqlite::workspace::StockListingSnapshot::interpret_at_observation(&self) -> core::result::Result<radroots_nostr::public_ingress::Interpretation, radroots_storage::command::OperationError> +pub const fn radroots_storage_sqlite::workspace::StockListingSnapshot::is_current_observed(&self) -> bool +pub const fn radroots_storage_sqlite::workspace::StockListingSnapshot::observed_at(&self) -> radroots_domain::context::UnixSeconds +pub fn radroots_storage_sqlite::workspace::StockListingSnapshot::raw_json(&self) -> &str +pub const fn radroots_storage_sqlite::workspace::StockListingSnapshot::receipt(&self) -> &radroots_storage_sqlite::workspace::StockListingReceipt +pub const fn radroots_storage_sqlite::workspace::StockListingSnapshot::selection_checkpoint(&self) -> radroots_storage::workspace::seller_stock::source::StockListingCheckpointRef +impl core::fmt::Debug for radroots_storage_sqlite::workspace::StockListingSnapshot +pub fn radroots_storage_sqlite::workspace::StockListingSnapshot::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub struct radroots_storage_sqlite::workspace::StockSourceCapture impl radroots_storage_sqlite::workspace::StockSourceCapture pub const fn radroots_storage_sqlite::workspace::StockSourceCapture::envelope_id(&self) -> radroots_domain::identifier::EnvelopeEventId diff --git a/contracts/architecture/decisions/shared_sdk_refactor.v1.json b/contracts/architecture/decisions/shared_sdk_refactor.v1.json @@ -75,7 +75,7 @@ "scope": "seller_stock_owner", "database": "stock_execution_v1.sqlite", "lock": ".stock_execution_v1.lock", - "schema_version": 7, + "schema_version": 8, "retained_enrollment_versions": [ 1 ], @@ -84,9 +84,28 @@ 3, 4, 5, - 6 + 6, + 7 ], - "authority_payload_schema": "radroots.seller_stock.authority.v7", + "authority_payload_schema": "radroots.seller_stock.authority.v8", + "public_source_payload_schemas": [ + "radroots.seller_stock.public_source_event.v1", + "radroots.seller_stock.public_source_head.v1", + "radroots.seller_stock.public_source_part.v1" + ], + "public_source_owner_administration_required": true, + "inventory_scope_grants_public_source_access": false, + "public_source_checkpoint_independent": true, + "public_source_input_requires_signature_evidence": true, + "public_source_read_reverifies_signature": true, + "public_source_global_completeness_claimed": false, + "public_source_profile_implies_actionability": false, + "public_source_head_policy": "nip01_timestamp_then_lowest_id_before_profile", + "public_source_duplicate_encodings": "retain_original_authenticated_event_id", + "public_source_raw_max_bytes": 65536, + "public_source_part_max_bytes": 16384, + "public_source_part_max_count": 4, + "public_source_worker_charge_bytes": 262144, "inventory_operation_payload_schema": "radroots.seller_stock.operation.v5", "operation_part_payload_schema": "radroots.seller_stock.operation_part.v1", "operation_body_max_bytes": 262144, diff --git a/crates/storage/src/workspace/seller_stock.rs b/crates/storage/src/workspace/seller_stock.rs @@ -15,7 +15,7 @@ pub use selection::{SellerAuthoritySelection, StockCapabilityContract}; mod permissions; pub use permissions::{StockAction, StockGrantScope, StockResources}; mod source; -pub use source::StockSourceCheckpointRef; +pub use source::{StockListingCheckpointRef, StockSourceCheckpointRef}; /// Explicit local enrollment inputs, supplied by a trusted host interaction. /// Only a qualified stock host may persist the resulting authority. pub struct SellerStockConfig { diff --git a/crates/storage/src/workspace/seller_stock/source.rs b/crates/storage/src/workspace/seller_stock/source.rs @@ -50,3 +50,36 @@ impl StockSourceCheckpointRef { self } } + +/// Independently retained public-listing observation progress. This metadata +/// proves neither a global current head nor permission to request or accept. +/// Its distinct type prevents accidentally passing private-record progress. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct StockListingCheckpointRef(StockSourceCheckpointRef); +impl StockListingCheckpointRef { + pub fn from_host_metadata( + authority: AuthorityRef, + revision: Sequence, + head: Option<CheckpointDigest>, + ) -> Result<Self, WorkspaceError> { + StockSourceCheckpointRef::from_host_metadata(authority, revision, head).map(Self) + } + pub const fn authority(self) -> AuthorityRef { + self.0.authority() + } + pub const fn revision(self) -> Sequence { + self.0.revision() + } + pub const fn head(self) -> Option<CheckpointDigest> { + self.0.head() + } + pub const fn authorization(self) -> Option<StockAuthorizationRef> { + self.0.authorization() + } + pub const fn with_authorization(self, state: StockAuthorizationRef) -> Self { + Self(self.0.with_authorization(state)) + } + pub const fn with_optional_authorization(self, state: Option<StockAuthorizationRef>) -> Self { + Self(self.0.with_optional_authorization(state)) + } +} diff --git a/crates/storage_sqlite/Cargo.toml b/crates/storage_sqlite/Cargo.toml @@ -42,7 +42,7 @@ radroots_event_codec = { workspace = true, default-features = false, features = "json", "std", ] } -radroots_nostr = { workspace = true, default-features = false, features = ["commerce"] } +radroots_nostr = { workspace = true, default-features = false, features = ["commerce", "public_ingress"] } radroots_protocol = { workspace = true, default-features = false, features = ["commerce"] } radroots_secrets = { workspace = true, default-features = false } radroots_storage = { workspace = true, default-features = false, features = [ diff --git a/crates/storage_sqlite/src/workspace/crypto.rs b/crates/storage_sqlite/src/workspace/crypto.rs @@ -709,7 +709,7 @@ fn stock_root_context( input: &super::AttachmentInput, version: i64, ) -> Result<EnvelopeContext, WorkspaceError> { - if matches!(version, 4..=7) { + if matches!(version, 4..=8) { use sha2::{Digest, Sha256}; let namespace = radroots_storage::workspace::seller_stock::SellerAuthoritySelection::from_attachment( @@ -728,8 +728,10 @@ fn stock_root_context( b"radroots.seller_stock.authority_context.v5\0" } else if version == 6 { b"radroots.seller_stock.authority_context.v6\0" - } else { + } else if version == 7 { b"radroots.seller_stock.authority_context.v7\0" + } else { + b"radroots.seller_stock.authority_context.v8\0" }); hash.update(wire.as_slice()); let subject = radroots_domain::CommandDigest::from_bytes(hash.finalize().into()); @@ -744,8 +746,10 @@ fn stock_root_context( "radroots.seller_stock.authority.v5" } else if version == 6 { "radroots.seller_stock.authority.v6" - } else { + } else if version == 7 { "radroots.seller_stock.authority.v7" + } else { + "radroots.seller_stock.authority.v8" }) .map_err(|_| WorkspaceError::InvalidInput)?, )); @@ -782,6 +786,18 @@ fn stock_record_context( "radroots.seller_stock.source_record", "radroots.seller_stock.source_record.v1", ), + "public_event" => ( + "radroots.seller_stock.public_source_event", + "radroots.seller_stock.public_source_event.v1", + ), + "public_head" => ( + "radroots.seller_stock.public_source_head", + "radroots.seller_stock.public_source_head.v1", + ), + "public_part" => ( + "radroots.seller_stock.public_source_part", + "radroots.seller_stock.public_source_part.v1", + ), "operation_part" => ( "radroots.seller_stock.operation_part", "radroots.seller_stock.operation_part.v1", @@ -835,12 +851,12 @@ fn stock_record_context_for_catalog( ) -> Result<EnvelopeContext, WorkspaceError> { let original = stock_record_context(input, kind, id)?; let schema = match (catalog, kind) { - (2, _) | (3..=7, "pool") => return Ok(original), + (2, _) | (3..=8, "pool") => return Ok(original), (3, "operation") => "radroots.seller_stock.operation.v2", (4, "operation") => "radroots.seller_stock.operation.v3", (5 | 6, "operation") => "radroots.seller_stock.operation.v4", - (7, "operation") => "radroots.seller_stock.operation.v5", - (3..=7, "movement") => "radroots.seller_stock.movement.v2", + (7 | 8, "operation") => "radroots.seller_stock.operation.v5", + (3..=8, "movement") => "radroots.seller_stock.movement.v2", _ => return Err(WorkspaceError::RecoveryRequired), }; Ok(EnvelopeContext::new( diff --git a/crates/storage_sqlite/src/workspace/mod.rs b/crates/storage_sqlite/src/workspace/mod.rs @@ -25,7 +25,8 @@ mod stock; pub use stock::{ SellerStockConfig, StockAuthorityReceipt, StockConsentCapture, StockConsentMode, StockConsentOutcome, StockConsentReceipt, StockEnrollment, StockGrantEnrollment, - StockGrantOutcome, StockGrantReceipt, StockSourceCapture, StockSourceOutcome, + StockGrantOutcome, StockGrantReceipt, StockListingCapture, StockListingOutcome, + StockListingReceipt, StockListingSnapshot, StockSourceCapture, StockSourceOutcome, StockSourceProfile, StockSourceReceipt, StockSourceSnapshot, }; mod worker; diff --git a/crates/storage_sqlite/src/workspace/stock.rs b/crates/storage_sqlite/src/workspace/stock.rs @@ -14,6 +14,10 @@ pub use consent::{ }; pub(in crate::workspace) mod grants; mod ledger; +pub(in crate::workspace) mod public_source; +pub use public_source::{ + StockListingCapture, StockListingOutcome, StockListingReceipt, StockListingSnapshot, +}; pub(in crate::workspace) mod source; use grants::StockRecord; pub use grants::{StockGrantEnrollment, StockGrantOutcome, StockGrantReceipt}; @@ -83,8 +87,17 @@ pub struct StockAuthorityReceipt { pub(super) revocation: Sequence, pub(super) inventory: Option<radroots_storage::inventory::InventoryCheckpointRef>, pub(super) sources: Option<radroots_storage::workspace::seller_stock::StockSourceCheckpointRef>, + pub(super) public_sources: + Option<radroots_storage::workspace::seller_stock::StockListingCheckpointRef>, } impl StockAuthorityReceipt { + /// Independently retained public observation progress; this certifies no + /// global head, profile readiness or business permission. + pub const fn listing_checkpoint( + &self, + ) -> Option<radroots_storage::workspace::seller_stock::StockListingCheckpointRef> { + self.public_sources + } /// Separately retained source progress; profile recognition proves no order /// actionability. Absent for retained catalogs without source retention. pub const fn source_checkpoint( @@ -170,6 +183,31 @@ struct Authority { inventory: Option<InventoryCheckpoint>, authorization: Option<StockAuthorizationRef>, sources: Option<SourceCheckpoint>, + public_sources: Option<PublicSourceCheckpoint>, +} +#[derive(Clone, Copy, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +struct PublicSourceCheckpoint { + revision: Sequence, + events: Sequence, + heads: Sequence, + parts: Sequence, + #[serde(deserialize_with = "required_nullable")] + head: Option<radroots_domain::CheckpointDigest>, +} +impl PublicSourceCheckpoint { + fn validate(self) -> Result<(), WorkspaceError> { + if self.revision != self.events + || (self.revision.get() == 0) != self.head.is_none() + || (self.revision.get() == 0) != (self.heads.get() == 0) + || self.heads.get() > self.events.get() + || self.parts.get() < self.events.get() + || self.parts.get() > self.events.get().saturating_mul(4) + { + return Err(WorkspaceError::RecoveryRequired); + } + Ok(()) + } } #[derive(Clone, Copy, Serialize, Deserialize)] #[serde(deny_unknown_fields)] @@ -361,8 +399,55 @@ struct AuthorityV7 { sources: SourceCheckpoint, authorization: StockAuthorizationRef, } +#[derive(Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +struct AuthorityV8 { + version: u8, + #[serde(deserialize_with = "object")] + namespace: SellerAuthoritySelection, + administrator: GrantId, + transaction: TransactionId, + revocation: Sequence, + #[serde(deserialize_with = "object")] + inventory: InventoryCheckpointUnified, + #[serde(deserialize_with = "object")] + sources: SourceCheckpoint, + #[serde(deserialize_with = "object")] + public_sources: PublicSourceCheckpoint, + authorization: StockAuthorizationRef, +} impl Authority { fn encode(&self) -> Result<zeroize::Zeroizing<Vec<u8>>, WorkspaceError> { + if self.catalog != 8 && self.public_sources.is_some() { + return Err(WorkspaceError::RecoveryRequired); + } + if self.catalog == 8 { + let public_sources = self + .public_sources + .ok_or(WorkspaceError::RecoveryRequired)?; + public_sources.validate()?; + let bytes = zeroize::Zeroizing::new( + serde_json::to_vec(&AuthorityV8 { + version: 8, + namespace: SellerAuthoritySelection::from_attachment(&self.input), + administrator: self.input.grant_id(), + transaction: self.transaction, + revocation: self.revocation, + inventory: self + .inventory + .ok_or(WorkspaceError::RecoveryRequired)? + .unified()?, + sources: self.sources.ok_or(WorkspaceError::RecoveryRequired)?, + public_sources, + authorization: self.authorization.ok_or(WorkspaceError::RecoveryRequired)?, + }) + .map_err(|_| WorkspaceError::StorageFailure)?, + ); + if bytes.len() > 16 * 1024 { + return Err(WorkspaceError::Capacity); + } + return Ok(bytes); + } if self.catalog == 7 { let bytes = zeroize::Zeroizing::new( serde_json::to_vec(&AuthorityV7 { @@ -476,6 +561,7 @@ impl Authority { inventory: None, authorization: None, sources: None, + public_sources: None, } } 2 | 3 => { @@ -493,6 +579,7 @@ impl Authority { inventory: Some(v.inventory.into()), authorization: None, sources: None, + public_sources: None, } } 4 => { @@ -511,6 +598,7 @@ impl Authority { inventory: Some(v.inventory.into()), authorization: Some(v.authorization), sources: None, + public_sources: None, } } 5 => { @@ -529,6 +617,7 @@ impl Authority { inventory: Some(v.inventory.into()), authorization: Some(v.authorization), sources: None, + public_sources: None, } } 6 => { @@ -552,6 +641,7 @@ impl Authority { inventory: Some(value.inventory.into()), authorization: Some(value.authorization), sources: Some(value.sources), + public_sources: None, } } 7 => { @@ -580,6 +670,37 @@ impl Authority { inventory: Some(value.inventory.into()), authorization: Some(value.authorization), sources: Some(value.sources), + public_sources: None, + } + } + 8 => { + let value: AuthorityV8 = closed_record(bytes)?; + value.public_sources.validate()?; + if value.version != 8 + || value.authorization.generation() != value.revocation + || (value.inventory.revision.get() == 0) != value.inventory.head.is_none() + || value.inventory.orders.get() > value.inventory.revision.get() + || value.inventory.pools.get() > value.inventory.revision.get() + || value.inventory.mappings.get() > value.inventory.revision.get() + || value.inventory.movements.get() + > value.inventory.revision.get().saturating_mul(64) + || (value.sources.revision.get() == 0) != value.sources.head.is_none() + || (value.sources.revision.get() == 0) != (value.sources.parts.get() == 0) + || value.sources.records.get() > value.sources.revision.get() + || value.sources.parts.get() / 3 < value.sources.revision.get() + || value.sources.parts.get() > value.sources.revision.get().saturating_mul(12) + { + return Err(WorkspaceError::RecoveryRequired); + } + Self { + catalog, + input: value.namespace.attachment(value.administrator)?, + transaction: value.transaction, + revocation: value.revocation, + inventory: Some(value.inventory.into()), + authorization: Some(value.authorization), + sources: Some(value.sources), + public_sources: Some(value.public_sources), } } _ => return Err(WorkspaceError::RecoveryRequired), @@ -611,6 +732,13 @@ pub(super) async fn initialize( namespace.validate()?; if let Some(initial) = initial { let mut authority = Authority { + public_sources: Some(PublicSourceCheckpoint { + revision: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, + events: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, + heads: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, + parts: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, + head: None, + }), sources: Some(SourceCheckpoint { revision: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, records: Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?, @@ -623,7 +751,7 @@ pub(super) async fn initialize( transaction: initial.transaction, revocation: Sequence::new(1).map_err(|_| WorkspaceError::InvalidInput)?, inventory: Some(InventoryCheckpoint { - orders: if schema::CURRENT == 7 { + orders: if schema::CURRENT >= 7 { Some(Sequence::new(0).map_err(|_| WorkspaceError::InvalidInput)?) } else { None @@ -675,7 +803,7 @@ pub(super) async fn initialize( .await .map_err(|_| WorkspaceError::StorageFailure)?; } - sqlx::query("PRAGMA user_version=7") + sqlx::query("PRAGMA user_version=8") .execute(&mut *tx) .await .map_err(|_| WorkspaceError::StorageFailure)?; @@ -762,6 +890,9 @@ async fn read( if let Some(checkpoint) = authority.sources { check_source_counts(connection, checkpoint).await?; } + if let Some(checkpoint) = authority.public_sources { + public_source::counts(connection, checkpoint).await?; + } Ok((authority, record, root, grant)) } pub(super) async fn authenticate( @@ -807,6 +938,7 @@ pub(super) async fn authenticate( namespace.validate()?; Ok(( StockAuthorityReceipt { + public_sources:authority.public_sources.map(|value|radroots_storage::workspace::seller_stock::StockListingCheckpointRef::from_host_metadata(expected.authority(),value.revision,value.head).map(|state|state.with_optional_authorization(authority.authorization))).transpose()?, sources:authority.sources.map(|value|radroots_storage::workspace::seller_stock::StockSourceCheckpointRef::from_host_metadata(expected.authority(),value.revision,value.head).map(|state|state.with_optional_authorization(authority.authorization))).transpose()?, input: authority.input, transaction: authority.transaction, diff --git a/crates/storage_sqlite/src/workspace/stock/consent.rs b/crates/storage_sqlite/src/workspace/stock/consent.rs @@ -419,7 +419,7 @@ pub(in crate::workspace) async fn issue( proof: AttachmentProof, ) -> Result<StockConsentOutcome, OperationError> { let access = turn.access(&binding, minimum, &proof).await?; - if access.authority.catalog != 7 { + if !matches!(access.authority.catalog, 7 | 8) { return Err(OperationError::UnsupportedOperation); } if !access.record.administrator() @@ -598,7 +598,7 @@ pub(in crate::workspace) async fn issue( }); let root = turn .crypto - .seal_stock_root(turn.selected, 7, &next.encode()?) + .seal_stock_root(turn.selected, access.authority.catalog, &next.encode()?) .await?; let receipt = StockConsentReceipt { operation: capture.operation, @@ -680,7 +680,7 @@ pub(in crate::workspace) async fn query( proof: AttachmentProof, ) -> Result<Option<StockConsentReceipt>, OperationError> { let access = turn.access(&binding, minimum, &proof).await?; - if access.authority.catalog != 7 { + if !matches!(access.authority.catalog, 7 | 8) { return Err(OperationError::UnsupportedOperation); } if !access.record.administrator() && access.current.input().grant_id() != subject { diff --git a/crates/storage_sqlite/src/workspace/stock/consent/test_provider.rs b/crates/storage_sqlite/src/workspace/stock/consent/test_provider.rs @@ -74,7 +74,7 @@ impl KeyWrapping for Provider { fn wrap<'a>(&'a self, request: WrapRequest<'a>) -> BoxFuture<'a, Result<WrappedSecret, Error>> { Box::pin(async move { let result = self.inner.wrap(request).await; - if request.context().payload_schema().as_str() == "radroots.seller_stock.authority.v7" { + if request.context().payload_schema().as_str() == "radroots.seller_stock.authority.v8" { self.gate.pause(); } result diff --git a/crates/storage_sqlite/src/workspace/stock/consent/tests.rs b/crates/storage_sqlite/src/workspace/stock/consent/tests.rs @@ -26,33 +26,51 @@ struct Rig { } impl Rig { async fn new() -> Self { + Self::with_catalog(None).await + } + async fn with_catalog(catalog: Option<i64>) -> Self { let fixture = CryptoFixture::new(); let path = fixture.root().join("consent"); let clock = Arc::new(Clock(AtomicU64::new(100))); - let enrollment = StockEnrollment::prepare( - SellerStockConfig::new( - participant(), - participant(), - "consent-owner", - UnixSeconds::new(200).unwrap(), + let (input, proof, store) = if let Some(catalog) = catalog { + let (input, proof) = + crate::workspace::stock::tests::literal_catalog(&fixture, &path, catalog).await; + let store = NativeWorkspace::open_seller_stock( + &path, + input.clone(), + fixture.crypto(), + clock.clone(), ) - .unwrap(), - clock.as_ref(), - ) - .unwrap(); - let input = enrollment.input().clone(); - let proof = enrollment - .proof() - .with_secret(|v| AttachmentProof::from_protected_input(v)) + .await .unwrap(); - let store = NativeWorkspace::initialize_seller_stock( - &path, - &enrollment, - fixture.crypto(), - clock.clone(), - ) - .await - .unwrap(); + (input, proof, store) + } else { + let enrollment = StockEnrollment::prepare( + SellerStockConfig::new( + participant(), + participant(), + "consent-owner", + UnixSeconds::new(200).unwrap(), + ) + .unwrap(), + clock.as_ref(), + ) + .unwrap(); + let input = enrollment.input().clone(); + let proof = enrollment + .proof() + .with_secret(|v| AttachmentProof::from_protected_input(v)) + .unwrap(); + let store = NativeWorkspace::initialize_seller_stock( + &path, + &enrollment, + fixture.crypto(), + clock.clone(), + ) + .await + .unwrap(); + (input, proof, store) + }; let binding = store.authenticate(input.clone(), &proof).await.unwrap(); let minimum = store .stock_authority(input.clone(), &proof) @@ -646,3 +664,67 @@ async fn recovery_only_can_bind_an_expired_original_command_to_an_explicit_repla ); r.store.close().await.unwrap(); } + +#[tokio::test] +async fn retained_catalog7_issues_original_consent_without_gaining_public_source_tables() { + use radroots_domain::listing::ListingCoordinate; + use radroots_storage::workspace::seller_stock::StockListingCheckpointRef; + let r = Rig::with_catalog(Some(7)).await; + let capture = r.capture(&r.binding, 0x31); + let receipt = committed( + r.store + .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) + .await + .unwrap(), + ); + assert!( + r.store + .stock_authority(r.input.clone(), &r.proof) + .await + .unwrap() + .listing_checkpoint() + .is_none() + ); + let public = StockListingCheckpointRef::from_host_metadata( + r.input.authority(), + Sequence::new(0).unwrap(), + None, + ) + .unwrap() + .with_optional_authorization(r.minimum.authorization()); + assert!(matches!( + r.store + .stock_listing_head( + r.binding.clone(), + public, + ListingCoordinate::new(r.input.participant(), "04".repeat(16).parse().unwrap()), + &r.proof + ) + .await, + Err(OperationError::UnsupportedOperation) + )); + let minimum = r.physical(0x41, receipt.checkpoint()).await; + r.store.close().await.unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.input.clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + assert_eq!( + store + .stock_consent( + r.binding.clone(), + minimum, + capture.command().context().operation_id(), + r.input.grant_id(), + &r.proof + ) + .await + .unwrap(), + Some(receipt) + ); + store.close().await.unwrap(); +} diff --git a/crates/storage_sqlite/src/workspace/stock/grants.rs b/crates/storage_sqlite/src/workspace/stock/grants.rs @@ -324,7 +324,7 @@ pub(in crate::workspace) async fn change( } let (mut authority, record, old_root, old_grant) = super::read(turn.connection, change.caller.input(), turn.crypto).await?; - if !(4..=7).contains(&authority.catalog) { + if !(4..=8).contains(&authority.catalog) { return Err(WorkspaceError::Unauthorized); } let catalog = authority.catalog; diff --git a/crates/storage_sqlite/src/workspace/stock/inventory.rs b/crates/storage_sqlite/src/workspace/stock/inventory.rs @@ -447,7 +447,7 @@ impl Turn<'_> { access.authority.authorization, mapping.as_ref().map(|value| value.effect), )?; - let framed = if catalog == 7 { + let framed = if matches!(catalog, 7 | 8) { Some( super::ledger::prepare( self.crypto, @@ -861,7 +861,7 @@ pub(super) async fn read_operation( .fetch_one(&mut *connection) .await .map_err(|_| OperationError::RecoveryRequired)?; - let (frame, request, decoded) = if catalog == 7 { + let (frame, request, decoded) = if matches!(catalog, 7 | 8) { let retained = super::ledger::read(connection, input, crypto, operation) .await? .ok_or(OperationError::RecoveryRequired)?; diff --git a/crates/storage_sqlite/src/workspace/stock/inventory/checkpoint.rs b/crates/storage_sqlite/src/workspace/stock/inventory/checkpoint.rs @@ -120,7 +120,7 @@ pub(in crate::workspace::stock) async fn authenticate_identity( let current = authority .inventory .ok_or(OperationError::UnsupportedOperation)?; - let multipart = authority.catalog == 7; + let multipart = matches!(authority.catalog, 7 | 8); let upper = current.revision.get(); let mut previous = current.head; let mut hash = history_hash(multipart); @@ -233,7 +233,7 @@ pub(super) async fn authenticate_minimum( } let lower = minimum.revision().get().max(1); let upper = current.revision.get(); - let multipart = authority.catalog == 7; + let multipart = matches!(authority.catalog, 7 | 8); let mut hash = history_hash(multipart); let mut expected = current.head; for revision in (lower..=upper).rev() { @@ -481,7 +481,7 @@ async fn authenticate_projected( .ok_or(OperationError::UnsupportedOperation)?; let upper = current.revision.get(); let mut expected = current.head; - let multipart = authority.catalog == 7; + let multipart = matches!(authority.catalog, 7 | 8); let mut hash = history_hash(multipart); for revision in (1..=upper).rev() { let id:Vec<u8>=sqlx::query_scalar("SELECT operation_id FROM stock_operations WHERE revision=? AND length(operation_id)=32").bind(revision as i64).fetch_optional(&mut *connection).await.map_err(|_|OperationError::RecoveryRequired)?.ok_or(OperationError::RecoveryRequired)?; diff --git a/crates/storage_sqlite/src/workspace/stock/inventory/codec.rs b/crates/storage_sqlite/src/workspace/stock/inventory/codec.rs @@ -120,7 +120,7 @@ pub(super) fn encode_operation( String::from_utf8(clear.to_vec()).map_err(|_| OperationError::StorageFailure)?, ) .map_err(|_| OperationError::StorageFailure)?; - if matches!(catalog, 5..=7) { + if matches!(catalog, 5..=8) { return super::encode(&OperationV4 { version: 4, authorization: authorization.ok_or(OperationError::RecoveryRequired)?, @@ -158,7 +158,7 @@ fn decode_inner( catalog: i64, allow_mapping: bool, ) -> Result<(InventoryRequest, OperationData), OperationError> { - if matches!(catalog, 5..=7) { + if matches!(catalog, 5..=8) { let decoded: OperationV4<'_> = super::closed_record(bytes).map_err(|_| OperationError::RecoveryRequired)?; if decoded.version != 4 { diff --git a/crates/storage_sqlite/src/workspace/stock/inventory/mapping.rs b/crates/storage_sqlite/src/workspace/stock/inventory/mapping.rs @@ -58,7 +58,7 @@ impl MappingRead { } } pub(super) fn require(access: &Access, key: OptionMappingKey) -> Result<(), OperationError> { - if !(5..=7).contains(&access.authority.catalog) { + if !(5..=8).contains(&access.authority.catalog) { return Err(OperationError::UnsupportedOperation); } if !access.record.administrator() diff --git a/crates/storage_sqlite/src/workspace/stock/inventory/plan.rs b/crates/storage_sqlite/src/workspace/stock/inventory/plan.rs @@ -3,7 +3,7 @@ use super::*; pub(super) fn record_version(catalog: i64) -> Result<u8, OperationError> { match catalog { 2 => Ok(1), - 3..=7 => Ok(2), + 3..=8 => Ok(2), _ => Err(OperationError::RecoveryRequired), } } diff --git a/crates/storage_sqlite/src/workspace/stock/public_source.rs b/crates/storage_sqlite/src/workspace/stock/public_source.rs @@ -0,0 +1,250 @@ +//! Original authenticated public listing observations. Local observation is not +//! a global head, supported profile, current business permission or stock hold. +use super::*; +use radroots_domain::{ + EnvelopeEventId, + listing::{ListingCoordinate, ListingId, ListingRevision}, +}; +use radroots_event::envelope::event_head::EventHeadCoordinate; +use radroots_nostr::public_ingress::ObservedHead; +use zeroize::Zeroizing; +mod checkpoint; +mod record; +#[cfg(test)] +mod tests; +mod transaction; +pub(in crate::workspace) use transaction::{Lookup, query, retain}; + +/// Captured before store IO, using only authenticated Nostr observation +/// evidence. Namespace comparison here is data validation, not store access. +pub struct StockListingCapture { + namespace: SellerAuthoritySelection, + transaction: TransactionId, + listing: ListingRevision, + created_at: u64, + raw: Zeroizing<Vec<u8>>, +} +impl StockListingCapture { + pub fn prepare( + namespace: SellerAuthoritySelection, + observed: &ObservedHead, + ) -> Result<Self, WorkspaceError> { + let selected = observed.selected().ok_or(WorkspaceError::InvalidInput)?; + let EventHeadCoordinate::Addressable { + kind, + pubkey, + d_tag, + } = &selected.coordinate + else { + return Err(WorkspaceError::InvalidInput); + }; + if *kind != radroots_protocol::listing::LISTING_KIND { + return Err(WorkspaceError::InvalidInput); + } + let discriminator: ListingId = d_tag.parse().map_err(|_| WorkspaceError::InvalidInput)?; + let coordinate = ListingCoordinate::new(*pubkey, discriminator); + if coordinate.author() != namespace.participant() { + return Err(WorkspaceError::WrongNamespace); + } + let raw = observed + .raw_json() + .ok_or(WorkspaceError::InvalidInput)? + .as_bytes(); + if raw.is_empty() || raw.len() > 64 * 1024 { + return Err(WorkspaceError::Capacity); + } + Ok(Self { + namespace, + transaction: TransactionId::from_bytes(super::super::random()?), + listing: ListingRevision::new( + coordinate, + EnvelopeEventId::from_bytes(*selected.event_id.as_bytes()), + ), + // NIP01 permits the full unsigned timestamp range. Preserve an + // authentic far-future head; clock readiness is evaluated separately. + created_at: selected.created_at, + raw: Zeroizing::new(raw.to_vec()), + }) + } + pub const fn transaction_id(&self) -> TransactionId { + self.transaction + } + pub const fn listing_revision(&self) -> ListingRevision { + self.listing + } + pub(super) fn retained_copy(&self) -> Self { + Self { + namespace: self.namespace.clone(), + transaction: self.transaction, + listing: self.listing, + created_at: self.created_at, + raw: Zeroizing::new(self.raw.to_vec()), + } + } +} +impl std::fmt::Debug for StockListingCapture { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("StockListingCapture(<authenticated observation>)") + } +} + +/// Original persisted observation. Selection is described at its original +/// retention, not promised for a later lookup or globally across relays. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct StockListingReceipt { + transaction: TransactionId, + listing: ListingRevision, + selected_at_retention: bool, + checkpoint: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, +} +impl StockListingReceipt { + pub const fn transaction_id(&self) -> TransactionId { + self.transaction + } + pub const fn listing_revision(&self) -> ListingRevision { + self.listing + } + pub const fn selected_at_retention(&self) -> bool { + self.selected_at_retention + } + pub const fn checkpoint( + &self, + ) -> radroots_storage::workspace::seller_stock::StockListingCheckpointRef { + self.checkpoint + } +} +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum StockListingOutcome { + Committed(Box<StockListingReceipt>), + Unknown { + transaction: TransactionId, + listing: ListingRevision, + }, +} +/// Original public evidence plus the independently acknowledged scope in which +/// its current-observed flag was checked. Neither grants business permission. +pub struct StockListingSnapshot { + receipt: StockListingReceipt, + selection_checkpoint: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + observed_at: radroots_domain::UnixSeconds, + current: bool, + raw: Zeroizing<String>, +} +impl StockListingSnapshot { + pub const fn receipt(&self) -> &StockListingReceipt { + &self.receipt + } + pub const fn selection_checkpoint( + &self, + ) -> radroots_storage::workspace::seller_stock::StockListingCheckpointRef { + self.selection_checkpoint + } + pub const fn observed_at(&self) -> radroots_domain::UnixSeconds { + self.observed_at + } + pub const fn is_current_observed(&self) -> bool { + self.current + } + pub fn raw_json(&self) -> &str { + &self.raw + } + /// Pure profile/time classification at the captured read observation. A + /// historical or unsupported result cannot be substituted as a live offer. + pub fn interpret_at_observation( + &self, + ) -> Result< + radroots_nostr::public_ingress::Interpretation, + radroots_storage::command::OperationError, + > { + use radroots_storage::command::OperationError; + let coordinate = self.receipt.listing.coordinate(); + let mut observed = ObservedHead::listing(coordinate.author(), &coordinate.d().to_string()) + .map_err(|_| OperationError::RecoveryRequired)?; + observed + .observe(&self.raw) + .map_err(|_| OperationError::RecoveryRequired)?; + observed + .interpret( + radroots_protocol::advertisement::UnixSeconds::new(self.observed_at.get()) + .map_err(|_| WorkspaceError::Unavailable)?, + ) + .ok_or(OperationError::RecoveryRequired) + } +} +impl std::fmt::Debug for StockListingSnapshot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("StockListingSnapshot(<original observation>)") + } +} + +impl NativeWorkspace { + /// Retains original signed listing evidence under current administrative + /// access. The borrowed capture keeps its original recovery identity if an + /// observer is lost; this does not publish or admit a business command. + pub async fn retain_stock_listing( + &self, + binding: WorkspaceBinding, + minimum: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + capture: &StockListingCapture, + proof: &AttachmentProof, + ) -> Result<StockListingOutcome, radroots_storage::command::OperationError> { + let proof = proof.with_secret(|secret| AttachmentProof::from_protected_input(secret))?; + self.worker + .retain_stock_listing(binding, minimum, capture.retained_copy(), proof) + .await + } + /// Reads one exact retained revision, including historical observations. + pub async fn stock_listing_source( + &self, + binding: WorkspaceBinding, + minimum: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + revision: ListingRevision, + proof: &AttachmentProof, + ) -> Result<Option<StockListingSnapshot>, radroots_storage::command::OperationError> { + let proof = proof.with_secret(|secret| AttachmentProof::from_protected_input(secret))?; + self.worker + .stock_listing(binding, minimum, Lookup::Revision(revision), proof) + .await + } + /// Reads the protected current observed head without older-profile fallback + /// or a claim of global relay completeness or business actionability. + pub async fn stock_listing_head( + &self, + binding: WorkspaceBinding, + minimum: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + coordinate: ListingCoordinate, + proof: &AttachmentProof, + ) -> Result<Option<StockListingSnapshot>, radroots_storage::command::OperationError> { + let proof = proof.with_secret(|secret| AttachmentProof::from_protected_input(secret))?; + self.worker + .stock_listing(binding, minimum, Lookup::Coordinate(coordinate), proof) + .await + } +} + +pub(super) async fn counts( + connection: &mut SqliteConnection, + current: PublicSourceCheckpoint, +) -> Result<(), WorkspaceError> { + use sqlx::Row; + current.validate()?; + let row=sqlx::query("SELECT count(*),coalesce(max(revision),0),coalesce(sum(CASE WHEN revision=? AND chain_head=? THEN 1 ELSE 0 END),0),(SELECT count(*) FROM stock_public_heads),(SELECT count(*) FROM stock_public_parts) FROM stock_public_events") + .bind(current.revision.get() as i64).bind(current.head.map(|head|head.as_bytes().to_vec())) + .fetch_one(connection).await.map_err(|_|WorkspaceError::RecoveryRequired)?; + for (column, expected) in [ + (0, current.events.get() as i64), + (1, current.revision.get() as i64), + (2, i64::from(current.head.is_some())), + (3, current.heads.get() as i64), + (4, current.parts.get() as i64), + ] { + if row + .try_get::<i64, _>(column) + .map_err(|_| WorkspaceError::RecoveryRequired)? + != expected + { + return Err(WorkspaceError::RecoveryRequired); + } + } + Ok(()) +} diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/checkpoint.rs b/crates/storage_sqlite/src/workspace/stock/public_source/checkpoint.rs @@ -0,0 +1,176 @@ +use super::*; +use radroots_domain::{CheckpointDigest, Sequence}; +use radroots_storage::{ + command::OperationError, workspace::seller_stock::StockListingCheckpointRef, +}; +use sha2::{Digest, Sha256}; +use sqlx::Row; + +#[derive(Clone, Copy, Eq, PartialEq)] +pub(super) struct Identity { + pub revision: Sequence, + pub head: CheckpointDigest, + pub protected: [u8; 32], +} +pub(super) enum Target { + Minimum(StockListingCheckpointRef), + Event(EnvelopeEventId, Option<Identity>), + Coordinate(ListingCoordinate, Option<record::Head>), +} +pub(super) struct Proof { + lower: u64, + upper: u64, + digest: [u8; 32], +} +fn hash() -> Sha256 { + let mut h = Sha256::new(); + h.update(b"radroots.seller_stock.public_source_ancestry_snapshot.v1\0"); + h +} +fn hash_retained(hash: &mut Sha256, value: &record::RetainedHeader) -> Result<(), OperationError> { + let header = &value.header; + let listing = header.manifest.listing; + hash.update(header.revision.get().to_be_bytes()); + hash.update(listing.event_id().as_bytes()); + hash.update(listing.coordinate().author().as_bytes()); + hash.update(listing.coordinate().d().as_bytes()); + hash.update(record::time(&header.manifest.created_at)?.to_be_bytes()); + hash.update(header.transaction.as_bytes()); + hash.update( + header + .head + .ok_or(OperationError::RecoveryRequired)? + .as_bytes(), + ); + hash.update((value.protected.len() as u64).to_be_bytes()); + hash.update(&value.protected); + Ok(()) +} +impl record::RetainedHeader { + pub(super) fn identity(&self) -> Result<Identity, OperationError> { + Ok(Identity { + revision: self.header.revision, + head: self.header.head.ok_or(OperationError::RecoveryRequired)?, + protected: Sha256::digest(&self.protected).into(), + }) + } +} +impl Proof { + /// Exact bounded-row witnesses are checked in the actual transaction, + /// after every provider callback and before reporting authenticated state. + pub async fn confirm(&self, connection: &mut SqliteConnection) -> Result<(), OperationError> { + let mut hash = hash(); + for revision in (self.lower..=self.upper).rev() { + let row=sqlx::query("SELECT event_id,listing_author,listing_d,created_at,transaction_id,chain_head,CASE WHEN length(protected) BETWEEN 1 AND 262144 THEN protected END FROM stock_public_events WHERE revision=?") + .bind(revision as i64).fetch_optional(&mut *connection).await.map_err(|_|OperationError::RecoveryRequired)?.ok_or(OperationError::RecoveryRequired)?; + hash.update(revision.to_be_bytes()); + for (column, length) in [(0, 32), (1, 32), (2, 16), (3, 8), (4, 32), (5, 32)] { + let value: Vec<u8> = row + .try_get(column) + .map_err(|_| OperationError::RecoveryRequired)?; + if value.len() != length { + return Err(OperationError::RecoveryRequired); + } + hash.update(value); + } + let protected: Vec<u8> = row + .try_get::<Option<Vec<u8>>, _>(6) + .map_err(|_| OperationError::RecoveryRequired)? + .ok_or(OperationError::RecoveryRequired)?; + hash.update((protected.len() as u64).to_be_bytes()); + hash.update(protected); + } + if <[u8; 32]>::from(hash.finalize()) != self.digest { + return Err(OperationError::RecoveryRequired); + } + Ok(()) + } +} +pub(super) async fn authenticate( + connection: &mut SqliteConnection, + input: &AttachmentInput, + crypto: &WorkspaceCrypto, + authority: &Authority, + target: Target, +) -> Result<Proof, OperationError> { + let current = authority + .public_sources + .ok_or(OperationError::UnsupportedOperation)?; + if let Target::Minimum(minimum) = &target { + if minimum.authority() != input.authority() { + return Err(WorkspaceError::StaleAuthority.into()); + } + if minimum.revision() > current.revision { + return Err(WorkspaceError::StaleCheckpoint.into()); + } + } + let upper = current.revision.get(); + let mut previous = current.head; + let mut hash = hash(); + for revision in (1..=upper).rev() { + let id: Vec<u8> = sqlx::query_scalar( + "SELECT event_id FROM stock_public_events WHERE revision=? AND length(event_id)=32", + ) + .bind(revision as i64) + .fetch_optional(&mut *connection) + .await + .map_err(|_| OperationError::RecoveryRequired)? + .ok_or(OperationError::RecoveryRequired)?; + let event = EnvelopeEventId::from_bytes( + id.try_into() + .map_err(|_| OperationError::RecoveryRequired)?, + ); + let original = record::read(connection, input, crypto, authority.input.grant_id(), event) + .await? + .ok_or(OperationError::RecoveryRequired)?; + let header = &original.header; + if header.revision.get() != revision || header.head != previous { + return Err(OperationError::RecoveryRequired); + } + hash_retained(&mut hash, &original)?; + let matched = match &target { + Target::Minimum(minimum) if minimum.revision().get() == revision => { + if minimum.head() != header.head { + return Err(WorkspaceError::StaleCheckpoint.into()); + } + true + } + Target::Event(wanted, expected) if *wanted == event => { + if *expected != Some(original.identity()?) { + return Err(OperationError::RecoveryRequired); + } + true + } + Target::Coordinate(coordinate, expected) + if *coordinate == header.manifest.listing.coordinate() => + { + if expected.as_ref() != Some(&header.after) { + return Err(OperationError::RecoveryRequired); + } + true + } + _ => false, + }; + if matched { + return Ok(Proof { + lower: revision, + upper, + digest: hash.finalize().into(), + }); + } + previous = header.previous; + } + if previous.is_some() { + return Err(OperationError::RecoveryRequired); + } + match target { + Target::Minimum(value) if value.revision().get() == 0 => {} + Target::Event(_, None) | Target::Coordinate(_, None) => {} + _ => return Err(OperationError::RecoveryRequired), + } + Ok(Proof { + lower: 1, + upper, + digest: hash.finalize().into(), + }) +} diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/record.rs b/crates/storage_sqlite/src/workspace/stock/public_source/record.rs @@ -0,0 +1,477 @@ +use super::*; +use radroots_domain::{CheckpointDigest, Sequence, UnixSeconds}; +use radroots_storage::command::OperationError; +use sha2::{Digest, Sha256}; + +pub(super) const PART_BYTES: usize = 16 * 1024; +pub(super) const RAW_MAX_BYTES: usize = 64 * 1024; + +fn listing_revision<'de, D: serde::Deserializer<'de>>(d: D) -> Result<ListingRevision, D::Error> { + #[derive(Deserialize)] + #[serde(deny_unknown_fields)] + struct Wire { + coordinate: ListingCoordinate, + event_id: EnvelopeEventId, + } + let value: Wire = super::super::object(d)?; + Ok(ListingRevision::new(value.coordinate, value.event_id)) +} + +pub(super) fn time(value: &str) -> Result<u64, OperationError> { + if value.is_empty() + || value.len() > 20 + || (value.len() > 1 && value.starts_with('0')) + || !value.bytes().all(|c| c.is_ascii_digit()) + { + return Err(OperationError::RecoveryRequired); + } + value.parse().map_err(|_| OperationError::RecoveryRequired) +} + +#[derive(Clone, Eq, PartialEq, Serialize)] +pub(super) struct Head { + pub version: u8, + pub listing: ListingRevision, + pub created_at: String, + pub revision: Sequence, +} +impl<'de> Deserialize<'de> for Head { + fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> { + #[derive(Deserialize)] + #[serde(deny_unknown_fields)] + struct Wire { + version: u8, + #[serde(deserialize_with = "listing_revision")] + listing: ListingRevision, + created_at: String, + revision: Sequence, + } + let value: Wire = super::super::object(d)?; + let value = Self { + version: value.version, + listing: value.listing, + created_at: value.created_at, + revision: value.revision, + }; + value.validate().map_err(serde::de::Error::custom)?; + Ok(value) + } +} +impl Head { + fn validate(&self) -> Result<(), OperationError> { + if self.version != 1 || self.revision.get() == 0 { + return Err(OperationError::RecoveryRequired); + } + time(&self.created_at)?; + Ok(()) + } +} +pub(super) fn select(before: Option<&Head>, candidate: Head) -> Result<Head, OperationError> { + candidate.validate()?; + let Some(before) = before else { + return Ok(candidate); + }; + before.validate()?; + if before.listing.coordinate() != candidate.listing.coordinate() { + return Err(OperationError::RecoveryRequired); + } + let old = time(&before.created_at)?; + let new = time(&candidate.created_at)?; + if old > new + || (old == new + && before.listing.event_id().as_bytes() <= candidate.listing.event_id().as_bytes()) + { + Ok(before.clone()) + } else { + Ok(candidate) + } +} + +#[derive(Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub(super) struct Manifest { + #[serde(deserialize_with = "listing_revision")] + pub listing: ListingRevision, + pub created_at: String, + pub bytes: u32, + pub digest: [u8; 32], + pub parts: u8, +} +#[derive(Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub(super) struct Header { + pub version: u8, + #[serde(deserialize_with = "super::super::object")] + pub namespace: SellerAuthoritySelection, + pub transaction: TransactionId, + pub revision: Sequence, + #[serde(deserialize_with = "super::super::required_nullable")] + pub previous: Option<CheckpointDigest>, + #[serde(deserialize_with = "super::super::required_nullable")] + pub head: Option<CheckpointDigest>, + pub grant: GrantId, + pub principal: String, + pub authorization: StockAuthorizationRef, + pub observed_at: UnixSeconds, + pub minimum_revision: Sequence, + #[serde(deserialize_with = "super::super::required_nullable")] + pub minimum_head: Option<CheckpointDigest>, + #[serde(deserialize_with = "super::super::object")] + pub manifest: Manifest, + #[serde(deserialize_with = "super::super::required_nullable")] + pub before: Option<Head>, + pub after: Head, +} +impl Header { + pub fn receipt(&self) -> Result<StockListingReceipt, OperationError> { + Ok(StockListingReceipt { + transaction:self.transaction,listing:self.manifest.listing, + selected_at_retention:self.after.listing.event_id()==self.manifest.listing.event_id(), + checkpoint:radroots_storage::workspace::seller_stock::StockListingCheckpointRef::from_host_metadata( + self.namespace.authority(),self.revision,self.head, + )?.with_authorization(self.authorization), + }) + } + pub fn calculate_head(&self) -> Result<CheckpointDigest, OperationError> { + // Version1 canonical preimage includes every provenance, scope, + // manifest and projection field, with only its own pointer cleared. + let mut preimage = self.clone(); + preimage.head = None; + let mut hash = Sha256::new(); + hash.update(b"radroots.seller_stock.public_source_chain.v1\0"); + hash.update(encode(&preimage)?.as_slice()); + Ok(CheckpointDigest::from_bytes(hash.finalize().into())) + } + pub fn validate( + &self, + input: &AttachmentInput, + administrator: GrantId, + ) -> Result<(), OperationError> { + let manifest = &self.manifest; + if self.version != 1 + || !self.namespace.matches_attachment(input) + || manifest.listing.coordinate().author() != input.participant() + || self.grant != administrator + || self.principal.is_empty() + || self.principal.len() > 128 + || self.principal.chars().any(char::is_control) + || self.observed_at.get() == 0 + || self.revision.get() == 0 + || (self.revision.get() == 1) != self.previous.is_none() + || self.minimum_revision.get() >= self.revision.get() + || (self.minimum_revision.get() == 0) != self.minimum_head.is_none() + || manifest.bytes == 0 + || manifest.bytes as usize > RAW_MAX_BYTES + || usize::from(manifest.parts) != (manifest.bytes as usize).div_ceil(PART_BYTES) + || self.head != Some(self.calculate_head()?) + { + return Err(OperationError::RecoveryRequired); + } + time(&manifest.created_at)?; + if let Some(before) = &self.before { + before.validate()?; + if before.revision >= self.revision + || before.listing.event_id() == manifest.listing.event_id() + { + return Err(OperationError::RecoveryRequired); + } + } + let candidate = Head { + version: 1, + listing: manifest.listing, + created_at: manifest.created_at.clone(), + revision: self.revision, + }; + if self.after != select(self.before.as_ref(), candidate)? { + return Err(OperationError::RecoveryRequired); + } + Ok(()) + } +} +pub(super) fn encode(value: &impl Serialize) -> Result<Zeroizing<Vec<u8>>, OperationError> { + let bytes = + Zeroizing::new(serde_json::to_vec(value).map_err(|_| OperationError::StorageFailure)?); + if bytes.len() > 16 * 1024 { + return Err(WorkspaceError::Capacity.into()); + } + Ok(bytes) +} + +pub(super) fn coordinate_id(coordinate: ListingCoordinate) -> [u8; 32] { + let mut hash = Sha256::new(); + hash.update(b"radroots.seller_stock.public_source_coordinate.v1\0"); + hash.update(coordinate.author().as_bytes()); + hash.update(coordinate.d().as_bytes()); + hash.finalize().into() +} +pub(super) fn part_id(event: EnvelopeEventId, part: u8) -> [u8; 32] { + let mut hash = Sha256::new(); + hash.update(b"radroots.seller_stock.public_source_part.v1\0"); + hash.update(event.as_bytes()); + hash.update([part]); + hash.finalize().into() +} + +pub(super) struct RetainedHeader { + pub header: Header, + pub protected: Vec<u8>, +} +pub(super) struct RetainedHead { + pub head: Head, + pub protected: Vec<u8>, +} +pub(super) struct Parts { + pub raw: Zeroizing<Vec<u8>>, + pub witness: [u8; 32], +} + +pub(super) async fn read( + connection: &mut SqliteConnection, + input: &AttachmentInput, + crypto: &WorkspaceCrypto, + administrator: GrantId, + event: EnvelopeEventId, +) -> Result<Option<RetainedHeader>, OperationError> { + use sqlx::Row; + let row=sqlx::query("SELECT listing_author,listing_d,created_at,transaction_id,revision,chain_head,CASE WHEN length(protected) BETWEEN 1 AND 262144 THEN protected END FROM stock_public_events WHERE event_id=?") + .bind(event.as_bytes().as_slice()).fetch_optional(&mut *connection).await.map_err(|_|OperationError::RecoveryRequired)?; + let Some(row) = row else { return Ok(None) }; + let protected: Vec<u8> = row + .try_get::<Option<Vec<u8>>, _>(6) + .map_err(|_| OperationError::RecoveryRequired)? + .ok_or(OperationError::RecoveryRequired)?; + let clear = crypto + .open_stock_record(input, "public_event", event.as_bytes(), &protected) + .await?; + let header: Header = clear.expose_secret(|bytes| super::super::closed_record(bytes))?; + header.validate(input, administrator)?; + let coordinate = header.manifest.listing.coordinate(); + if header.manifest.listing.event_id() != event { + return Err(OperationError::RecoveryRequired); + } + let author: Vec<u8> = row + .try_get(0) + .map_err(|_| OperationError::RecoveryRequired)?; + let discriminator: Vec<u8> = row + .try_get(1) + .map_err(|_| OperationError::RecoveryRequired)?; + let created: Vec<u8> = row + .try_get(2) + .map_err(|_| OperationError::RecoveryRequired)?; + let transaction: Vec<u8> = row + .try_get(3) + .map_err(|_| OperationError::RecoveryRequired)?; + let revision: i64 = row + .try_get(4) + .map_err(|_| OperationError::RecoveryRequired)?; + let head: Vec<u8> = row + .try_get(5) + .map_err(|_| OperationError::RecoveryRequired)?; + if author != coordinate.author().as_bytes() + || discriminator != coordinate.d().as_bytes() + || created != time(&header.manifest.created_at)?.to_be_bytes() + || transaction != header.transaction.as_bytes() + || revision <= 0 + || revision as u64 != header.revision.get() + || head + != header + .head + .ok_or(OperationError::RecoveryRequired)? + .as_bytes() + { + return Err(OperationError::RecoveryRequired); + } + Ok(Some(RetainedHeader { header, protected })) +} +pub(super) async fn read_head( + connection: &mut SqliteConnection, + input: &AttachmentInput, + crypto: &WorkspaceCrypto, + coordinate: ListingCoordinate, +) -> Result<Option<RetainedHead>, OperationError> { + use sqlx::Row; + let row=sqlx::query("SELECT event_id,revision,CASE WHEN length(protected) BETWEEN 1 AND 262144 THEN protected END FROM stock_public_heads WHERE listing_author=? AND listing_d=?") + .bind(coordinate.author().as_bytes().as_slice()).bind(coordinate.d().as_bytes().as_slice()) + .fetch_optional(connection).await.map_err(|_|OperationError::RecoveryRequired)?; + let Some(row) = row else { return Ok(None) }; + let protected: Vec<u8> = row + .try_get::<Option<Vec<u8>>, _>(2) + .map_err(|_| OperationError::RecoveryRequired)? + .ok_or(OperationError::RecoveryRequired)?; + let clear = crypto + .open_stock_record(input, "public_head", &coordinate_id(coordinate), &protected) + .await?; + let head: Head = clear.expose_secret(|bytes| super::super::closed_record(bytes))?; + head.validate()?; + let event: Vec<u8> = row + .try_get(0) + .map_err(|_| OperationError::RecoveryRequired)?; + let revision: i64 = row + .try_get(1) + .map_err(|_| OperationError::RecoveryRequired)?; + if head.listing.coordinate() != coordinate + || coordinate.author() != input.participant() + || event != head.listing.event_id().as_bytes() + || revision <= 0 + || revision as u64 != head.revision.get() + { + return Err(OperationError::RecoveryRequired); + } + Ok(Some(RetainedHead { head, protected })) +} +fn part_hash() -> Sha256 { + let mut hash = Sha256::new(); + hash.update(b"radroots.seller_stock.public_source_parts_snapshot.v1\0"); + hash +} +fn hash_part(hash: &mut Sha256, part: u8, protected: &[u8]) { + hash.update([part]); + hash.update((protected.len() as u64).to_be_bytes()); + hash.update(protected); +} +pub(super) async fn parts_witness( + connection: &mut SqliteConnection, + event: EnvelopeEventId, +) -> Result<(u8, [u8; 32]), OperationError> { + let count: i64 = sqlx::query_scalar("SELECT count(*) FROM stock_public_parts WHERE event_id=?") + .bind(event.as_bytes().as_slice()) + .fetch_one(&mut *connection) + .await + .map_err(|_| OperationError::RecoveryRequired)?; + if !(1..=4).contains(&count) { + return Err(OperationError::RecoveryRequired); + } + let mut hash = part_hash(); + for part in 0..count { + let protected:Vec<u8>=sqlx::query_scalar("SELECT protected FROM stock_public_parts WHERE event_id=? AND part=? AND length(protected) BETWEEN 1 AND 262144") + .bind(event.as_bytes().as_slice()).bind(part).fetch_optional(&mut *connection).await.map_err(|_|OperationError::RecoveryRequired)?.ok_or(OperationError::RecoveryRequired)?; + hash_part(&mut hash, part as u8, &protected); + } + Ok((count as u8, hash.finalize().into())) +} +pub(super) async fn read_parts( + connection: &mut SqliteConnection, + input: &AttachmentInput, + crypto: &WorkspaceCrypto, + header: &Header, +) -> Result<Parts, OperationError> { + let event = header.manifest.listing.event_id(); + let mut raw = Zeroizing::new(Vec::with_capacity(header.manifest.bytes as usize)); + let mut hash = part_hash(); + for part in 0..header.manifest.parts { + let protected:Vec<u8>=sqlx::query_scalar("SELECT protected FROM stock_public_parts WHERE event_id=? AND part=? AND length(protected) BETWEEN 1 AND 262144") + .bind(event.as_bytes().as_slice()).bind(i64::from(part)).fetch_optional(&mut *connection).await.map_err(|_|OperationError::RecoveryRequired)?.ok_or(OperationError::RecoveryRequired)?; + hash_part(&mut hash, part, &protected); + let clear = crypto + .open_stock_record(input, "public_part", &part_id(event, part), &protected) + .await?; + clear.expose_secret(|bytes| { + let expected = if part + 1 == header.manifest.parts { + header.manifest.bytes as usize - usize::from(part) * PART_BYTES + } else { + PART_BYTES + }; + if bytes.len() != expected { + return Err(OperationError::RecoveryRequired); + } + raw.extend_from_slice(bytes); + Ok(()) + })?; + } + let witness: [u8; 32] = hash.finalize().into(); + if raw.len() != header.manifest.bytes as usize + || <[u8; 32]>::from(Sha256::digest(raw.as_slice())) != header.manifest.digest + || parts_witness(connection, event).await? != (header.manifest.parts, witness) + { + return Err(OperationError::RecoveryRequired); + } + // Original signature verification can reconstruct public observation + // evidence; private authenticated-opening tokens are never reconstructed. + let mut observed = ObservedHead::listing( + header.manifest.listing.coordinate().author(), + &header.manifest.listing.coordinate().d().to_string(), + ) + .map_err(|_| OperationError::RecoveryRequired)?; + observed + .observe(std::str::from_utf8(&raw).map_err(|_| OperationError::RecoveryRequired)?) + .map_err(|_| OperationError::RecoveryRequired)?; + let selected = observed + .selected() + .ok_or(OperationError::RecoveryRequired)?; + if selected.event_id.as_bytes() != event.as_bytes() + || selected.created_at != time(&header.manifest.created_at)? + { + return Err(OperationError::RecoveryRequired); + } + Ok(Parts { raw, witness }) +} + +pub(super) async fn confirm_head( + connection: &mut SqliteConnection, + coordinate: ListingCoordinate, + original: Option<&RetainedHead>, +) -> Result<(), OperationError> { + let count: i64 = if let Some(original) = original { + sqlx::query_scalar("SELECT count(*) FROM stock_public_heads WHERE listing_author=? AND listing_d=? AND event_id=? AND revision=? AND protected=?") + .bind(coordinate.author().as_bytes().as_slice()).bind(coordinate.d().as_bytes().as_slice()) + .bind(original.head.listing.event_id().as_bytes().as_slice()).bind(original.head.revision.get() as i64).bind(&original.protected) + .fetch_one(connection).await.map_err(|_|OperationError::RecoveryRequired)? + } else { + sqlx::query_scalar( + "SELECT count(*) FROM stock_public_heads WHERE listing_author=? AND listing_d=?", + ) + .bind(coordinate.author().as_bytes().as_slice()) + .bind(coordinate.d().as_bytes().as_slice()) + .fetch_one(connection) + .await + .map_err(|_| OperationError::RecoveryRequired)? + }; + if count != i64::from(original.is_some()) { + return Err(OperationError::RecoveryRequired); + } + Ok(()) +} +pub(super) struct PreparedParts { + protected: Vec<Vec<u8>>, +} +impl PreparedParts { + pub async fn prepare( + crypto: &WorkspaceCrypto, + input: &AttachmentInput, + capture: &StockListingCapture, + ) -> Result<Self, OperationError> { + if capture.raw.is_empty() || capture.raw.len() > RAW_MAX_BYTES { + return Err(WorkspaceError::Capacity.into()); + } + let mut protected = Vec::with_capacity(capture.raw.len().div_ceil(PART_BYTES)); + for (part, bytes) in capture.raw.chunks(PART_BYTES).enumerate() { + protected.push( + crypto + .seal_stock_record( + input, + "public_part", + &part_id(capture.listing.event_id(), part as u8), + bytes, + ) + .await?, + ); + } + Ok(Self { protected }) + } + pub async fn insert( + &self, + connection: &mut SqliteConnection, + event: EnvelopeEventId, + ) -> Result<(), OperationError> { + for (part, protected) in self.protected.iter().enumerate() { + sqlx::query("INSERT INTO stock_public_parts(event_id,part,protected) VALUES(?,?,?)") + .bind(event.as_bytes().as_slice()) + .bind(part as i64) + .bind(protected) + .execute(&mut *connection) + .await + .map_err(|_| OperationError::StorageFailure)?; + } + Ok(()) + } +} diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/test_provider.rs b/crates/storage_sqlite/src/workspace/stock/public_source/test_provider.rs @@ -0,0 +1,321 @@ +use super::*; +use radroots_secrets::{ + Error, + file::FileProvider, + id::BackendKind, + provider::{SecretCapabilities, SecretProvider}, + wrapping::{KeyWrapping, SecretMaterial, UnwrapRequest, WrapRequest, WrappedSecret}, +}; +use radroots_transport::BoxFuture; +use std::{ + sync::{Condvar, Mutex}, + time::Duration, +}; +#[derive(Clone, Copy, Eq, PartialEq)] +enum Direction { + Wrap, + Unwrap, +} +struct Selection { + direction: Direction, + schema: &'static str, + skip: usize, +} +struct State { + selection: Option<Selection>, + entered: bool, + released: bool, +} +struct Gate { + state: Mutex<State>, + changed: Condvar, +} +impl Gate { + fn new() -> Self { + Self { + state: Mutex::new(State { + selection: None, + entered: false, + released: false, + }), + changed: Condvar::new(), + } + } + fn arm(&self, direction: Direction, schema: &'static str, skip: usize) { + *self.state.lock().unwrap() = State { + selection: Some(Selection { + direction, + schema, + skip, + }), + entered: false, + released: false, + }; + } + fn pause(&self, direction: Direction, schema: &str) { + let mut state = self.state.lock().unwrap(); + let Some(selection) = state.selection.as_mut() else { + return; + }; + if selection.direction != direction || selection.schema != schema { + return; + } + if selection.skip > 0 { + selection.skip -= 1; + return; + } + state.selection = None; + state.entered = true; + self.changed.notify_all(); + let (state, timeout) = self + .changed + .wait_timeout_while(state, Duration::from_secs(20), |state| !state.released) + .unwrap(); + assert!( + !timeout.timed_out() && state.released, + "test must release provider" + ); + } + fn entered(&self) { + let (state, timeout) = self + .changed + .wait_timeout_while( + self.state.lock().unwrap(), + Duration::from_secs(20), + |state| !state.entered, + ) + .unwrap(); + assert!( + !timeout.timed_out() && state.entered, + "worker must reach actual provider IO" + ); + } + fn release(&self) { + self.state.lock().unwrap().released = true; + self.changed.notify_all(); + } +} +struct Provider { + inner: Arc<FileProvider>, + gate: Gate, +} +impl SecretProvider for Provider { + fn backend_kind(&self) -> BackendKind { + self.inner.backend_kind() + } + fn capabilities(&self) -> SecretCapabilities { + self.inner.capabilities() + } +} +impl KeyWrapping for Provider { + fn wrap<'a>(&'a self, request: WrapRequest<'a>) -> BoxFuture<'a, Result<WrappedSecret, Error>> { + Box::pin(async move { + let result = self.inner.wrap(request).await; + self.gate + .pause(Direction::Wrap, request.context().payload_schema().as_str()); + result + }) + } + fn unwrap<'a>( + &'a self, + request: UnwrapRequest<'a>, + ) -> BoxFuture<'a, Result<SecretMaterial, Error>> { + Box::pin(async move { + let result = self.inner.unwrap(request).await; + self.gate.pause( + Direction::Unwrap, + request.context().payload_schema().as_str(), + ); + result + }) + } +} +async fn reopen(r: &mut Rig) -> Arc<Provider> { + r.store.close().await.unwrap(); + let provider = Arc::new(Provider { + inner: r.fixture.provider.clone(), + gate: Gate::new(), + }); + r.store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto_with_provider(provider.clone()), + r.clock.clone(), + ) + .await + .unwrap(); + provider +} + +#[tokio::test] +async fn public_source_close_drains_admitted_work_after_observer_loss() { + let mut r = Rig::new().await; + let provider = reopen(&mut r).await; + let capture = r.capture("listing_fixed"); + let minimum = r.minimum().await; + provider + .gate + .arm(Direction::Wrap, "radroots.seller_stock.authority.v8", 0); + let mut future = Box::pin(r.store.retain_stock_listing( + r.binding.clone(), + minimum, + &capture, + r.enrollment.proof(), + )); + assert!(futures::poll!(future.as_mut()).is_pending()); + provider.gate.entered(); + drop(future); + assert!(matches!( + NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone() + ) + .await, + Err(WorkspaceError::WriterActive) + )); + provider.gate.release(); + r.store.close().await.unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + let source = store + .stock_listing_source( + r.binding.clone(), + minimum, + capture.listing_revision(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(source.receipt().transaction_id(), capture.transaction_id()); + assert_eq!(source.raw_json(), vector("listing_fixed")); + store.close().await.unwrap(); +} + +#[tokio::test] +async fn public_source_writes_recheck_expiry_and_head_rows_after_actual_protection_io() { + for changed_head in [false, true] { + let mut r = Rig::new().await; + r.retain(&r.capture("listing_fixed")).await; + let provider = reopen(&mut r).await; + let capture = r.capture("listing_unsupported"); + let minimum = r.minimum().await; + let mut raw = database(&r).await; + provider + .gate + .arm(Direction::Wrap, "radroots.seller_stock.authority.v8", 0); + let mut future = Box::pin(r.store.retain_stock_listing( + r.binding.clone(), + minimum, + &capture, + r.enrollment.proof(), + )); + assert!(futures::poll!(future.as_mut()).is_pending()); + provider.gate.entered(); + let original: Vec<u8> = sqlx::query_scalar("SELECT protected FROM stock_public_heads") + .fetch_one(&mut raw) + .await + .unwrap(); + if changed_head { + sqlx::query("UPDATE stock_public_heads SET protected=randomblob(length(protected))") + .execute(&mut raw) + .await + .unwrap(); + } else { + r.clock.0.store(300, Ordering::SeqCst); + } + provider.gate.release(); + let result = future.await; + if changed_head { + assert_eq!(result.unwrap_err().code(), "recovery_required"); + } else { + assert_eq!( + result, + Err(OperationError::Workspace(WorkspaceError::GrantExpired)) + ); + } + let count: i64 = sqlx::query_scalar("SELECT count(*) FROM stock_public_events") + .fetch_one(&mut raw) + .await + .unwrap(); + assert_eq!(count, 1); + if changed_head { + sqlx::query("UPDATE stock_public_heads SET protected=?") + .bind(original) + .execute(&mut raw) + .await + .unwrap(); + } + raw.close().await.unwrap(); + r.store.close().await.unwrap(); + } +} + +#[tokio::test] +async fn public_source_reads_recheck_parts_changed_after_their_successful_authenticated_opening() { + let mut r = Rig::new().await; + let capture = r.capture("listing_fixed"); + let receipt = r.retain(&capture).await; + let provider = reopen(&mut r).await; + let mut raw = database(&r).await; + // Minimum, coordinate and original reads precede raw-part admission; pause + // the fourth event-header opening in final positive identity verification. + provider.gate.arm( + Direction::Unwrap, + "radroots.seller_stock.public_source_event.v1", + 3, + ); + let mut future = Box::pin(r.store.stock_listing_head( + r.binding.clone(), + receipt.checkpoint(), + capture.listing_revision().coordinate(), + r.enrollment.proof(), + )); + assert!(futures::poll!(future.as_mut()).is_pending()); + provider.gate.entered(); + let original: Vec<u8> = + sqlx::query_scalar("SELECT protected FROM stock_public_parts WHERE part=0") + .fetch_one(&mut raw) + .await + .unwrap(); + sqlx::query( + "UPDATE stock_public_parts SET protected=randomblob(length(protected)) WHERE part=0", + ) + .execute(&mut raw) + .await + .unwrap(); + provider.gate.release(); + assert!(matches!( + future.await, + Err(OperationError::RecoveryRequired) + )); + sqlx::query("UPDATE stock_public_parts SET protected=? WHERE part=0") + .bind(original) + .execute(&mut raw) + .await + .unwrap(); + assert_eq!( + r.store + .stock_listing_head( + r.binding.clone(), + receipt.checkpoint(), + capture.listing_revision().coordinate(), + r.enrollment.proof() + ) + .await + .unwrap() + .unwrap() + .raw_json(), + vector("listing_fixed") + ); + raw.close().await.unwrap(); + r.store.close().await.unwrap(); +} diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/tests.rs b/crates/storage_sqlite/src/workspace/stock/public_source/tests.rs @@ -0,0 +1,966 @@ +//! Real native observation persistence over independent signed inputs. A +//! selected head remains observation evidence, never business permission. +use super::*; +use crate::workspace::tests::{CryptoFixture, participant}; +use radroots_domain::{PublicKey, UnixSeconds}; +use radroots_storage::{ + command::OperationError, workspace::seller_stock::StockListingCheckpointRef, +}; +use std::sync::atomic::{AtomicU64, Ordering}; +#[path = "test_provider.rs"] +mod provider; + +struct Clock(AtomicU64); +impl WorkspaceClock for Clock { + fn now(&self) -> Result<UnixSeconds, WorkspaceError> { + UnixSeconds::new(self.0.load(Ordering::SeqCst)).map_err(|_| WorkspaceError::Unavailable) + } +} +fn vectors() -> serde_json::Value { + serde_json::from_str(include_str!( + "../../../../tests/fixtures/stock_public_sources.v1.json" + )) + .unwrap() +} +fn vector(name: &str) -> String { + vectors()["vectors"] + .as_array() + .unwrap() + .iter() + .find(|row| row["name"] == name) + .unwrap()["raw"] + .as_str() + .unwrap() + .into() +} +struct Rig { + fixture: CryptoFixture, + path: std::path::PathBuf, + store: NativeWorkspace, + enrollment: StockEnrollment, + binding: WorkspaceBinding, + clock: Arc<Clock>, +} +impl Rig { + async fn new() -> Self { + let fixture = CryptoFixture::new(); + let path = fixture.root().join("public-sources"); + let owner = PublicKey::from_hex(vectors()["author"].as_str().unwrap()).unwrap(); + let clock = Arc::new(Clock(AtomicU64::new(150))); + let enrollment = StockEnrollment::prepare( + SellerStockConfig::new( + owner, + participant(), + "public-source-owner", + UnixSeconds::new(300).unwrap(), + ) + .unwrap(), + clock.as_ref(), + ) + .unwrap(); + let store = NativeWorkspace::initialize_seller_stock( + &path, + &enrollment, + fixture.crypto(), + clock.clone(), + ) + .await + .unwrap(); + let binding = store + .authenticate(enrollment.input().clone(), enrollment.proof()) + .await + .unwrap(); + Self { + fixture, + path, + store, + enrollment, + binding, + clock, + } + } + fn capture_raw(&self, raw: &str) -> StockListingCapture { + let mut observed = ObservedHead::listing( + self.enrollment.input().participant(), + vectors()["d"].as_str().unwrap(), + ) + .unwrap(); + observed.observe(raw).unwrap(); + StockListingCapture::prepare( + SellerAuthoritySelection::from_attachment(self.enrollment.input()), + &observed, + ) + .unwrap() + } + fn capture(&self, name: &str) -> StockListingCapture { + self.capture_raw(&vector(name)) + } + async fn minimum(&self) -> StockListingCheckpointRef { + self.store + .stock_authority(self.enrollment.input().clone(), self.enrollment.proof()) + .await + .unwrap() + .listing_checkpoint() + .unwrap() + } + async fn retain(&self, capture: &StockListingCapture) -> StockListingReceipt { + committed( + self.store + .retain_stock_listing( + self.binding.clone(), + self.minimum().await, + capture, + self.enrollment.proof(), + ) + .await + .unwrap(), + ) + } +} +fn committed(value: StockListingOutcome) -> StockListingReceipt { + match value { + StockListingOutcome::Committed(value) => *value, + _ => panic!("retention must confirm"), + } +} + +#[tokio::test] +async fn native_original_observation_reopens_and_deduplicates_transport_encodings_without_replacement() + { + let r = Rig::new().await; + let capture = r.capture("listing_fixed"); + let before = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap(); + let receipt = r.retain(&capture).await; + assert_eq!(receipt.transaction_id(), capture.transaction_id()); + assert_eq!(receipt.checkpoint().revision().get(), 1); + assert!(receipt.selected_at_retention()); + let alias = serde_json::to_string_pretty( + &serde_json::from_str::<serde_json::Value>(&vector("listing_fixed")).unwrap(), + ) + .unwrap(); + assert_ne!(alias, vector("listing_fixed")); + let alias = r.capture_raw(&alias); + assert_ne!(alias.transaction_id(), capture.transaction_id()); + assert_eq!(r.retain(&alias).await, receipt); + let after = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap(); + assert_eq!(before.inventory_checkpoint(), after.inventory_checkpoint()); + assert_eq!(before.source_checkpoint(), after.source_checkpoint()); + let source = r + .store + .stock_listing_source( + r.binding.clone(), + receipt.checkpoint(), + capture.listing_revision(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(source.raw_json(), vector("listing_fixed")); + assert!(source.is_current_observed()); + assert!(matches!( + source.interpret_at_observation().unwrap(), + radroots_nostr::public_ingress::Interpretation::Listing(_) + )); + r.store.close().await.unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + let source = store + .stock_listing_head( + r.binding.clone(), + receipt.checkpoint(), + capture.listing_revision().coordinate(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(source.receipt(), &receipt); + assert_eq!(source.raw_json(), vector("listing_fixed")); + store.close().await.unwrap(); +} + +#[tokio::test] +async fn protected_heads_match_independent_timestamp_and_id_oracles_without_profile_fallback() { + for steps in vectors()["ranking_oracles"].as_array().unwrap() { + let r = Rig::new().await; + for step in steps.as_array().unwrap() { + let capture = r.capture(step["input"].as_str().unwrap()); + r.retain(&capture).await; + let head = r + .store + .stock_listing_head( + r.binding.clone(), + r.minimum().await, + capture.listing_revision().coordinate(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!( + head.receipt().listing_revision().event_id().to_string(), + step["head"].as_str().unwrap() + ); + } + let old = r.capture("listing_fixed"); + let original = r + .store + .stock_listing_source( + r.binding.clone(), + r.minimum().await, + old.listing_revision(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(original.raw_json(), vector("listing_fixed")); + r.store.close().await.unwrap(); + } + for (name, expected) in [ + ("listing_unsupported", "unsupported"), + ("listing_unknown_field", "invalid"), + ("listing_future", "clock_ahead"), + ] { + let r = Rig::new().await; + let old = r.capture("listing_fixed"); + r.retain(&old).await; + let next = r.capture(name); + r.retain(&next).await; + let head = r + .store + .stock_listing_head( + r.binding.clone(), + r.minimum().await, + old.listing_revision().coordinate(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(head.receipt().listing_revision(), next.listing_revision()); + let classification = match head.interpret_at_observation().unwrap() { + radroots_nostr::public_ingress::Interpretation::Unsupported => "unsupported", + radroots_nostr::public_ingress::Interpretation::Invalid => "invalid", + radroots_nostr::public_ingress::Interpretation::ClockAhead => "clock_ahead", + _ => panic!("must not fall back"), + }; + assert_eq!(classification, expected); + let old = r + .store + .stock_listing_source( + r.binding.clone(), + r.minimum().await, + old.listing_revision(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert!(!old.is_current_observed()); + assert!(old.receipt().selected_at_retention()); + r.store.close().await.unwrap(); + } +} + +#[tokio::test] +async fn full_event_bounds_and_invalid_profile_bytes_are_retained_after_signature_admission() { + for name in [ + "listing_exact_event_bound", + "listing_large_profile", + "listing_duplicate_d", + "listing_ambiguous_d", + "listing_contradictory_price", + "listing_recurring_price", + "listing_duplicate_profile", + ] { + let r = Rig::new().await; + let capture = r.capture(name); + let receipt = r.retain(&capture).await; + let source = r + .store + .stock_listing_source( + r.binding.clone(), + receipt.checkpoint(), + capture.listing_revision(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(source.raw_json(), vector(name)); + if name == "listing_exact_event_bound" { + assert_eq!(source.raw_json().len(), 65536); + } + r.store.close().await.unwrap(); + } + let r = Rig::new().await; + for name in ["bad_id", "bad_signature", "capability"] { + let mut observed = ObservedHead::listing( + r.enrollment.input().participant(), + vectors()["d"].as_str().unwrap(), + ) + .unwrap(); + assert!(observed.observe(&vector(name)).is_err()); + assert!( + StockListingCapture::prepare( + SellerAuthoritySelection::from_attachment(r.enrollment.input()), + &observed + ) + .is_err() + ); + } + let capture = r.capture("listing_fixed"); + let wrong = SellerStockConfig::new( + participant(), + participant(), + "wrong", + UnixSeconds::new(300).unwrap(), + ) + .unwrap() + .enroll( + UnixSeconds::new(150).unwrap(), + WorkspaceId::from_bytes([1; 32]), + ExecutorId::from_bytes([2; 32]), + GrantId::from_bytes([3; 32]), + AttachmentProof::from_protected_input(&[4; 32]).unwrap(), + ) + .unwrap() + .0; + let mut observed = ObservedHead::listing( + r.enrollment.input().participant(), + vectors()["d"].as_str().unwrap(), + ) + .unwrap(); + observed.observe(&vector("listing_fixed")).unwrap(); + assert!(matches!( + StockListingCapture::prepare(SellerAuthoritySelection::from_attachment(&wrong), &observed), + Err(WorkspaceError::WrongNamespace) + )); + let wrong_proof = AttachmentProof::from_protected_input(&[9; 32]).unwrap(); + assert!( + r.store + .retain_stock_listing(r.binding.clone(), r.minimum().await, &capture, &wrong_proof) + .await + .is_err() + ); + r.clock.0.store(300, Ordering::SeqCst); + assert!(matches!( + r.store + .retain_stock_listing( + r.binding.clone(), + StockListingCheckpointRef::from_host_metadata( + r.enrollment.input().authority(), + radroots_domain::Sequence::new(0).unwrap(), + None + ) + .unwrap(), + &capture, + r.enrollment.proof() + ) + .await, + Err(OperationError::Workspace(WorkspaceError::GrantExpired)) + )); + r.store.close().await.unwrap(); +} + +async fn database(r: &Rig) -> SqliteConnection { + SqliteConnection::connect_with( + &sqlx::sqlite::SqliteConnectOptions::new() + .filename(r.path.join("stock_execution_v1.sqlite")) + .foreign_keys(false), + ) + .await + .unwrap() +} + +#[tokio::test] +async fn every_public_write_window_rolls_back_exact_progress_and_retained_originals() { + for (initial, trigger) in [ + ( + false, + "CREATE TRIGGER fault BEFORE INSERT ON stock_public_events BEGIN SELECT RAISE(ABORT,'fixture'); END", + ), + ( + false, + "CREATE TRIGGER fault BEFORE INSERT ON stock_public_parts BEGIN SELECT RAISE(ABORT,'fixture'); END", + ), + ( + false, + "CREATE TRIGGER fault BEFORE INSERT ON stock_public_heads BEGIN SELECT RAISE(ABORT,'fixture'); END", + ), + ( + true, + "CREATE TRIGGER fault BEFORE UPDATE ON stock_public_heads BEGIN SELECT RAISE(ABORT,'fixture'); END", + ), + ( + false, + "CREATE TRIGGER fault BEFORE UPDATE ON stock_authority BEGIN SELECT RAISE(ABORT,'fixture'); END", + ), + ] { + let r = Rig::new().await; + if initial { + r.retain(&r.capture("listing_fixed")).await; + } + let minimum = r.minimum().await; + let capture = r.capture("listing_unsupported"); + let mut raw = database(&r).await; + sqlx::raw_sql(trigger).execute(&mut raw).await.unwrap(); + assert_eq!( + r.store + .retain_stock_listing(r.binding.clone(), minimum, &capture, r.enrollment.proof()) + .await, + Err(OperationError::StorageFailure) + ); + assert_eq!(r.minimum().await, minimum); + let events: i64 = sqlx::query_scalar("SELECT count(*) FROM stock_public_events") + .fetch_one(&mut raw) + .await + .unwrap(); + assert_eq!(events, i64::from(initial)); + let parts: i64 = sqlx::query_scalar("SELECT count(*) FROM stock_public_parts") + .fetch_one(&mut raw) + .await + .unwrap(); + assert_eq!(parts, i64::from(initial)); + sqlx::raw_sql("DROP TRIGGER fault") + .execute(&mut raw) + .await + .unwrap(); + raw.close().await.unwrap(); + assert_eq!( + r.retain(&capture).await.transaction_id(), + capture.transaction_id() + ); + r.store.close().await.unwrap(); + } +} + +#[tokio::test] +async fn failed_public_commit_keeps_original_identity_and_requires_drain_and_reopen() { + let r = Rig::new().await; + let capture = r.capture("listing_fixed"); + let minimum = r.minimum().await; + let mut raw = database(&r).await; + sqlx::raw_sql("CREATE TABLE deferred_fault(value INTEGER REFERENCES stock_authority(singleton) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER fault AFTER INSERT ON stock_public_events BEGIN INSERT INTO deferred_fault VALUES(2); END").execute(&mut raw).await.unwrap(); + assert_eq!( + r.store + .retain_stock_listing(r.binding.clone(), minimum, &capture, r.enrollment.proof()) + .await + .unwrap(), + StockListingOutcome::Unknown { + transaction: capture.transaction_id(), + listing: capture.listing_revision() + } + ); + assert!(matches!( + r.store + .stock_listing_head( + r.binding.clone(), + minimum, + capture.listing_revision().coordinate(), + r.enrollment.proof() + ) + .await, + Err(OperationError::RecoveryRequired) + )); + r.store.close().await.unwrap(); + sqlx::raw_sql("DROP TRIGGER fault; DROP TABLE deferred_fault") + .execute(&mut raw) + .await + .unwrap(); + raw.close().await.unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + assert!( + store + .stock_listing_head( + r.binding.clone(), + minimum, + capture.listing_revision().coordinate(), + r.enrollment.proof() + ) + .await + .unwrap() + .is_none() + ); + let receipt = committed( + store + .retain_stock_listing(r.binding.clone(), minimum, &capture, r.enrollment.proof()) + .await + .unwrap(), + ); + assert_eq!(receipt.transaction_id(), capture.transaction_id()); + store.close().await.unwrap(); +} + +#[tokio::test] +async fn changed_projection_and_hidden_original_identity_refuse_without_repair() { + for projection in [true, false] { + let r = Rig::new().await; + let original = r.capture("listing_fixed"); + r.retain(&original).await; + r.retain(&r.capture("listing_unsupported")).await; + let minimum = r.minimum().await; + let mut raw = database(&r).await; + if projection { + sqlx::query("UPDATE stock_public_heads SET listing_d=?") + .bind([0x77_u8; 16].as_slice()) + .execute(&mut raw) + .await + .unwrap(); + } else { + sqlx::query("UPDATE stock_public_events SET event_id=? WHERE event_id=?") + .bind([0x78_u8; 32].as_slice()) + .bind(original.listing_revision().event_id().as_bytes().as_slice()) + .execute(&mut raw) + .await + .unwrap(); + } + assert!( + r.store + .stock_listing_source( + r.binding.clone(), + minimum, + original.listing_revision(), + r.enrollment.proof() + ) + .await + .is_err() + ); + if !projection { + assert!( + r.store + .retain_stock_listing( + r.binding.clone(), + minimum, + &original, + r.enrollment.proof() + ) + .await + .is_err() + ); + sqlx::query("UPDATE stock_public_events SET event_id=? WHERE event_id=?") + .bind(original.listing_revision().event_id().as_bytes().as_slice()) + .bind([0x78_u8; 32].as_slice()) + .execute(&mut raw) + .await + .unwrap(); + } else { + sqlx::query("UPDATE stock_public_heads SET listing_d=?") + .bind( + original + .listing_revision() + .coordinate() + .d() + .as_bytes() + .as_slice(), + ) + .execute(&mut raw) + .await + .unwrap(); + } + assert_eq!( + r.store + .stock_listing_source( + r.binding.clone(), + minimum, + original.listing_revision(), + r.enrollment.proof() + ) + .await + .unwrap() + .unwrap() + .raw_json(), + vector("listing_fixed") + ); + raw.close().await.unwrap(); + r.store.close().await.unwrap(); + } +} + +#[tokio::test] +async fn physical_grants_have_no_public_source_access_and_exact_current_generation_is_required() { + let r = Rig::new().await; + let capture = r.capture("listing_fixed"); + let original = r.retain(&capture).await; + let stale = r.minimum().await; + let inventory = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap() + .inventory_checkpoint() + .unwrap(); + let child = StockGrantEnrollment::prepare( + &SellerAuthoritySelection::from_attachment(r.enrollment.input()), + "physical".into(), + UnixSeconds::new(290).unwrap(), + StockGrantScope::full_inventory(), + ) + .unwrap(); + assert!(matches!( + r.store + .enroll_stock_grant(r.binding.clone(), inventory, r.enrollment.proof(), &child) + .await + .unwrap(), + StockGrantOutcome::Committed(_) + )); + assert_eq!( + r.store + .retain_stock_listing(r.binding.clone(), stale, &capture, r.enrollment.proof()) + .await, + Err(OperationError::Workspace(WorkspaceError::StaleCheckpoint)) + ); + let minimum = r.minimum().await; + let binding = r + .store + .authenticate(child.input().clone(), child.proof()) + .await + .unwrap(); + assert_eq!( + r.store + .retain_stock_listing(binding.clone(), minimum, &capture, child.proof()) + .await, + Err(OperationError::Unauthorized) + ); + assert!(matches!( + r.store + .stock_listing_head( + binding, + minimum, + capture.listing_revision().coordinate(), + child.proof() + ) + .await, + Err(OperationError::Unauthorized) + )); + let receipt = r.retain(&capture).await; + assert_eq!(receipt, original); + assert_eq!(minimum.revision(), stale.revision()); + assert_eq!(minimum.head(), stale.head()); + assert_ne!(minimum.authorization(), stale.authorization()); + let read = r + .store + .stock_listing_head( + r.binding.clone(), + minimum, + capture.listing_revision().coordinate(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(read.selection_checkpoint(), minimum); + assert_eq!(read.receipt(), &original); + let fork = StockListingCheckpointRef::from_host_metadata( + r.enrollment.input().authority(), + minimum.revision(), + Some(radroots_domain::CheckpointDigest::from_bytes([0x44; 32])), + ) + .unwrap() + .with_optional_authorization(minimum.authorization()); + assert!( + r.store + .stock_listing_head( + r.binding.clone(), + fork, + capture.listing_revision().coordinate(), + r.enrollment.proof() + ) + .await + .is_err() + ); + r.clock.0.store(149, Ordering::SeqCst); + assert!( + r.store + .stock_listing_source( + r.binding.clone(), + minimum, + capture.listing_revision(), + r.enrollment.proof() + ) + .await + .is_err() + ); + r.store.close().await.unwrap(); +} + +#[tokio::test] +async fn acknowledged_public_progress_detects_whole_database_restore() { + let r = Rig::new().await; + let first = r.capture("listing_fixed"); + r.retain(&first).await; + r.store.close().await.unwrap(); + let snapshot = r.fixture.root().join("old-public.sqlite"); + std::fs::copy(r.path.join("stock_execution_v1.sqlite"), &snapshot).unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + let minimum = store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap() + .listing_checkpoint() + .unwrap(); + let next = r.capture("listing_unsupported"); + let latest = committed( + store + .retain_stock_listing(r.binding.clone(), minimum, &next, r.enrollment.proof()) + .await + .unwrap(), + ); + store.close().await.unwrap(); + std::fs::copy(snapshot, r.path.join("stock_execution_v1.sqlite")).unwrap(); + let store = NativeWorkspace::open_seller_stock( + &r.path, + r.enrollment.input().clone(), + r.fixture.crypto(), + r.clock.clone(), + ) + .await + .unwrap(); + assert!( + store + .stock_listing_head( + r.binding.clone(), + latest.checkpoint(), + first.listing_revision().coordinate(), + r.enrollment.proof() + ) + .await + .is_err() + ); + store.close().await.unwrap(); +} + +#[tokio::test] +async fn actual_inventory_private_sources_consent_and_grant_changes_preserve_public_progress() { + use nostr::{EventBuilder, JsonUtil, Keys, Kind, Timestamp}; + use radroots_domain::{CommandContextData, OperationId, PoolId}; + use radroots_protocol::command::CapturedOrderAcceptance; + use radroots_signing::{provider::ProviderCall, request::CancellationSignal}; + use radroots_storage::inventory::{InventoryOutcome, InventoryRequest, InventoryStore}; + use radroots_storage::workspace::seller_stock::StockResources; + let r = Rig::new().await; + let public = r.capture("listing_fixed"); + let first = r.retain(&public).await; + let inventory = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap() + .inventory_checkpoint() + .unwrap(); + let context = CommandContextData::new( + OperationId::from_bytes([0x61; 32]), + r.binding.actor(), + r.enrollment.input().workspace_id(), + r.enrollment.input().authority(), + r.enrollment.input().route_digest(), + None, + None, + UnixSeconds::new(250).unwrap(), + None, + ) + .unwrap(); + let wire = serde_json::json!({"type":"stock.create_pool","context":context,"input":{"id":PoolId::from_bytes([0x62;32]),"label":"source coexistence","unit":"each","tick_scale":"0","initial_quantity":"1"}}); + let request = InventoryRequest::from_protected_wire( + r.binding.clone(), + inventory, + &serde_json::to_vec(&wire).unwrap(), + ) + .unwrap(); + let created = match r + .store + .execute_inventory( + request, + r.enrollment + .proof() + .with_secret(|secret| AttachmentProof::from_protected_input(secret)) + .unwrap(), + ) + .await + .unwrap() + { + InventoryOutcome::Committed(receipt) => receipt, + _ => panic!("pool must confirm"), + }; + let sender = Keys::parse(&format!("{:064x}", 1)).unwrap(); + let recipient = + nostr::PublicKey::from_hex(&r.enrollment.input().participant().to_hex()).unwrap(); + let rumor = EventBuilder::new(Kind::from(14), "synthetic source coexistence") + .custom_created_at(Timestamp::from(150)) + .build(sender.public_key()); + let wrap = EventBuilder::gift_wrap(&sender, &recipient, rumor, []) + .await + .unwrap(); + let signer = radroots_nostr::signing::LocalSigner::with_clock( + radroots_nostr::key::SecretKey::parse(&format!("{:064x}", 3)).unwrap(), + || Ok(150), + ) + .unwrap(); + let opened = radroots_nostr::commerce::open( + &signer, + ProviderCall::new( + r.enrollment.input().participant(), + std::num::NonZeroU64::new(2000).unwrap(), + CancellationSignal::new(), + ), + &wrap.as_json(), + ) + .await + .unwrap(); + let private = StockSourceCapture::prepare( + SellerAuthoritySelection::from_attachment(r.enrollment.input()), + &opened, + ) + .unwrap(); + let state = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap(); + let private_receipt = match r + .store + .retain_stock_source( + r.binding.clone(), + state.source_checkpoint().unwrap(), + &private, + r.enrollment.proof(), + ) + .await + .unwrap() + { + StockSourceOutcome::Committed(receipt) => receipt, + _ => panic!("private evidence must confirm"), + }; + let mut wire = serde_json::json!({"type":"orders.accept","context":context,"input":{"request":"21".repeat(32),"terms_digest":"24".repeat(32),"allocation":{"type":"automatic"}}}); + wire["context"]["operation_id"] = serde_json::json!(OperationId::from_bytes([0x63; 32])); + wire["context"]["expected"] = serde_json::json!({"agreement":null,"buyer_head":"21".repeat(32),"checkpoint":{"coverage":"scope_satisfied","digest":"22".repeat(32),"missing":[],"sequence":"1"},"order_id":"23".repeat(32),"seller_sequence":"0"}); + let unapproved = CapturedOrderAcceptance::parse(&serde_json::to_vec(&wire).unwrap()).unwrap(); + wire["context"]["approval"] = serde_json::json!({"intent_digest":unapproved.approval_intent_digest(),"scope":"orders.accept","expires_at":"250"}); + let consent = StockConsentCapture::prepare( + SellerAuthoritySelection::from_attachment(r.enrollment.input()), + r.enrollment.input().grant_id(), + StockConsentMode::ExecuteAndRecover, + StockResources::all_pools(), + UnixSeconds::new(240).unwrap(), + CapturedOrderAcceptance::parse(&serde_json::to_vec(&wire).unwrap()).unwrap(), + ) + .unwrap(); + let consent = match r + .store + .issue_stock_consent( + r.binding.clone(), + created.checkpoint(), + &consent, + r.enrollment.proof(), + ) + .await + .unwrap() + { + StockConsentOutcome::Committed(receipt) => receipt, + _ => panic!("consent must confirm"), + }; + let child = StockGrantEnrollment::prepare( + &SellerAuthoritySelection::from_attachment(r.enrollment.input()), + "coexistence".into(), + UnixSeconds::new(290).unwrap(), + StockGrantScope::full_inventory(), + ) + .unwrap(); + assert!(matches!( + r.store + .enroll_stock_grant( + r.binding.clone(), + consent.checkpoint(), + r.enrollment.proof(), + &child + ) + .await + .unwrap(), + StockGrantOutcome::Committed(_) + )); + let state = r + .store + .stock_authority(r.enrollment.input().clone(), r.enrollment.proof()) + .await + .unwrap(); + let current = state.listing_checkpoint().unwrap(); + assert_eq!(current.revision(), first.checkpoint().revision()); + assert_eq!(current.head(), first.checkpoint().head()); + let current_private = state.source_checkpoint().unwrap(); + assert_eq!( + current_private.revision(), + private_receipt.checkpoint().revision() + ); + assert_eq!(current_private.head(), private_receipt.checkpoint().head()); + assert_eq!(state.inventory_checkpoint().unwrap().revision().get(), 2); + let source = r + .store + .stock_listing_head( + r.binding.clone(), + current, + public.listing_revision().coordinate(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(source.raw_json(), vector("listing_fixed")); + assert!( + r.store + .stock_source( + r.binding.clone(), + current_private, + private.envelope_id(), + r.enrollment.proof() + ) + .await + .unwrap() + .is_some() + ); + let pool = r + .store + .pool( + r.binding.clone(), + state.inventory_checkpoint().unwrap(), + created.pool().id(), + r.enrollment + .proof() + .with_secret(|secret| AttachmentProof::from_protected_input(secret)) + .unwrap(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(pool.snapshot().balances().physical().available.get(), 1); + r.store.close().await.unwrap(); +} diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/transaction.rs b/crates/storage_sqlite/src/workspace/stock/public_source/transaction.rs @@ -0,0 +1,482 @@ +use super::*; +use checkpoint::{Proof, Target}; +use radroots_domain::Sequence; +use radroots_storage::{ + command::{OperationError, protected::same_binding}, + workspace::seller_stock::StockListingCheckpointRef, +}; +use sha2::{Digest, Sha256}; + +struct Access { + authority: Authority, + record: StockRecord, + root: Vec<u8>, + grant: Vec<u8>, + current: WorkspaceBinding, + minimum: Proof, +} +async fn access( + turn: &mut inventory::Turn<'_>, + binding: &WorkspaceBinding, + minimum: StockListingCheckpointRef, + proof: &AttachmentProof, +) -> Result<Access, OperationError> { + if *turn.uncertain { + return Err(OperationError::RecoveryRequired); + } + turn.namespace.validate()?; + if !SellerAuthoritySelection::from_attachment(turn.selected).matches_attachment(binding.input()) + { + return Err(OperationError::Unauthorized); + } + let (authority, record, root, grant) = + super::super::read(turn.connection, binding.input(), turn.crypto).await?; + if authority.catalog != 8 || authority.public_sources.is_none() { + return Err(OperationError::UnsupportedOperation); + } + let current = record.authenticate(binding.input(), proof, turn.clock.now()?)?; + same_binding(binding, &current)?; + if current.scope() != WorkspaceScope::SellerStockOwner || !record.administrator() { + return Err(OperationError::Unauthorized); + } + if current.observed_at() < binding.observed_at() { + return Err(WorkspaceError::Unavailable.into()); + } + if minimum.authorization() != authority.authorization { + return Err(WorkspaceError::StaleCheckpoint.into()); + } + let minimum = checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &authority, + Target::Minimum(minimum), + ) + .await?; + Ok(Access { + authority, + record, + root, + grant, + current, + minimum, + }) +} +impl Access { + async fn confirm( + &self, + connection: &mut SqliteConnection, + namespace: &Namespace, + clock: &dyn WorkspaceClock, + proof: &AttachmentProof, + ) -> Result<WorkspaceBinding, OperationError> { + namespace.validate()?; + super::super::unchanged( + connection, + self.current.input(), + self.authority.catalog, + &self.root, + &self.grant, + ) + .await?; + grants::check_state( + connection, + self.authority + .authorization + .ok_or(OperationError::RecoveryRequired)?, + ) + .await?; + counts( + connection, + self.authority + .public_sources + .ok_or(OperationError::RecoveryRequired)?, + ) + .await?; + self.minimum.confirm(connection).await?; + let current = self + .record + .authenticate(self.current.input(), proof, clock.now()?)?; + same_binding(&self.current, &current)?; + if !self.record.administrator() { + return Err(OperationError::Unauthorized); + } + if current.observed_at() < self.current.observed_at() { + return Err(WorkspaceError::Unavailable.into()); + } + namespace.validate()?; + Ok(current) + } +} +fn add(value: Sequence, delta: u64) -> Result<Sequence, OperationError> { + Sequence::new( + value + .get() + .checked_add(delta) + .ok_or(WorkspaceError::Capacity)?, + ) + .map_err(|_| WorkspaceError::Capacity.into()) +} + +pub(in crate::workspace) async fn retain( + turn: &mut inventory::Turn<'_>, + binding: WorkspaceBinding, + minimum: StockListingCheckpointRef, + capture: StockListingCapture, + proof: AttachmentProof, +) -> Result<StockListingOutcome, OperationError> { + let access = access(turn, &binding, minimum, &proof).await?; + if capture.namespace != SellerAuthoritySelection::from_attachment(turn.selected) { + return Err(OperationError::Unauthorized); + } + let event = capture.listing.event_id(); + let coordinate = capture.listing.coordinate(); + let original = record::read( + turn.connection, + turn.selected, + turn.crypto, + access.authority.input.grant_id(), + event, + ) + .await?; + if let Some(original) = original { + if original.header.manifest.listing != capture.listing + || record::time(&original.header.manifest.created_at)? != capture.created_at + { + return Err(OperationError::RecoveryRequired); + } + // Both captures independently verified the same NIP01 identity. A + // transport re-encoding may deduplicate, never replace original bytes. + let parts = record::read_parts( + turn.connection, + turn.selected, + turn.crypto, + &original.header, + ) + .await?; + let identity = checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &access.authority, + Target::Event(event, Some(original.identity()?)), + ) + .await?; + let receipt = original.header.receipt()?; + let mut tx = turn + .connection + .begin_with("BEGIN IMMEDIATE") + .await + .map_err(|_| OperationError::StorageFailure)?; + let checked: Result<(), OperationError> = async { + access + .confirm(&mut tx, turn.namespace, turn.clock, &proof) + .await?; + identity.confirm(&mut tx).await?; + if record::parts_witness(&mut tx, event).await? + != (original.header.manifest.parts, parts.witness) + { + return Err(OperationError::RecoveryRequired); + } + Ok(()) + } + .await; + if tx.rollback().await.is_err() { + *turn.uncertain = true; + return Err(OperationError::RecoveryRequired); + } + checked?; + return Ok(StockListingOutcome::Committed(Box::new(receipt))); + } + let absence = checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &access.authority, + Target::Event(event, None), + ) + .await?; + let before = record::read_head(turn.connection, turn.selected, turn.crypto, coordinate).await?; + let projection = checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &access.authority, + Target::Coordinate(coordinate, before.as_ref().map(|value| value.head.clone())), + ) + .await?; + let progress = access + .authority + .public_sources + .ok_or(OperationError::RecoveryRequired)?; + let revision = add(progress.revision, 1)?; + let candidate = record::Head { + version: 1, + listing: capture.listing, + created_at: capture.created_at.to_string(), + revision, + }; + let after = record::select(before.as_ref().map(|value| &value.head), candidate)?; + let selected = after.listing.event_id() == event; + let authorization = access + .authority + .authorization + .ok_or(OperationError::RecoveryRequired)?; + let mut header = record::Header { + version: 1, + namespace: capture.namespace.clone(), + transaction: capture.transaction, + revision, + previous: progress.head, + head: None, + grant: access.current.input().grant_id(), + principal: access.current.principal_id().into(), + authorization, + observed_at: access.current.observed_at(), + minimum_revision: minimum.revision(), + minimum_head: minimum.head(), + manifest: record::Manifest { + listing: capture.listing, + created_at: capture.created_at.to_string(), + bytes: capture.raw.len() as u32, + digest: Sha256::digest(capture.raw.as_slice()).into(), + parts: capture.raw.len().div_ceil(record::PART_BYTES) as u8, + }, + before: before.as_ref().map(|value| value.head.clone()), + after, + }; + header.head = Some(header.calculate_head()?); + header.validate(turn.selected, access.authority.input.grant_id())?; + let receipt = header.receipt()?; + let parts = record::PreparedParts::prepare(turn.crypto, turn.selected, &capture).await?; + let protected = turn + .crypto + .seal_stock_record( + turn.selected, + "public_event", + event.as_bytes(), + &record::encode(&header)?, + ) + .await?; + let protected_head = if selected { + Some( + turn.crypto + .seal_stock_record( + turn.selected, + "public_head", + &record::coordinate_id(coordinate), + &record::encode(&header.after)?, + ) + .await?, + ) + } else { + None + }; + let mut next = access.authority.clone(); + next.public_sources = Some(PublicSourceCheckpoint { + revision, + events: add(progress.events, 1)?, + heads: add(progress.heads, u64::from(before.is_none()))?, + parts: add(progress.parts, u64::from(header.manifest.parts))?, + head: header.head, + }); + let root = turn + .crypto + .seal_stock_root(turn.selected, 8, &next.encode()?) + .await?; + turn.namespace.validate()?; + let mut tx = turn + .connection + .begin_with("BEGIN IMMEDIATE") + .await + .map_err(|_| OperationError::StorageFailure)?; + let changed:Result<(),OperationError>=async { + access.confirm(&mut tx,turn.namespace,turn.clock,&proof).await?; + absence.confirm(&mut tx).await?;projection.confirm(&mut tx).await?; + record::confirm_head(&mut tx,coordinate,before.as_ref()).await?; + let present:i64=sqlx::query_scalar("SELECT count(*) FROM stock_public_events WHERE event_id=?").bind(event.as_bytes().as_slice()).fetch_one(&mut *tx).await.map_err(|_|OperationError::RecoveryRequired)?; + if present!=0 {return Err(OperationError::StaleState);} + sqlx::query("INSERT INTO stock_public_events(event_id,listing_author,listing_d,created_at,transaction_id,revision,chain_head,protected) VALUES(?,?,?,?,?,?,?,?)") + .bind(event.as_bytes().as_slice()).bind(coordinate.author().as_bytes().as_slice()).bind(coordinate.d().as_bytes().as_slice()) + .bind(capture.created_at.to_be_bytes().as_slice()).bind(capture.transaction.as_bytes().as_slice()).bind(revision.get() as i64) + .bind(header.head.ok_or(OperationError::RecoveryRequired)?.as_bytes().as_slice()).bind(&protected).execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; + parts.insert(&mut tx,event).await?; + if let Some(protected)=&protected_head { + if let Some(before)=&before { + let changed=sqlx::query("UPDATE stock_public_heads SET event_id=?,revision=?,protected=? WHERE listing_author=? AND listing_d=? AND protected=?") + .bind(event.as_bytes().as_slice()).bind(revision.get() as i64).bind(protected) + .bind(coordinate.author().as_bytes().as_slice()).bind(coordinate.d().as_bytes().as_slice()).bind(&before.protected) + .execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; + if changed.rows_affected()!=1 {return Err(OperationError::RecoveryRequired);} + } else { + sqlx::query("INSERT INTO stock_public_heads(listing_author,listing_d,event_id,revision,protected) VALUES(?,?,?,?,?)") + .bind(coordinate.author().as_bytes().as_slice()).bind(coordinate.d().as_bytes().as_slice()) + .bind(event.as_bytes().as_slice()).bind(revision.get() as i64).bind(protected) + .execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; + } + } + let changed=sqlx::query("UPDATE stock_authority SET protected=? WHERE singleton=1 AND protected=?").bind(root).bind(&access.root) + .execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; + if changed.rows_affected()!=1 {return Err(OperationError::RecoveryRequired);} + turn.namespace.validate()?;Ok(()) + }.await; + let unknown = || StockListingOutcome::Unknown { + transaction: capture.transaction, + listing: capture.listing, + }; + if let Err(error) = changed { + if tx.rollback().await.is_err() { + *turn.uncertain = true; + return Ok(unknown()); + } + return Err(error); + } + if tx.commit().await.is_err() { + *turn.uncertain = true; + return Ok(unknown()); + } + Ok(StockListingOutcome::Committed(Box::new(receipt))) +} + +pub(in crate::workspace) enum Lookup { + Revision(ListingRevision), + Coordinate(ListingCoordinate), +} +pub(in crate::workspace) async fn query( + turn: &mut inventory::Turn<'_>, + binding: WorkspaceBinding, + minimum: StockListingCheckpointRef, + lookup: Lookup, + proof: AttachmentProof, +) -> Result<Option<StockListingSnapshot>, OperationError> { + let access = access(turn, &binding, minimum, &proof).await?; + let coordinate = match &lookup { + Lookup::Revision(value) => value.coordinate(), + Lookup::Coordinate(value) => *value, + }; + if coordinate.author() != turn.selected.participant() { + return Err(OperationError::Unauthorized); + } + let head = record::read_head(turn.connection, turn.selected, turn.crypto, coordinate).await?; + let projection = checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &access.authority, + Target::Coordinate(coordinate, head.as_ref().map(|value| value.head.clone())), + ) + .await?; + let wanted = match lookup { + Lookup::Revision(value) => Some(value), + Lookup::Coordinate(_) => head.as_ref().map(|value| value.head.listing), + }; + let original = if let Some(wanted) = wanted { + let original = record::read( + turn.connection, + turn.selected, + turn.crypto, + access.authority.input.grant_id(), + wanted.event_id(), + ) + .await?; + if original + .as_ref() + .is_some_and(|original| original.header.manifest.listing != wanted) + { + return Err(OperationError::InvalidCommand); + } + original + } else { + None + }; + let parts = if let Some(original) = &original { + Some( + record::read_parts( + turn.connection, + turn.selected, + turn.crypto, + &original.header, + ) + .await?, + ) + } else { + None + }; + let identity = if let Some(wanted) = wanted { + Some( + checkpoint::authenticate( + turn.connection, + turn.selected, + turn.crypto, + &access.authority, + Target::Event( + wanted.event_id(), + original + .as_ref() + .map(|original| original.identity()) + .transpose()?, + ), + ) + .await?, + ) + } else { + None + }; + let selected = original.as_ref().is_some_and(|original| { + head.as_ref() + .is_some_and(|head| head.head.listing == original.header.manifest.listing) + }); + let progress = access + .authority + .public_sources + .ok_or(OperationError::RecoveryRequired)?; + let selected_at = StockListingCheckpointRef::from_host_metadata( + turn.selected.authority(), + progress.revision, + progress.head, + )? + .with_optional_authorization(access.authority.authorization); + let mut tx = turn + .connection + .begin_with("BEGIN IMMEDIATE") + .await + .map_err(|_| OperationError::StorageFailure)?; + let checked: Result<WorkspaceBinding, OperationError> = async { + let current = access + .confirm(&mut tx, turn.namespace, turn.clock, &proof) + .await?; + projection.confirm(&mut tx).await?; + if let Some(identity) = &identity { + identity.confirm(&mut tx).await?; + } + record::confirm_head(&mut tx, coordinate, head.as_ref()).await?; + if let (Some(original), Some(parts)) = (&original, &parts) + && record::parts_witness(&mut tx, original.header.manifest.listing.event_id()).await? + != (original.header.manifest.parts, parts.witness) + { + return Err(OperationError::RecoveryRequired); + } + turn.namespace.validate()?; + Ok(current) + } + .await; + if tx.rollback().await.is_err() { + *turn.uncertain = true; + return Err(OperationError::RecoveryRequired); + } + let current = checked?; + match (original, parts) { + (Some(original), Some(parts)) => Ok(Some(StockListingSnapshot { + receipt: original.header.receipt()?, + selection_checkpoint: selected_at, + observed_at: current.observed_at(), + current: selected, + raw: Zeroizing::new( + String::from_utf8(parts.raw.to_vec()) + .map_err(|_| OperationError::RecoveryRequired)?, + ), + })), + (None, None) => Ok(None), + _ => Err(OperationError::RecoveryRequired), + } +} diff --git a/crates/storage_sqlite/src/workspace/stock/schema.rs b/crates/storage_sqlite/src/workspace/stock/schema.rs @@ -1,7 +1,7 @@ //! Exact stock catalogs. Enrollment-only version1 is retained without upgrade. use super::WorkspaceError; use sqlx::SqliteConnection; -pub(super) const CURRENT: i64 = 7; +pub(super) const CURRENT: i64 = 8; const AUTHORITY: &str = "CREATE TABLE stock_authority (singleton INTEGER PRIMARY KEY CHECK(singleton=1), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT"; const GRANTS: &str = "CREATE TABLE stock_grants (grant_id BLOB PRIMARY KEY CHECK(length(grant_id)=32), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID"; const POOLS: &str = "CREATE TABLE stock_pools (pool_id BLOB PRIMARY KEY CHECK(length(pool_id)=32), revision INTEGER NOT NULL CHECK(revision>0), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID"; @@ -23,13 +23,13 @@ pub(super) fn objects( ]; match version { 1 => {} - 2..=7 => objects.extend([ + 2..=8 => objects.extend([ ("table", "stock_pools", "stock_pools", POOLS), ( "table", "stock_operations", "stock_operations", - if version == 7 { + if version >= 7 { OPERATIONS_V7 } else { OPERATIONS @@ -70,7 +70,7 @@ pub(super) fn objects( if version >= 5 { objects.push(("table","stock_mappings","stock_mappings","CREATE TABLE stock_mappings (listing_author BLOB NOT NULL CHECK(length(listing_author)=32), listing_d BLOB NOT NULL CHECK(length(listing_d)=16), option_id BLOB NOT NULL CHECK(length(option_id)=32), pool_id BLOB NOT NULL REFERENCES stock_pools(pool_id), revision INTEGER NOT NULL CHECK(revision>0), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144), PRIMARY KEY(listing_author,listing_d,option_id)) STRICT, WITHOUT ROWID")); } - if matches!(version, 6 | 7) { + if (6..=8).contains(&version) { objects.push(("table","stock_source_records","stock_source_records","CREATE TABLE stock_source_records (record_id BLOB PRIMARY KEY CHECK(length(record_id)=32), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID")); objects.push(("table","stock_source_evidence","stock_source_evidence","CREATE TABLE stock_source_evidence (envelope_id BLOB PRIMARY KEY CHECK(length(envelope_id)=32), record_id BLOB REFERENCES stock_source_records(record_id), transaction_id BLOB NOT NULL CHECK(length(transaction_id)=32), revision INTEGER NOT NULL CHECK(revision>0), chain_head BLOB NOT NULL CHECK(length(chain_head)=32), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID")); objects.push(("index","stock_source_transaction_identity","stock_source_evidence","CREATE UNIQUE INDEX stock_source_transaction_identity ON stock_source_evidence(transaction_id)")); @@ -88,12 +88,30 @@ pub(super) fn objects( )); objects.push(("table","stock_source_parts","stock_source_parts","CREATE TABLE stock_source_parts (envelope_id BLOB NOT NULL REFERENCES stock_source_evidence(envelope_id), role INTEGER NOT NULL CHECK(role BETWEEN 0 AND 2), part INTEGER NOT NULL CHECK(part BETWEEN 0 AND 3), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144), PRIMARY KEY(envelope_id,role,part)) STRICT, WITHOUT ROWID")); } - if version == 7 { + if version >= 7 { objects.push(("table","stock_operation_parts","stock_operation_parts","CREATE TABLE stock_operation_parts (actor BLOB NOT NULL CHECK(length(actor)=32), grant_id BLOB NOT NULL CHECK(length(grant_id)=32), operation_id BLOB NOT NULL CHECK(length(operation_id)=32), part INTEGER NOT NULL CHECK(part BETWEEN 0 AND 15), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144), PRIMARY KEY(actor,operation_id,part), FOREIGN KEY(actor,grant_id,operation_id) REFERENCES stock_operations(actor,grant_id,operation_id)) STRICT, WITHOUT ROWID")); objects.push(("index","stock_consent_target_identity","stock_operations","CREATE UNIQUE INDEX stock_consent_target_identity ON stock_operations(actor,related_operation,subject_grant) WHERE family=1")); objects.push(("index","stock_order_operation_position","stock_operations","CREATE INDEX stock_order_operation_position ON stock_operations(order_id,revision) WHERE order_id IS NOT NULL")); objects.push(("table","stock_orders","stock_orders","CREATE TABLE stock_orders (order_id BLOB PRIMARY KEY CHECK(length(order_id)=32), revision INTEGER NOT NULL CHECK(revision>0), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID")); } + if version == 8 { + objects.push(("table","stock_public_events","stock_public_events","CREATE TABLE stock_public_events (event_id BLOB PRIMARY KEY CHECK(length(event_id)=32), listing_author BLOB NOT NULL CHECK(length(listing_author)=32), listing_d BLOB NOT NULL CHECK(length(listing_d)=16), created_at BLOB NOT NULL CHECK(length(created_at)=8), transaction_id BLOB NOT NULL CHECK(length(transaction_id)=32), revision INTEGER NOT NULL CHECK(revision>0), chain_head BLOB NOT NULL CHECK(length(chain_head)=32), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144)) STRICT, WITHOUT ROWID")); + objects.push(("index","stock_public_transaction_identity","stock_public_events","CREATE UNIQUE INDEX stock_public_transaction_identity ON stock_public_events(transaction_id)")); + objects.push(( + "index", + "stock_public_revision_identity", + "stock_public_events", + "CREATE UNIQUE INDEX stock_public_revision_identity ON stock_public_events(revision)", + )); + objects.push(( + "index", + "stock_public_head_identity", + "stock_public_events", + "CREATE UNIQUE INDEX stock_public_head_identity ON stock_public_events(chain_head)", + )); + objects.push(("table","stock_public_parts","stock_public_parts","CREATE TABLE stock_public_parts (event_id BLOB NOT NULL REFERENCES stock_public_events(event_id), part INTEGER NOT NULL CHECK(part BETWEEN 0 AND 3), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144), PRIMARY KEY(event_id,part)) STRICT, WITHOUT ROWID")); + objects.push(("table","stock_public_heads","stock_public_heads","CREATE TABLE stock_public_heads (listing_author BLOB NOT NULL CHECK(length(listing_author)=32), listing_d BLOB NOT NULL CHECK(length(listing_d)=16), event_id BLOB NOT NULL REFERENCES stock_public_events(event_id), revision INTEGER NOT NULL CHECK(revision>0), protected BLOB NOT NULL CHECK(length(protected)>0 AND length(protected)<=262144), PRIMARY KEY(listing_author,listing_d)) STRICT, WITHOUT ROWID")); + } Ok(objects) } pub(super) async fn admit(connection: &mut SqliteConnection) -> Result<i64, WorkspaceError> { diff --git a/crates/storage_sqlite/src/workspace/stock/source/transaction.rs b/crates/storage_sqlite/src/workspace/stock/source/transaction.rs @@ -28,7 +28,7 @@ async fn access( } let (authority, record, root, grant) = super::super::read(turn.connection, binding.input(), turn.crypto).await?; - if !matches!(authority.catalog, 6 | 7) { + if !(6..=8).contains(&authority.catalog) { return Err(OperationError::UnsupportedOperation); } let current = record.authenticate(binding.input(), proof, turn.clock.now()?)?; diff --git a/crates/storage_sqlite/src/workspace/stock/tests.rs b/crates/storage_sqlite/src/workspace/stock/tests.rs @@ -109,7 +109,7 @@ async fn current_grant_set_reopens_with_original_namespace_after_one_grant_chang ) .await .unwrap(); - assert_eq!(schema::admit(&mut connection).await, Ok(7)); + assert_eq!(schema::admit(&mut connection).await, Ok(8)); assert_eq!(schema::integrity(&mut connection).await, Ok(())); let root: Vec<u8> = sqlx::query_scalar("SELECT protected FROM stock_authority") .fetch_one(&mut connection) @@ -117,18 +117,18 @@ async fn current_grant_set_reopens_with_original_namespace_after_one_grant_chang .unwrap(); let clear = fixture .crypto() - .open_stock_root(enrollment.input(), 7, &root) + .open_stock_root(enrollment.input(), 8, &root) .await .unwrap(); let authority = clear - .expose_secret(|bytes| Authority::decode(bytes, 7)) + .expose_secret(|bytes| Authority::decode(bytes, 8)) .unwrap(); clear.expose_secret(|bytes| { let original:serde_json::Value=serde_json::from_slice(bytes).unwrap(); assert_eq!(original["inventory"]["mappings"],"0"); for bad in [serde_json::json!([]),serde_json::json!({"revision":"1","pools":"1","movements":"1","head":original["inventory"]["head"]})] { let mut value=original.clone();value["inventory"]=bad; - assert!(Authority::decode(&serde_json::to_vec(&value).unwrap(),7).is_err()); + assert!(Authority::decode(&serde_json::to_vec(&value).unwrap(),8).is_err()); } for bad in [ serde_json::json!([]), @@ -139,7 +139,7 @@ async fn current_grant_set_reopens_with_original_namespace_after_one_grant_chang serde_json::json!({"revision":"1","records":"2","parts":"3","head":"01".repeat(32)}), ] { let mut value=original.clone();value["sources"]=bad; - assert!(Authority::decode(&serde_json::to_vec(&value).unwrap(),7).is_err()); + assert!(Authority::decode(&serde_json::to_vec(&value).unwrap(),8).is_err()); } }); assert_eq!(authority.input, *enrollment.input()); @@ -189,7 +189,7 @@ async fn current_and_retained_roots_bind_the_complete_namespace_with_distinct_ca let caller = namespace.attachment(GrantId::from_bytes([9; 32])).unwrap(); let crypto = fixture.crypto(); let clear = b"synthetic context payload"; - for version in [4, 5, 6, 7] { + for version in [4, 5, 6, 7, 8] { let current = crypto .seal_stock_root(&owner, version, clear) .await @@ -260,10 +260,14 @@ async fn retained_inventory_v6_preserves_original_physical_and_source_capabiliti retained_inventory_catalog(6).await; } #[tokio::test] -async fn current_v7_physical_ledger_uses_protected_parts() { - assert_eq!(schema::CURRENT, 7); +async fn retained_inventory_v7_keeps_consent_ledger_without_public_source_tables() { retained_inventory_catalog(7).await; } +#[tokio::test] +async fn current_v8_preserves_physical_and_private_source_progress_with_public_sources() { + assert_eq!(schema::CURRENT, 8); + retained_inventory_catalog(8).await; +} // Exact catalog fixtures exercise retained/successor codecs; they are not // evidence from a predecessor executable or a factory migration. pub(super) async fn literal_catalog( @@ -321,9 +325,13 @@ pub(super) async fn literal_catalog( value["sources"] = serde_json::json!({"revision":"0","records":"0","parts":"0","head":null}); } - if catalog == 7 { + if catalog >= 7 { value["inventory"]["orders"] = serde_json::json!("0"); } + if catalog == 8 { + value["public_sources"] = + serde_json::json!({"revision":"0","events":"0","heads":"0","parts":"0","head":null}); + } let clear = zeroize::Zeroizing::new(serde_json::to_vec(&value).unwrap()); let root = crypto .seal_stock_root(&input, catalog, &clear) @@ -360,6 +368,7 @@ pub(super) async fn literal_catalog( 5 => "PRAGMA user_version=5", 6 => "PRAGMA user_version=6", 7 => "PRAGMA user_version=7", + 8 => "PRAGMA user_version=8", _ => unreachable!(), }) .execute(&mut *tx) @@ -383,6 +392,7 @@ async fn retained_inventory_catalog(catalog: i64) { let binding = store.authenticate(input.clone(), &proof).await.unwrap(); let authority = store.stock_authority(input.clone(), &proof).await.unwrap(); assert_eq!(authority.source_checkpoint().is_some(), catalog >= 6); + assert_eq!(authority.listing_checkpoint().is_some(), catalog == 8); let minimum = authority.inventory_checkpoint().unwrap(); let context = CommandContextData::new( OperationId::from_bytes([7; 32]), @@ -624,7 +634,7 @@ async fn retained_inventory_catalog(catalog: i64) { .fetch_one(&mut connection) .await .unwrap(); - let old = if catalog == 7 { + let old = if matches!(catalog, 7 | 8) { let retained = ledger::read( &mut connection, &input, @@ -677,7 +687,7 @@ async fn retained_inventory_catalog(catalog: i64) { // inside a real SQL transaction. Row counts and the protected header // stay unchanged while one referenced ciphertext changes. for part in [false, true] { - if part && catalog != 7 { + if part && !matches!(catalog, 7 | 8) { continue; } let (authority, _, _, _) = read(&mut connection, &input, &fixture.crypto()) @@ -747,6 +757,7 @@ async fn retained_inventory_catalog(catalog: i64) { 5 => "PRAGMA user_version=6", 6 => "PRAGMA user_version=7", 7 => "PRAGMA user_version=6", + 8 => "PRAGMA user_version=7", _ => unreachable!(), }) .execute(&mut connection) diff --git a/crates/storage_sqlite/src/workspace/worker.rs b/crates/storage_sqlite/src/workspace/worker.rs @@ -38,6 +38,20 @@ const QUEUE_MAX_BYTES: usize = 4 * 1024 * 1024; const QUEUE_CAPACITY: usize = 32; type Reply<T, E = WorkspaceError> = oneshot::Sender<Result<T, E>>; enum Job { + RetainStockListing( + Box<WorkspaceBinding>, + radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + Box<stock::StockListingCapture>, + AttachmentProof, + Reply<stock::StockListingOutcome, OperationError>, + ), + StockListing( + Box<WorkspaceBinding>, + radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + stock::public_source::Lookup, + AttachmentProof, + Reply<Option<stock::StockListingSnapshot>, OperationError>, + ), IssueStockConsent( Box<WorkspaceBinding>, radroots_storage::inventory::InventoryCheckpointRef, @@ -204,6 +218,12 @@ enum Job { impl Job { fn reject_recovery(self) { match self { + Self::RetainStockListing(_, _, _, _, reply) => { + let _ = reply.send(Err(OperationError::RecoveryRequired)); + } + Self::StockListing(_, _, _, _, reply) => { + let _ = reply.send(Err(OperationError::RecoveryRequired)); + } Self::IssueStockConsent(_, _, _, _, reply) => { let _ = reply.send(Err(OperationError::RecoveryRequired)); } @@ -424,6 +444,8 @@ impl Handle { && !matches!( &job, Job::Authenticate(..) + | Job::RetainStockListing(..) + | Job::StockListing(..) | Job::IssueStockConsent(..) | Job::StockConsent(..) | Job::ChangeStockGrant(..) @@ -577,6 +599,56 @@ impl Handle { }; let _ = reply.send(result); } + Job::RetainStockListing( + binding, + minimum, + capture, + proof, + reply, + ) => { + let result = if kind == Kind::SellerStock { + stock::public_source::retain( + &mut stock::inventory::Turn { + connection, + namespace: &namespace, + selected: &input, + crypto: &crypto, + clock: clock.as_ref(), + uncertain: &mut uncertain, + }, + *binding, + minimum, + *capture, + proof, + ) + .await + } else { + Err(OperationError::UnsupportedOperation) + }; + let _ = reply.send(result); + } + Job::StockListing(binding, minimum, lookup, proof, reply) => { + let result = if kind == Kind::SellerStock { + stock::public_source::query( + &mut stock::inventory::Turn { + connection, + namespace: &namespace, + selected: &input, + crypto: &crypto, + clock: clock.as_ref(), + uncertain: &mut uncertain, + }, + *binding, + minimum, + lookup, + proof, + ) + .await + } else { + Err(OperationError::UnsupportedOperation) + }; + let _ = reply.send(result); + } Job::RetainStockSource(binding, minimum, capture, proof, reply) => { let result = if kind == Kind::SellerStock { stock::source::retain( @@ -1096,6 +1168,44 @@ impl Handle { ))?; result.await.map_err(|_| OperationError::RecoveryRequired)? } + pub(super) async fn retain_stock_listing( + &self, + binding: WorkspaceBinding, + minimum: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + capture: stock::StockListingCapture, + proof: AttachmentProof, + ) -> Result<stock::StockListingOutcome, OperationError> { + let anchor = stock::StockListingOutcome::Unknown { + transaction: capture.transaction_id(), + listing: capture.listing_revision(), + }; + let (reply, result) = oneshot::channel(); + self.send(Job::RetainStockListing( + Box::new(binding), + minimum, + Box::new(capture), + proof, + reply, + ))?; + result.await.unwrap_or(Ok(anchor)) + } + pub(super) async fn stock_listing( + &self, + binding: WorkspaceBinding, + minimum: radroots_storage::workspace::seller_stock::StockListingCheckpointRef, + lookup: stock::public_source::Lookup, + proof: AttachmentProof, + ) -> Result<Option<stock::StockListingSnapshot>, OperationError> { + let (reply, result) = oneshot::channel(); + self.send(Job::StockListing( + Box::new(binding), + minimum, + lookup, + proof, + reply, + ))?; + result.await.map_err(|_| OperationError::RecoveryRequired)? + } pub(super) async fn retain_stock_source( &self, binding: WorkspaceBinding, @@ -1164,6 +1274,7 @@ impl Handle { } fn send(&self, job: Job) -> Result<(), WorkspaceError> { let bytes = match &job { + Job::RetainStockListing(..) => 256 * 1024, Job::IssueStockConsent(..) => 512 * 1024, Job::RetainStockSource(..) => 256 * 1024, Job::ChangeStockGrant(..) | Job::ExecuteInventory(..) => 64 * 1024, diff --git a/crates/storage_sqlite/tests/fixtures/stock_public_sources.v1.json b/crates/storage_sqlite/tests/fixtures/stock_public_sources.v1.json @@ -0,0 +1,155 @@ +{ + "schema": "radroots.stock.public_sources.v1", + "author": "f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9", + "d": "01010101010101010101010101010101", + "observed_at": 150, + "vectors": [ + { + "name": "listing_fixed", + "raw": "{\"id\":\"46a96db48adfd8cb0bd89b33a169fde05888c5e1dc1fd5157834f5bf6bbe452b\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"7ead70c1825f09d2fac04c0501baa4e5d46e0117d8d04b15cb901d663ef425c192a992d595b21dbaf1e73626706314a42111858556c65e27482d2ae7696329b5\"}", + "expected": "listing" + }, + { + "name": "listing_large_profile", + "raw": "{\"id\":\"303b06a1a85665000a9abfdffcfb0220d50727035c687d0461286ae7d99e1e41\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"d2a836c87961fd6533577f0fb1e6545ea991382bcd9da31180ed908f092ad5b0d9cccbdc60899df7af0cf0466d5fb34126972bc52bd54b8ba235b0c54869cb40\"}", + "expected": "listing" + }, + { + "name": "listing_exact_event_bound", + "raw": "{\"id\":\"54e6e8567e5cede9c33707c0f76db569db819ec0d321234390949863dd4207f1\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬🥬\",\"sig\":\"4c57b9bd6b96a6c9ceaf630b771e7108c9439ee1a4d2b2f7673aacd1f654847a8714fe6c116f7ba024a180ed0a6b5086c3ed2894dfc2d268ae298560a8a03a1b\"}", + "expected": "listing" + }, + { + "name": "listing_shuffled", + "raw": "{\"id\":\"3f654a24fe6ffaee5406fc9639c16b17456dce231568c1b47b05830d8cc6ee68\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"price\",\"3.25\",\"CAD\"],[\"status\",\"active\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"radroots:price_unit\",\"bunch\"],[\"location\",\"Example region\"],[\"published_at\",\"99\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"title\",\"Carrot bunch\"],[\"d\",\"01010101010101010101010101010101\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"bc25c49996e84f98d2a978b93e1c9aa397829304aa8816c4d76ec91672a73af2b01f314b44b2c6d01ae66ff6a3ac98aee145199ffc4ea5747df52a94b4b64bd1\"}", + "expected": "listing" + }, + { + "name": "listing_equivalent_price_extra_zero", + "raw": "{\"id\":\"4835731d71bb6d8d4ab847e150bf68da2ed45cdc3eac21f0245ac4088c91a404\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.250\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"d8e93ed3342a6b56875f34f9120591f7635427ec06120c6949d833af0b08c4e192fe2fa7d47e37cffd28a47e8ab884b9e6a60b12be3a1cf45ef4a69a368329c6\"}", + "expected": "listing" + }, + { + "name": "listing_equivalent_price_extra_zeros", + "raw": "{\"id\":\"8dfbe28852e9b17ce778a6089e06ffcddd5cab7197010c2bb67bf8fce667e0af\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.2500\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"e7effc25e63c4f4aca5c2f2f9da05c9ce2f7004b88e52e240408e0a4b83cfd159314f18e6a95985ce356f7f961ccac4c1f8e2f414e882e48adb1d191665a7b24\"}", + "expected": "listing" + }, + { + "name": "listing_quote", + "raw": "{\"id\":\"539b61387667674d210f8547fbc4eca3288f00a122fb4725d5472cb623dab74a\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"type\\\":\\\"quote_required\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"f98560f1d82c7083189f34b72e57156d2a0a9f357d7f2ef540fb735ee3f5d272de6839b0995519b02555355d581a6ef2766fa18901cb402a4487f9171e1cbe22\"}", + "expected": "listing" + }, + { + "name": "listing_variable", + "raw": "{\"id\":\"47d8acc8fbcccd8617c8dd26f39938e3700e85aa013fd59b8dd92969e0b42171\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"maximum_per_sale_unit\\\":\\\"2\\\",\\\"maximum_per_sale_unit_total\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"650\\\"},\\\"measurement_unit\\\":\\\"kg\\\",\\\"minimum_per_sale_unit\\\":\\\"1\\\",\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"type\\\":\\\"variable_weight\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"8af0e0cc88efb0801a7b4704f8c8f183bfd4adea385ced7342710a23edd72bed049cf2eec32b4a245a4953025580b1f8cd917efd7a852aa798ef70cf7ff608f6\"}", + "expected": "listing" + }, + { + "name": "listing_paused", + "raw": "{\"id\":\"d16b2181f382904f9ed260647b07afe5847c031bf8b78e5202913ac574a16c1c\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":101,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"Unavailable: paused\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"paused\\\",\\\"version\\\":1}\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: paused\",\"sig\":\"9b0573c69856b6d13678c40aebd2abef4130aa7f11a2cc12ffefe5b8c091b72a0c57eb91778ca4d4d276eec12818e8ace824218c49a8d6dff8243b0f327fc9e8\"}", + "expected": "listing" + }, + { + "name": "listing_withdrawn", + "raw": "{\"id\":\"e8b61c31fff716b0bba82651277e36455111a89900bbceb2b26e7c33948966f4\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":101,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"Unavailable: withdrawn\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"withdrawn\\\",\\\"version\\\":1}\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: withdrawn\",\"sig\":\"0dd0b95132bfb9d5d12c2125189ff72a71c55256c41b9834f6fd823f3ca2845f91791f196d341aa6b64b11d3434e048d744793a7e350628a415ca78bc6a59138\"}", + "expected": "listing" + }, + { + "name": "listing_unsupported", + "raw": "{\"id\":\"bdf57664a406989694d16d082b2a75d2bfe2b67179e6c244e3752c0fda9e8d18\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":101,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":2}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"1c1e2e15e4e42ad042e4818a5133cb81f5245484ec4860013fcf18a6910a3905fd9004ebcfd3954f8ef549584fbc4c7f68381fe21334254d5f111f8dbc56789f\"}", + "expected": "unsupported" + }, + { + "name": "listing_unknown_field", + "raw": "{\"id\":\"7ec7bb57ab1f4834adcb2b4e841ced4452afe4d06eca6985eac989ad1e9af8e0\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":102,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"extra\\\":true,\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"1a6131afb337f7f3ea4ad3ebde41d6643e31667b740bd68a6e5551077496d17c3c5011376f0392615e0f46112db43daa6dbd85e661b15ade30387271e9b0a2ad\"}", + "expected": "invalid" + }, + { + "name": "listing_duplicate_d", + "raw": "{\"id\":\"9155a8512facd4b3f9146d6b32c15ffe21d7498e6dff3d229c6f33b0ac9d66d5\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":103,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"],[\"d\",\"ffffffffffffffffffffffffffffffff\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"e5eb60a09684e4136569283b223d064986b908bf4c63336661c9b3ab228c12adbce85de776e1e41fbfac2a6bdcad69a89dbf89fb1112ccf4fc3e48414dc41f83\"}", + "expected": "invalid" + }, + { + "name": "listing_ambiguous_d", + "raw": "{\"id\":\"455a9f86a3c891add3d7c6fa68a37bde139635d45954856d56629e17981ef16c\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":103,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\",\"ambiguous\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"062a172c706ead053d8ff97c96ca5f6962eba3a9d801b4309a695820fc993e2340dfc607efa2b86fbd39e16c1e421d0882fe07023e2541937912b5cb43314b1a\"}", + "expected": "invalid" + }, + { + "name": "listing_contradictory_price", + "raw": "{\"id\":\"e5effab01281ab8ae54ce66e72ce86c2596f89d77a5e8cbfe6c769776a906d1e\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":104,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"0\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"3fa8a0b012b88b5e191c4fa3c8cb84deef7275c693efee86fc56b7c275df1d7206d10a36f247af8ed773a57cae2f209776851a3c2caef0b09e9c394b4d5111a8\"}", + "expected": "invalid" + }, + { + "name": "listing_recurring_price", + "raw": "{\"id\":\"42989d6ae331ac70c63d1fefb759dc9f751fd0cc83197ec201665ad1e1c369bf\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":104,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\",\"month\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"a181d64442af4bb5ae9bc1b3932173e8e884c9e5bf2141326209239977d850a2968ca0059abdbc7100a6673030551fd208f073421a749853d2681757bbec491b\"}", + "expected": "invalid" + }, + { + "name": "listing_duplicate_profile", + "raw": "{\"id\":\"f5c1b43a1bef2baa530fb33a31ea5a26b562ccd60b99ec56fd5b2c93fc06e8a9\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":104,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"e98571a7874bac5bfb4bdf7e6b443d0b9424a54e9aa0c53a4bda04951c2a47dd81123ae152ccdc9aaeba0d55b90a7f91cb4480ff9a630de28e87de260c7aa48c\"}", + "expected": "invalid" + }, + { + "name": "bad_signature", + "raw": "{\"id\":\"dee33b0e27d44de73bc72411d92a60e0973d217143a4a2a6840c86897a1f66ee\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":105,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"}", + "expected": "unauthenticated" + }, + { + "name": "bad_id", + "raw": "{\"id\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"7ead70c1825f09d2fac04c0501baa4e5d46e0117d8d04b15cb901d663ef425c192a992d595b21dbaf1e73626706314a42111858556c65e27482d2ae7696329b5\"}", + "expected": "unauthenticated" + }, + { + "name": "capability", + "raw": "{\"id\":\"c8a5e8941cbbe3f9789983f9cab17ea79fb7c0a94420e20f1fdb1064b5e2118c\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":100,\"kind\":18890,\"tags\":[],\"content\":\"{\\\"profile\\\":\\\"radroots.capabilities\\\",\\\"supported_profiles\\\":[{\\\"features\\\":[\\\"base-order-v1\\\",\\\"bounded-variable-weight-v1\\\"],\\\"profile\\\":\\\"radroots.commerce\\\",\\\"versions\\\":[1,65535]}],\\\"valid_until\\\":\\\"200\\\",\\\"version\\\":1}\",\"sig\":\"e96a5498a06eb733d41c180978f72f501fac702507ec6661e014770e79dc8fd1635c9f6c6d89901689ef3ee50325526e674551a012b3b5a0da35c4123bedda07\"}", + "expected": "capabilities" + }, + { + "name": "listing_future", + "raw": "{\"id\":\"75512953afcd7964dc09838cf664c4d59df3144e1287d77df39112d38cddccb2\",\"pubkey\":\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\",\"created_at\":1000,\"kind\":30402,\"tags\":[[\"d\",\"01010101010101010101010101010101\"],[\"title\",\"Carrot bunch\"],[\"summary\",\"One bunch; CAD 3.25 per bunch\"],[\"published_at\",\"99\"],[\"location\",\"Example region\"],[\"radroots:price_unit\",\"bunch\"],[\"radroots:listing\",\"{\\\"authority\\\":null,\\\"default_option\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"fulfillment\\\":{\\\"area\\\":\\\"Example region\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"modes\\\":[\\\"pickup\\\"]},\\\"media\\\":[],\\\"options\\\":[{\\\"id\\\":\\\"0202020202020202020202020202020202020202020202020202020202020202\\\",\\\"increment\\\":\\\"1\\\",\\\"label\\\":\\\"One bunch\\\",\\\"lead_seconds\\\":\\\"0\\\",\\\"minimum\\\":\\\"1\\\",\\\"price\\\":{\\\"basis\\\":\\\"1\\\",\\\"discount_bps\\\":0,\\\"rate\\\":{\\\"currency\\\":\\\"CAD\\\",\\\"exponent\\\":2,\\\"minor\\\":\\\"325\\\"},\\\"tiers\\\":[],\\\"type\\\":\\\"fixed\\\"},\\\"supply\\\":{\\\"type\\\":\\\"unknown\\\"},\\\"unit\\\":{\\\"contents\\\":{\\\"type\\\":\\\"unspecified\\\"},\\\"label\\\":\\\"bunch\\\",\\\"type\\\":\\\"package\\\"}}],\\\"product\\\":{\\\"description\\\":\\\"Independent public conformance fixture\\\",\\\"name\\\":\\\"Carrots 🥕\\\",\\\"origin_summary\\\":\\\"Example region\\\",\\\"producer\\\":\\\"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9\\\"},\\\"profile\\\":\\\"radroots.listing\\\",\\\"state\\\":\\\"active\\\",\\\"version\\\":1}\"],[\"status\",\"active\"],[\"price\",\"3.25\",\"CAD\"]],\"content\":\"Synthetic carrots; availability: active\",\"sig\":\"c3f9ad1b48b9e61bee280165415861eaf75a54a1d5eee3748fc45cfe39ed0d3983f4ea660afa9dd3713ae34c8e0888b3d80171d2ca57dc3ee0ee5b23e9f2b8b9\"}", + "expected": "clock_ahead" + } + ], + "ranking_oracles": [ + [ + { + "input": "listing_fixed", + "head": "46a96db48adfd8cb0bd89b33a169fde05888c5e1dc1fd5157834f5bf6bbe452b" + }, + { + "input": "listing_unsupported", + "head": "bdf57664a406989694d16d082b2a75d2bfe2b67179e6c244e3752c0fda9e8d18" + }, + { + "input": "listing_unknown_field", + "head": "7ec7bb57ab1f4834adcb2b4e841ced4452afe4d06eca6985eac989ad1e9af8e0" + }, + { + "input": "listing_future", + "head": "75512953afcd7964dc09838cf664c4d59df3144e1287d77df39112d38cddccb2" + }, + { + "input": "listing_shuffled", + "head": "75512953afcd7964dc09838cf664c4d59df3144e1287d77df39112d38cddccb2" + } + ], + [ + { + "input": "listing_shuffled", + "head": "3f654a24fe6ffaee5406fc9639c16b17456dce231568c1b47b05830d8cc6ee68" + }, + { + "input": "listing_fixed", + "head": "3f654a24fe6ffaee5406fc9639c16b17456dce231568c1b47b05830d8cc6ee68" + }, + { + "input": "listing_equivalent_price_extra_zero", + "head": "3f654a24fe6ffaee5406fc9639c16b17456dce231568c1b47b05830d8cc6ee68" + }, + { + "input": "listing_equivalent_price_extra_zeros", + "head": "3f654a24fe6ffaee5406fc9639c16b17456dce231568c1b47b05830d8cc6ee68" + } + ] + ] +} diff --git a/crates/storage_sqlite/tests/fixtures/stock_public_sources.v1.provenance.json b/crates/storage_sqlite/tests/fixtures/stock_public_sources.v1.provenance.json @@ -0,0 +1,11 @@ +{ + "schema_version": 1, + "source_repository": "https://github.com/radrootslabs/lib", + "source_revision": "c79337d8851ee6da0b18aa7d7e97bc5b83d537ce", + "source_path": "crates/nostr/tests/fixtures/public_heads.v1.json", + "source_sha256": "96aef2300e1b6d0b13a4ce60ab3d106c223d08fffa640e43b2598ce2b6c4c7e9", + "producer": "Pinned nostr-tools2.23.5 and NobleCurves2.0.1; BIP340 primary vector0 matched first; independent synthetic test data only", + "selection": "Every listing-prefixed public vector, invalid signature/ID and a non-listing capability scope. Raw signed bytes and expected classifications are preserved without regeneration.", + "oracle": "Python integer timestamps descending, then exact lowercase hexadecimal event IDs ascending; not a Rust ranking or storage implementation.", + "output_sha256": "85c4a71e7238757fa7505ca1578d12dc4e2b1dcefc63ba204c33daef2fc7285d" +} diff --git a/crates/storage_sqlite/tests/support/stock_authority.rs b/crates/storage_sqlite/tests/support/stock_authority.rs @@ -602,7 +602,7 @@ async fn changed_catalog_after_protected_reads_is_refused_before_authenticated_c clock.release(); assert_eq!(operation.await, Err(WorkspaceError::RecoveryRequired)); store.close().await.unwrap(); - sqlx::query("PRAGMA user_version=7") + sqlx::query("PRAGMA user_version=8") .execute(&mut connection) .await .unwrap(); diff --git a/tools/xtask/src/architecture/decision_package.rs b/tools/xtask/src/architecture/decision_package.rs @@ -124,6 +124,20 @@ struct NativeSellerStockAuthority { retained_enrollment_versions: Vec<u16>, retained_inventory_versions: Vec<u16>, authority_payload_schema: String, + public_source_payload_schemas: Vec<String>, + public_source_owner_administration_required: bool, + inventory_scope_grants_public_source_access: bool, + public_source_checkpoint_independent: bool, + public_source_input_requires_signature_evidence: bool, + public_source_read_reverifies_signature: bool, + public_source_global_completeness_claimed: bool, + public_source_profile_implies_actionability: bool, + public_source_head_policy: String, + public_source_duplicate_encodings: String, + public_source_raw_max_bytes: u32, + public_source_part_max_bytes: u32, + public_source_part_max_count: u16, + public_source_worker_charge_bytes: u32, inventory_operation_payload_schema: String, operation_part_payload_schema: String, operation_body_max_bytes: u32, @@ -341,10 +355,29 @@ fn validate_bytes(raw: &[u8]) -> Result<(), String> { && stock.scope == "seller_stock_owner" && stock.database == "stock_execution_v1.sqlite" && stock.lock == ".stock_execution_v1.lock" - && stock.schema_version == 7 + && stock.schema_version == 8 && stock.retained_enrollment_versions == [1] - && stock.retained_inventory_versions == [2, 3, 4, 5, 6] - && stock.authority_payload_schema == "radroots.seller_stock.authority.v7" + && stock.retained_inventory_versions == [2, 3, 4, 5, 6, 7] + && stock.authority_payload_schema == "radroots.seller_stock.authority.v8" + && stock.public_source_payload_schemas + == [ + "radroots.seller_stock.public_source_event.v1", + "radroots.seller_stock.public_source_head.v1", + "radroots.seller_stock.public_source_part.v1", + ] + && stock.public_source_owner_administration_required + && !stock.inventory_scope_grants_public_source_access + && stock.public_source_checkpoint_independent + && stock.public_source_input_requires_signature_evidence + && stock.public_source_read_reverifies_signature + && !stock.public_source_global_completeness_claimed + && !stock.public_source_profile_implies_actionability + && stock.public_source_head_policy == "nip01_timestamp_then_lowest_id_before_profile" + && stock.public_source_duplicate_encodings == "retain_original_authenticated_event_id" + && stock.public_source_raw_max_bytes == 65536 + && stock.public_source_part_max_bytes == 16384 + && stock.public_source_part_max_count == 4 + && stock.public_source_worker_charge_bytes == 262144 && stock.inventory_operation_payload_schema == "radroots.seller_stock.operation.v5" && stock.operation_part_payload_schema == "radroots.seller_stock.operation_part.v1" && stock.operation_body_max_bytes == 262144 @@ -946,6 +979,43 @@ mod tests { } #[test] + fn public_sources_require_original_signatures_bounded_parts_and_profile_independent_heads() { + for (field, bad) in [ + ("schema_version", json!(7)), + ("retained_inventory_versions", json!([2, 3, 4, 5, 6])), + ("public_source_payload_schemas", json!([])), + ("public_source_owner_administration_required", json!(false)), + ("inventory_scope_grants_public_source_access", json!(true)), + ("public_source_checkpoint_independent", json!(false)), + ( + "public_source_input_requires_signature_evidence", + json!(false), + ), + ("public_source_read_reverifies_signature", json!(false)), + ("public_source_global_completeness_claimed", json!(true)), + ("public_source_profile_implies_actionability", json!(true)), + ("public_source_head_policy", json!("latest_supported")), + ( + "public_source_duplicate_encodings", + json!("replace_original"), + ), + ("public_source_raw_max_bytes", json!(65537)), + ("public_source_part_max_bytes", json!(16385)), + ("public_source_part_max_count", json!(5)), + ("public_source_worker_charge_bytes", json!(16384)), + ] { + assert!( + validate_bytes(&changed( + &format!("/native_seller_stock_authority/{field}"), + bad + )) + .is_err(), + "{field}" + ); + } + } + + #[test] fn consent_ledger_requires_bounded_parts_explicit_scopes_and_protected_identity() { for (field, bad) in [ ("schema_version", json!(6)),