diff --git a/Cargo.lock b/Cargo.lock index ad6d30a75..85b7e814e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2164,7 +2164,6 @@ name = "dao-voting-onft-staked" version = "2.4.2" dependencies = [ "anyhow", - "chrono", "cosmwasm-schema", "cosmwasm-std", "cw-controllers 1.1.2", @@ -2182,12 +2181,8 @@ dependencies = [ "dao-test-custom-factory", "dao-testing", "dao-voting 2.4.2", - "osmosis-std", - "osmosis-std-derive", + "omniflix-std", "osmosis-test-tube", - "prost 0.12.3", - "prost-types 0.12.3", - "schemars", "serde", "thiserror", ] @@ -3161,6 +3156,35 @@ dependencies = [ "memchr", ] +[[package]] +name = "omniflix-std" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a662bd7782ef6ad1af3747a2b73d37f8e6a230bb7b1624d96c05b3567501600" +dependencies = [ + "chrono", + "cosmwasm-std", + "omniflix-std-derive", + "prost 0.12.3", + "prost-types 0.12.3", + "schemars", + "serde", + "serde-cw-value", +] + +[[package]] +name = "omniflix-std-derive" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bbd85582e3ef1a23fa7b12e0415ea604260c114e72faf40d829c2c40f1c745e" +dependencies = [ + "itertools 0.10.5", + "proc-macro2", + "prost-types 0.11.9", + "quote", + "syn 1.0.109", +] + [[package]] name = "once_cell" version = "1.18.0" diff --git a/Cargo.toml b/Cargo.toml index 0cc1d76e4..e25cf0700 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ overflow-checks = true [workspace.dependencies] anyhow = { version = "1.0" } assert_matches = "1.5" -chrono = { version = "0.4.27", default-features = false } cosm-orc = { version = "4.0" } cosm-tome = "0.2" cosmos-sdk-proto = "0.19" @@ -56,6 +55,7 @@ cw721 = "0.18" cw721-base = "0.18" env_logger = "0.10" once_cell = "1.18" +omniflix-std = "0.1.8" osmosis-std = "0.20.1" osmosis-std-derive = "0.20.1" osmosis-test-tube = "20.1.1" diff --git a/contracts/voting/dao-voting-onft-staked/Cargo.toml b/contracts/voting/dao-voting-onft-staked/Cargo.toml index 99e0326fe..41f50ea62 100644 --- a/contracts/voting/dao-voting-onft-staked/Cargo.toml +++ b/contracts/voting/dao-voting-onft-staked/Cargo.toml @@ -27,7 +27,6 @@ test-tube = [] # default = ["test-tube"] [dependencies] -chrono = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } @@ -40,11 +39,7 @@ dao-dao-macros = { workspace = true } dao-hooks = { workspace = true } dao-interface = { workspace = true } dao-voting = { workspace = true } -osmosis-std = { workspace = true } -osmosis-std-derive = { workspace = true } -prost = { workspace = true } -prost-types = { workspace = true } -schemars = { workspace = true } +omniflix-std = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/contracts/voting/dao-voting-onft-staked/src/lib.rs b/contracts/voting/dao-voting-onft-staked/src/lib.rs index e22b7d020..e6784285f 100644 --- a/contracts/voting/dao-voting-onft-staked/src/lib.rs +++ b/contracts/voting/dao-voting-onft-staked/src/lib.rs @@ -5,7 +5,6 @@ mod error; pub mod msg; mod omniflix; pub mod state; -use osmosis_std::shim; // #[cfg(test)] // mod testing; diff --git a/contracts/voting/dao-voting-onft-staked/src/omniflix.rs b/contracts/voting/dao-voting-onft-staked/src/omniflix.rs index 58a137d0a..fe018ef0e 100644 --- a/contracts/voting/dao-voting-onft-staked/src/omniflix.rs +++ b/contracts/voting/dao-voting-onft-staked/src/omniflix.rs @@ -1,262 +1,8 @@ -use cosmwasm_std::{to_json_binary, CosmosMsg, Deps, QueryRequest, StdError, StdResult}; -use osmosis_std_derive::CosmwasmExt; -use std::convert::{TryFrom, TryInto}; - -use ::serde::{Deserialize, Deserializer, Serialize, Serializer}; -use chrono::{DateTime, NaiveDateTime, Utc}; -use serde::de; -use serde::de::Visitor; - -use std::fmt; -use std::str::FromStr; - -// see https://github.com/OmniFlix/omniflixhub/blob/main/proto/OmniFlix/onft/v1beta1 - -/// ONFT info -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, -)] -pub struct Onft { - #[prost(string, tag = "1")] - pub id: ::prost::alloc::string::String, - #[prost(message, tag = "2")] - pub metadata: ::core::option::Option, - #[prost(string, tag = "3")] - pub data: ::prost::alloc::string::String, - #[prost(string, tag = "4")] - pub owner: ::prost::alloc::string::String, - #[prost(bool, tag = "5")] - pub transferable: bool, - #[prost(bool, tag = "6")] - pub extensible: bool, - #[prost(message, tag = "7")] - pub created_at: ::core::option::Option, - #[prost(bool, tag = "8")] - pub nsfw: bool, - #[prost(string, tag = "9")] - pub royalty_share: ::prost::alloc::string::String, -} - -/// ONFT metadata -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, -)] -pub struct Metadata { - #[prost(string, tag = "1")] - pub name: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub description: ::prost::alloc::string::String, - #[prost(string, tag = "3")] - pub media_uri: ::prost::alloc::string::String, - #[prost(string, tag = "4")] - pub preview_uri: ::prost::alloc::string::String, - #[prost(string, tag = "5")] - pub uri_hash: ::prost::alloc::string::String, -} - -/// QueryONFTRequest requests the info for a single ONFT. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.QueryONFTRequest")] -pub struct QueryONFTRequest { - #[prost(string, tag = "1")] - pub denom_id: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub id: ::prost::alloc::string::String, -} - -/// QueryONFTResponse returns the info for a single ONFT. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.QueryONFTResponse")] -pub struct QueryONFTResponse { - #[prost(message, tag = "1")] - pub onft: ::core::option::Option, -} - -/// QuerySupplyRequest requests the supply of the denom. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.QuerySupplyRequest")] -pub struct QuerySupplyRequest { - #[prost(string, tag = "1")] - pub denom_id: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub owner: ::prost::alloc::string::String, -} - -/// QuerySupplyResponse returns the supply of the denom. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.QuerySupplyResponse")] -pub struct QuerySupplyResponse { - #[prost(uint64, tag = "1")] - pub amount: u64, -} - -/// MsgTransferONFT transfers an ONFT. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.MsgTransferONFT")] -pub struct MsgTransferONFT { - #[prost(string, tag = "1")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub denom_id: ::prost::alloc::string::String, - #[prost(string, tag = "3")] - pub sender: ::prost::alloc::string::String, - #[prost(string, tag = "4")] - pub recipient: ::prost::alloc::string::String, -} - -/// MsgTransferONFTResponse is the return type of MsgTransferONFT. -#[derive( - Clone, - PartialEq, - Eq, - ::prost::Message, - serde::Serialize, - serde::Deserialize, - schemars::JsonSchema, - CosmwasmExt, -)] -#[proto_message(type_url = "/omniflix.onft.v1beta1.MsgTransferONFTResponse")] -pub struct MsgTransferONFTResponse {} - -#[derive(Clone, PartialEq, Eq, ::prost::Message, schemars::JsonSchema)] -pub struct Timestamp { - /// Represents seconds of UTC time since Unix epoch - /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to - /// 9999-12-31T23:59:59Z inclusive. - #[prost(int64, tag = "1")] - pub seconds: i64, - /// Non-negative fractions of a second at nanosecond resolution. Negative - /// second values with fractions must still have non-negative nanos values - /// that count forward in time. Must be from 0 to 999,999,999 - /// inclusive. - #[prost(int32, tag = "2")] - pub nanos: i32, -} - -impl Serialize for Timestamp { - fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> - where - S: Serializer, - { - let mut ts = prost_types::Timestamp { - seconds: self.seconds, - nanos: self.nanos, - }; - ts.normalize(); - let dt = NaiveDateTime::from_timestamp_opt(ts.seconds, ts.nanos as u32) - .expect("invalid or out-of-range datetime"); - let dt: DateTime = DateTime::from_naive_utc_and_offset(dt, Utc); - serializer.serialize_str(format!("{:?}", dt).as_str()) - } -} - -impl<'de> Deserialize<'de> for Timestamp { - fn deserialize(deserializer: D) -> Result>::Error> - where - D: Deserializer<'de>, - { - struct TimestampVisitor; - - impl<'de> Visitor<'de> for TimestampVisitor { - type Value = Timestamp; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("Timestamp in RFC3339 format") - } - - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { - let utc: DateTime = chrono::DateTime::from_str(value).map_err(|err| { - serde::de::Error::custom(format!( - "Failed to parse {} as datetime: {:?}", - value, err - )) - })?; - let ts = Timestamp::from(utc); - Ok(ts) - } - } - deserializer.deserialize_str(TimestampVisitor) - } -} - -impl From> for Timestamp { - fn from(dt: DateTime) -> Self { - Timestamp { - seconds: dt.timestamp(), - nanos: dt.timestamp_subsec_nanos() as i32, - } - } -} +use cosmwasm_std::{CosmosMsg, Deps, StdError, StdResult}; +use omniflix_std::types::omniflix::onft::v1beta1::{MsgTransferOnft, OnftQuerier}; pub fn query_onft_owner(deps: Deps, denom_id: &str, token_id: &str) -> StdResult { - let res: QueryONFTResponse = deps.querier.query(&QueryRequest::Stargate { - path: "/omniflix.onft.v1beta1.Query/ONFT".to_string(), - data: to_json_binary(&QueryONFTRequest { - denom_id: denom_id.to_string(), - id: token_id.to_string(), - })?, - })?; - + let res = OnftQuerier::new(&deps.querier).onft(denom_id.to_string(), token_id.to_string())?; let owner = res .onft .ok_or(StdError::generic_err("ONFT not found"))? @@ -266,14 +12,7 @@ pub fn query_onft_owner(deps: Deps, denom_id: &str, token_id: &str) -> StdResult } pub fn query_onft_supply(deps: Deps, id: &str) -> StdResult { - let res: QuerySupplyResponse = deps.querier.query(&QueryRequest::Stargate { - path: "/omniflix.onft.v1beta1.Query/Supply".to_string(), - data: to_json_binary(&QuerySupplyRequest { - denom_id: id.to_string(), - owner: "".to_string(), - })?, - })?; - + let res = OnftQuerier::new(&deps.querier).supply(id.to_string(), "".to_string())?; Ok(res.amount) } @@ -283,7 +22,7 @@ pub fn get_onft_transfer_msg( sender: &str, recipient: &str, ) -> CosmosMsg { - MsgTransferONFT { + MsgTransferOnft { denom_id: denom_id.to_string(), id: token_id.to_string(), sender: sender.to_string(),