pub struct MetadataApi {
pub ipfs: Ipfs,
}Expand description
High-level facade mirroring MetadataApi from the TypeScript SDK.
All operations are available as free functions in this module;
MetadataApi groups them under a single type that carries an optional
Ipfs configuration, so callers do not have to thread IPFS settings
through every call.
§Typical workflow
use cow_app_data::{Ipfs, MetadataApi};
// 1. Create the API (with optional IPFS config).
let api = MetadataApi::new();
// 2. Build an app-data document.
let doc = api.generate_app_data_doc("MyDApp");
// 3. Validate it.
let result = api.validate_app_data_doc(&doc);
assert!(result.is_valid());
// 4. Derive the hash + CID.
let info = api.get_app_data_info(&doc).unwrap();
assert!(info.app_data_hex.starts_with("0x"));Fields§
§ipfs: IpfsOptional IPFS configuration.
Implementations§
Source§impl MetadataApi
impl MetadataApi
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MetadataApi with default IPFS settings.
Uses DEFAULT_IPFS_READ_URI for fetching and
DEFAULT_IPFS_WRITE_URI for uploads. No Pinata credentials are
configured — set them via with_ipfs if you need
upload capability.
§Returns
A new MetadataApi with default Ipfs configuration.
Sourcepub const fn with_ipfs(ipfs: Ipfs) -> Self
pub const fn with_ipfs(ipfs: Ipfs) -> Self
Create a MetadataApi with custom IPFS configuration.
§Parameters
ipfs— theIpfssettings (gateway URIs, Pinata credentials).
§Returns
A new MetadataApi using the given configuration.
§Example
use cow_app_data::{Ipfs, MetadataApi};
let api = MetadataApi::with_ipfs(
Ipfs::default().with_read_uri("https://my-gateway.io/ipfs").with_pinata("key", "secret"),
);Sourcepub fn generate_app_data_doc(&self, app_code: impl Into<String>) -> AppDataDoc
pub fn generate_app_data_doc(&self, app_code: impl Into<String>) -> AppDataDoc
Generate a minimal AppDataDoc for app_code.
§Example
use cow_app_data::MetadataApi;
let api = MetadataApi::new();
let doc = api.generate_app_data_doc("CoW Swap");
assert_eq!(doc.app_code.as_deref(), Some("CoW Swap"));Sourcepub fn validate_app_data_doc(&self, doc: &AppDataDoc) -> ValidationResult
pub fn validate_app_data_doc(&self, doc: &AppDataDoc) -> ValidationResult
Validate an AppDataDoc.
§Example
use cow_app_data::{AppDataDoc, MetadataApi};
let api = MetadataApi::new();
let doc = AppDataDoc::new("CoW Swap");
let result = api.validate_app_data_doc(&doc);
assert!(result.is_valid());Sourcepub fn appdata_hex(&self, doc: &AppDataDoc) -> Result<B256, CowError>
pub fn appdata_hex(&self, doc: &AppDataDoc) -> Result<B256, CowError>
Compute the keccak256 hash of doc as a B256.
Delegates to appdata_hex. The document
is serialised to deterministic JSON before hashing.
§Parameters
doc— theAppDataDocto hash.
§Returns
A 32-byte B256 digest.
§Errors
Propagates CowError::AppData on serialisation failure.
Sourcepub fn get_app_data_info(
&self,
doc: &AppDataDoc,
) -> Result<AppDataInfo, CowError>
pub fn get_app_data_info( &self, doc: &AppDataDoc, ) -> Result<AppDataInfo, CowError>
Derive the full AppDataInfo (JSON content, hex hash, CID) from
doc.
Delegates to get_app_data_info. This is the most common method
for obtaining everything needed to submit an order and pin data on
IPFS.
§Parameters
doc— theAppDataDocto process.
§Returns
An AppDataInfo with canonical JSON, hex hash, and CID.
§Errors
Propagates CowError::AppData.
§Example
use cow_app_data::{AppDataDoc, MetadataApi};
let api = MetadataApi::new();
let doc = AppDataDoc::new("CoW Swap");
let info = api.get_app_data_info(&doc)?;
assert!(info.app_data_hex.starts_with("0x"));Sourcepub fn get_app_data_info_from_str(
&self,
json: &str,
) -> Result<AppDataInfo, CowError>
pub fn get_app_data_info_from_str( &self, json: &str, ) -> Result<AppDataInfo, CowError>
Derive AppDataInfo from a pre-serialised JSON string.
Hashes json directly without re-serialising, preserving the exact
byte sequence as the canonical keccak256 pre-image.
§Parameters
json— the canonical JSON string.
§Returns
An AppDataInfo where app_data_content is json verbatim.
§Errors
Propagates CowError::AppData.
Sourcepub fn app_data_hex_to_cid(
&self,
app_data_hex: &str,
) -> Result<String, CowError>
pub fn app_data_hex_to_cid( &self, app_data_hex: &str, ) -> Result<String, CowError>
Convert app_data_hex to a CIDv1 base16 string.
Delegates to
appdata_hex_to_cid.
§Parameters
app_data_hex— theappDatahex value, with or without0x.
§Returns
A base16 CIDv1 string (prefix f).
§Errors
Propagates CowError::AppData.
Sourcepub fn cid_to_app_data_hex(&self, cid: &str) -> Result<String, CowError>
pub fn cid_to_app_data_hex(&self, cid: &str) -> Result<String, CowError>
Extract the appData hex digest from a CIDv1 string.
Delegates to
cid_to_appdata_hex.
§Parameters
cid— a base16 multibase CID string.
§Returns
A 0x-prefixed hex string of the 32-byte digest.
§Errors
Propagates CowError::AppData.
Sourcepub async fn fetch_doc_from_cid(
&self,
cid: &str,
) -> Result<AppDataDoc, CowError>
pub async fn fetch_doc_from_cid( &self, cid: &str, ) -> Result<AppDataDoc, CowError>
Fetch an AppDataDoc from IPFS by CIDv1.
Uses the configured ipfs.read_uri or DEFAULT_IPFS_READ_URI
when no custom gateway is set.
§Parameters
cid— theCIDv1base16 string identifying the document on IPFS.
§Returns
The deserialised AppDataDoc.
§Errors
Propagates CowError::Http on network failure or
CowError::Parse if the response is not valid JSON.
Sourcepub async fn fetch_doc_from_app_data_hex(
&self,
app_data_hex: &str,
) -> Result<AppDataDoc, CowError>
pub async fn fetch_doc_from_app_data_hex( &self, app_data_hex: &str, ) -> Result<AppDataDoc, CowError>
Fetch an AppDataDoc from IPFS by appData hex value.
Converts app_data_hex to a CIDv1, then fetches the document
from the configured IPFS gateway.
§Parameters
app_data_hex— the0x-prefixed 32-byte hex value.
§Returns
The deserialised AppDataDoc.
§Errors
Propagates CowError::AppData, CowError::Http, or
CowError::Parse.
Sourcepub async fn upload_app_data(
&self,
doc: &AppDataDoc,
) -> Result<String, CowError>
pub async fn upload_app_data( &self, doc: &AppDataDoc, ) -> Result<String, CowError>
Upload doc to IPFS via the Pinata pinning service.
The document is serialised to deterministic JSON, hashed, and
pinned to Pinata. Requires Ipfs::pinata_api_key and
Ipfs::pinata_api_secret to be set on the configured Ipfs
instance.
§Parameters
doc— theAppDataDocto upload.
§Returns
The IPFS CIDv1 hash string of the pinned content.
§Errors
Returns CowError::AppData when credentials are missing,
CowError::Http on transport failure, or CowError::Api on a
non-2xx Pinata response.
Sourcepub fn get_app_data_info_legacy(
&self,
doc: &AppDataDoc,
) -> Result<AppDataInfo, CowError>
👎Deprecated: Use get_app_data_info instead
pub fn get_app_data_info_legacy( &self, doc: &AppDataDoc, ) -> Result<AppDataInfo, CowError>
Use get_app_data_info instead
Sourcepub async fn fetch_doc_from_app_data_hex_legacy(
&self,
app_data_hex: &str,
) -> Result<AppDataDoc, CowError>
👎Deprecated: Use fetch_doc_from_app_data_hex instead
pub async fn fetch_doc_from_app_data_hex_legacy( &self, app_data_hex: &str, ) -> Result<AppDataDoc, CowError>
Use fetch_doc_from_app_data_hex instead
Fetch an AppDataDoc from IPFS using the legacy CID derivation.
§Errors
Propagates CowError::AppData, CowError::Http, or CowError::Parse.
Sourcepub async fn upload_metadata_doc_to_ipfs_legacy(
&self,
doc: &AppDataDoc,
) -> Result<IpfsUploadResult, CowError>
👎Deprecated: Use upload_app_data instead
pub async fn upload_metadata_doc_to_ipfs_legacy( &self, doc: &AppDataDoc, ) -> Result<IpfsUploadResult, CowError>
Use upload_app_data instead
Upload doc to IPFS via Pinata using the legacy method.
§Errors
Returns CowError::AppData, CowError::Http, or CowError::Api.
Sourcepub fn get_app_data_schema(&self, version: &str) -> Result<AppDataDoc, CowError>
pub fn get_app_data_schema(&self, version: &str) -> Result<AppDataDoc, CowError>
Get the app-data schema for a given version.
Delegates to get_app_data_schema. Currently known versions:
"0.7.0", "1.3.0".
§Parameters
version— semver string (e.g."1.3.0").
§Returns
An AppDataDoc placeholder with the requested version.
§Errors
Returns CowError::AppData when the version doesn’t exist.
Sourcepub fn import_schema(&self, version: &str) -> Result<AppDataDoc, CowError>
pub fn import_schema(&self, version: &str) -> Result<AppDataDoc, CowError>
Import a schema by version string.
Delegates to import_schema.
§Parameters
version— semver string.
§Returns
An AppDataDoc placeholder with the requested version.
§Errors
Returns CowError::AppData if the version is invalid or unknown.
Sourcepub fn app_data_hex_to_cid_legacy(
&self,
app_data_hex: &str,
) -> Result<String, CowError>
👎Deprecated: Use app_data_hex_to_cid instead
pub fn app_data_hex_to_cid_legacy( &self, app_data_hex: &str, ) -> Result<String, CowError>
Use app_data_hex_to_cid instead
Sourcepub fn parse_cid(&self, ipfs_hash: &str) -> Result<CidComponents, CowError>
pub fn parse_cid(&self, ipfs_hash: &str) -> Result<CidComponents, CowError>
Parse a CID string into its constituent CidComponents.
Delegates to parse_cid. Only base16
CIDs (prefix f or F) are supported.
§Parameters
ipfs_hash— a multibase-encoded CID string.
§Returns
A CidComponents with version, codec,
hash function, hash length, and raw digest.
§Errors
Propagates CowError::AppData.
Sourcepub fn decode_cid(&self, bytes: &[u8]) -> Result<CidComponents, CowError>
pub fn decode_cid(&self, bytes: &[u8]) -> Result<CidComponents, CowError>
Decode raw CID bytes into their constituent CidComponents.
Delegates to decode_cid.
§Parameters
bytes— raw CID bytes ([version, codec, hash_fn, hash_len, ...digest]).
§Returns
A CidComponents with the parsed fields.
§Errors
Propagates CowError::AppData if the slice is too short.
Sourcepub fn extract_digest(&self, cid: &str) -> Result<String, CowError>
pub fn extract_digest(&self, cid: &str) -> Result<String, CowError>
Extract the multihash digest from a CID string as 0x-prefixed hex.
Delegates to extract_digest.
§Parameters
cid— a base16 multibase CID string.
§Returns
A 0x-prefixed hex string of the raw digest bytes.
§Errors
Propagates CowError::AppData.
Trait Implementations§
Source§impl Clone for MetadataApi
impl Clone for MetadataApi
Source§fn clone(&self) -> MetadataApi
fn clone(&self) -> MetadataApi
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetadataApi
impl Debug for MetadataApi
Source§impl Default for MetadataApi
impl Default for MetadataApi
Source§fn default() -> MetadataApi
fn default() -> MetadataApi
Auto Trait Implementations§
impl Freeze for MetadataApi
impl RefUnwindSafe for MetadataApi
impl Send for MetadataApi
impl Sync for MetadataApi
impl Unpin for MetadataApi
impl UnsafeUnpin for MetadataApi
impl UnwindSafe for MetadataApi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.