Skip to content

Commit

Permalink
Update cw 0.11 (#40)
Browse files Browse the repository at this point in the history
* Update to cw-plus 0.11

* Update deps

* Apply review recommendations
  • Loading branch information
orkunkl authored Dec 29, 2021
1 parent ec1e047 commit 3509738
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 51 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions contracts/cw721-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw721-base"
version = "0.10.1"
version = "0.11.1"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Basic implementation cw721 NFTs"
Expand All @@ -25,10 +25,10 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cw0 = { version = "0.10" }
cw2 = { version = "0.10" }
cw721 = { path = "../../packages/cw721", version = "0.10" }
cw-storage-plus = { version = "0.10" }
cw-utils = { version = "0.11" }
cw2 = { version = "0.11" }
cw721 = { path = "../../packages/cw721", version = "0.11.1" }
cw-storage-plus = { version = "0.11" }
cosmwasm-std = { version = "1.0.0-beta" }
schemars = "0.8.6"
serde = { version = "1.0.130", default-features = false, features = ["derive"] }
Expand Down
22 changes: 11 additions & 11 deletions contracts/cw721-base/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use serde::de::DeserializeOwned;
use serde::Serialize;

use cosmwasm_std::{to_binary, Binary, BlockInfo, Deps, Env, Order, Record, StdError, StdResult};
use cosmwasm_std::{to_binary, Addr, Binary, BlockInfo, Deps, Env, Order, StdError, StdResult};

use cw0::maybe_addr;
use cw721::{
AllNftInfoResponse, ApprovalResponse, ApprovalsResponse, ContractInfoResponse, CustomMsg,
Cw721Query, Expiration, NftInfoResponse, NumTokensResponse, OperatorsResponse, OwnerOfResponse,
TokensResponse,
};
use cw_storage_plus::Bound;
use cw_utils::maybe_addr;

use crate::msg::{MinterResponse, QueryMsg};
use crate::state::{Approval, Cw721Contract, TokenInfo};
Expand Down Expand Up @@ -143,17 +143,16 @@ where
let start = start_after.map(Bound::exclusive);

let owner_addr = deps.api.addr_validate(&owner)?;
let pks: Vec<_> = self
let tokens: Vec<String> = self
.tokens
.idx
.owner
.prefix(owner_addr)
.keys(deps.storage, start, None, Order::Ascending)
.take(limit)
.collect();
.map(|x| x.map(|addr| addr.to_string()))
.collect::<StdResult<Vec<_>>>()?;

let res: Result<Vec<_>, _> = pks.iter().map(|v| String::from_utf8(v.to_vec())).collect();
let tokens = res.map_err(StdError::invalid_utf8)?;
Ok(TokensResponse { tokens })
}

Expand All @@ -170,8 +169,9 @@ where
.tokens
.range(deps.storage, start, None, Order::Ascending)
.take(limit)
.map(|item| item.map(|(k, _)| String::from_utf8_lossy(&k).to_string()))
.map(|item| item.map(|(k, _)| k))
.collect();

Ok(TokensResponse { tokens: tokens? })
}

Expand Down Expand Up @@ -271,10 +271,10 @@ where
}
}

fn parse_approval(item: StdResult<Record<Expiration>>) -> StdResult<cw721::Approval> {
item.and_then(|(k, expires)| {
let spender = String::from_utf8(k)?;
Ok(cw721::Approval { spender, expires })
fn parse_approval(item: StdResult<(Addr, Expiration)>) -> StdResult<cw721::Approval> {
item.map(|(spender, expires)| cw721::Approval {
spender: spender.to_string(),
expires,
})
}

Expand Down
7 changes: 3 additions & 4 deletions contracts/cw721-base/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ pub struct TokenIndexes<'a, T>
where
T: Serialize + DeserializeOwned + Clone,
{
// pk goes to second tuple element
pub owner: MultiIndex<'a, (Addr, Vec<u8>), TokenInfo<T>>,
pub owner: MultiIndex<'a, Addr, TokenInfo<T>, Addr>,
}

impl<'a, T> IndexList<TokenInfo<T>> for TokenIndexes<'a, T>
Expand All @@ -136,6 +135,6 @@ where
}
}

pub fn token_owner_idx<T>(d: &TokenInfo<T>, k: Vec<u8>) -> (Addr, Vec<u8>) {
(d.owner.clone(), k)
pub fn token_owner_idx<T>(d: &TokenInfo<T>) -> Addr {
d.owner.clone()
}
6 changes: 3 additions & 3 deletions contracts/cw721-metadata-onchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw721-metadata-onchain"
version = "0.10.1"
version = "0.11.1"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Example extending CW721 NFT to store metadata on chain"
Expand All @@ -25,8 +25,8 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cw721 = { path = "../../packages/cw721", version = "0.10" }
cw721-base = { path = "../cw721-base", version = "0.10", features = ["library"] }
cw721 = { path = "../../packages/cw721", version = "0.11.1" }
cw721-base = { path = "../cw721-base", version = "0.11.1", features = ["library"] }
cosmwasm-std = { version = "1.0.0-beta" }
schemars = "0.8.6"
serde = { version = "1.0.130", default-features = false, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions packages/cw721/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw721"
version = "0.10.1"
version = "0.11.1"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Definition and types for the CosmWasm-721 NFT interface"
Expand All @@ -10,7 +10,7 @@ homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cw0 = { version = "0.10" }
cw-utils = { version = "0.11" }
cosmwasm-std = { version = "1.0.0-beta" }
schemars = "0.8.6"
serde = { version = "1.0.130", default-features = false, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod query;
mod receiver;
mod traits;

pub use cw0::Expiration;
pub use cw_utils::Expiration;

pub use crate::msg::Cw721ExecuteMsg;
pub use crate::query::{
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::Binary;
use cw0::Expiration;
use cw_utils::Expiration;

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cw0::Expiration;
use cw_utils::Expiration;

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
Expand Down
2 changes: 1 addition & 1 deletion packages/cw721/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
NumTokensResponse, OperatorsResponse, OwnerOfResponse, TokensResponse,
};
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cw0::Expiration;
use cw_utils::Expiration;

// TODO: move this somewhere else... ideally cosmwasm-std
pub trait CustomMsg: Clone + std::fmt::Debug + PartialEq + JsonSchema {}
Expand Down

0 comments on commit 3509738

Please sign in to comment.