lib

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

commit ea66fdfb93519bb515195e0f14fd766a2388e84a
parent c6beaf75f8d2f50ea92c5706ffeccf6ba38c524b
Author: triesap <tyson@radroots.org>
Date:   Mon, 22 Dec 2025 21:11:04 +0000

workspace: update bindings targets and no_std alloc imports


- Add trade bindings target and list it in Makefile bindings
- Switch bindings builds from yarn to npm for events, tangle-schema, and types
- Expand `radroots-events-codec` no_std alloc imports to include ToString/ToOwned and vec

Diffstat:
MCargo.lock | 2+-
MMakefile | 13+++++++++----
Mevents-codec/src/comment/decode.rs | 2+-
Mevents-codec/src/event_ref.rs | 2+-
Mevents-codec/src/follow/encode.rs | 2+-
Mevents-codec/src/job/encode.rs | 2+-
Mevents-codec/src/job/feedback/decode.rs | 2+-
Mevents-codec/src/job/feedback/encode.rs | 2+-
Mevents-codec/src/job/request/encode.rs | 2+-
Mevents-codec/src/job/result/decode.rs | 2+-
Mevents-codec/src/job/result/encode.rs | 2+-
Mevents-codec/src/job/traits.rs | 2+-
Mevents-codec/src/job/util.rs | 2+-
Mevents-codec/src/listing/decode.rs | 2+-
Mevents-codec/src/listing/encode.rs | 2+-
Mevents-codec/src/post/decode.rs | 2+-
Mevents-codec/src/post/encode.rs | 2+-
Mevents-codec/src/profile/decode.rs | 2+-
Mevents-codec/src/reaction/decode.rs | 2+-
Mevents-codec/src/wire.rs | 2+-
Mevents/bindings/ts/src/types.ts | 2++
Mevents/src/typeshare_kinds.rs | 2--
Mtrade/Cargo.toml | 7++++---
Mtrade/bindings/ts/package.json | 8++++----
Mtrade/bindings/ts/src/lib.ts | 49++++++++++++++++++++++++++++++++++++-------------
Mtrade/bindings/ts/src/types.ts | 222++++++++++++++++++-------------------------------------------------------------
Atrade/build.rs | 13+++++++++++++
Mtrade/src/listing/kinds.rs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mtrade/src/listing/meta.rs | 77++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Mtrade/src/listing/model.rs | 17+++++++++++++++--
Mtrade/src/listing/stage/accept.rs | 8++++++--
Mtrade/src/listing/stage/conveyance.rs | 12+++++++++---
Mtrade/src/listing/stage/fulfillment.rs | 14+++++++++++---
Mtrade/src/listing/stage/invoice.rs | 11+++++++++--
Mtrade/src/listing/stage/order.rs | 17++++++++++++++---
Mtrade/src/listing/stage/payment.rs | 12+++++++++---
Mtrade/src/listing/stage/receipt.rs | 9+++++++--
37 files changed, 330 insertions(+), 275 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1897,7 +1897,7 @@ dependencies = [ "radroots-events", "radroots-events-codec", "serde", - "typeshare", + "ts-rs", ] [[package]] diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ .PHONY: all bindings clean help \ - bindings-events bindings-tangle-schema bindings-types \ + bindings-events bindings-tangle-schema bindings-trade bindings-types \ build build-tangle-sql-wasm SHELL := /bin/bash @@ -9,6 +9,7 @@ TS_RS_FEATURE ?= ts-rs BINDINGS_TARGETS := \ bindings-events \ bindings-tangle-schema \ + bindings-trade \ bindings-types BUILD_TARGETS := \ @@ -36,15 +37,19 @@ help: bindings-events: @(cd events && cargo test --features $(TS_RS_FEATURE)) typeshare --lang typescript --output-file events/bindings/ts/src/typeshare-types.ts events - @(cd events/bindings/ts && yarn build) + @(cd events/bindings/ts && npm run build) bindings-tangle-schema: @(cd tangle-schema && cargo test --features $(TS_RS_FEATURE)) - @(cd tangle-schema/bindings/ts && yarn build) + @(cd tangle-schema/bindings/ts && npm run build) + +bindings-trade: + @(cd trade && cargo test --features $(TS_RS_FEATURE)) + @(cd trade/bindings/ts && npm run build) bindings-types: @(cd types && cargo test --features $(TS_RS_FEATURE)) - @(cd types/bindings/ts && yarn build) + @(cd types/bindings/ts && npm run build) build-tangle-sql-wasm: wasm-pack build tangle-sql-wasm --release --target web \ diff --git a/events-codec/src/comment/decode.rs b/events-codec/src/comment/decode.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::{ RadrootsNostrEvent, diff --git a/events-codec/src/event_ref.rs b/events-codec/src/event_ref.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::RadrootsNostrEventRef; diff --git a/events-codec/src/follow/encode.rs b/events-codec/src/follow/encode.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::follow::{RadrootsFollow, RadrootsFollowProfile}; diff --git a/events-codec/src/job/encode.rs b/events-codec/src/job/encode.rs @@ -1,7 +1,7 @@ use core::fmt; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::String, vec, vec::Vec}; pub use crate::wire::{canonicalize_tags, empty_content, to_draft, EventDraft, WireEventParts}; diff --git a/events-codec/src/job/feedback/decode.rs b/events-codec/src/job/feedback/decode.rs @@ -8,7 +8,7 @@ use radroots_events::{ }; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use crate::job::{ error::JobParseError, diff --git a/events-codec/src/job/feedback/encode.rs b/events-codec/src/job/feedback/encode.rs @@ -4,7 +4,7 @@ use crate::job::encode::{JobEncodeError, WireEventParts, canonicalize_tags}; use crate::job::util::{feedback_status_tag, push_amount_tag_msat}; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec, vec::Vec}; pub fn job_feedback_build_tags(fb: &RadrootsJobFeedback) -> Vec<Vec<String>> { let mut tags: Vec<Vec<String>> = Vec::with_capacity( diff --git a/events-codec/src/job/request/encode.rs b/events-codec/src/job/request/encode.rs @@ -4,7 +4,7 @@ use crate::job::encode::{JobEncodeError, WireEventParts, canonicalize_tags}; use crate::job::util::{job_input_type_tag, push_bid_tag_msat}; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec, vec::Vec}; pub fn job_request_build_tags(req: &RadrootsJobRequest) -> Vec<Vec<String>> { let mut tags: Vec<Vec<String>> = Vec::with_capacity( diff --git a/events-codec/src/job/result/decode.rs b/events-codec/src/job/result/decode.rs @@ -7,7 +7,7 @@ use radroots_events::{ }; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use crate::job::{ error::JobParseError, diff --git a/events-codec/src/job/result/encode.rs b/events-codec/src/job/result/encode.rs @@ -6,7 +6,7 @@ use crate::job::encode::{ use crate::job::util::{job_input_type_tag, push_amount_tag_msat}; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec, vec::Vec}; pub fn job_result_build_tags(res: &RadrootsJobResult) -> Vec<Vec<String>> { let mut tags: Vec<Vec<String>> = Vec::with_capacity( diff --git a/events-codec/src/job/traits.rs b/events-codec/src/job/traits.rs @@ -2,7 +2,7 @@ extern crate alloc; #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; use radroots_events::{ job_feedback::{RadrootsJobFeedbackEventIndex, RadrootsJobFeedbackEventMetadata}, job_request::{RadrootsJobRequestEventIndex, RadrootsJobRequestEventMetadata}, diff --git a/events-codec/src/job/util.rs b/events-codec/src/job/util.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec, vec::Vec}; use radroots_events::{ job::{JobFeedbackStatus, JobInputType}, diff --git a/events-codec/src/listing/decode.rs b/events-codec/src/listing/decode.rs @@ -1,7 +1,7 @@ #![cfg(feature = "serde_json")] #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::{ RadrootsNostrEvent, diff --git a/events-codec/src/listing/encode.rs b/events-codec/src/listing/encode.rs @@ -1,7 +1,7 @@ #![cfg(feature = "serde_json")] #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec, vec::Vec}; use radroots_events::{listing::RadrootsListing, tags::TAG_D}; diff --git a/events-codec/src/post/decode.rs b/events-codec/src/post/decode.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::{ RadrootsNostrEvent, diff --git a/events-codec/src/post/encode.rs b/events-codec/src/post/encode.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::vec::Vec; use radroots_events::post::RadrootsPost; diff --git a/events-codec/src/profile/decode.rs b/events-codec/src/profile/decode.rs @@ -1,7 +1,7 @@ #![cfg(feature = "serde_json")] #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::{ RadrootsNostrEvent, diff --git a/events-codec/src/reaction/decode.rs b/events-codec/src/reaction/decode.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; use radroots_events::{ RadrootsNostrEvent, diff --git a/events-codec/src/wire.rs b/events-codec/src/wire.rs @@ -1,5 +1,5 @@ #[cfg(not(feature = "std"))] -use alloc::{string::String, vec::Vec}; +use alloc::{string::{String, ToString}, vec::Vec}; #[derive(Debug, Clone)] pub struct WireEventParts { diff --git a/events/bindings/ts/src/types.ts b/events/bindings/ts/src/types.ts @@ -1,3 +1,5 @@ +import type { RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, RadrootsCoreQuantityPrice } from "@radroots/core-bindings"; + // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. export type JobFeedbackStatus = "payment_required" | "processing" | "error" | "success" | "partial"; diff --git a/events/src/typeshare_kinds.rs b/events/src/typeshare_kinds.rs @@ -1,5 +1,3 @@ -// Typeshare-only view for kind constants; this file is not part of the crate module tree. - #[typeshare::typeshare] pub const KIND_APPLICATION_HANDLER: u32 = 31990; diff --git a/trade/Cargo.toml b/trade/Cargo.toml @@ -5,16 +5,17 @@ edition.workspace = true authors = ["Radroots Authors"] rust-version.workspace = true license.workspace = true +build = "build.rs" [features] -default = ["std", "serde", "typeshare"] +default = ["std", "serde", "ts-rs"] std = [] serde = ["dep:serde", "radroots-core/serde", "radroots-events/serde", "radroots-events-codec/serde"] -typeshare = ["dep:typeshare"] +ts-rs = ["dep:ts-rs"] [dependencies] radroots-core = { workspace = true, default-features = false } radroots-events = { workspace = true, default-features = false } radroots-events-codec = { workspace = true, default-features = false } serde = { workspace = true, default-features = false, features = ["alloc", "derive"], optional = true } -typeshare = { workspace = true, optional = true } +ts-rs = { workspace = true, optional = true } diff --git a/trade/bindings/ts/package.json b/trade/bindings/ts/package.json @@ -21,8 +21,9 @@ "scripts": { "build:esm": "tsc -p tsconfig.esm.json", "build:cjs": "tsc -p tsconfig.cjs.json", - "build": "npm run clean && npm run build:esm && npm run build:cjs", - "prebuild": "npm run clean", + "build": "npm run build:esm && npm run build:cjs", + "prebuild": "npm run clean && npm run prepend-imports", + "prepend-imports": "bash -c 'f=./src/types.ts; line=\"import type { RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantityPrice, RadrootsCoreUnit } from \\\"@radroots/core-bindings\\\";\"; grep -qxF \"$line\" \"$f\" || (echo -e \"$line\\n\\n$(cat $f)\" > \"$f\")' && bash -c 'f=./src/types.ts; line=\"import type { RadrootsListingDiscount, RadrootsListingQuantity, RadrootsNostrEventPtr } from \\\"@radroots/events-bindings\\\";\"; grep -qxF \"$line\" \"$f\" || (echo -e \"$line\\n\\n$(cat $f)\" > \"$f\")'", "clean": "rimraf dist", "dev": "npm run watch", "watch": "tsc -w" @@ -40,4 +41,4 @@ "publishConfig": { "access": "public" } -} -\ No newline at end of file +} diff --git a/trade/bindings/ts/src/lib.ts b/trade/bindings/ts/src/lib.ts @@ -1,13 +1,36 @@ -export const MARKER_LISTING = "listing"; -export const MARKER_PAYLOAD = "payload"; -export const MARKER_PREVIOUS = "previous"; -export const MARKER_ORDER_RESULT = "order_result"; -export const MARKER_ACCEPT_RESULT = "accept_result"; -export const MARKER_CONVEYANCE_RESULT = "conveyance_result"; -export const MARKER_INVOICE_RESULT = "invoice_result"; -export const MARKER_PAYMENT_RESULT = "payment_result"; -export const MARKER_FULFILLMENT_RESULT = "fulfillment_result"; -export const MARKER_RECEIPT_RESULT = "receipt_result"; -export const MARKER_CANCEL_RESULT = "cancel_result"; -export const MARKER_REFUND_RESULT = "refund_result"; -export const MARKER_PROOF = "proof"; +import { TradeListingKind, TradeListingMarker } from "./types.js"; + +export { TradeListingKind, TradeListingMarker }; + +export const MARKER_LISTING = TradeListingMarker["listing"]; +export const MARKER_PAYLOAD = TradeListingMarker["payload"]; +export const MARKER_PREVIOUS = TradeListingMarker["previous"]; +export const MARKER_ORDER_RESULT = TradeListingMarker["order_result"]; +export const MARKER_ACCEPT_RESULT = TradeListingMarker["accept_result"]; +export const MARKER_CONVEYANCE_RESULT = TradeListingMarker["conveyance_result"]; +export const MARKER_INVOICE_RESULT = TradeListingMarker["invoice_result"]; +export const MARKER_PAYMENT_RESULT = TradeListingMarker["payment_result"]; +export const MARKER_FULFILLMENT_RESULT = TradeListingMarker["fulfillment_result"]; +export const MARKER_RECEIPT_RESULT = TradeListingMarker["receipt_result"]; +export const MARKER_CANCEL_RESULT = TradeListingMarker["cancel_result"]; +export const MARKER_REFUND_RESULT = TradeListingMarker["refund_result"]; +export const MARKER_PROOF = TradeListingMarker["proof"]; + +export const KIND_TRADE_LISTING_ORDER_REQ = TradeListingKind.KIND_TRADE_LISTING_ORDER_REQ; +export const KIND_TRADE_LISTING_ORDER_RES = TradeListingKind.KIND_TRADE_LISTING_ORDER_RES; +export const KIND_TRADE_LISTING_ACCEPT_REQ = TradeListingKind.KIND_TRADE_LISTING_ACCEPT_REQ; +export const KIND_TRADE_LISTING_ACCEPT_RES = TradeListingKind.KIND_TRADE_LISTING_ACCEPT_RES; +export const KIND_TRADE_LISTING_CONVEYANCE_REQ = TradeListingKind.KIND_TRADE_LISTING_CONVEYANCE_REQ; +export const KIND_TRADE_LISTING_CONVEYANCE_RES = TradeListingKind.KIND_TRADE_LISTING_CONVEYANCE_RES; +export const KIND_TRADE_LISTING_INVOICE_REQ = TradeListingKind.KIND_TRADE_LISTING_INVOICE_REQ; +export const KIND_TRADE_LISTING_INVOICE_RES = TradeListingKind.KIND_TRADE_LISTING_INVOICE_RES; +export const KIND_TRADE_LISTING_PAYMENT_REQ = TradeListingKind.KIND_TRADE_LISTING_PAYMENT_REQ; +export const KIND_TRADE_LISTING_PAYMENT_RES = TradeListingKind.KIND_TRADE_LISTING_PAYMENT_RES; +export const KIND_TRADE_LISTING_FULFILL_REQ = TradeListingKind.KIND_TRADE_LISTING_FULFILL_REQ; +export const KIND_TRADE_LISTING_FULFILL_RES = TradeListingKind.KIND_TRADE_LISTING_FULFILL_RES; +export const KIND_TRADE_LISTING_RECEIPT_REQ = TradeListingKind.KIND_TRADE_LISTING_RECEIPT_REQ; +export const KIND_TRADE_LISTING_RECEIPT_RES = TradeListingKind.KIND_TRADE_LISTING_RECEIPT_RES; +export const KIND_TRADE_LISTING_CANCEL_REQ = TradeListingKind.KIND_TRADE_LISTING_CANCEL_REQ; +export const KIND_TRADE_LISTING_CANCEL_RES = TradeListingKind.KIND_TRADE_LISTING_CANCEL_RES; +export const KIND_TRADE_LISTING_REFUND_REQ = TradeListingKind.KIND_TRADE_LISTING_REFUND_REQ; +export const KIND_TRADE_LISTING_REFUND_RES = TradeListingKind.KIND_TRADE_LISTING_REFUND_RES; diff --git a/trade/bindings/ts/src/types.ts b/trade/bindings/ts/src/types.ts @@ -1,171 +1,51 @@ -import { RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantityPrice, RadrootsCoreUnit } from "@radroots/core-bindings"; -import { RadrootsListingDiscount, RadrootsListingQuantity, RadrootsNostrEventPtr } from "@radroots/events-bindings"; - -/* - Generated by typeshare 1.13.3 -*/ - -export interface RadrootsTradeListingSubtotal { - price_amount: RadrootsCoreMoney; - price_currency: RadrootsCoreCurrency; - quantity_amount: RadrootsCoreDecimal; - quantity_unit: RadrootsCoreUnit; -} - -export interface RadrootsTradeListingTotal { - price_amount: RadrootsCoreMoney; - price_currency: RadrootsCoreCurrency; - quantity_amount: RadrootsCoreDecimal; - quantity_unit: RadrootsCoreUnit; -} - -export interface TradeListingAcceptRequest { - order_result_event_id: string; - listing_event_id: string; -} - -export interface TradeListingAcceptResult { - listing_event_id: string; - order_result_event_id: string; - accepted_by: string; -} - -export type TradeListingConveyanceMethod = - | { kind: "seller_delivery", amount: { - window?: string; - notes?: string; -}} - | { kind: "buyer_pickup", amount: { - location_hint?: string; - by_when?: string; -}} - | { kind: "third_party", amount: { - provider: string; - ref_id?: string; - notes?: string; -}}; - -export interface TradeListingConveyanceRequest { - accept_result_event_id: string; - method: TradeListingConveyanceMethod; -} - -export interface TradeListingConveyanceResult { - verified: boolean; - method: TradeListingConveyanceMethod; - message?: string; -} - -export interface TradeListingFulfillmentRequest { - payment_result_event_id: string; -} - -export enum TradeListingFulfillmentState { - Preparing = "Preparing", - Shipped = "Shipped", - ReadyForPickup = "ReadyForPickup", - Delivered = "Delivered", - Canceled = "Canceled", -} - -export interface TradeListingFulfillmentResult { - state: TradeListingFulfillmentState; - tracking?: string; - eta?: string; - notes?: string; -} - -export interface TradeListingInvoiceRequest { - accept_result_event_id: string; -} - -export interface TradeListingInvoiceResult { - total_sat: number; - bolt11?: string; - note?: string; - expires_at?: number; -} - -export interface TradeListingOrderRequestPayload { - price: RadrootsCoreQuantityPrice; - quantity: RadrootsListingQuantity; -} - -export interface TradeListingOrderRequest { - event: RadrootsNostrEventPtr; - payload: TradeListingOrderRequestPayload; -} - -export interface TradeListingOrderResult { - quantity: RadrootsListingQuantity; - price: RadrootsCoreQuantityPrice; - discounts: RadrootsListingDiscount[]; - subtotal: RadrootsTradeListingSubtotal; - total: RadrootsTradeListingTotal; -} - -export type TradeListingPaymentProof = - | { kind: "zap_event", amount: { - id: string; -}} - | { kind: "preimage", amount: { - hex: string; -}} - | { kind: "txid", amount: { - id: string; -}} - | { kind: "external_ref", amount: { - provider: string; - ref_id: string; -}}; - -export interface TradeListingPaymentProofRequest { - invoice_result_event_id: string; - proof: TradeListingPaymentProof; -} - -export interface TradeListingPaymentResult { - verified: boolean; - message?: string; -} - -export interface TradeListingReceiptRequest { - fulfillment_result_event_id: string; - note?: string; -} - -export interface TradeListingReceiptResult { - acknowledged: boolean; - at: number; -} - -export enum TradeListingStage { - Order = "Order", - Accept = "Accept", - Conveyance = "Conveyance", - Invoice = "Invoice", - Payment = "Payment", - Fulfillment = "Fulfillment", - Receipt = "Receipt", - Cancel = "Cancel", - Refund = "Refund", -} - -export const KIND_TRADE_LISTING_ORDER_REQ: number = 5301; -export const KIND_TRADE_LISTING_ORDER_RES: number = 6301; -export const KIND_TRADE_LISTING_ACCEPT_REQ: number = 5302; -export const KIND_TRADE_LISTING_ACCEPT_RES: number = 6302; -export const KIND_TRADE_LISTING_CONVEYANCE_REQ: number = 5303; -export const KIND_TRADE_LISTING_CONVEYANCE_RES: number = 6303; -export const KIND_TRADE_LISTING_INVOICE_REQ: number = 5304; -export const KIND_TRADE_LISTING_INVOICE_RES: number = 6304; -export const KIND_TRADE_LISTING_PAYMENT_REQ: number = 5305; -export const KIND_TRADE_LISTING_PAYMENT_RES: number = 6305; -export const KIND_TRADE_LISTING_FULFILL_REQ: number = 5306; -export const KIND_TRADE_LISTING_FULFILL_RES: number = 6306; -export const KIND_TRADE_LISTING_RECEIPT_REQ: number = 5307; -export const KIND_TRADE_LISTING_RECEIPT_RES: number = 6307; -export const KIND_TRADE_LISTING_CANCEL_REQ: number = 5309; -export const KIND_TRADE_LISTING_CANCEL_RES: number = 6309; -export const KIND_TRADE_LISTING_REFUND_REQ: number = 5310; -export const KIND_TRADE_LISTING_REFUND_RES: number = 6310; +import type { RadrootsListingDiscount, RadrootsListingQuantity, RadrootsNostrEventPtr } from "@radroots/events-bindings"; + +import type { RadrootsCoreCurrency, RadrootsCoreDecimal, RadrootsCoreMoney, RadrootsCoreQuantityPrice, RadrootsCoreUnit } from "@radroots/core-bindings"; + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type RadrootsTradeListingSubtotal = { price_amount: RadrootsCoreMoney, price_currency: RadrootsCoreCurrency, quantity_amount: RadrootsCoreDecimal, quantity_unit: RadrootsCoreUnit, }; + +export type RadrootsTradeListingTotal = { price_amount: RadrootsCoreMoney, price_currency: RadrootsCoreCurrency, quantity_amount: RadrootsCoreDecimal, quantity_unit: RadrootsCoreUnit, }; + +export type TradeListingAcceptRequest = { order_result_event_id: string, listing_event_id: string, }; + +export type TradeListingAcceptResult = { listing_event_id: string, order_result_event_id: string, accepted_by: string, }; + +export type TradeListingConveyanceMethod = { "kind": "seller_delivery", "amount": { window: string | null, notes: string | null, } } | { "kind": "buyer_pickup", "amount": { location_hint: string | null, by_when: string | null, } } | { "kind": "third_party", "amount": { provider: string, ref_id: string | null, notes: string | null, } }; + +export type TradeListingConveyanceRequest = { accept_result_event_id: string, method: TradeListingConveyanceMethod, }; + +export type TradeListingConveyanceResult = { verified: boolean, method: TradeListingConveyanceMethod, message?: string | null, }; + +export type TradeListingFulfillmentRequest = { payment_result_event_id: string, }; + +export type TradeListingFulfillmentResult = { state: TradeListingFulfillmentState, tracking?: string | null, eta?: string | null, notes?: string | null, }; + +export type TradeListingFulfillmentState = { "kind": "preparing" } | { "kind": "shipped" } | { "kind": "ready_for_pickup" } | { "kind": "delivered" } | { "kind": "canceled" }; + +export type TradeListingInvoiceRequest = { accept_result_event_id: string, }; + +export type TradeListingInvoiceResult = { total_sat: number, bolt11?: string | null, note?: string | null, expires_at?: number | null, }; + +export type TradeListingOrderRequest = { event: RadrootsNostrEventPtr, payload: TradeListingOrderRequestPayload, }; + +export type TradeListingOrderRequestPayload = { price: RadrootsCoreQuantityPrice, quantity: RadrootsListingQuantity, }; + +export type TradeListingOrderResult = { quantity: RadrootsListingQuantity, price: RadrootsCoreQuantityPrice, discounts: RadrootsListingDiscount[], subtotal: RadrootsTradeListingSubtotal, total: RadrootsTradeListingTotal, }; + +export type TradeListingPaymentProof = { "kind": "zap_event", "amount": { id: string, } } | { "kind": "preimage", "amount": { hex: string, } } | { "kind": "txid", "amount": { id: string, } } | { "kind": "external_ref", "amount": { provider: string, ref_id: string, } }; + +export type TradeListingPaymentProofRequest = { invoice_result_event_id: string, proof: TradeListingPaymentProof, }; + +export type TradeListingPaymentResult = { verified: boolean, message?: string | null, }; + +export type TradeListingReceiptRequest = { fulfillment_result_event_id: string, note?: string | null, }; + +export type TradeListingReceiptResult = { acknowledged: boolean, at: number, }; + +export type TradeListingStage = { "kind": "order" } | { "kind": "accept" } | { "kind": "conveyance" } | { "kind": "invoice" } | { "kind": "payment" } | { "kind": "fulfillment" } | { "kind": "receipt" } | { "kind": "cancel" } | { "kind": "refund" }; + +export enum TradeListingMarker { "listing" = "listing", "payload" = "payload", "previous" = "previous", "order_result" = "order_result", "accept_result" = "accept_result", "conveyance_result" = "conveyance_result", "invoice_result" = "invoice_result", "payment_result" = "payment_result", "fulfillment_result" = "fulfillment_result", "receipt_result" = "receipt_result", "cancel_result" = "cancel_result", "refund_result" = "refund_result", "proof" = "proof" } + +export enum TradeListingKind { "KIND_TRADE_LISTING_ORDER_REQ" = 5301, "KIND_TRADE_LISTING_ORDER_RES" = 6301, "KIND_TRADE_LISTING_ACCEPT_REQ" = 5302, "KIND_TRADE_LISTING_ACCEPT_RES" = 6302, "KIND_TRADE_LISTING_CONVEYANCE_REQ" = 5303, "KIND_TRADE_LISTING_CONVEYANCE_RES" = 6303, "KIND_TRADE_LISTING_INVOICE_REQ" = 5304, "KIND_TRADE_LISTING_INVOICE_RES" = 6304, "KIND_TRADE_LISTING_PAYMENT_REQ" = 5305, "KIND_TRADE_LISTING_PAYMENT_RES" = 6305, "KIND_TRADE_LISTING_FULFILL_REQ" = 5306, "KIND_TRADE_LISTING_FULFILL_RES" = 6306, "KIND_TRADE_LISTING_RECEIPT_REQ" = 5307, "KIND_TRADE_LISTING_RECEIPT_RES" = 6307, "KIND_TRADE_LISTING_CANCEL_REQ" = 5309, "KIND_TRADE_LISTING_CANCEL_RES" = 6309, "KIND_TRADE_LISTING_REFUND_REQ" = 5310, "KIND_TRADE_LISTING_REFUND_RES" = 6310 } diff --git a/trade/build.rs b/trade/build.rs @@ -0,0 +1,13 @@ +use std::{env, fs, path::Path}; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + if env::var_os("CARGO_FEATURE_TS_RS").is_some() { + println!("cargo:rustc-env=TS_RS_EXPORT_DIR=./bindings/ts/src"); + let out_dir = Path::new("bindings/ts/src"); + if !out_dir.exists() { + fs::create_dir_all(out_dir).expect("create TS export dir"); + } + println!("cargo:rerun-if-changed=src"); + } +} diff --git a/trade/src/listing/kinds.rs b/trade/src/listing/kinds.rs @@ -1,48 +1,66 @@ -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + pub const KIND_TRADE_LISTING_ORDER_REQ: u16 = 5301; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_ORDER_RES: u16 = 6301; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_ACCEPT_REQ: u16 = 5302; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_ACCEPT_RES: u16 = 6302; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_CONVEYANCE_REQ: u16 = 5303; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_CONVEYANCE_RES: u16 = 6303; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_INVOICE_REQ: u16 = 5304; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_INVOICE_RES: u16 = 6304; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_PAYMENT_REQ: u16 = 5305; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_PAYMENT_RES: u16 = 6305; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_FULFILL_REQ: u16 = 5306; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_FULFILL_RES: u16 = 6306; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_RECEIPT_REQ: u16 = 5307; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_RECEIPT_RES: u16 = 6307; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_CANCEL_REQ: u16 = 5309; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_CANCEL_RES: u16 = 6309; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_REFUND_REQ: u16 = 5310; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] pub const KIND_TRADE_LISTING_REFUND_RES: u16 = 6310; +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr( + feature = "ts-rs", + ts( + export, + export_to = "types.ts", + rename_all = "SCREAMING_SNAKE_CASE", + repr(enum) + ) +)] +#[repr(u16)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum TradeListingKind { + KindTradeListingOrderReq = KIND_TRADE_LISTING_ORDER_REQ, + KindTradeListingOrderRes = KIND_TRADE_LISTING_ORDER_RES, + KindTradeListingAcceptReq = KIND_TRADE_LISTING_ACCEPT_REQ, + KindTradeListingAcceptRes = KIND_TRADE_LISTING_ACCEPT_RES, + KindTradeListingConveyanceReq = KIND_TRADE_LISTING_CONVEYANCE_REQ, + KindTradeListingConveyanceRes = KIND_TRADE_LISTING_CONVEYANCE_RES, + KindTradeListingInvoiceReq = KIND_TRADE_LISTING_INVOICE_REQ, + KindTradeListingInvoiceRes = KIND_TRADE_LISTING_INVOICE_RES, + KindTradeListingPaymentReq = KIND_TRADE_LISTING_PAYMENT_REQ, + KindTradeListingPaymentRes = KIND_TRADE_LISTING_PAYMENT_RES, + KindTradeListingFulfillReq = KIND_TRADE_LISTING_FULFILL_REQ, + KindTradeListingFulfillRes = KIND_TRADE_LISTING_FULFILL_RES, + KindTradeListingReceiptReq = KIND_TRADE_LISTING_RECEIPT_REQ, + KindTradeListingReceiptRes = KIND_TRADE_LISTING_RECEIPT_RES, + KindTradeListingCancelReq = KIND_TRADE_LISTING_CANCEL_REQ, + KindTradeListingCancelRes = KIND_TRADE_LISTING_CANCEL_RES, + KindTradeListingRefundReq = KIND_TRADE_LISTING_REFUND_REQ, + KindTradeListingRefundRes = KIND_TRADE_LISTING_REFUND_RES, +} + #[inline] pub const fn is_trade_listing_request_kind(kind: u16) -> bool { matches!( @@ -120,10 +138,22 @@ mod tests { KIND_TRADE_LISTING_CONVEYANCE_REQ, KIND_TRADE_LISTING_CONVEYANCE_RES, ), - (KIND_TRADE_LISTING_INVOICE_REQ, KIND_TRADE_LISTING_INVOICE_RES), - (KIND_TRADE_LISTING_PAYMENT_REQ, KIND_TRADE_LISTING_PAYMENT_RES), - (KIND_TRADE_LISTING_FULFILL_REQ, KIND_TRADE_LISTING_FULFILL_RES), - (KIND_TRADE_LISTING_RECEIPT_REQ, KIND_TRADE_LISTING_RECEIPT_RES), + ( + KIND_TRADE_LISTING_INVOICE_REQ, + KIND_TRADE_LISTING_INVOICE_RES, + ), + ( + KIND_TRADE_LISTING_PAYMENT_REQ, + KIND_TRADE_LISTING_PAYMENT_RES, + ), + ( + KIND_TRADE_LISTING_FULFILL_REQ, + KIND_TRADE_LISTING_FULFILL_RES, + ), + ( + KIND_TRADE_LISTING_RECEIPT_REQ, + KIND_TRADE_LISTING_RECEIPT_RES, + ), (KIND_TRADE_LISTING_CANCEL_REQ, KIND_TRADE_LISTING_CANCEL_RES), (KIND_TRADE_LISTING_REFUND_REQ, KIND_TRADE_LISTING_REFUND_RES), ]; diff --git a/trade/src/listing/meta.rs b/trade/src/listing/meta.rs @@ -1,23 +1,65 @@ -//! Trade listing metadata and NIP-90 lifecycle mapping. -//! See refs/nips/90.md for the base data vending machine flow. - use core::fmt; use core::str::FromStr; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr( + feature = "ts-rs", + ts(export, export_to = "types.ts", rename_all = "snake_case", repr(enum = name)) +)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum TradeListingMarker { + Listing, + Payload, + Previous, + OrderResult, + AcceptResult, + ConveyanceResult, + InvoiceResult, + PaymentResult, + FulfillmentResult, + ReceiptResult, + CancelResult, + RefundResult, + Proof, +} + +impl TradeListingMarker { + #[inline] + pub const fn as_str(self) -> &'static str { + match self { + TradeListingMarker::Listing => "listing", + TradeListingMarker::Payload => "payload", + TradeListingMarker::Previous => "previous", + TradeListingMarker::OrderResult => "order_result", + TradeListingMarker::AcceptResult => "accept_result", + TradeListingMarker::ConveyanceResult => "conveyance_result", + TradeListingMarker::InvoiceResult => "invoice_result", + TradeListingMarker::PaymentResult => "payment_result", + TradeListingMarker::FulfillmentResult => "fulfillment_result", + TradeListingMarker::ReceiptResult => "receipt_result", + TradeListingMarker::CancelResult => "cancel_result", + TradeListingMarker::RefundResult => "refund_result", + TradeListingMarker::Proof => "proof", + } + } +} -pub const MARKER_LISTING: &str = "listing"; -pub const MARKER_PAYLOAD: &str = "payload"; -pub const MARKER_PREVIOUS: &str = "previous"; +pub const MARKER_LISTING: &str = TradeListingMarker::Listing.as_str(); +pub const MARKER_PAYLOAD: &str = TradeListingMarker::Payload.as_str(); +pub const MARKER_PREVIOUS: &str = TradeListingMarker::Previous.as_str(); -pub const MARKER_ORDER_RESULT: &str = "order_result"; -pub const MARKER_ACCEPT_RESULT: &str = "accept_result"; -pub const MARKER_CONVEYANCE_RESULT: &str = "conveyance_result"; -pub const MARKER_INVOICE_RESULT: &str = "invoice_result"; -pub const MARKER_PAYMENT_RESULT: &str = "payment_result"; -pub const MARKER_FULFILLMENT_RESULT: &str = "fulfillment_result"; -pub const MARKER_RECEIPT_RESULT: &str = "receipt_result"; -pub const MARKER_CANCEL_RESULT: &str = "cancel_result"; -pub const MARKER_REFUND_RESULT: &str = "refund_result"; -pub const MARKER_PROOF: &str = "proof"; +pub const MARKER_ORDER_RESULT: &str = TradeListingMarker::OrderResult.as_str(); +pub const MARKER_ACCEPT_RESULT: &str = TradeListingMarker::AcceptResult.as_str(); +pub const MARKER_CONVEYANCE_RESULT: &str = TradeListingMarker::ConveyanceResult.as_str(); +pub const MARKER_INVOICE_RESULT: &str = TradeListingMarker::InvoiceResult.as_str(); +pub const MARKER_PAYMENT_RESULT: &str = TradeListingMarker::PaymentResult.as_str(); +pub const MARKER_FULFILLMENT_RESULT: &str = TradeListingMarker::FulfillmentResult.as_str(); +pub const MARKER_RECEIPT_RESULT: &str = TradeListingMarker::ReceiptResult.as_str(); +pub const MARKER_CANCEL_RESULT: &str = TradeListingMarker::CancelResult.as_str(); +pub const MARKER_REFUND_RESULT: &str = TradeListingMarker::RefundResult.as_str(); +pub const MARKER_PROOF: &str = TradeListingMarker::Proof.as_str(); const MARKERS_ORDER_REQUEST: [&str; 2] = [MARKER_LISTING, MARKER_PAYLOAD]; const MARKERS_ACCEPT_REQUEST: [&str; 2] = [MARKER_ORDER_RESULT, MARKER_LISTING]; @@ -29,7 +71,8 @@ const MARKERS_RECEIPT_REQUEST: [&str; 2] = [MARKER_FULFILLMENT_RESULT, MARKER_PA const MARKERS_CANCEL_REQUEST: [&str; 2] = [MARKER_PREVIOUS, MARKER_PAYLOAD]; const MARKERS_REFUND_REQUEST: [&str; 2] = [MARKER_PAYMENT_RESULT, MARKER_PAYLOAD]; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr( diff --git a/trade/src/listing/model.rs b/trade/src/listing/model.rs @@ -1,19 +1,32 @@ -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct RadrootsTradeListingSubtotal { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] pub price_amount: radroots_core::RadrootsCoreMoney, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreCurrency"))] pub price_currency: radroots_core::RadrootsCoreCurrency, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreDecimal"))] pub quantity_amount: radroots_core::RadrootsCoreDecimal, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreUnit"))] pub quantity_unit: radroots_core::RadrootsCoreUnit, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct RadrootsTradeListingTotal { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] pub price_amount: radroots_core::RadrootsCoreMoney, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreCurrency"))] pub price_currency: radroots_core::RadrootsCoreCurrency, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreDecimal"))] pub quantity_amount: radroots_core::RadrootsCoreDecimal, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreUnit"))] pub quantity_unit: radroots_core::RadrootsCoreUnit, } diff --git a/trade/src/listing/stage/accept.rs b/trade/src/listing/stage/accept.rs @@ -1,7 +1,10 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingAcceptRequest { @@ -9,7 +12,8 @@ pub struct TradeListingAcceptRequest { pub listing_event_id: String, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingAcceptResult { diff --git a/trade/src/listing/stage/conveyance.rs b/trade/src/listing/stage/conveyance.rs @@ -1,7 +1,10 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] #[cfg_attr( @@ -24,7 +27,8 @@ pub enum TradeListingConveyanceMethod { }, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingConveyanceRequest { @@ -32,11 +36,13 @@ pub struct TradeListingConveyanceRequest { pub method: TradeListingConveyanceMethod, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingConveyanceResult { pub verified: bool, pub method: TradeListingConveyanceMethod, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub message: Option<String>, } diff --git a/trade/src/listing/stage/fulfillment.rs b/trade/src/listing/stage/fulfillment.rs @@ -1,14 +1,18 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingFulfillmentRequest { pub payment_result_event_id: String, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] #[cfg_attr( @@ -23,12 +27,16 @@ pub enum TradeListingFulfillmentState { Canceled, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingFulfillmentResult { pub state: TradeListingFulfillmentState, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub tracking: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub eta: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub notes: Option<String>, } diff --git a/trade/src/listing/stage/invoice.rs b/trade/src/listing/stage/invoice.rs @@ -1,19 +1,26 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingInvoiceRequest { pub accept_result_event_id: String, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingInvoiceResult { pub total_sat: u32, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub bolt11: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub note: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number | null"))] pub expires_at: Option<u32>, } diff --git a/trade/src/listing/stage/order.rs b/trade/src/listing/stage/order.rs @@ -2,31 +2,42 @@ use alloc::vec::Vec; use radroots_core::RadrootsCoreQuantityPrice; use radroots_events::listing::{RadrootsListingDiscount, RadrootsListingQuantity}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; use crate::listing::model::{RadrootsTradeListingSubtotal, RadrootsTradeListingTotal}; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingOrderRequestPayload { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantityPrice"))] pub price: RadrootsCoreQuantityPrice, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsListingQuantity"))] pub quantity: RadrootsListingQuantity, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingOrderRequest { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsNostrEventPtr"))] pub event: radroots_events::RadrootsNostrEventPtr, pub payload: TradeListingOrderRequestPayload, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingOrderResult { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsListingQuantity"))] pub quantity: RadrootsListingQuantity, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantityPrice"))] pub price: RadrootsCoreQuantityPrice, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsListingDiscount[]"))] pub discounts: Vec<RadrootsListingDiscount>, pub subtotal: RadrootsTradeListingSubtotal, pub total: RadrootsTradeListingTotal, diff --git a/trade/src/listing/stage/payment.rs b/trade/src/listing/stage/payment.rs @@ -1,7 +1,10 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] #[cfg_attr( @@ -15,7 +18,8 @@ pub enum TradeListingPaymentProof { ExternalRef { provider: String, ref_id: String }, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingPaymentProofRequest { @@ -23,10 +27,12 @@ pub struct TradeListingPaymentProofRequest { pub proof: TradeListingPaymentProof, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingPaymentResult { pub verified: bool, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub message: Option<String>, } diff --git a/trade/src/listing/stage/receipt.rs b/trade/src/listing/stage/receipt.rs @@ -1,15 +1,20 @@ #[cfg(not(feature = "std"))] use alloc::string::String; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingReceiptRequest { pub fulfillment_result_event_id: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub note: Option<String>, } -#[cfg_attr(feature = "typeshare", typeshare::typeshare)] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug)] pub struct TradeListingReceiptResult {