Skip to content

Commit

Permalink
use omniflix-std
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 17, 2024
1 parent 0cc8ae9 commit ac4cb9b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 280 deletions.
36 changes: 30 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
7 changes: 1 addition & 6 deletions contracts/voting/dao-voting-onft-staked/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }

Expand Down
1 change: 0 additions & 1 deletion contracts/voting/dao-voting-onft-staked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod error;
pub mod msg;
mod omniflix;
pub mod state;
use osmosis_std::shim;

// #[cfg(test)]
// mod testing;
Expand Down
271 changes: 5 additions & 266 deletions contracts/voting/dao-voting-onft-staked/src/omniflix.rs
Original file line number Diff line number Diff line change
@@ -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<Metadata>,
#[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<Timestamp>,
#[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<Onft>,
}

/// 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<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::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<Utc> = DateTime::from_naive_utc_and_offset(dt, Utc);
serializer.serialize_str(format!("{:?}", dt).as_str())
}
}

impl<'de> Deserialize<'de> for Timestamp {
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::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<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
let utc: DateTime<Utc> = 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<DateTime<Utc>> for Timestamp {
fn from(dt: DateTime<Utc>) -> 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<String> {
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"))?

Check warning on line 8 in contracts/voting/dao-voting-onft-staked/src/omniflix.rs

View check run for this annotation

Codecov / codecov/patch

contracts/voting/dao-voting-onft-staked/src/omniflix.rs#L4-L8

Added lines #L4 - L8 were not covered by tests
Expand All @@ -266,14 +12,7 @@ pub fn query_onft_owner(deps: Deps, denom_id: &str, token_id: &str) -> StdResult
}

Check warning on line 12 in contracts/voting/dao-voting-onft-staked/src/omniflix.rs

View check run for this annotation

Codecov / codecov/patch

contracts/voting/dao-voting-onft-staked/src/omniflix.rs#L11-L12

Added lines #L11 - L12 were not covered by tests

pub fn query_onft_supply(deps: Deps, id: &str) -> StdResult<u64> {
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)
}

Check warning on line 17 in contracts/voting/dao-voting-onft-staked/src/omniflix.rs

View check run for this annotation

Codecov / codecov/patch

contracts/voting/dao-voting-onft-staked/src/omniflix.rs#L14-L17

Added lines #L14 - L17 were not covered by tests

Expand All @@ -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(),
Expand Down

0 comments on commit ac4cb9b

Please sign in to comment.