Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"crates/nexum-sdk-test",
"crates/nexum-status-body",
"crates/nexum-tasks",
"crates/nexum-venue-sdk",
"crates/nexum-venue-test",
"crates/nexum-world",
"crates/no-std-probe",
Expand All @@ -19,6 +18,7 @@ members = [
"crates/shepherd-sdk",
"crates/shepherd-sdk-test",
"crates/videre-host",
"crates/videre-sdk",
"modules/ethflow-watcher",
"modules/example",
"modules/examples/balance-tracker",
Expand Down
4 changes: 2 additions & 2 deletions crates/cow-venue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workspace = true
borsh = { workspace = true, optional = true }
# Source of the `IntentBody` derive and trait the version enum implements,
# and the typed intent client the `client` slice binds to the CoW venue.
nexum-venue-sdk = { path = "../nexum-venue-sdk", optional = true }
videre-sdk = { path = "../videre-sdk", optional = true }
# `client` slice only: the keeper `RetryAction` the generated
# classification table maps each errorType to. The TOML parse happens in
# `build.rs`, so serde/toml/thiserror are build- and dev-only and never
Expand All @@ -47,5 +47,5 @@ thiserror = { workspace = true }
# depend on a future `adapter` slice without pulling the codec or the
# keeper transitively.
default = ["body"]
body = ["dep:borsh", "dep:nexum-venue-sdk"]
body = ["dep:borsh", "dep:videre-sdk"]
client = ["body", "dep:nexum-sdk"]
6 changes: 3 additions & 3 deletions crates/cow-venue/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//! per-venue version enum the venue publishes, and `#[derive(IntentBody)]`
//! gives it the borsh codec: a one-byte version tag plus the borsh
//! payload, with an unknown tag failing as a typed
//! [`BodyError`](nexum_venue_sdk::BodyError) rather than a stringly borsh
//! [`BodyError`](videre_sdk::BodyError) rather than a stringly borsh
//! error. The one non-obvious invariant: the tag order is the schema, so
//! new versions append at the end and no variant is ever reordered or
//! removed.

use borsh::{BorshDeserialize, BorshSerialize};
use nexum_venue_sdk::IntentBody;
use videre_sdk::IntentBody;

use crate::composable::ComposableBody;
use crate::order::OrderBody;
Expand All @@ -36,7 +36,7 @@ pub enum CowIntentBody {
#[cfg(test)]
mod tests {
use super::*;
use nexum_venue_sdk::BodyError;
use videre_sdk::BodyError;

use crate::order::{BuyTokenDestination, OrderKind, SellTokenSource};

Expand Down
22 changes: 11 additions & 11 deletions crates/cow-venue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//! slice so the client that submits an order and the table that
//! classifies its rejection version together.

use nexum_venue_sdk::client::{ClientError, IntentClient, VenueClient};
use nexum_venue_sdk::{IntentStatus, SubmitOutcome};
use videre_sdk::client::{ClientError, IntentClient, VenueClient, VenueId};
use videre_sdk::{IntentStatus, SubmitOutcome};

use crate::body::CowIntentBody;

Expand All @@ -34,7 +34,7 @@ impl<P: VenueClient> CowClient<P> {
}

/// The venue id every call routes to (always [`VENUE`]).
pub fn venue(&self) -> &str {
pub fn venue(&self) -> &VenueId {
self.inner.venue()
}

Expand All @@ -57,9 +57,9 @@ impl<P: VenueClient> CowClient<P> {
#[cfg(test)]
mod tests {
use super::*;
use nexum_venue_sdk::VenueError;
use std::cell::RefCell;
use std::rc::Rc;
use videre_sdk::VenueFault;

/// One recorded submit: the venue it routed to and the wire bytes.
type SubmitLog = Rc<RefCell<Vec<(String, Vec<u8>)>>>;
Expand All @@ -75,24 +75,24 @@ mod tests {
impl VenueClient for SpyClient {
fn quote(
&self,
_venue: &str,
_venue: &VenueId,
_body: Vec<u8>,
) -> Result<nexum_venue_sdk::Quotation, VenueError> {
) -> Result<videre_sdk::Quotation, VenueFault> {
unreachable!("quote not exercised")
}

fn submit(&self, venue: &str, body: Vec<u8>) -> Result<SubmitOutcome, VenueError> {
fn submit(&self, venue: &VenueId, body: Vec<u8>) -> Result<SubmitOutcome, VenueFault> {
self.submitted
.borrow_mut()
.push((venue.to_string(), body.clone()));
Ok(SubmitOutcome::Accepted(body))
}

fn status(&self, _venue: &str, _receipt: &[u8]) -> Result<IntentStatus, VenueError> {
fn status(&self, _venue: &VenueId, _receipt: &[u8]) -> Result<IntentStatus, VenueFault> {
unreachable!("status not exercised")
}

fn cancel(&self, _venue: &str, _receipt: &[u8]) -> Result<(), VenueError> {
fn cancel(&self, _venue: &VenueId, _receipt: &[u8]) -> Result<(), VenueFault> {
unreachable!("cancel not exercised")
}
}
Expand All @@ -118,14 +118,14 @@ mod tests {

#[test]
fn submit_routes_to_the_cow_venue_with_encoded_body() {
use nexum_venue_sdk::IntentBody;
use videre_sdk::IntentBody;

let spy = SpyClient::default();
let body = sample_body();
let expected = body.to_bytes().expect("body encodes");

let client = CowClient::new(spy.clone());
assert_eq!(client.venue(), VENUE);
assert_eq!(client.venue().as_str(), VENUE);
client.submit(&body).expect("submit succeeds");

let calls = spy.submitted.borrow();
Expand Down
2 changes: 1 addition & 1 deletion crates/cow-venue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! typed client and the adapter component are later slices.
//!
//! The body slice is dependency-light on purpose. It links only the
//! venue SDK (for the [`IntentBody`](nexum_venue_sdk::IntentBody) derive)
//! venue SDK (for the [`IntentBody`](videre_sdk::IntentBody) derive)
//! and borsh, so a venue adapter component or a strategy module can carry
//! the body types and codec without dragging in the host-side CoW
//! machinery. The crate is `#![no_std]` (tests aside): the derive's
Expand Down
31 changes: 17 additions & 14 deletions crates/nexum-macros/src/intent_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! its type's `BorshDeserialize`.
//!
//! Generated code names the venue SDK by its crate path
//! (`::nexum_venue_sdk`), so the derive is only usable through that
//! (`::videre_sdk`), so the derive is only usable through that
//! crate's re-export. The expansion names only `::core` and the SDK's
//! `__private` re-exports (borsh, `alloc`), so a `#![no_std]` consumer
//! needs no `extern crate alloc`.
Expand Down Expand Up @@ -82,23 +82,23 @@ pub(crate) fn expand(input: &DeriveInput) -> syn::Result<TokenStream> {

encode_arms.push(quote! {
Self::#ident(payload) => {
let mut out = ::nexum_venue_sdk::body::__private::alloc::vec::Vec::new();
let mut out = ::videre_sdk::body::__private::alloc::vec::Vec::new();
out.push(#tag);
::nexum_venue_sdk::body::__private::borsh::to_writer(&mut out, payload).map_err(
|err| ::nexum_venue_sdk::body::BodyError::Encode {
::videre_sdk::body::__private::borsh::to_writer(&mut out, payload).map_err(
|err| ::videre_sdk::body::BodyError::Encode {
version: #tag,
detail: ::nexum_venue_sdk::body::__private::alloc::string::ToString::to_string(&err),
detail: ::videre_sdk::body::__private::alloc::string::ToString::to_string(&err),
},
)?;
::core::result::Result::Ok(out)
}
});
decode_arms.push(quote! {
#tag => ::core::result::Result::Ok(Self::#ident(
::nexum_venue_sdk::body::__private::borsh::from_slice::<#payload_ty>(payload)
.map_err(|err| ::nexum_venue_sdk::body::BodyError::Malformed {
::videre_sdk::body::__private::borsh::from_slice::<#payload_ty>(payload)
.map_err(|err| ::videre_sdk::body::BodyError::Malformed {
version: #tag,
detail: ::nexum_venue_sdk::body::__private::alloc::string::ToString::to_string(
detail: ::videre_sdk::body::__private::alloc::string::ToString::to_string(
&err,
),
})?,
Expand All @@ -108,12 +108,15 @@ pub(crate) fn expand(input: &DeriveInput) -> syn::Result<TokenStream> {

Ok(quote! {
#[automatically_derived]
impl ::nexum_venue_sdk::body::IntentBody for #name {
impl ::videre_sdk::body::__private::Derived for #name {}

#[automatically_derived]
impl ::videre_sdk::body::IntentBody for #name {
fn to_bytes(
&self,
) -> ::core::result::Result<
::nexum_venue_sdk::body::__private::alloc::vec::Vec<u8>,
::nexum_venue_sdk::body::BodyError,
::videre_sdk::body::__private::alloc::vec::Vec<u8>,
::videre_sdk::body::BodyError,
> {
match self {
#(#encode_arms)*
Expand All @@ -122,14 +125,14 @@ pub(crate) fn expand(input: &DeriveInput) -> syn::Result<TokenStream> {

fn from_bytes(
bytes: &[u8],
) -> ::core::result::Result<Self, ::nexum_venue_sdk::body::BodyError> {
) -> ::core::result::Result<Self, ::videre_sdk::body::BodyError> {
let (version, payload) = bytes
.split_first()
.ok_or(::nexum_venue_sdk::body::BodyError::Empty)?;
.ok_or(::videre_sdk::body::BodyError::Empty)?;
match *version {
#(#decode_arms)*
version => ::core::result::Result::Err(
::nexum_venue_sdk::body::BodyError::UnknownVersion { version },
::videre_sdk::body::BodyError::UnknownVersion { version },
),
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/nexum-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! over a per-venue version enum.
//!
//! Consumers reach these through the SDK re-exports (`nexum_sdk::module`,
//! `nexum_venue_sdk::venue`, `nexum_venue_sdk::IntentBody`) rather than
//! `videre_sdk::venue`, `videre_sdk::IntentBody`) rather than
//! depending on this crate directly.

mod intent_body;
Expand All @@ -36,7 +36,7 @@ use syn::{DeriveInput, ImplItem, ItemImpl, Type};
/// fails typedly as `BodyError::UnknownVersion`.
///
/// Generated code resolves the SDK by crate path, so use the
/// `nexum_venue_sdk::IntentBody` re-export with `nexum-venue-sdk` as a
/// `videre_sdk::IntentBody` re-export with `videre-sdk` as a
/// direct dependency.
#[proc_macro_derive(IntentBody)]
pub fn derive_intent_body(input: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -307,7 +307,7 @@ pub fn venue(attr: TokenStream, item: TokenStream) -> TokenStream {
if !attr.is_empty() {
return syn::Error::new(
proc_macro2::Span::call_site(),
"#[nexum_venue_sdk::venue] takes no arguments",
"#[videre_sdk::venue] takes no arguments",
)
.to_compile_error()
.into();
Expand All @@ -319,23 +319,23 @@ pub fn venue(attr: TokenStream, item: TokenStream) -> TokenStream {
if !is_plain_type(self_ty) {
return syn::Error::new_spanned(
self_ty,
"#[nexum_venue_sdk::venue] must be applied to an inherent impl of a named type",
"#[videre_sdk::venue] must be applied to an inherent impl of a named type",
)
.to_compile_error()
.into();
}
if let Some((_, trait_path, _)) = &input.trait_ {
return syn::Error::new_spanned(
trait_path,
"#[nexum_venue_sdk::venue] must be applied to an inherent impl, not a trait impl",
"#[videre_sdk::venue] must be applied to an inherent impl, not a trait impl",
)
.to_compile_error()
.into();
}
if !input.generics.params.is_empty() {
return syn::Error::new_spanned(
&input.generics,
"#[nexum_venue_sdk::venue] must be applied to a non-generic impl",
"#[videre_sdk::venue] must be applied to a non-generic impl",
)
.to_compile_error()
.into();
Expand All @@ -355,7 +355,7 @@ pub fn venue(attr: TokenStream, item: TokenStream) -> TokenStream {
return syn::Error::new_spanned(
self_ty,
format!(
"#[nexum_venue_sdk::venue] requires the adapter face; this impl is missing {:?}. \
"#[videre_sdk::venue] requires the adapter face; this impl is missing {:?}. \
Define all of `derive_header`, `quote`, `submit`, `status`, `cancel` (plus an \
optional `init`)",
missing
Expand Down Expand Up @@ -553,7 +553,7 @@ fn derive_module_world() -> Result<(Vec<String>, world::ModuleWorld), String> {
/// declarations. Returns the manifest path (for the rebuild anchor)
/// alongside the world.
fn derive_venue_world() -> Result<(String, world::ModuleWorld), String> {
let (manifest_path, declared) = read_manifest_capabilities("#[nexum_venue_sdk::venue]")?;
let (manifest_path, declared) = read_manifest_capabilities("#[videre_sdk::venue]")?;
let venue_world =
world::synthesize_venue(&declared).map_err(|e| format!("{manifest_path}: {e}"))?;
Ok((manifest_path, venue_world))
Expand Down
2 changes: 1 addition & 1 deletion crates/nexum-venue-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nexum-sdk = { path = "../nexum-sdk" }
nexum-sdk-test = { path = "../nexum-sdk-test" }
# The contract under test: `IntentBody`, `BodyError`, the intent
# header types, and the `MessagingHost` seam.
nexum-venue-sdk = { path = "../nexum-venue-sdk" }
videre-sdk = { path = "../videre-sdk" }
serde = { workspace = true }
serde_json.workspace = true
thiserror.workspace = true
Expand Down
Loading
Loading