From 98b20f5f7a78e320506b38a97e619d298e657f09 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 12 Feb 2024 16:47:03 -0500 Subject: [PATCH] Erc721Metadata added to core types --- .../packages/app_store/app_store/src/types.rs | 28 +++---------------- lib/src/core.rs | 26 +++++++++++------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/kinode/packages/app_store/app_store/src/types.rs b/kinode/packages/app_store/app_store/src/types.rs index 34c225fa..116c7277 100644 --- a/kinode/packages/app_store/app_store/src/types.rs +++ b/kinode/packages/app_store/app_store/src/types.rs @@ -49,27 +49,7 @@ pub struct PackageListing { pub name: String, pub publisher: NodeId, pub metadata_hash: String, - pub metadata: Option, -} - -/// metadata derived from metadata hash in listing event -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Erc721Metadata { - pub name: Option, - pub description: Option, - pub image: Option, - pub external_url: Option, - pub animation_url: Option, - pub properties: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Erc721Properties { - pub package_name: String, - pub publisher: String, - pub current_version: String, - pub mirrors: Vec, - pub code_hashes: HashMap, + pub metadata: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -95,7 +75,7 @@ pub struct PackageState { pub mirroring: bool, /// if we get a listing data update, will we try to download it? pub auto_update: bool, - pub metadata: Option, + pub metadata: Option, } /// this process's saved state @@ -543,7 +523,7 @@ fn dnswire_decode(wire_format_bytes: &[u8]) -> Result anyhow::Result { +fn fetch_metadata(metadata_url: &str, metadata_hash: &str) -> anyhow::Result { let url = url::Url::parse(metadata_url)?; let _response = http::send_request_await_response(http::Method::GET, url, None, 5, vec![])?; let Some(body) = get_blob() else { @@ -551,7 +531,7 @@ fn fetch_metadata(metadata_url: &str, metadata_hash: &str) -> anyhow::Result(&body.bytes)?) + Ok(serde_json::from_slice::(&body.bytes)?) } else { Err(anyhow::anyhow!( "metadata hash mismatch: got {hash}, expected {metadata_hash}" diff --git a/lib/src/core.rs b/lib/src/core.rs index f4bbdf2d..29f827b3 100644 --- a/lib/src/core.rs +++ b/lib/src/core.rs @@ -1042,17 +1042,25 @@ impl std::fmt::Display for PersistedProcess { } } -pub type PackageVersion = (u32, u32, u32); - /// the type that gets deserialized from `metadata.json` in a package -#[derive(Debug, Serialize, Deserialize)] -pub struct PackageMetadata { - pub package: String, - pub publisher: String, - pub version: PackageVersion, - pub wit_version: Option<(u32, u32, u32)>, +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Erc721Metadata { + pub name: Option, pub description: Option, - pub website: Option, + pub image: Option, + pub external_url: Option, + pub animation_url: Option, + pub properties: Option, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Erc721Properties { + pub package_name: String, + pub publisher: String, + pub current_version: String, + pub mirrors: Vec, + pub code_hashes: HashMap, + pub wit_version: Option<(u32, u32, u32)>, } /// the type that gets deserialized from each entry in the array in `manifest.json`