mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 08:32:23 +03:00
Erc721Metadata added to core types
This commit is contained in:
parent
c8367f2ad7
commit
98b20f5f7a
@ -49,27 +49,7 @@ pub struct PackageListing {
|
||||
pub name: String,
|
||||
pub publisher: NodeId,
|
||||
pub metadata_hash: String,
|
||||
pub metadata: Option<Erc721Metadata>,
|
||||
}
|
||||
|
||||
/// metadata derived from metadata hash in listing event
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Erc721Metadata {
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub image: Option<String>,
|
||||
pub external_url: Option<String>,
|
||||
pub animation_url: Option<String>,
|
||||
pub properties: Option<Erc721Properties>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Erc721Properties {
|
||||
pub package_name: String,
|
||||
pub publisher: String,
|
||||
pub current_version: String,
|
||||
pub mirrors: Vec<NodeId>,
|
||||
pub code_hashes: HashMap<String, String>,
|
||||
pub metadata: Option<kt::Erc721Metadata>,
|
||||
}
|
||||
|
||||
#[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<Erc721Metadata>,
|
||||
pub metadata: Option<kt::Erc721Metadata>,
|
||||
}
|
||||
|
||||
/// this process's saved state
|
||||
@ -543,7 +523,7 @@ fn dnswire_decode(wire_format_bytes: &[u8]) -> Result<String, std::string::FromU
|
||||
}
|
||||
|
||||
/// fetch metadata from metadata_url and verify it matches metadata_hash
|
||||
fn fetch_metadata(metadata_url: &str, metadata_hash: &str) -> anyhow::Result<Erc721Metadata> {
|
||||
fn fetch_metadata(metadata_url: &str, metadata_hash: &str) -> anyhow::Result<kt::Erc721Metadata> {
|
||||
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<Erc
|
||||
};
|
||||
let hash = generate_metadata_hash(&body.bytes);
|
||||
if &hash == metadata_hash {
|
||||
Ok(serde_json::from_slice::<Erc721Metadata>(&body.bytes)?)
|
||||
Ok(serde_json::from_slice::<kt::Erc721Metadata>(&body.bytes)?)
|
||||
} else {
|
||||
Err(anyhow::anyhow!(
|
||||
"metadata hash mismatch: got {hash}, expected {metadata_hash}"
|
||||
|
@ -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<String>,
|
||||
pub description: Option<String>,
|
||||
pub website: Option<String>,
|
||||
pub image: Option<String>,
|
||||
pub external_url: Option<String>,
|
||||
pub animation_url: Option<String>,
|
||||
pub properties: Option<Erc721Properties>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Erc721Properties {
|
||||
pub package_name: String,
|
||||
pub publisher: String,
|
||||
pub current_version: String,
|
||||
pub mirrors: Vec<NodeId>,
|
||||
pub code_hashes: HashMap<String, String>,
|
||||
pub wit_version: Option<(u32, u32, u32)>,
|
||||
}
|
||||
|
||||
/// the type that gets deserialized from each entry in the array in `manifest.json`
|
||||
|
Loading…
Reference in New Issue
Block a user