Skip to content

Commit

Permalink
Cargo deps to use version + MultiEraBlock::from_explicit_network_cbor… (
Browse files Browse the repository at this point in the history
dcSpark#261)

* Cargo deps to use version + MultiEraBlock::from_explicit_network_cbor_bytes

* All crates now use a version dep to allow publishing

* MultiEraBlock::from_explicit_network_cbor_bytes()

This is added to help working directly from pallas/oura/other tools so
their "raw" block CBOR can be directly parsed by CML without looking
into the CBOR wrapper.

* Conway / Mary test cases
  • Loading branch information
rooooooooob authored Oct 2, 2023
1 parent dcd2ad2 commit 624e1f1
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 75 deletions.
4 changes: 2 additions & 2 deletions chain/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ keywords = ["cardano"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-core = { "path" = "../../core/rust" }
cml-crypto = { "path" = "../../crypto/rust" }
cml-core = { "path" = "../../core/rust", version = "0.1.0" }
cml-crypto = { "path" = "../../crypto/rust", version = "0.1.0" }
cbor_event = "2.2.0"
linked-hash-map = "0.5.3"
derivative = "2.2.0"
Expand Down
10 changes: 5 additions & 5 deletions chain/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ keywords = ["cardano"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-chain = { path = "../rust" }
cml-core = { path = "../../core/rust" }
cml-core-wasm = { path = "../../core/wasm" }
cml-chain = { path = "../rust", version = "0.1.0" }
cml-core = { path = "../../core/rust", version = "0.1.0" }
cml-core-wasm = { path = "../../core/wasm", version = "0.1.0" }
# TODO: remove this dependency if possible to reduce confusion? maybe pub export necessary things in crypto-wasm?
cml-crypto = { path = "../../crypto/rust" }
cml-crypto-wasm = { path = "../../crypto/wasm" }
cml-crypto = { path = "../../crypto/rust", version = "0.1.0" }
cml-crypto-wasm = { path = "../../crypto/wasm", version = "0.1.0" }
cbor_event = "2.4.0"
wasm-bindgen = { version = "=0.2.83", features = ["serde-serialize"] }
linked-hash-map = "0.5.3"
Expand Down
6 changes: 3 additions & 3 deletions cip25/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ keywords = ["cardano"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-chain = { "path" = "../../chain/rust" }
cml-core = { "path" = "../../core/rust" }
cml-crypto = { "path" = "../../crypto/rust" }
cml-chain = { "path" = "../../chain/rust", version = "0.1.0" }
cml-core = { "path" = "../../core/rust", version = "0.1.0" }
cml-crypto = { "path" = "../../crypto/rust", version = "0.1.0" }
cbor_event = "2.2.0"
hex = "0.4.0"
schemars = "0.8.8"
Expand Down
10 changes: 5 additions & 5 deletions cip25/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
cbor_event = "2.2.0"
cml-chain = { path = "../../chain/rust" }
cml-chain-wasm = { path = "../../chain/wasm" }
cml-core = { path = "../../core/rust" }
cml-core-wasm = { path = "../../core/wasm" }
core = { path = "../rust", package = "cml-cip25" }
cml-chain = { path = "../../chain/rust", version = "0.1.0" }
cml-chain-wasm = { path = "../../chain/wasm", version = "0.1.0" }
cml-core = { path = "../../core/rust", version = "0.1.0" }
cml-core-wasm = { path = "../../core/wasm", version = "0.1.0" }
cml-cip25 = { path = "../rust", version = "1.1.0" }
linked-hash-map = "0.5.3"
serde_json = "1.0.57"
serde-wasm-bindgen = "0.4.5"
Expand Down
2 changes: 1 addition & 1 deletion cip25/wasm/json-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ keywords = ["cardano"]
[dependencies]
serde_json = "1.0.57"
schemars = "0.8.8"
core = { path = "../../rust", package = "cml-cip25" }
cml-cip25 = { path = "../../rust", version = "1.1.0" }
2 changes: 1 addition & 1 deletion cip25/wasm/json-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::*;
use cml_cip25::*;

fn main() {
macro_rules! gen_json_schema {
Expand Down
56 changes: 30 additions & 26 deletions cip25/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cml_core_wasm::{
};
pub use utils::LabelMetadata;

pub use core::CIP25Version;
pub use cml_cip25::CIP25Version;

use wasm_bindgen::prelude::{wasm_bindgen, JsValue};

Expand All @@ -22,9 +22,9 @@ use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
/// Parsing from CBOR bytes should be marginally faster.
#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct CIP25Metadata(core::CIP25Metadata);
pub struct CIP25Metadata(cml_cip25::CIP25Metadata);

impl_wasm_conversions!(core::CIP25Metadata, CIP25Metadata);
impl_wasm_conversions!(cml_cip25::CIP25Metadata, CIP25Metadata);

// we manually write to_cbor_bytes/from_cbor_bytes so we can add the comments

Expand All @@ -35,18 +35,18 @@ impl CIP25Metadata {
/// Serialize to CBOR bytes compatible with tx metadata
/// Does not guarantee any specific type of CBOR format and should NOT
/// be used with round-tripping. It will ignore all non-CIP25 keys.
/// Use core::metadate crate for round-tripping metadata.
/// Use cml_cip25::metadate crate for round-tripping metadata.
pub fn to_cbor_bytes(&self) -> Vec<u8> {
use core::serialization::ToBytes;
use cml_cip25::serialization::ToBytes;
ToBytes::to_bytes(&self.0)
}

/// Deserialize from CBOR bytes compatible with tx metadata
/// Does not guarantee any specific type of CBOR format and should NOT
/// be used with round-tripping. It will ignore all non-CIP25 keys.
/// Use core::metadate crate for round-tripping metadata.
/// Use cml_cip25::metadate crate for round-tripping metadata.
pub fn from_cbor_bytes(data: Vec<u8>) -> Result<CIP25Metadata, JsValue> {
use core::serialization::FromBytes;
use cml_cip25::serialization::FromBytes;
FromBytes::from_bytes(data)
.map(Self)
.map_err(|e| JsValue::from_str(&format!("from_cbor_bytes: {e}")))
Expand All @@ -58,7 +58,7 @@ impl CIP25Metadata {
}

pub fn new(key_721: &LabelMetadata) -> Self {
Self(core::CIP25Metadata::new(key_721.clone().into()))
Self(cml_cip25::CIP25Metadata::new(key_721.clone().into()))
}
}

Expand All @@ -71,39 +71,43 @@ impl CIP25Metadata {
/// ```
#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct ChunkableString(core::ChunkableString);
pub struct ChunkableString(cml_cip25::ChunkableString);

impl_wasm_conversions!(core::ChunkableString, ChunkableString);
impl_wasm_conversions!(cml_cip25::ChunkableString, ChunkableString);

impl_wasm_cbor_json_api_cbor_event_serialize!(ChunkableString);

#[wasm_bindgen]
impl ChunkableString {
pub fn new_single(single: &String64) -> Self {
Self(core::ChunkableString::new_single(single.clone().into()))
Self(cml_cip25::ChunkableString::new_single(
single.clone().into(),
))
}

pub fn new_chunked(chunked: &String64List) -> Self {
Self(core::ChunkableString::new_chunked(chunked.clone().into()))
Self(cml_cip25::ChunkableString::new_chunked(
chunked.clone().into(),
))
}

pub fn kind(&self) -> ChunkableStringKind {
match &self.0 {
core::ChunkableString::Single(_) => ChunkableStringKind::Single,
core::ChunkableString::Chunked(_) => ChunkableStringKind::Chunked,
cml_cip25::ChunkableString::Single(_) => ChunkableStringKind::Single,
cml_cip25::ChunkableString::Chunked(_) => ChunkableStringKind::Chunked,
}
}

pub fn as_single(&self) -> Option<String64> {
match &self.0 {
core::ChunkableString::Single(single) => Some(single.clone().into()),
cml_cip25::ChunkableString::Single(single) => Some(single.clone().into()),
_ => None,
}
}

pub fn as_chunked(&self) -> Option<String64List> {
match &self.0 {
core::ChunkableString::Chunked(chunked) => Some(chunked.clone().into()),
cml_cip25::ChunkableString::Chunked(chunked) => Some(chunked.clone().into()),
_ => None,
}
}
Expand All @@ -117,9 +121,9 @@ pub enum ChunkableStringKind {

#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct FilesDetails(core::FilesDetails);
pub struct FilesDetails(cml_cip25::FilesDetails);

impl_wasm_conversions!(core::FilesDetails, FilesDetails);
impl_wasm_conversions!(cml_cip25::FilesDetails, FilesDetails);

impl_wasm_cbor_json_api_cbor_event_serialize!(FilesDetails);

Expand All @@ -138,21 +142,21 @@ impl FilesDetails {
}

pub fn new(name: &String64, media_type: &String64, src: &ChunkableString) -> Self {
Self(core::FilesDetails::new(
Self(cml_cip25::FilesDetails::new(
name.clone().into(),
media_type.clone().into(),
src.clone().into(),
))
}
}

impl_wasm_list!(core::FilesDetails, FilesDetails, FilesDetailsList);
impl_wasm_list!(cml_cip25::FilesDetails, FilesDetails, FilesDetailsList);

#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct MetadataDetails(core::MetadataDetails);
pub struct MetadataDetails(cml_cip25::MetadataDetails);

impl_wasm_conversions!(core::MetadataDetails, MetadataDetails);
impl_wasm_conversions!(cml_cip25::MetadataDetails, MetadataDetails);

impl_wasm_cbor_json_api_cbor_event_serialize!(MetadataDetails);

Expand Down Expand Up @@ -191,7 +195,7 @@ impl MetadataDetails {
}

pub fn new(name: &String64, image: &ChunkableString) -> Self {
Self(core::MetadataDetails::new(
Self(cml_cip25::MetadataDetails::new(
name.clone().into(),
image.clone().into(),
))
Expand All @@ -202,9 +206,9 @@ impl MetadataDetails {
/// This is to conform with Cardano metadata restrictions.
#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct String64(core::String64);
pub struct String64(cml_cip25::String64);

impl_wasm_conversions!(core::String64, String64);
impl_wasm_conversions!(cml_cip25::String64, String64);

impl_wasm_cbor_json_api_cbor_event_serialize!(String64);

Expand All @@ -215,4 +219,4 @@ impl String64 {
}
}

impl_wasm_list!(core::String64, String64, String64List);
impl_wasm_list!(cml_cip25::String64, String64, String64List);
25 changes: 14 additions & 11 deletions cip25/wasm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl CIP25Metadata {
/// Read the CIP25 schema from a Metadata. Ignores all other data besides CIP25
/// Can fail if the Metadata does not conform to CIP25
pub fn from_metadata(metadata: &Metadata) -> Result<CIP25Metadata, JsError> {
core::CIP25Metadata::from_metadata(metadata.as_ref())
cml_cip25::CIP25Metadata::from_metadata(metadata.as_ref())
.map(Self)
.map_err(Into::into)
}
Expand All @@ -35,7 +35,9 @@ impl CIP25Metadata {
#[wasm_bindgen]
impl String64 {
pub fn new(s: &str) -> Result<String64, JsError> {
core::String64::new_str(s).map(Self).map_err(Into::into)
cml_cip25::String64::new_str(s)
.map(Self)
.map_err(Into::into)
}

pub fn to_str(&self) -> String {
Expand All @@ -51,7 +53,7 @@ impl String64 {

impl ChunkableString {
pub fn from_string(str: &str) -> Self {
Self(core::ChunkableString::from(str))
Self(cml_cip25::ChunkableString::from(str))
}

#[allow(clippy::inherent_to_string)]
Expand All @@ -62,16 +64,16 @@ impl ChunkableString {

#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct MiniMetadataDetails(core::utils::MiniMetadataDetails);
pub struct MiniMetadataDetails(cml_cip25::utils::MiniMetadataDetails);

impl_wasm_conversions!(core::utils::MiniMetadataDetails, MiniMetadataDetails);
impl_wasm_conversions!(cml_cip25::utils::MiniMetadataDetails, MiniMetadataDetails);

impl_wasm_json_api!(MiniMetadataDetails);

#[wasm_bindgen]
impl MiniMetadataDetails {
pub fn new() -> Self {
MiniMetadataDetails(core::utils::MiniMetadataDetails {
MiniMetadataDetails(cml_cip25::utils::MiniMetadataDetails {
name: None,
image: None,
})
Expand All @@ -96,17 +98,18 @@ impl MiniMetadataDetails {
/// loose parsing of CIP25 metadata to allow for common exceptions to the format
/// `metadatum` should represent the data where the `MetadataDetails` is in the cip25 structure
pub fn loose_parse(metadatum: &TransactionMetadatum) -> Result<MiniMetadataDetails, JsValue> {
let parsed_data = core::utils::MiniMetadataDetails::loose_parse(&metadatum.clone().into())
.map_err(|e| JsValue::from_str(&format!("loose_parse: {e}")))?;
let parsed_data =
cml_cip25::utils::MiniMetadataDetails::loose_parse(&metadatum.clone().into())
.map_err(|e| JsValue::from_str(&format!("loose_parse: {e}")))?;
Ok(MiniMetadataDetails(parsed_data))
}
}

#[derive(Clone, Debug)]
#[wasm_bindgen]
pub struct LabelMetadata(core::LabelMetadata);
pub struct LabelMetadata(cml_cip25::LabelMetadata);

impl_wasm_conversions!(core::LabelMetadata, LabelMetadata);
impl_wasm_conversions!(cml_cip25::LabelMetadata, LabelMetadata);

impl_wasm_cbor_json_api_cbor_event_serialize!(LabelMetadata);

Expand All @@ -115,7 +118,7 @@ impl LabelMetadata {
/// Note that Version 1 can only support utf8 string asset names.
/// Version 2 can support any asset name.
pub fn new(version: CIP25Version) -> Self {
Self(core::LabelMetadata::new(version))
Self(cml_cip25::LabelMetadata::new(version))
}

/// If this is version 1 and the asset name is not a utf8 asset name
Expand Down
6 changes: 3 additions & 3 deletions cip36/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ keywords = ["cardano", "cip36"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-core = { "path" = "../../core/rust" }
cml-crypto = { "path" = "../../crypto/rust" }
cml-chain = { "path" = "../../chain/rust" }
cml-core = { "path" = "../../core/rust", version = "0.1.0" }
cml-crypto = { "path" = "../../crypto/rust", version = "0.1.0" }
cml-chain = { "path" = "../../chain/rust", version = "0.1.0" }
cbor_event = "2.2.0"
linked-hash-map = "0.5.3"
derivative = "2.2.0"
Expand Down
12 changes: 6 additions & 6 deletions cip36/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ keywords = ["cardano", "cip36"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-cip36 = { path = "../rust" }
cml-crypto = { path = "../../crypto/rust" }
cml-crypto-wasm = { path = "../../crypto/wasm" }
cml-chain-wasm = { path = "../../chain/wasm" }
cml-core = { path = "../../core/rust" }
cml-core-wasm = { path = "../../core/wasm" }
cml-cip36 = { path = "../rust", version = "0.1.0" }
cml-crypto = { path = "../../crypto/rust", version = "0.1.0" }
cml-crypto-wasm = { path = "../../crypto/wasm", version = "0.1.0" }
cml-chain-wasm = { path = "../../chain/wasm", version = "0.1.0" }
cml-core = { path = "../../core/rust", version = "0.1.0" }
cml-core-wasm = { path = "../../core/wasm", version = "0.1.0" }
cbor_event = "2.2.0"
wasm-bindgen = { version = "=0.2.83", features = ["serde-serialize"] }
linked-hash-map = "0.5.3"
Expand Down
2 changes: 1 addition & 1 deletion crypto/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["cardano"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-core = { "path" = "../../core/rust" }
cml-core = { "path" = "../../core/rust", version = "0.1.0" }
cbor_event = "2.2.0"
cryptoxide = "0.4.2"
ed25519-bip32 = "0.4.1"
Expand Down
2 changes: 1 addition & 1 deletion crypto/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["cardano"]
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-crypto = { path = "../rust" }
cml-crypto = { path = "../rust", version = "0.1.0" }
cbor_event = "2.2.0"
wasm-bindgen = { version = "=0.2.83", features = ["serde-serialize"] }
linked-hash-map = "0.5.3"
Expand Down
6 changes: 3 additions & 3 deletions multi-era/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2018"
crate-type = ["cdylib", "rlib"]

[dependencies]
cml-core = { path = "../../core/rust" }
cml-crypto = { path = "../../crypto/rust" }
cml-chain = { path = "../../chain/rust" }
cml-core = { path = "../../core/rust", version = "0.1.0" }
cml-crypto = { path = "../../crypto/rust", version = "0.1.0" }
cml-chain = { path = "../../chain/rust", version = "0.1.0" }
cbor_event = "2.4.0"
linked-hash-map = "0.5.3"
derivative = "2.2.0"
Expand Down
1 change: 1 addition & 0 deletions multi-era/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod byron;
pub mod mary;
pub mod serialization;
pub mod shelley;
pub mod utils;
// This file was code-generated using an experimental CDDL to rust tool:
// https://github.com/dcSpark/cddl-codegen

Expand Down
Loading

0 comments on commit 624e1f1

Please sign in to comment.