lib

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

commit 7e8744dab5447b4d1767ac211052fb36941260f7
parent dadd796c4cc113ec3fd8511342b7707d553124b0
Author: triesap <tyson@radroots.org>
Date:   Mon, 27 Jul 2026 16:38:25 +0000

core: migrate workspace consumers

- Replace event trade codec and replica consumers with canonical core names
- Route pricing concepts through the governed pricing module
- Preserve language descriptors through explicit boundary overrides
- Correct adapter transport failures to count attempted delivery targets

Diffstat:
Mcrates/event/src/operational_listing.rs | 30++++++++++++++++++------------
Mcrates/event/src/order.rs | 116+++++++++++++++++++++++++++++++++----------------------------------------------
Mcrates/event/src/order_economics.rs | 49+++++++++++++++++++++++++++++++------------------
Mcrates/event/src/resource_cap.rs | 11+++++++----
Mcrates/event_codec/src/farm/mod.rs | 22+++++-----------------
Mcrates/event_codec/src/operational_listing/decode.rs | 49++++++++++++++++++++++---------------------------
Mcrates/event_codec/src/operational_listing/encode.rs | 17+++++++----------
Mcrates/event_codec/src/operational_listing/tags.rs | 108++++++++++++++++++++++++++++++++-----------------------------------------------
Mcrates/event_codec/src/order/decode.rs | 16+++++++---------
Mcrates/event_codec/src/resource_cap/encode.rs | 7++-----
Mcrates/event_codec/src/resource_cap/mod.rs | 12+++---------
Mcrates/event_codec/tests/domain_encode_non_serde.rs | 64++++++++++++++++++++++++++--------------------------------------
Mcrates/event_codec/tests/operational_listing.rs | 94++++++++++++++++++++++++++++++-------------------------------------------------
Mcrates/event_codec/tests/structured_decode.rs | 7++-----
Mcrates/event_codec/tests/structured_encode_default.rs | 27+++++++--------------------
Mcrates/event_codec/tests/tag_builders.rs | 32+++++++++++---------------------
Mcrates/replica_sync/src/ingest.rs | 35+++++++++++------------------------
Mcrates/trade/src/dto.rs | 20++++++++++----------
Mcrates/trade/src/operational_listing/draft.rs | 26+++++++-------------------
Mcrates/trade/src/operational_listing/model.rs | 16++++++++--------
Mcrates/trade/src/operational_listing/mutation.rs | 24++++++------------------
Mcrates/trade/src/operational_listing/price_ext.rs | 89+++++++++++++++++++++++++++++++------------------------------------------------
Mcrates/trade/src/operational_listing/validation.rs | 50++++++++++++++++++--------------------------------
Mcrates/transport_nostr/src/publish.rs | 2+-
Mcrates/transport_nostr/tests/transport.rs | 3++-
25 files changed, 374 insertions(+), 552 deletions(-)

diff --git a/crates/event/src/operational_listing.rs b/crates/event/src/operational_listing.rs @@ -1,7 +1,5 @@ -use radroots_core::{ - RadrootsCoreDecimal, RadrootsCoreDiscount, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::pricing::Discount; +use radroots_core::{Decimal, Money, Quantity, QuantityPrice, Unit}; use crate::farm::RadrootsFarmRef; use crate::ids::{RadrootsDTag, RadrootsInventoryBinId}; @@ -127,8 +125,10 @@ pub struct RadrootsOperationalListing { pub bins: Vec<RadrootsOperationalListingBin>, pub resource_area: Option<RadrootsResourceAreaRef>, pub plot: Option<RadrootsPlotRef>, - pub discounts: Option<Vec<RadrootsCoreDiscount>>, - pub inventory_available: Option<RadrootsCoreDecimal>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Array<Discount>")))] + pub discounts: Option<Vec<Discount>>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Decimal")))] + pub inventory_available: Option<Decimal>, pub availability: Option<RadrootsOperationalListingAvailability>, pub delivery_method: Option<RadrootsOperationalListingDeliveryMethod>, pub location: Option<RadrootsOperationalListingPublicLocation>, @@ -169,13 +169,19 @@ pub struct RadrootsOperationalListingProductTagKeys; #[derive(Clone, Debug)] pub struct RadrootsOperationalListingBin { pub bin_id: RadrootsInventoryBinId, - pub quantity: RadrootsCoreQuantity, - pub price_per_canonical_unit: RadrootsCoreQuantityPrice, - pub display_amount: Option<RadrootsCoreDecimal>, - pub display_unit: Option<RadrootsCoreUnit>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Quantity")))] + pub quantity: Quantity, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "QuantityPrice")))] + pub price_per_canonical_unit: QuantityPrice, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Decimal")))] + pub display_amount: Option<Decimal>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Unit")))] + pub display_unit: Option<Unit>, pub display_label: Option<String>, - pub display_price: Option<RadrootsCoreMoney>, - pub display_price_unit: Option<RadrootsCoreUnit>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub display_price: Option<Money>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Unit")))] + pub display_price_unit: Option<Unit>, } #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] diff --git a/crates/event/src/order.rs b/crates/event/src/order.rs @@ -17,7 +17,7 @@ use crate::operational_listing::RadrootsOperationalListingParseError; pub use crate::order_economics::*; #[cfg(test)] use crate::trade_validation::RadrootsOperationalListingValidationError; -use radroots_core::{RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney}; +use radroots_core::{Currency, Decimal, Money}; pub const RADROOTS_COMMERCIAL_LISTING_DOMAIN: &str = "trade:listing"; pub const RADROOTS_ORDER_ENVELOPE_VERSION: u16 = 1; @@ -48,13 +48,13 @@ impl RadrootsOrderEconomics { return Err(RadrootsOrderPayloadError::MissingEconomicItems); } - let mut subtotal = RadrootsCoreMoney::zero(self.currency); + let mut subtotal = Money::zero(self.currency); for (index, item) in self.items.iter().enumerate() { let line_subtotal = validate_economic_item(item, self.currency, index)?; subtotal = checked_money_add(&subtotal, &line_subtotal, "subtotal")?; } - let mut discount_total = RadrootsCoreMoney::zero(self.currency); + let mut discount_total = Money::zero(self.currency); for (index, line) in self.discounts.iter().enumerate() { validate_economic_line(line, self.currency, "discounts", index)?; if line.kind != RadrootsOrderEconomicLineKind::ListingDiscount { @@ -72,7 +72,7 @@ impl RadrootsOrderEconomics { discount_total = checked_money_add(&discount_total, &line.amount, "discount_total")?; } - let mut adjustment_total = RadrootsCoreMoney::zero(self.currency); + let mut adjustment_total = Money::zero(self.currency); let mut total = checked_money_sub_non_negative(&subtotal, &discount_total, "total")?; for (index, line) in self.adjustments.iter().enumerate() { validate_economic_line(line, self.currency, "adjustments", index)?; @@ -527,9 +527,9 @@ fn validate_order_items(items: &[RadrootsOrderItem]) -> Result<(), RadrootsOrder fn validate_economic_item( item: &RadrootsOrderEconomicItem, - expected_currency: RadrootsCoreCurrency, + expected_currency: Currency, index: usize, -) -> Result<RadrootsCoreMoney, RadrootsOrderPayloadError> { +) -> Result<Money, RadrootsOrderPayloadError> { validate_required_field(&item.bin_id, "economics.items.bin_id")?; if item.bin_count == 0 { return Err(RadrootsOrderPayloadError::InvalidEconomicItemBinCount { index }); @@ -551,11 +551,8 @@ fn validate_economic_item( "items.line_subtotal", )?; - let quantity_total = checked_decimal_mul( - item.quantity_amount, - RadrootsCoreDecimal::from(item.bin_count), - ) - .ok_or(RadrootsOrderPayloadError::InvalidEconomicItemSubtotal { index })?; + let quantity_total = checked_decimal_mul(item.quantity_amount, Decimal::from(item.bin_count)) + .ok_or(RadrootsOrderPayloadError::InvalidEconomicItemSubtotal { index })?; let expected_subtotal = checked_decimal_mul(item.unit_price_amount, quantity_total) .ok_or(RadrootsOrderPayloadError::InvalidEconomicItemSubtotal { index })?; if item.line_subtotal.amount != expected_subtotal { @@ -621,7 +618,7 @@ fn normalized_order_item_counts( fn validate_economic_line( line: &RadrootsOrderEconomicLine, - expected_currency: RadrootsCoreCurrency, + expected_currency: Currency, field: &'static str, index: usize, ) -> Result<(), RadrootsOrderPayloadError> { @@ -662,8 +659,8 @@ fn validate_economic_line_order( } fn validate_total_money( - money: &RadrootsCoreMoney, - expected_currency: RadrootsCoreCurrency, + money: &Money, + expected_currency: Currency, field: &'static str, ) -> Result<(), RadrootsOrderPayloadError> { if money.currency != expected_currency { @@ -676,8 +673,8 @@ fn validate_total_money( } fn validate_total_matches( - actual: &RadrootsCoreMoney, - expected: &RadrootsCoreMoney, + actual: &Money, + expected: &Money, field: &'static str, ) -> Result<(), RadrootsOrderPayloadError> { if actual.currency != expected.currency { @@ -689,45 +686,36 @@ fn validate_total_matches( Ok(()) } -fn checked_decimal_add( - left: RadrootsCoreDecimal, - right: RadrootsCoreDecimal, -) -> Option<RadrootsCoreDecimal> { - left.0.checked_add(right.0).map(RadrootsCoreDecimal) +fn checked_decimal_add(left: Decimal, right: Decimal) -> Option<Decimal> { + left.0.checked_add(right.0).map(Decimal) } -fn checked_decimal_sub( - left: RadrootsCoreDecimal, - right: RadrootsCoreDecimal, -) -> Option<RadrootsCoreDecimal> { - left.0.checked_sub(right.0).map(RadrootsCoreDecimal) +fn checked_decimal_sub(left: Decimal, right: Decimal) -> Option<Decimal> { + left.0.checked_sub(right.0).map(Decimal) } -fn checked_decimal_mul( - left: RadrootsCoreDecimal, - right: RadrootsCoreDecimal, -) -> Option<RadrootsCoreDecimal> { - left.0.checked_mul(right.0).map(RadrootsCoreDecimal) +fn checked_decimal_mul(left: Decimal, right: Decimal) -> Option<Decimal> { + left.0.checked_mul(right.0).map(Decimal) } fn checked_money_add( - left: &RadrootsCoreMoney, - right: &RadrootsCoreMoney, + left: &Money, + right: &Money, field: &'static str, -) -> Result<RadrootsCoreMoney, RadrootsOrderPayloadError> { +) -> Result<Money, RadrootsOrderPayloadError> { if left.currency != right.currency { return Err(RadrootsOrderPayloadError::InvalidEconomicCurrency { field }); } let amount = checked_decimal_add(left.amount, right.amount) .ok_or(RadrootsOrderPayloadError::InvalidEconomicTotal { field })?; - Ok(RadrootsCoreMoney::new(amount, left.currency)) + Ok(Money::new(amount, left.currency)) } fn checked_money_sub_non_negative( - left: &RadrootsCoreMoney, - right: &RadrootsCoreMoney, + left: &Money, + right: &Money, field: &'static str, -) -> Result<RadrootsCoreMoney, RadrootsOrderPayloadError> { +) -> Result<Money, RadrootsOrderPayloadError> { if left.currency != right.currency { return Err(RadrootsOrderPayloadError::InvalidEconomicCurrency { field }); } @@ -736,7 +724,7 @@ fn checked_money_sub_non_negative( if amount.is_sign_negative() { return Err(RadrootsOrderPayloadError::InvalidEconomicTotal { field }); } - Ok(RadrootsCoreMoney::new(amount, left.currency)) + Ok(Money::new(amount, left.currency)) } fn validate_inventory_commitments( @@ -757,9 +745,7 @@ fn validate_inventory_commitments( #[cfg(test)] mod tests { use super::*; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Unit}; fn pubkey(character: char) -> RadrootsPublicKey { core::iter::repeat_n(character, 64) @@ -808,12 +794,12 @@ mod tests { } } - fn decimal(raw: &str) -> RadrootsCoreDecimal { + fn decimal(raw: &str) -> Decimal { raw.parse().unwrap() } - fn usd(raw: &str) -> RadrootsCoreMoney { - RadrootsCoreMoney::new(decimal(raw), RadrootsCoreCurrency::USD) + fn usd(raw: &str) -> Money { + Money::new(decimal(raw), Currency::USD) } fn sample_order_economics() -> RadrootsOrderEconomics { @@ -821,24 +807,24 @@ mod tests { quote_id: quote_id("quote-1"), quote_version: 1, pricing_basis: RadrootsOrderPricingBasis::ListingEvent, - currency: RadrootsCoreCurrency::USD, + currency: Currency::USD, items: vec![ RadrootsOrderEconomicItem { bin_id: bin_id("bin-a"), bin_count: 2, quantity_amount: decimal("1.5"), - quantity_unit: RadrootsCoreUnit::Each, + quantity_unit: Unit::Each, unit_price_amount: decimal("4"), - unit_price_currency: RadrootsCoreCurrency::USD, + unit_price_currency: Currency::USD, line_subtotal: usd("12"), }, RadrootsOrderEconomicItem { bin_id: bin_id("bin-b"), bin_count: 1, quantity_amount: decimal("2"), - quantity_unit: RadrootsCoreUnit::Each, + quantity_unit: Unit::Each, unit_price_amount: decimal("3"), - unit_price_currency: RadrootsCoreCurrency::USD, + unit_price_currency: Currency::USD, line_subtotal: usd("6"), }, ], @@ -880,14 +866,14 @@ mod tests { quote_id: quote_id("quote-bound-1"), quote_version: 1, pricing_basis: RadrootsOrderPricingBasis::ListingEvent, - currency: RadrootsCoreCurrency::USD, + currency: Currency::USD, items: vec![RadrootsOrderEconomicItem { bin_id: bin_id("bin-1"), bin_count: 2, quantity_amount: decimal("1"), - quantity_unit: RadrootsCoreUnit::Each, + quantity_unit: Unit::Each, unit_price_amount: decimal("5"), - unit_price_currency: RadrootsCoreCurrency::USD, + unit_price_currency: Currency::USD, line_subtotal: usd("10"), }], discounts: Vec::new(), @@ -1128,7 +1114,7 @@ mod tests { #[test] fn order_economics_validation_rejects_mixed_currency() { let mut economics = sample_order_economics(); - economics.items[0].unit_price_currency = RadrootsCoreCurrency::EUR; + economics.items[0].unit_price_currency = Currency::EUR; assert_eq!( economics.validate().unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicCurrency { @@ -1137,8 +1123,7 @@ mod tests { ); let mut economics = sample_order_economics(); - economics.adjustments[0].amount = - RadrootsCoreMoney::new(decimal("2"), RadrootsCoreCurrency::EUR); + economics.adjustments[0].amount = Money::new(decimal("2"), Currency::EUR); assert_eq!( economics.validate().unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicCurrency { @@ -1164,8 +1149,7 @@ mod tests { ); let mut economics = sample_order_economics(); - economics.items[0].line_subtotal = - RadrootsCoreMoney::new(decimal("12"), RadrootsCoreCurrency::EUR); + economics.items[0].line_subtotal = Money::new(decimal("12"), Currency::EUR); assert_eq!( economics.validate().unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicCurrency { @@ -1222,7 +1206,7 @@ mod tests { ); let mut economics = sample_order_economics(); - economics.subtotal = RadrootsCoreMoney::new(decimal("18"), RadrootsCoreCurrency::EUR); + economics.subtotal = Money::new(decimal("18"), Currency::EUR); assert_eq!( economics.validate().unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicCurrency { field: "subtotal" } @@ -1350,22 +1334,18 @@ mod tests { #[test] fn order_economics_helpers_cover_currency_error_paths() { assert_eq!( - validate_total_money(&usd("-1"), RadrootsCoreCurrency::USD, "subtotal").unwrap_err(), + validate_total_money(&usd("-1"), Currency::USD, "subtotal").unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicTotal { field: "subtotal" } ); assert_eq!( - validate_total_matches( - &usd("1"), - &RadrootsCoreMoney::new(decimal("1"), RadrootsCoreCurrency::EUR), - "total" - ) - .unwrap_err(), + validate_total_matches(&usd("1"), &Money::new(decimal("1"), Currency::EUR), "total") + .unwrap_err(), RadrootsOrderPayloadError::InvalidEconomicCurrency { field: "total" } ); assert_eq!( checked_money_add( &usd("1"), - &RadrootsCoreMoney::new(decimal("1"), RadrootsCoreCurrency::EUR), + &Money::new(decimal("1"), Currency::EUR), "subtotal" ) .unwrap_err(), @@ -1374,7 +1354,7 @@ mod tests { assert_eq!( checked_money_sub_non_negative( &usd("1"), - &RadrootsCoreMoney::new(decimal("1"), RadrootsCoreCurrency::EUR), + &Money::new(decimal("1"), Currency::EUR), "total" ) .unwrap_err(), diff --git a/crates/event/src/order_economics.rs b/crates/event/src/order_economics.rs @@ -3,9 +3,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreUnit, -}; +use radroots_core::{Currency, Decimal, Money, Unit}; use crate::ids::{RadrootsInventoryBinId, RadrootsOrderQuoteId}; @@ -99,11 +97,16 @@ pub enum RadrootsOrderEconomicEffect { pub struct RadrootsOrderEconomicItem { pub bin_id: RadrootsInventoryBinId, pub bin_count: u32, - pub quantity_amount: RadrootsCoreDecimal, - pub quantity_unit: RadrootsCoreUnit, - pub unit_price_amount: RadrootsCoreDecimal, - pub unit_price_currency: RadrootsCoreCurrency, - pub line_subtotal: RadrootsCoreMoney, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Decimal")))] + pub quantity_amount: Decimal, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Unit")))] + pub quantity_unit: Unit, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Decimal")))] + pub unit_price_amount: Decimal, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Currency")))] + pub unit_price_currency: Currency, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub line_subtotal: Money, } #[cfg_attr(feature = "dto-bindgen", derive(dto_bindgen::Dto))] @@ -119,7 +122,8 @@ pub struct RadrootsOrderEconomicLine { pub kind: RadrootsOrderEconomicLineKind, pub actor: RadrootsOrderEconomicActor, pub effect: RadrootsOrderEconomicEffect, - pub amount: RadrootsCoreMoney, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub amount: Money, pub reason: String, } @@ -132,10 +136,14 @@ pub struct RadrootsOrderEconomicLine { )] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOrderEconomicTotals { - pub subtotal: RadrootsCoreMoney, - pub discount_total: RadrootsCoreMoney, - pub adjustment_total: RadrootsCoreMoney, - pub total: RadrootsCoreMoney, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub subtotal: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub discount_total: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub adjustment_total: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub total: Money, } #[cfg_attr( @@ -149,12 +157,17 @@ pub struct RadrootsOrderEconomics { pub quote_id: RadrootsOrderQuoteId, pub quote_version: u32, pub pricing_basis: RadrootsOrderPricingBasis, - pub currency: RadrootsCoreCurrency, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Currency")))] + pub currency: Currency, pub items: Vec<RadrootsOrderEconomicItem>, pub discounts: Vec<RadrootsOrderEconomicLine>, pub adjustments: Vec<RadrootsOrderEconomicLine>, - pub subtotal: RadrootsCoreMoney, - pub discount_total: RadrootsCoreMoney, - pub adjustment_total: RadrootsCoreMoney, - pub total: RadrootsCoreMoney, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub subtotal: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub discount_total: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub adjustment_total: Money, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Money")))] + pub total: Money, } diff --git a/crates/event/src/resource_cap.rs b/crates/event/src/resource_cap.rs @@ -1,6 +1,6 @@ #![forbid(unsafe_code)] -use radroots_core::{RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreUnit}; +use radroots_core::{Decimal, Quantity, Unit}; use crate::resource_area::RadrootsResourceAreaRef; @@ -34,9 +34,12 @@ pub struct RadrootsResourceHarvestCap { pub start: u64, #[cfg_attr(feature = "dto-bindgen", dto(int = "json_string"))] pub end: u64, - pub cap_quantity: RadrootsCoreQuantity, - pub display_amount: Option<RadrootsCoreDecimal>, - pub display_unit: Option<RadrootsCoreUnit>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Quantity")))] + pub cap_quantity: Quantity, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Decimal")))] + pub display_amount: Option<Decimal>, + #[cfg_attr(feature = "dto-bindgen", dto(ts(type = "Unit")))] + pub display_unit: Option<Unit>, pub display_label: Option<String>, pub tags: Option<Vec<String>>, } diff --git a/crates/event_codec/src/farm/mod.rs b/crates/event_codec/src/farm/mod.rs @@ -14,10 +14,7 @@ mod tests { farm_members_list_set, farm_operational_listings_list_set_from_listings, farm_plots_list_set_from_plots, member_of_farms_list_set, }; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::farm::{RadrootsFarm, RadrootsFarmPublicLocation, RadrootsFarmRef}; use radroots_event::ids::{RadrootsDTag, RadrootsInventoryBinId}; #[cfg(feature = "serde_json")] @@ -499,19 +496,10 @@ mod tests { primary_bin_id: bin_id("bin-1"), bins: vec![RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::Each, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new( - RadrootsCoreDecimal::from(10u32), - RadrootsCoreCurrency::USD, - ), - RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::Each, - ), + quantity: Quantity::new(Decimal::from(1u32), Unit::Each), + price_per_canonical_unit: QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::Each), ), display_amount: None, display_unit: None, diff --git a/crates/event_codec/src/operational_listing/decode.rs b/crates/event_codec/src/operational_listing/decode.rs @@ -4,10 +4,8 @@ use alloc::{ vec::Vec, }; -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreDiscount, RadrootsCoreMoney, - RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::pricing::Discount; +use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ RadrootsEventEnvelope, farm::RadrootsFarmRef, @@ -115,9 +113,9 @@ struct OperationalListingLocationDraft { fn parse_decimal( value: &str, field: &'static str, -) -> Result<RadrootsCoreDecimal, OperationalListingDecodeError> { +) -> Result<Decimal, OperationalListingDecodeError> { value - .parse::<RadrootsCoreDecimal>() + .parse::<Decimal>() .map_err(|_| OperationalListingDecodeError::InvalidNumber(field)) } @@ -160,18 +158,15 @@ fn reject_private_listing_location_content( fn parse_currency( value: &str, field: &'static str, -) -> Result<RadrootsCoreCurrency, OperationalListingDecodeError> { +) -> Result<Currency, OperationalListingDecodeError> { let upper = value.trim().to_ascii_uppercase(); - RadrootsCoreCurrency::from_str_upper(&upper) + Currency::from_str_upper(&upper) .map_err(|_| OperationalListingDecodeError::InvalidCurrency(field)) } -fn parse_unit( - value: &str, - field: &'static str, -) -> Result<RadrootsCoreUnit, OperationalListingDecodeError> { +fn parse_unit(value: &str, field: &'static str) -> Result<Unit, OperationalListingDecodeError> { value - .parse::<RadrootsCoreUnit>() + .parse::<Unit>() .map_err(|_| OperationalListingDecodeError::InvalidUnit(field)) } @@ -391,9 +386,9 @@ fn decode_operational_listing_from_event_parts( let mut primary_bin_id: Option<String> = None; let mut bin_drafts: Vec<BinDraft> = Vec::new(); let mut bin_order = 0usize; - let mut discounts: Vec<RadrootsCoreDiscount> = Vec::new(); + let mut discounts: Vec<Discount> = Vec::new(); let mut location: Option<OperationalListingLocationDraft> = None; - let mut inventory_available: Option<RadrootsCoreDecimal> = None; + let mut inventory_available: Option<Decimal> = None; let mut availability_status: Option<RadrootsOperationalListingStatus> = None; let mut availability_start: Option<u64> = None; let mut availability_end: Option<u64> = None; @@ -477,7 +472,7 @@ fn decode_operational_listing_from_event_parts( if bin.quantity.is_some() { return Err(OperationalListingDecodeError::InvalidTag(TAG_RADROOTS_BIN)); } - bin.quantity = Some(RadrootsCoreQuantity::new(amount, unit)); + bin.quantity = Some(Quantity::new(amount, unit)); match tag.as_slice() { [_, _, _, _, display_amount_raw, display_unit_raw] @@ -509,9 +504,9 @@ fn decode_operational_listing_from_event_parts( let currency = parse_currency(&tag[3], TAG_RADROOTS_PRICE)?; let per_amount = parse_decimal(&tag[4], TAG_RADROOTS_PRICE)?; let per_unit = parse_unit(&tag[5], TAG_RADROOTS_PRICE)?; - let price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(amount, currency), - RadrootsCoreQuantity::new(per_amount, per_unit), + let price_per_canonical_unit = QuantityPrice::new( + Money::new(amount, currency), + Quantity::new(per_amount, per_unit), ); if !price_per_canonical_unit.is_price_per_canonical_unit() { return Err(OperationalListingDecodeError::InvalidTag( @@ -535,7 +530,7 @@ fn decode_operational_listing_from_event_parts( [_, _, _, _, _, _, display_price_raw, display_unit_raw] => { let display_price = parse_decimal(display_price_raw, TAG_RADROOTS_PRICE)?; let display_unit = parse_unit(display_unit_raw, TAG_RADROOTS_PRICE)?; - bin.display_price = Some(RadrootsCoreMoney::new(display_price, currency)); + bin.display_price = Some(Money::new(display_price, currency)); bin.display_price_unit = Some(display_unit); } _ => {} @@ -808,7 +803,7 @@ fn parse_image_size(value: &str) -> Option<RadrootsOperationalListingImageSize> Some(RadrootsOperationalListingImageSize { w, h }) } -fn parse_discount(payload: &str) -> Result<RadrootsCoreDiscount, OperationalListingDecodeError> { +fn parse_discount(payload: &str) -> Result<Discount, OperationalListingDecodeError> { #[cfg(feature = "serde_json")] { serde_json::from_str(payload) @@ -825,13 +820,13 @@ fn parse_discount(payload: &str) -> Result<RadrootsCoreDiscount, OperationalList struct BinDraft { bin_id: String, order_index: usize, - quantity: Option<RadrootsCoreQuantity>, - display_amount: Option<RadrootsCoreDecimal>, - display_unit: Option<RadrootsCoreUnit>, + quantity: Option<Quantity>, + display_amount: Option<Decimal>, + display_unit: Option<Unit>, display_label: Option<String>, - price_per_canonical_unit: Option<RadrootsCoreQuantityPrice>, - display_price: Option<RadrootsCoreMoney>, - display_price_unit: Option<RadrootsCoreUnit>, + price_per_canonical_unit: Option<QuantityPrice>, + display_price: Option<Money>, + display_price_unit: Option<Unit>, } fn upsert_bin<'a>( diff --git a/crates/event_codec/src/operational_listing/encode.rs b/crates/event_codec/src/operational_listing/encode.rs @@ -71,18 +71,15 @@ fn operational_listing_markdown_content(listing: &RadrootsOperationalListing) -> mod tests { use super::*; use core::str::FromStr; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ farm::RadrootsFarmRef, ids::{RadrootsDTag, RadrootsInventoryBinId}, operational_listing::{RadrootsOperationalListingBin, RadrootsOperationalListingProduct}, }; - fn decimal(value: &str) -> RadrootsCoreDecimal { - RadrootsCoreDecimal::from_str(value).expect("decimal") + fn decimal(value: &str) -> Decimal { + Decimal::from_str(value).expect("decimal") } fn listing_with(title: &str, summary: Option<&str>) -> RadrootsOperationalListing { @@ -107,10 +104,10 @@ mod tests { primary_bin_id: RadrootsInventoryBinId::parse("bin-1").expect("bin id"), bins: vec![RadrootsOperationalListingBin { bin_id: RadrootsInventoryBinId::parse("bin-1").expect("bin id"), - quantity: RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassG), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("1"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::MassG), + quantity: Quantity::new(decimal("1"), Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(decimal("1"), Currency::USD), + Quantity::new(Decimal::ONE, Unit::MassG), ), display_amount: None, display_unit: None, diff --git a/crates/event_codec/src/operational_listing/tags.rs b/crates/event_codec/src/operational_listing/tags.rs @@ -8,9 +8,9 @@ use alloc::{ vec::Vec, }; +use radroots_core::Money; #[cfg(any(feature = "serde_json", test))] -use radroots_core::RadrootsCoreDiscount; -use radroots_core::RadrootsCoreMoney; +use radroots_core::pricing::Discount; use radroots_event::farm::RadrootsFarmRef; use radroots_event::kinds::{KIND_FARM, KIND_PLOT, KIND_RESOURCE_AREA}; use radroots_event::location::{has_textual_locality, is_public_geohash5}; @@ -384,15 +384,13 @@ fn tag_listing_price(bin: &RadrootsOperationalListingBin) -> Result<Vec<String>, Ok(tag) } -fn bin_total_price( - bin: &RadrootsOperationalListingBin, -) -> Result<RadrootsCoreMoney, EventEncodeError> { +fn bin_total_price(bin: &RadrootsOperationalListingBin) -> Result<Money, EventEncodeError> { bin.price_per_canonical_unit .try_cost_for_quantity_in(&bin.quantity) .map_err(|_| EventEncodeError::EmptyRequiredField("bin.price_per_canonical_unit")) } -fn tag_listing_price_generic(price: &RadrootsCoreMoney) -> Vec<String> { +fn tag_listing_price_generic(price: &Money) -> Vec<String> { let mut tag = Vec::with_capacity(4); tag.push(TAG_PRICE.to_string()); tag.push(price.amount.to_string()); @@ -434,7 +432,7 @@ fn clean_value(value: &str) -> Option<String> { } #[cfg(any(feature = "serde_json", test))] -fn discount_tag_payload(discount: &RadrootsCoreDiscount) -> Result<String, EventEncodeError> { +fn discount_tag_payload(discount: &Discount) -> Result<String, EventEncodeError> { #[cfg(feature = "serde_json")] { serde_json::to_string(discount).map_err(|_| EventEncodeError::Json) @@ -462,11 +460,8 @@ mod tests { use crate::test_fixtures::{ CDN_PRIMARY_HTTPS, FIXTURE_ALICE_NPUB, FIXTURE_ALICE_PUBLIC_KEY_HEX, }; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreDiscountScope, - RadrootsCoreDiscountThreshold, RadrootsCoreDiscountValue, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::pricing::{DiscountScope, DiscountThreshold, DiscountValue}; + use radroots_core::{Currency, Decimal, Quantity, QuantityPrice, Unit}; use radroots_event::ids::{RadrootsDTag, RadrootsInventoryBinId}; use radroots_event::operational_listing::{ RadrootsOperationalListingImageSize, RadrootsOperationalListingProduct, @@ -482,8 +477,8 @@ mod tests { format!("{CDN_PRIMARY_HTTPS}/{path}") } - fn decimal(value: &str) -> RadrootsCoreDecimal { - RadrootsCoreDecimal::from_str(value).expect("valid decimal") + fn decimal(value: &str) -> Decimal { + Decimal::from_str(value).expect("valid decimal") } fn d_tag(raw: &str) -> RadrootsDTag { @@ -511,20 +506,16 @@ mod tests { fn base_bin() -> RadrootsOperationalListingBin { RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new(decimal("1000"), RadrootsCoreUnit::MassG) - .with_label("bag"), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("0.01"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::MassG), + quantity: Quantity::new(decimal("1000"), Unit::MassG).with_label("bag"), + price_per_canonical_unit: QuantityPrice::new( + Money::new(decimal("0.01"), Currency::USD), + Quantity::new(Decimal::ONE, Unit::MassG), ), display_amount: Some(decimal("1")), - display_unit: Some(RadrootsCoreUnit::MassKg), + display_unit: Some(Unit::MassKg), display_label: Some("kilobag".to_string()), - display_price: Some(RadrootsCoreMoney::new( - decimal("10"), - RadrootsCoreCurrency::USD, - )), - display_price_unit: Some(RadrootsCoreUnit::MassKg), + display_price: Some(Money::new(decimal("10"), Currency::USD)), + display_price_unit: Some(Unit::MassKg), } } @@ -704,16 +695,13 @@ mod tests { #[test] fn discount_payload_without_serde_json_errors() { - let discount = RadrootsCoreDiscount { - scope: RadrootsCoreDiscountScope::Bin, - threshold: RadrootsCoreDiscountThreshold::BinCount { + let discount = Discount { + scope: DiscountScope::Bin, + threshold: DiscountThreshold::BinCount { bin_id: "bin-1".to_string(), min: 2, }, - value: RadrootsCoreDiscountValue::MoneyPerBin(RadrootsCoreMoney::new( - decimal("1"), - RadrootsCoreCurrency::USD, - )), + value: DiscountValue::MoneyPerBin(Money::new(decimal("1"), Currency::USD)), }; #[cfg(feature = "serde_json")] { @@ -803,7 +791,7 @@ mod tests { assert_eq!(generic_tag[0], "price"); let mut non_canonical = base_bin(); - non_canonical.quantity = RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassKg); + non_canonical.quantity = Quantity::new(decimal("1"), Unit::MassKg); let err = tag_listing_bin(&non_canonical).expect_err("non canonical quantity"); assert!(matches!( err, @@ -834,9 +822,9 @@ mod tests { assert_eq!(no_display_tag.len(), 4); let mut invalid_unit_price = base_bin(); - invalid_unit_price.price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(decimal("2"), RadrootsCoreUnit::MassG), + invalid_unit_price.price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(decimal("2"), Unit::MassG), ); let err = tag_listing_price(&invalid_unit_price).expect_err("not unit price"); assert!(matches!( @@ -845,10 +833,7 @@ mod tests { )); let mut mismatch_display_currency = base_bin(); - mismatch_display_currency.display_price = Some(RadrootsCoreMoney::new( - decimal("10"), - RadrootsCoreCurrency::EUR, - )); + mismatch_display_currency.display_price = Some(Money::new(decimal("10"), Currency::EUR)); let err = tag_listing_price(&mismatch_display_currency).expect_err("currency mismatch"); assert!(matches!( err, @@ -880,9 +865,9 @@ mod tests { assert_eq!(tag.len(), 6); let mut invalid_cost = base_bin(); - invalid_cost.price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::Each), + invalid_cost.price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(Decimal::ONE, Unit::Each), ); let err = bin_total_price(&invalid_cost).expect_err("invalid cost conversion"); assert!(matches!( @@ -895,9 +880,9 @@ mod tests { fn operational_listing_tags_propagate_bin_and_resource_area_validation_errors() { let mut listing = base_listing(); listing.discounts = None; - listing.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(decimal("2"), RadrootsCoreUnit::MassG), + listing.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(decimal("2"), Unit::MassG), ); let err = operational_listing_tags_with_options( &listing, @@ -911,11 +896,10 @@ mod tests { let mut listing = base_listing(); listing.discounts = None; - listing.bins[0].quantity = - RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassKg); - listing.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::MassG), + listing.bins[0].quantity = Quantity::new(decimal("1"), Unit::MassKg); + listing.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(Decimal::ONE, Unit::MassG), ); let err = operational_listing_tags_with_options( &listing, @@ -929,11 +913,10 @@ mod tests { let mut listing = base_listing(); listing.discounts = None; - listing.bins[0].quantity = - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::Each); - listing.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::ONE, RadrootsCoreUnit::MassG), + listing.bins[0].quantity = Quantity::new(Decimal::ONE, Unit::Each); + listing.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(Decimal::ONE, Unit::MassG), ); let err = operational_listing_tags_with_options( &listing, @@ -965,16 +948,13 @@ mod tests { #[test] fn operational_listing_tags_required_errors_and_success_paths() { let mut listing_with_discount = base_listing(); - listing_with_discount.discounts = Some(vec![RadrootsCoreDiscount { - scope: RadrootsCoreDiscountScope::Bin, - threshold: RadrootsCoreDiscountThreshold::BinCount { + listing_with_discount.discounts = Some(vec![Discount { + scope: DiscountScope::Bin, + threshold: DiscountThreshold::BinCount { bin_id: "bin-1".to_string(), min: 2, }, - value: RadrootsCoreDiscountValue::MoneyPerBin(RadrootsCoreMoney::new( - decimal("1"), - RadrootsCoreCurrency::USD, - )), + value: DiscountValue::MoneyPerBin(Money::new(decimal("1"), Currency::USD)), }]); #[cfg(feature = "serde_json")] { @@ -1300,7 +1280,7 @@ mod tests { let mut first = base_bin(); first.bin_id = bin_id("bin-2"); first.display_label = None; - first.quantity = RadrootsCoreQuantity::new(decimal("1000"), RadrootsCoreUnit::MassG); + first.quantity = Quantity::new(decimal("1000"), Unit::MassG); let mut second = base_bin(); second.bin_id = bin_id("bin-1"); listing_without_primary_match.primary_bin_id = bin_id("bin-missing"); diff --git a/crates/event_codec/src/order/decode.rs b/crates/event_codec/src/order/decode.rs @@ -350,9 +350,7 @@ mod tests { order_cancellation_event_build, order_decision_event_build, order_request_event_build, }; use crate::order::tags::TAG_LISTING_EVENT; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Unit}; use radroots_event::{ RadrootsEventEnvelope, RadrootsEventEnvelopeParts, RadrootsEventPtr, ids::{ @@ -462,12 +460,12 @@ mod tests { } } - fn decimal(raw: &str) -> RadrootsCoreDecimal { + fn decimal(raw: &str) -> Decimal { raw.parse().unwrap() } - fn usd(raw: &str) -> RadrootsCoreMoney { - RadrootsCoreMoney::new(decimal(raw), RadrootsCoreCurrency::USD) + fn usd(raw: &str) -> Money { + Money::new(decimal(raw), Currency::USD) } fn request_economics() -> RadrootsOrderEconomics { @@ -475,14 +473,14 @@ mod tests { quote_id: quote_id("quote-1"), quote_version: 1, pricing_basis: RadrootsOrderPricingBasis::ListingEvent, - currency: RadrootsCoreCurrency::USD, + currency: Currency::USD, items: vec![RadrootsOrderEconomicItem { bin_id: bin_id("lb"), bin_count: 3, quantity_amount: decimal("1"), - quantity_unit: RadrootsCoreUnit::Each, + quantity_unit: Unit::Each, unit_price_amount: decimal("5"), - unit_price_currency: RadrootsCoreCurrency::USD, + unit_price_currency: Currency::USD, line_subtotal: usd("15"), }], discounts: Vec::<RadrootsOrderEconomicLine>::new(), diff --git a/crates/event_codec/src/resource_cap/encode.rs b/crates/event_codec/src/resource_cap/encode.rs @@ -106,7 +106,7 @@ pub fn to_wire_parts_with_kind( mod tests { use super::*; use crate::test_fixtures::FIXTURE_ALICE_PUBLIC_KEY_HEX; - use radroots_core::{RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreUnit}; + use radroots_core::{Decimal, Quantity, Unit}; use radroots_event::resource_area::RadrootsResourceAreaRef; use radroots_event::resource_cap::RadrootsResourceHarvestProduct; @@ -123,10 +123,7 @@ mod tests { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, diff --git a/crates/event_codec/src/resource_cap/mod.rs b/crates/event_codec/src/resource_cap/mod.rs @@ -7,7 +7,7 @@ pub mod encode; mod tests { use crate::error::EventEncodeError; use crate::resource_cap::encode::resource_harvest_cap_build_tags; - use radroots_core::{RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreUnit}; + use radroots_core::{Decimal, Quantity, Unit}; use radroots_event::resource_area::RadrootsResourceAreaRef; use radroots_event::resource_cap::{ RadrootsResourceHarvestCap, RadrootsResourceHarvestProduct, @@ -27,10 +27,7 @@ mod tests { }, start: 1735689600, end: 1767225600, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(100000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(100000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, @@ -74,10 +71,7 @@ mod tests { }, start: 1735689600, end: 1767225600, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(100000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(100000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, diff --git a/crates/event_codec/tests/domain_encode_non_serde.rs b/crates/event_codec/tests/domain_encode_non_serde.rs @@ -3,10 +3,7 @@ mod test_fixtures; use std::str::FromStr; -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ coop::{RadrootsCoop, RadrootsCoopLocation, RadrootsCoopRef}, document::{RadrootsDocument, RadrootsDocumentSubject}, @@ -54,8 +51,8 @@ const VALID_AREA_D_TAG: &str = "AAAAAAAAAAAAAAAAAAAAAw"; const VALID_CAP_D_TAG: &str = "AAAAAAAAAAAAAAAAAAAABA"; const VALID_DOC_D_TAG: &str = "AAAAAAAAAAAAAAAAAAAAAg"; -fn decimal(value: &str) -> RadrootsCoreDecimal { - RadrootsCoreDecimal::from_str(value).expect("valid decimal") +fn decimal(value: &str) -> Decimal { + Decimal::from_str(value).expect("valid decimal") } fn listing_d_tag(raw: &str) -> RadrootsDTag { @@ -160,10 +157,9 @@ fn sample_plot() -> RadrootsPlot { } fn sample_listing() -> RadrootsOperationalListing { - let quantity = - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each); - let price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), + let quantity = Quantity::new(Decimal::from(1u32), Unit::Each); + let price_per_canonical_unit = QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), quantity.clone(), ); @@ -239,7 +235,7 @@ fn sample_resource_cap() -> RadrootsResourceHarvestCap { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new(decimal("1000"), RadrootsCoreUnit::MassG), + cap_quantity: Quantity::new(decimal("1000"), Unit::MassG), display_amount: None, display_unit: None, display_label: None, @@ -676,7 +672,7 @@ fn listing_encode_paths() { .clone() .with_label("fallback-label"); listing_with_display_fallback.bins[0].display_amount = Some(decimal("1")); - listing_with_display_fallback.bins[0].display_unit = Some(RadrootsCoreUnit::Each); + listing_with_display_fallback.bins[0].display_unit = Some(Unit::Each); listing_with_display_fallback.bins[0].display_label = None; let display_tags = operational_listing_tags_with_options( &listing_with_display_fallback, @@ -862,7 +858,7 @@ fn listing_encode_paths() { let mut invalid = sample_listing(); invalid.bins[0].display_price = None; - invalid.bins[0].display_price_unit = Some(RadrootsCoreUnit::Each); + invalid.bins[0].display_price_unit = Some(Unit::Each); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) .expect_err("missing display price"); @@ -872,10 +868,7 @@ fn listing_encode_paths() { )); let mut invalid = sample_listing(); - invalid.bins[0].display_price = Some(RadrootsCoreMoney::new( - decimal("10"), - RadrootsCoreCurrency::USD, - )); + invalid.bins[0].display_price = Some(Money::new(decimal("10"), Currency::USD)); invalid.bins[0].display_price_unit = None; let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) @@ -886,11 +879,9 @@ fn listing_encode_paths() { )); let mut listing_with_display_price = sample_listing(); - listing_with_display_price.bins[0].display_price = Some(RadrootsCoreMoney::new( - decimal("10"), - RadrootsCoreCurrency::USD, - )); - listing_with_display_price.bins[0].display_price_unit = Some(RadrootsCoreUnit::Each); + listing_with_display_price.bins[0].display_price = + Some(Money::new(decimal("10"), Currency::USD)); + listing_with_display_price.bins[0].display_price_unit = Some(Unit::Each); let display_price_tags = operational_listing_tags_with_options( &listing_with_display_price, OperationalListingTagOptions::default(), @@ -903,10 +894,7 @@ fn listing_encode_paths() { })); let mut invalid = listing_with_display_price.clone(); - invalid.bins[0].display_price = Some(RadrootsCoreMoney::new( - decimal("10"), - RadrootsCoreCurrency::EUR, - )); + invalid.bins[0].display_price = Some(Money::new(decimal("10"), Currency::EUR)); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) .expect_err("display price currency mismatch"); @@ -917,7 +905,7 @@ fn listing_encode_paths() { let mut invalid = sample_listing(); invalid.bins[0].display_amount = None; - invalid.bins[0].display_unit = Some(RadrootsCoreUnit::Each); + invalid.bins[0].display_unit = Some(Unit::Each); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) .expect_err("missing display amount"); @@ -927,10 +915,10 @@ fn listing_encode_paths() { )); let mut invalid = sample_listing(); - invalid.bins[0].quantity = RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassKg); - invalid.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassG), + invalid.bins[0].quantity = Quantity::new(decimal("1"), Unit::MassKg); + invalid.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(decimal("1"), Unit::MassG), ); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) @@ -941,9 +929,9 @@ fn listing_encode_paths() { )); let mut invalid = sample_listing(); - invalid.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(decimal("2"), RadrootsCoreUnit::Each), + invalid.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(decimal("2"), Unit::Each), ); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) @@ -954,9 +942,9 @@ fn listing_encode_paths() { )); let mut invalid = sample_listing(); - invalid.bins[0].price_per_canonical_unit = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(decimal("10"), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(decimal("1"), RadrootsCoreUnit::MassG), + invalid.bins[0].price_per_canonical_unit = QuantityPrice::new( + Money::new(decimal("10"), Currency::USD), + Quantity::new(decimal("1"), Unit::MassG), ); let err = operational_listing_tags_with_options(&invalid, OperationalListingTagOptions::default()) @@ -1302,6 +1290,6 @@ fn document_encode_paths() { #[test] fn resource_harvest_cap_money_type_sanity() { - let money = RadrootsCoreMoney::new(decimal("1"), RadrootsCoreCurrency::USD); + let money = Money::new(decimal("1"), Currency::USD); assert_eq!(money.amount.to_string(), "1"); } diff --git a/crates/event_codec/tests/operational_listing.rs b/crates/event_codec/tests/operational_listing.rs @@ -1,10 +1,7 @@ #![cfg(feature = "serde_json")] -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreDiscount, RadrootsCoreDiscountScope, - RadrootsCoreDiscountThreshold, RadrootsCoreDiscountValue, RadrootsCoreMoney, - RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::pricing::{Discount, DiscountScope, DiscountThreshold, DiscountValue}; +use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ RadrootsEventEnvelope, RadrootsEventEnvelopeParts, farm::RadrootsFarmRef, @@ -103,10 +100,9 @@ fn assert_invalid_tag(tags: Vec<Vec<String>>, expected: &'static str) { } fn sample_listing(d_tag: &str) -> RadrootsOperationalListing { - let quantity = - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each); - let price = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), + let quantity = Quantity::new(Decimal::from(1u32), Unit::Each); + let price = QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), quantity.clone(), ); @@ -222,8 +218,8 @@ fn operational_listing_from_event_parts_does_not_allow_json_content_to_override_ let mut listing = sample_listing("AAAAAAAAAAAAAAAAAAAAAg"); listing.product.title = "Content override".to_string(); listing.product.category = "Content category".to_string(); - listing.inventory_available = Some(RadrootsCoreDecimal::from(99u32)); - listing.bins[0].quantity.amount = RadrootsCoreDecimal::from(42u32); + listing.inventory_available = Some(Decimal::from(99u32)); + listing.bins[0].quantity.amount = Decimal::from(42u32); let decoded = operational_listing_from_event_parts(&tags, &serde_json::to_string(&listing).unwrap()) @@ -232,10 +228,7 @@ fn operational_listing_from_event_parts_does_not_allow_json_content_to_override_ assert_eq!(decoded.product.title, "Widget"); assert_eq!(decoded.product.category, "Tools"); assert_eq!(decoded.inventory_available, None); - assert_eq!( - decoded.bins[0].quantity.amount, - RadrootsCoreDecimal::from(1u32) - ); + assert_eq!(decoded.bins[0].quantity.amount, Decimal::from(1u32)); } #[test] @@ -351,10 +344,10 @@ fn execute_listing_parse_vector(vector: &Value, id: &str) { } fn sample_listing_full(d_tag: &str) -> RadrootsOperationalListing { - let qty_amount = RadrootsCoreDecimal::from_str("1000").unwrap(); - let price_amount = RadrootsCoreDecimal::from_str("0.01").unwrap(); - let display_qty = RadrootsCoreDecimal::from_str("1").unwrap(); - let display_price = RadrootsCoreDecimal::from_str("10").unwrap(); + let qty_amount = Decimal::from_str("1000").unwrap(); + let price_amount = Decimal::from_str("0.01").unwrap(); + let display_qty = Decimal::from_str("1").unwrap(); + let display_price = Decimal::from_str("10").unwrap(); RadrootsOperationalListing { d_tag: listing_d_tag(d_tag), @@ -377,31 +370,28 @@ fn sample_listing_full(d_tag: &str) -> RadrootsOperationalListing { primary_bin_id: bin_id("bin-1"), bins: vec![RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new(qty_amount, RadrootsCoreUnit::MassG), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(price_amount, RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::MassG), + quantity: Quantity::new(qty_amount, Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(price_amount, Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::MassG), ), display_amount: Some(display_qty), - display_unit: Some(RadrootsCoreUnit::MassKg), + display_unit: Some(Unit::MassKg), display_label: Some("bag".to_string()), - display_price: Some(RadrootsCoreMoney::new( - display_price, - RadrootsCoreCurrency::USD, - )), - display_price_unit: Some(RadrootsCoreUnit::MassKg), + display_price: Some(Money::new(display_price, Currency::USD)), + display_price_unit: Some(Unit::MassKg), }], resource_area: None, plot: None, - discounts: Some(vec![RadrootsCoreDiscount { - scope: RadrootsCoreDiscountScope::Bin, - threshold: RadrootsCoreDiscountThreshold::BinCount { + discounts: Some(vec![Discount { + scope: DiscountScope::Bin, + threshold: DiscountThreshold::BinCount { bin_id: "bin-1".to_string(), min: 5, }, - value: RadrootsCoreDiscountValue::MoneyPerBin(RadrootsCoreMoney::new( - RadrootsCoreDecimal::from_str("2").unwrap(), - RadrootsCoreCurrency::USD, + value: DiscountValue::MoneyPerBin(Money::new( + Decimal::from_str("2").unwrap(), + Currency::USD, )), }]), inventory_available: None, @@ -735,11 +725,8 @@ fn operational_listing_from_event_covers_bin_and_price_error_paths() { ); let decoded = operational_listing_from_event(KIND_CLASSIFIED_LISTING, &tags, "# Widget").unwrap(); - assert_eq!( - decoded.bins[0].display_amount, - Some(RadrootsCoreDecimal::from(1u32)) - ); - assert_eq!(decoded.bins[0].display_unit, Some(RadrootsCoreUnit::Each)); + assert_eq!(decoded.bins[0].display_amount, Some(Decimal::from(1u32))); + assert_eq!(decoded.bins[0].display_unit, Some(Unit::Each)); assert_eq!(decoded.bins[0].display_label, None); let mut tags = sample_operational_listing_tags(); @@ -1325,25 +1312,16 @@ fn operational_listing_tags_full_uses_single_generic_price_for_primary_bin() { let mut listing = sample_listing_full("AAAAAAAAAAAAAAAAAAAAAw"); listing.bins.push(RadrootsOperationalListingBin { bin_id: bin_id("bin-2"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from_str("500").unwrap(), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new( - RadrootsCoreDecimal::from_str("0.02").unwrap(), - RadrootsCoreCurrency::USD, - ), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::MassG), + quantity: Quantity::new(Decimal::from_str("500").unwrap(), Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(Decimal::from_str("0.02").unwrap(), Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::MassG), ), - display_amount: Some(RadrootsCoreDecimal::from(500u32)), - display_unit: Some(RadrootsCoreUnit::MassG), + display_amount: Some(Decimal::from(500u32)), + display_unit: Some(Unit::MassG), display_label: Some("sample".to_string()), - display_price: Some(RadrootsCoreMoney::new( - RadrootsCoreDecimal::from_str("10").unwrap(), - RadrootsCoreCurrency::USD, - )), - display_price_unit: Some(RadrootsCoreUnit::MassG), + display_price: Some(Money::new(Decimal::from_str("10").unwrap(), Currency::USD)), + display_price_unit: Some(Unit::MassG), }); let tags = operational_listing_tags_full(&listing).unwrap(); @@ -1365,7 +1343,7 @@ fn operational_listing_tags_full_uses_single_generic_price_for_primary_bin() { #[test] fn operational_listing_tags_full_includes_trade_fields() { let mut listing = sample_listing("AAAAAAAAAAAAAAAAAAAAAg"); - let inventory = RadrootsCoreDecimal::from_str("12.5").unwrap(); + let inventory = Decimal::from_str("12.5").unwrap(); let inventory_value = inventory.to_string(); listing.inventory_available = Some(inventory); listing.availability = Some(RadrootsOperationalListingAvailability::Window { diff --git a/crates/event_codec/tests/structured_decode.rs b/crates/event_codec/tests/structured_decode.rs @@ -6,7 +6,7 @@ mod test_fixtures; mod common; use common::{EVENT_ID, EVENT_SIG}; -use radroots_core::{RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreUnit}; +use radroots_core::{Decimal, Quantity, Unit}; use radroots_event::coop::RadrootsCoop; use radroots_event::document::{RadrootsDocument, RadrootsDocumentSubject}; use radroots_event::farm::{RadrootsFarm, RadrootsFarmRef}; @@ -176,10 +176,7 @@ fn sample_resource_cap(d_tag: &str) -> RadrootsResourceHarvestCap { }, start: 100, end: 200, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, diff --git a/crates/event_codec/tests/structured_encode_default.rs b/crates/event_codec/tests/structured_encode_default.rs @@ -3,10 +3,7 @@ #[path = "../src/test_fixtures.rs"] mod test_fixtures; -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::coop::{RadrootsCoop, RadrootsCoopLocation, RadrootsCoopRef}; use radroots_event::document::{RadrootsDocument, RadrootsDocumentSubject}; use radroots_event::farm::{RadrootsFarm, RadrootsFarmPublicLocation, RadrootsFarmRef}; @@ -110,10 +107,9 @@ fn sample_gcs() -> RadrootsGcsLocation { } fn sample_listing(d_tag: &str) -> RadrootsOperationalListing { - let quantity = - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each); - let price = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), + let quantity = Quantity::new(Decimal::from(1u32), Unit::Each); + let price = QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), quantity.clone(), ); RadrootsOperationalListing { @@ -260,10 +256,7 @@ fn sample_resource_cap() -> RadrootsResourceHarvestCap { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, @@ -571,10 +564,7 @@ fn structured_build_tags_cover_optional_and_error_paths() { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, @@ -831,10 +821,7 @@ fn structured_build_tags_cover_required_field_errors() { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, diff --git a/crates/event_codec/tests/tag_builders.rs b/crates/event_codec/tests/tag_builders.rs @@ -1,11 +1,8 @@ #[path = "../src/test_fixtures.rs"] mod test_fixtures; -use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreDiscount, RadrootsCoreDiscountScope, - RadrootsCoreDiscountThreshold, RadrootsCoreDiscountValue, RadrootsCoreMoney, - RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreUnit, -}; +use radroots_core::pricing::{Discount, DiscountScope, DiscountThreshold, DiscountValue}; +use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::RadrootsEventPtr; use radroots_event::app_data::RadrootsAppData; use radroots_event::coop::RadrootsCoop; @@ -112,10 +109,9 @@ fn sample_gcs() -> RadrootsGcsLocation { } fn sample_listing() -> RadrootsOperationalListing { - let quantity = - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each); - let price = RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), + let quantity = Quantity::new(Decimal::from(1u32), Unit::Each); + let price = QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), quantity.clone(), ); @@ -272,10 +268,7 @@ fn event_tag_builder_impls_build_tags_for_all_supported_types() { }, start: 1, end: 2, - cap_quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), + cap_quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), display_amount: None, display_unit: None, display_label: None, @@ -455,7 +448,7 @@ fn listing_and_message_builders_cover_optional_shapes() { assert!(!operational_listing_build_tags(&listing).unwrap().is_empty()); let mut listing_with_trade = listing.clone(); - listing_with_trade.inventory_available = Some(RadrootsCoreDecimal::from(12u32)); + listing_with_trade.inventory_available = Some(Decimal::from(12u32)); let with_trade_fields: fn() -> OperationalListingTagOptions = OperationalListingTagOptions::with_trade_fields; let trade_options = with_trade_fields(); @@ -571,16 +564,13 @@ fn listing_and_message_builders_cover_optional_shapes() { )); let mut listing_with_discount_payload = listing_with_trade.clone(); - listing_with_discount_payload.discounts = Some(vec![RadrootsCoreDiscount { - scope: RadrootsCoreDiscountScope::Bin, - threshold: RadrootsCoreDiscountThreshold::BinCount { + listing_with_discount_payload.discounts = Some(vec![Discount { + scope: DiscountScope::Bin, + threshold: DiscountThreshold::BinCount { bin_id: "bin-1".to_string(), min: 2, }, - value: RadrootsCoreDiscountValue::MoneyPerBin(RadrootsCoreMoney::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreCurrency::USD, - )), + value: DiscountValue::MoneyPerBin(Money::new(Decimal::from(1u32), Currency::USD)), }]); #[cfg(feature = "serde_json")] { diff --git a/crates/replica_sync/src/ingest.rs b/crates/replica_sync/src/ingest.rs @@ -11,7 +11,7 @@ use base64::Engine; #[cfg(feature = "std")] use base64::engine::general_purpose::URL_SAFE_NO_PAD; -use radroots_core::RadrootsCoreDecimal; +use radroots_core::Decimal; #[cfg(test)] use radroots_event::RadrootsEventEnvelopeParts; use radroots_event::contract::RadrootsEventClass; @@ -770,10 +770,7 @@ fn primary_listing_bin( }) } -fn decimal_to_i64( - value: &RadrootsCoreDecimal, - field: &str, -) -> Result<i64, RadrootsReplicaEventsError> { +fn decimal_to_i64(value: &Decimal, field: &str) -> Result<i64, RadrootsReplicaEventsError> { let value = decimal_to_u64(value, field)?; match i64::try_from(value) { Ok(value) => Ok(value), @@ -783,10 +780,7 @@ fn decimal_to_i64( } } -fn decimal_to_f64( - value: &RadrootsCoreDecimal, - field: &str, -) -> Result<f64, RadrootsReplicaEventsError> { +fn decimal_to_f64(value: &Decimal, field: &str) -> Result<f64, RadrootsReplicaEventsError> { match value.to_f64_lossy() { Some(value) => Ok(value), None => Err(RadrootsReplicaEventsError::InvalidData(format!( @@ -795,10 +789,7 @@ fn decimal_to_f64( } } -fn decimal_to_u64( - value: &RadrootsCoreDecimal, - field: &str, -) -> Result<u64, RadrootsReplicaEventsError> { +fn decimal_to_u64(value: &Decimal, field: &str) -> Result<u64, RadrootsReplicaEventsError> { match value.to_u64_exact() { Some(value) => Ok(value), None => Err(RadrootsReplicaEventsError::InvalidData(format!( @@ -1631,10 +1622,7 @@ mod tests { use std::sync::atomic::{AtomicUsize, Ordering}; use nostr::{EventBuilder, Keys, Kind, Tag, Timestamp}; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreMoney, RadrootsCoreQuantity, RadrootsCoreQuantityPrice, - RadrootsCoreUnit, - }; + use radroots_core::{Currency, Money, Quantity, QuantityPrice, Unit}; use radroots_event::farm::{RadrootsFarm, RadrootsFarmPublicLocation, RadrootsFarmRef}; use radroots_event::gcs::{RadrootsGcsLocation, RadrootsGeoJsonPoint, RadrootsGeoJsonPolygon}; use radroots_event::kinds::{KIND_LIST_SET_FOLLOW, KIND_LIST_SET_GENERIC}; @@ -2129,11 +2117,11 @@ mod tests { ) } - fn listing_decimal(raw: &str) -> RadrootsCoreDecimal { + fn listing_decimal(raw: &str) -> Decimal { raw.parse().expect("decimal") } - fn listing_currency() -> RadrootsCoreCurrency { + fn listing_currency() -> Currency { "USD".parse().expect("currency") } @@ -2159,11 +2147,10 @@ mod tests { primary_bin_id: "bin-a".parse().expect("primary bin id"), bins: vec![RadrootsOperationalListingBin { bin_id: "bin-a".parse().expect("bin id"), - quantity: RadrootsCoreQuantity::new(listing_decimal("12"), RadrootsCoreUnit::Each) - .with_label("unit label"), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(listing_decimal("6"), listing_currency()), - RadrootsCoreQuantity::new(listing_decimal("1"), RadrootsCoreUnit::Each), + quantity: Quantity::new(listing_decimal("12"), Unit::Each).with_label("unit label"), + price_per_canonical_unit: QuantityPrice::new( + Money::new(listing_decimal("6"), listing_currency()), + Quantity::new(listing_decimal("1"), Unit::Each), ), display_amount: None, display_unit: None, diff --git a/crates/trade/src/dto.rs b/crates/trade/src/dto.rs @@ -89,28 +89,28 @@ impl Dto for RadrootsOperationalListingTradeProjection { .with_field(field( "bin_quantity", "bin_quantity", - ts_ref("RadrootsCoreQuantity"), + ts_ref("Quantity"), "crates/trade/src/operational_listing/validation.rs", 33, )) .with_field(field( "unit", "unit", - ts_ref("RadrootsCoreUnit"), + ts_ref("Unit"), "crates/trade/src/operational_listing/validation.rs", 34, )) .with_field(field( "unit_price", "unit_price", - ts_ref("RadrootsCoreMoney"), + ts_ref("Money"), "crates/trade/src/operational_listing/validation.rs", 35, )) .with_field(field( "inventory_available", "inventory_available", - ts_ref("RadrootsCoreDecimal"), + ts_ref("Decimal"), "crates/trade/src/operational_listing/validation.rs", 36, )) @@ -182,28 +182,28 @@ fn operational_listing_total_like( .with_field(field( "price_amount", "price_amount", - ts_ref("RadrootsCoreMoney"), + ts_ref("Money"), file, line + 1, )) .with_field(field( "price_currency", "price_currency", - ts_ref("RadrootsCoreCurrency"), + ts_ref("Currency"), file, line + 2, )) .with_field(field( "quantity_amount", "quantity_amount", - ts_ref("RadrootsCoreDecimal"), + ts_ref("Decimal"), file, line + 3, )) .with_field(field( "quantity_unit", "quantity_unit", - ts_ref("RadrootsCoreUnit"), + ts_ref("Unit"), file, line + 4, )); @@ -285,7 +285,7 @@ mod tests { assert_eq!( typescript_override_target(field_ty(listing, "inventory_available")), - Some("RadrootsCoreDecimal") + Some("Decimal") ); assert_eq!( typescript_override_target(field_ty(listing, "listing")), @@ -293,7 +293,7 @@ mod tests { ); assert_eq!( typescript_override_target(field_ty(subtotal, "price_currency")), - Some("RadrootsCoreCurrency") + Some("Currency") ); } diff --git a/crates/trade/src/operational_listing/draft.rs b/crates/trade/src/operational_listing/draft.rs @@ -194,10 +194,7 @@ pub fn canonicalize_operational_listing_edit( #[cfg(test)] mod tests { use radroots_authority::RadrootsActorContext; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ contract::RadrootsActorRole, farm::RadrootsFarmRef, @@ -253,19 +250,10 @@ mod tests { primary_bin_id: bin_id("bin-1"), bins: vec![RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice { - amount: RadrootsCoreMoney::new( - RadrootsCoreDecimal::from(20u32), - RadrootsCoreCurrency::USD, - ), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::MassG, - ), + quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice { + amount: Money::new(Decimal::from(20u32), Currency::USD), + quantity: Quantity::new(Decimal::from(1u32), Unit::MassG), }, display_amount: None, display_unit: None, @@ -276,7 +264,7 @@ mod tests { resource_area: None, plot: None, discounts: None, - inventory_available: Some(RadrootsCoreDecimal::from(5u32)), + inventory_available: Some(Decimal::from(5u32)), availability: Some(RadrootsOperationalListingAvailability::Status { status: RadrootsOperationalListingStatus::Active, }), @@ -560,7 +548,7 @@ mod tests { let mut mismatched_unit_listing = listing(); let mut secondary_bin = mismatched_unit_listing.bins[0].clone(); secondary_bin.bin_id = bin_id("bin-2"); - secondary_bin.price_per_canonical_unit.quantity.unit = RadrootsCoreUnit::Each; + secondary_bin.price_per_canonical_unit.quantity.unit = Unit::Each; mismatched_unit_listing.bins.push(secondary_bin); let error = RadrootsOperationalListingCanonicalEdit::new( diff --git a/crates/trade/src/operational_listing/model.rs b/crates/trade/src/operational_listing/model.rs @@ -1,17 +1,17 @@ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOperationalListingSubtotal { - pub price_amount: radroots_core::RadrootsCoreMoney, - pub price_currency: radroots_core::RadrootsCoreCurrency, - pub quantity_amount: radroots_core::RadrootsCoreDecimal, - pub quantity_unit: radroots_core::RadrootsCoreUnit, + pub price_amount: radroots_core::Money, + pub price_currency: radroots_core::Currency, + pub quantity_amount: radroots_core::Decimal, + pub quantity_unit: radroots_core::Unit, } #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct RadrootsOperationalListingTotal { - pub price_amount: radroots_core::RadrootsCoreMoney, - pub price_currency: radroots_core::RadrootsCoreCurrency, - pub quantity_amount: radroots_core::RadrootsCoreDecimal, - pub quantity_unit: radroots_core::RadrootsCoreUnit, + pub price_amount: radroots_core::Money, + pub price_currency: radroots_core::Currency, + pub quantity_amount: radroots_core::Decimal, + pub quantity_unit: radroots_core::Unit, } diff --git a/crates/trade/src/operational_listing/mutation.rs b/crates/trade/src/operational_listing/mutation.rs @@ -169,10 +169,7 @@ pub fn build_operational_listing_mutation_draft( #[cfg(test)] mod tests { - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ contract::validate_event_contract_shape, farm::RadrootsFarmRef, @@ -236,19 +233,10 @@ mod tests { primary_bin_id: bin_id("bin-1"), bins: vec![RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice { - amount: RadrootsCoreMoney::new( - RadrootsCoreDecimal::from(20u32), - RadrootsCoreCurrency::USD, - ), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::MassG, - ), + quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice { + amount: Money::new(Decimal::from(20u32), Currency::USD), + quantity: Quantity::new(Decimal::from(1u32), Unit::MassG), }, display_amount: None, display_unit: None, @@ -259,7 +247,7 @@ mod tests { resource_area: None, plot: None, discounts: None, - inventory_available: Some(RadrootsCoreDecimal::from(5u32)), + inventory_available: Some(Decimal::from(5u32)), availability: Some(RadrootsOperationalListingAvailability::Status { status: RadrootsOperationalListingStatus::Active, }), diff --git a/crates/trade/src/operational_listing/price_ext.rs b/crates/trade/src/operational_listing/price_ext.rs @@ -1,10 +1,8 @@ use crate::operational_listing::model::{ RadrootsOperationalListingSubtotal, RadrootsOperationalListingTotal, }; -use radroots_core::{ - RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreQuantityPriceError, - RadrootsCoreQuantityPriceOps, -}; +use radroots_core::pricing::{Error as PricingError, QuantityPriceOps}; +use radroots_core::{Decimal, Quantity}; use radroots_event::operational_listing::RadrootsOperationalListingBin; pub trait BinPricingExt { @@ -16,17 +14,17 @@ pub trait BinPricingTryExt { fn try_subtotal_for_count( &self, bin_count: u32, - ) -> Result<RadrootsOperationalListingSubtotal, RadrootsCoreQuantityPriceError>; + ) -> Result<RadrootsOperationalListingSubtotal, PricingError>; fn try_total_for_count( &self, bin_count: u32, - ) -> Result<RadrootsOperationalListingTotal, RadrootsCoreQuantityPriceError>; + ) -> Result<RadrootsOperationalListingTotal, PricingError>; } #[inline] -fn effective_quantity(bin: &RadrootsOperationalListingBin, bin_count: u32) -> RadrootsCoreQuantity { - let amount = bin.quantity.amount * RadrootsCoreDecimal::from(bin_count); - RadrootsCoreQuantity::new(amount, bin.quantity.unit) +fn effective_quantity(bin: &RadrootsOperationalListingBin, bin_count: u32) -> Quantity { + let amount = bin.quantity.amount * Decimal::from(bin_count); + Quantity::new(amount, bin.quantity.unit) } impl BinPricingExt for RadrootsOperationalListingBin { @@ -60,7 +58,7 @@ impl BinPricingTryExt for RadrootsOperationalListingBin { fn try_subtotal_for_count( &self, bin_count: u32, - ) -> Result<RadrootsOperationalListingSubtotal, RadrootsCoreQuantityPriceError> { + ) -> Result<RadrootsOperationalListingSubtotal, PricingError> { let effective_qty = effective_quantity(self, bin_count); let money = self .price_per_canonical_unit @@ -78,7 +76,7 @@ impl BinPricingTryExt for RadrootsOperationalListingBin { fn try_total_for_count( &self, bin_count: u32, - ) -> Result<RadrootsOperationalListingTotal, RadrootsCoreQuantityPriceError> { + ) -> Result<RadrootsOperationalListingTotal, PricingError> { let sub = self.try_subtotal_for_count(bin_count)?; Ok(RadrootsOperationalListingTotal { price_amount: sub.price_amount, @@ -92,10 +90,8 @@ impl BinPricingTryExt for RadrootsOperationalListingBin { #[cfg(test)] mod tests { use super::{BinPricingExt, BinPricingTryExt}; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreQuantityPriceError, RadrootsCoreUnit, - }; + use radroots_core::pricing::Error as PricingError; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::ids::RadrootsInventoryBinId; use radroots_event::operational_listing::RadrootsOperationalListingBin; @@ -106,13 +102,10 @@ mod tests { fn valid_bin() -> RadrootsOperationalListingBin { RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(2u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(5u32), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::MassG), + quantity: Quantity::new(Decimal::from(2u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(Decimal::from(5u32), Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::MassG), ), display_amount: None, display_unit: None, @@ -126,13 +119,10 @@ mod tests { fn try_subtotal_for_rejects_unit_mismatch() { let bin = RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each), + quantity: Quantity::new(Decimal::from(1u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::Each), ), display_amount: None, display_unit: None, @@ -144,9 +134,9 @@ mod tests { let err = bin.try_subtotal_for_count(1).unwrap_err(); assert_eq!( err, - RadrootsCoreQuantityPriceError::UnitMismatch { - have: RadrootsCoreUnit::MassG, - want: RadrootsCoreUnit::Each, + PricingError::UnitMismatch { + have: Unit::MassG, + want: Unit::Each, } ); } @@ -157,13 +147,10 @@ mod tests { let subtotal = bin.subtotal_for_count(3); let total = bin.total_for_count(3); - assert_eq!(subtotal.quantity_amount, RadrootsCoreDecimal::from(6u32)); - assert_eq!(subtotal.quantity_unit, RadrootsCoreUnit::MassG); - assert_eq!( - subtotal.price_amount.amount, - RadrootsCoreDecimal::from(30u32) - ); - assert_eq!(subtotal.price_currency, RadrootsCoreCurrency::USD); + assert_eq!(subtotal.quantity_amount, Decimal::from(6u32)); + assert_eq!(subtotal.quantity_unit, Unit::MassG); + assert_eq!(subtotal.price_amount.amount, Decimal::from(30u32)); + assert_eq!(subtotal.price_currency, Currency::USD); assert_eq!(total.quantity_amount, subtotal.quantity_amount); assert_eq!(total.quantity_unit, subtotal.quantity_unit); @@ -177,11 +164,8 @@ mod tests { let subtotal = bin.try_subtotal_for_count(4).expect("subtotal"); let total = bin.try_total_for_count(4).expect("total"); - assert_eq!(subtotal.quantity_amount, RadrootsCoreDecimal::from(8u32)); - assert_eq!( - subtotal.price_amount.amount, - RadrootsCoreDecimal::from(40u32) - ); + assert_eq!(subtotal.quantity_amount, Decimal::from(8u32)); + assert_eq!(subtotal.price_amount.amount, Decimal::from(40u32)); assert_eq!(total.quantity_amount, subtotal.quantity_amount); assert_eq!(total.price_amount, subtotal.price_amount); } @@ -190,13 +174,10 @@ mod tests { fn try_total_for_count_propagates_subtotal_errors() { let bin = RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice::new( - RadrootsCoreMoney::new(RadrootsCoreDecimal::from(10u32), RadrootsCoreCurrency::USD), - RadrootsCoreQuantity::new(RadrootsCoreDecimal::from(1u32), RadrootsCoreUnit::Each), + quantity: Quantity::new(Decimal::from(1u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice::new( + Money::new(Decimal::from(10u32), Currency::USD), + Quantity::new(Decimal::from(1u32), Unit::Each), ), display_amount: None, display_unit: None, @@ -208,9 +189,9 @@ mod tests { let err = bin.try_total_for_count(1).unwrap_err(); assert_eq!( err, - RadrootsCoreQuantityPriceError::UnitMismatch { - have: RadrootsCoreUnit::MassG, - want: RadrootsCoreUnit::Each, + PricingError::UnitMismatch { + have: Unit::MassG, + want: Unit::Each, } ); } diff --git a/crates/trade/src/operational_listing/validation.rs b/crates/trade/src/operational_listing/validation.rs @@ -6,9 +6,7 @@ use alloc::{ string::{String, ToString}, }; -use radroots_core::{ - RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, RadrootsCoreUnit, -}; +use radroots_core::{Decimal, Money, Quantity, Unit}; use radroots_event::{ classified_listing::{RadrootsClassifiedListingPartition, classify_classified_listing_tags}, ids::{RadrootsClassifiedListingAddress, RadrootsPublicKey}, @@ -37,10 +35,10 @@ pub struct RadrootsOperationalListingTradeProjection { pub description: String, pub product_type: String, pub primary_bin_id: String, - pub bin_quantity: RadrootsCoreQuantity, - pub unit: RadrootsCoreUnit, - pub unit_price: RadrootsCoreMoney, - pub inventory_available: RadrootsCoreDecimal, + pub bin_quantity: Quantity, + pub unit: Unit, + pub unit_price: Money, + pub inventory_available: Decimal, pub availability: RadrootsOperationalListingAvailability, pub location: RadrootsOperationalListingPublicLocation, pub delivery_method: RadrootsOperationalListingDeliveryMethod, @@ -239,10 +237,7 @@ mod tests { validate_operational_listing_model, }; use nostr::{EventBuilder, Keys, Kind, Tag, Timestamp}; - use radroots_core::{ - RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, RadrootsCoreUnit, - }; + use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; use radroots_event::{ RadrootsEventEnvelope, RadrootsEventEnvelopeParts, farm::RadrootsFarmRef, @@ -302,19 +297,10 @@ mod tests { primary_bin_id: bin_id("bin-1"), bins: vec![RadrootsOperationalListingBin { bin_id: bin_id("bin-1"), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1000u32), - RadrootsCoreUnit::MassG, - ), - price_per_canonical_unit: RadrootsCoreQuantityPrice { - amount: RadrootsCoreMoney::new( - RadrootsCoreDecimal::from(20u32), - RadrootsCoreCurrency::USD, - ), - quantity: RadrootsCoreQuantity::new( - RadrootsCoreDecimal::from(1u32), - RadrootsCoreUnit::MassG, - ), + quantity: Quantity::new(Decimal::from(1000u32), Unit::MassG), + price_per_canonical_unit: QuantityPrice { + amount: Money::new(Decimal::from(20u32), Currency::USD), + quantity: Quantity::new(Decimal::from(1u32), Unit::MassG), }, display_amount: None, display_unit: None, @@ -325,7 +311,7 @@ mod tests { resource_area: None, plot: None, discounts: None, - inventory_available: Some(RadrootsCoreDecimal::from(5u32)), + inventory_available: Some(Decimal::from(5u32)), availability: Some(RadrootsOperationalListingAvailability::Status { status: radroots_event::operational_listing::RadrootsOperationalListingStatus::Active, @@ -624,7 +610,7 @@ mod tests { OperationalListingValidationError::InvalidBin, ); assert_secondary_bin_model_error( - |bin| bin.quantity.unit = RadrootsCoreUnit::MassKg, + |bin| bin.quantity.unit = Unit::MassKg, OperationalListingValidationError::InvalidBin, ); } @@ -633,13 +619,13 @@ mod tests { fn model_validation_rejects_invalid_secondary_bin_prices() { assert_secondary_bin_model_error( |bin| { - bin.price_per_canonical_unit.quantity.amount = RadrootsCoreDecimal::from(2u32); + bin.price_per_canonical_unit.quantity.amount = Decimal::from(2u32); }, OperationalListingValidationError::InvalidPrice, ); assert_secondary_bin_model_error( |bin| { - bin.price_per_canonical_unit.quantity.unit = RadrootsCoreUnit::MassKg; + bin.price_per_canonical_unit.quantity.unit = Unit::MassKg; }, OperationalListingValidationError::InvalidPrice, ); @@ -652,7 +638,7 @@ mod tests { ); assert_secondary_bin_model_error( |bin| { - bin.price_per_canonical_unit.quantity.unit = RadrootsCoreUnit::Each; + bin.price_per_canonical_unit.quantity.unit = Unit::Each; }, OperationalListingValidationError::InvalidPrice, ); @@ -847,7 +833,7 @@ mod tests { #[test] fn validate_listing_rejects_non_canonical_quantity() { let mut listing = base_listing(); - listing.bins[0].quantity.unit = RadrootsCoreUnit::MassKg; + listing.bins[0].quantity.unit = Unit::MassKg; assert_validation_err( listing, OperationalListingValidationError::ParseError { @@ -859,7 +845,7 @@ mod tests { #[test] fn validate_listing_rejects_non_canonical_price_quantity() { let mut listing = base_listing(); - listing.bins[0].price_per_canonical_unit.quantity.unit = RadrootsCoreUnit::MassKg; + listing.bins[0].price_per_canonical_unit.quantity.unit = Unit::MassKg; assert_validation_err( listing, OperationalListingValidationError::ParseError { @@ -878,7 +864,7 @@ mod tests { #[test] fn validate_listing_rejects_price_unit_mismatch() { let mut listing = base_listing(); - listing.bins[0].price_per_canonical_unit.quantity.unit = RadrootsCoreUnit::Each; + listing.bins[0].price_per_canonical_unit.quantity.unit = Unit::Each; assert_validation_err( listing, OperationalListingValidationError::ParseError { diff --git a/crates/transport_nostr/src/publish.rs b/crates/transport_nostr/src/publish.rs @@ -641,7 +641,7 @@ fn transport_failure_target_receipts( .iter() .cloned() .map(|target| { - RadrootsTransportTargetReceipt::skipped( + RadrootsTransportTargetReceipt::attempted( target, RadrootsTransportOutcome::new(RadrootsTransportOutcomeKind::ConnectionFailed) .with_message(message.to_owned()), diff --git a/crates/transport_nostr/tests/transport.rs b/crates/transport_nostr/tests/transport.rs @@ -1382,7 +1382,8 @@ async fn nostr_transport_facade_preserves_adapter_failure_and_omission_evidence( .expect("failure receipts"); assert_eq!(failed.target_receipts().len(), 2); assert!(failed.target_receipts().iter().all(|receipt| { - receipt.outcome.kind == RadrootsTransportOutcomeKind::ConnectionFailed + receipt.attempted + && receipt.outcome.kind == RadrootsTransportOutcomeKind::ConnectionFailed && receipt.status == RadrootsTransportDeliveryTargetStatus::FailedRetryable }));