-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escrow 721 setup #5
Changes from 21 commits
a745030
ed9bb6d
74ce4e3
9699446
ed8e7cc
294f83a
0326a7c
65f2db5
837d0f4
a1d0e40
f6e8f15
1979b7d
16cd95d
e22d94c
57ae1b1
c3568f0
69458d8
ceac211
f2c06f2
766fd88
50b8d11
a694720
b3cdbed
dac2db1
edce0d0
086c137
b546368
4fe8d48
337d228
f0d7981
36c93d5
1a6eacb
4ffd6f2
accb69e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" | ||
schema = "run --example schema" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[package] | ||
authors = ["Michael Scotto"] | ||
edition = "2021" | ||
name = "escrow721" | ||
version = "0.12.0" | ||
|
||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
# use library feature to disable all instantiate/execute/query exports | ||
library = [] | ||
|
||
[package.metadata.scripts] | ||
optimize = """docker run --rm -v "$(pwd)":/code \ | ||
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ | ||
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ | ||
cosmwasm/rust-optimizer:0.12.3 | ||
""" | ||
|
||
[dependencies] | ||
cosmwasm-std = { version = "1.0.0-beta8", features = ["stargate"] } | ||
cosmwasm-storage = { version = "1.0.0-beta8" } | ||
cw-storage-plus = "0.13.2" | ||
cw-utils = "0.13.2" | ||
cw2 = "0.13.2" | ||
cw20-ics20 = { version = "0.13.2", features = ["library"] } | ||
sg721 = { version = "0.12.0", features = ["library"] } | ||
cw721-base-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", version = "0.13.2", branch="main", features = ["library"]} | ||
cw721-ibc = { git = "https://github.com/public-awesome/cw721-ibc.git", branch="main", version = "0.13.2"} | ||
schemars = "0.8.8" | ||
serde = { version = "1.0.133", default-features = false, features = ["derive"] } | ||
thiserror = { version = "1.0.30" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "1.0.0-beta8" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use cosmwasm_std::entry_point; | ||
use cosmwasm_std::Response; | ||
use cosmwasm_std::StdError; | ||
#[cfg(not(feature = "library"))] | ||
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult}; | ||
use cw721_base_ibc::msg::{ExecuteMsg, InstantiateMsg, MintMsg, QueryMsg}; | ||
use cw721_base_ibc::{ContractError, Cw721Contract}; | ||
use cw721_ibc::{Cw721Execute, Cw721Query, NftInfoResponse, OwnerOfResponse}; | ||
|
||
pub type CW721ContractWrapper<'a> = Cw721Contract<'a, Empty, Empty>; | ||
use crate::state::CLASS_STORAGE; | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
msg: InstantiateMsg, | ||
) -> StdResult<cosmwasm_std::Response> { | ||
CW721ContractWrapper::default().instantiate(deps, _env, _info, msg) | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn execute( | ||
deps: DepsMut, | ||
env: Env, | ||
info: MessageInfo, | ||
msg: ExecuteMsg<Empty>, | ||
) -> Result<Response<Empty>, ContractError> { | ||
match msg { | ||
ExecuteMsg::SaveClass { | ||
class_id, | ||
class_uri, | ||
} => save_class(deps, class_id, class_uri), | ||
_ => CW721ContractWrapper::default().execute(deps, env, info, msg), | ||
} | ||
} | ||
|
||
pub fn save_class( | ||
deps: DepsMut, | ||
class_id: String, | ||
class_uri: String, | ||
) -> Result<Response<Empty>, ContractError> { | ||
CLASS_STORAGE.save(deps.storage, class_id, &class_uri)?; | ||
Ok(Response::default()) | ||
} | ||
|
||
pub fn transfer( | ||
deps: DepsMut, | ||
env: Env, | ||
info: MessageInfo, | ||
recipient: String, | ||
class_id: String, | ||
token_id: String, | ||
) -> Result<cosmwasm_std::Response, ContractError> { | ||
CW721ContractWrapper::default().transfer_nft(deps, env, info, recipient, class_id, token_id) | ||
} | ||
|
||
pub fn mint( | ||
deps: DepsMut, | ||
_env: Env, | ||
info: MessageInfo, | ||
class_id: String, | ||
token_id: String, | ||
token_uri: String, | ||
receiver: String, | ||
) -> Result<cosmwasm_std::Response, ContractError> { | ||
let mint_msg = MintMsg { | ||
class_id, | ||
token_id, | ||
owner: receiver, | ||
token_uri: Some(token_uri), | ||
extension: Empty {}, | ||
}; | ||
|
||
CW721ContractWrapper::default().mint(deps, _env, info, mint_msg) | ||
} | ||
|
||
pub fn burn( | ||
deps: DepsMut, | ||
_env: Env, | ||
info: MessageInfo, | ||
class_id: String, | ||
token_id: String, | ||
) -> Result<cosmwasm_std::Response, ContractError> { | ||
CW721ContractWrapper::default().burn(deps, _env, info, class_id, token_id) | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> { | ||
match msg { | ||
QueryMsg::OwnerOf { | ||
class_id, | ||
token_id, | ||
include_expired, | ||
} => to_binary(&get_owner( | ||
deps, | ||
_env, | ||
class_id, | ||
token_id, | ||
include_expired.unwrap_or(false), | ||
)?), | ||
QueryMsg::NftInfo { class_id, token_id } => to_binary(&nft_info(deps, class_id, token_id)?), | ||
QueryMsg::HasClass { class_id } => to_binary(&has_class(deps, class_id)), | ||
QueryMsg::GetClass { class_id } => to_binary(&get_class(deps, class_id)?), | ||
_ => Err(StdError::GenericErr { | ||
msg: "Unsupported message type".to_string(), | ||
}), | ||
} | ||
} | ||
|
||
pub fn get_owner( | ||
deps: Deps, | ||
env: Env, | ||
class_id: String, | ||
token_id: String, | ||
include_expired: bool, | ||
) -> StdResult<OwnerOfResponse> { | ||
CW721ContractWrapper::default().owner_of(deps, env, class_id, token_id, include_expired) | ||
} | ||
|
||
fn nft_info(deps: Deps, class_id: String, token_id: String) -> StdResult<NftInfoResponse<Empty>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CW Standard: add
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mccallofthewild per the IBC spec this should actually be called "GetNFT" I would like to stay with the spec names wherever possible Let me know what you think (I changed it to GetNFT for now which is what I originally intended) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @humanalgorithm It may be wise to make the functions public as well. The main purpose for the query naming convention is to make it easy to wrap/extend the contract without losing compatibility with the canonical codebase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mccallofthewild I'll make the query functions public |
||
CW721ContractWrapper::default().nft_info(deps, class_id, token_id) | ||
} | ||
|
||
fn has_class(deps: Deps, class_id: String) -> bool { | ||
CLASS_STORAGE.has(deps.storage, class_id) | ||
} | ||
|
||
fn get_class(deps: Deps, class_id: String) -> StdResult<(String, String)> { | ||
match CLASS_STORAGE.load(deps.storage, class_id.clone()) { | ||
Ok(class_uri) => Ok((class_id, class_uri)), | ||
Err(_) => Err(StdError::generic_err(format!( | ||
"Class {} not found", | ||
class_id | ||
))), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod contract; | ||
pub mod state; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use cw_storage_plus::Map; | ||
|
||
pub const CLASS_STORAGE: Map<String, String> = Map::new("class_storage"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's preferable to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment about what these strings represent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to <&str, String> with a comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package e2e_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
) | ||
|
||
type Account struct { | ||
PrivKey secp256k1.PrivKey | ||
PubKey crypto.PubKey | ||
Address sdk.AccAddress | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add response attributes for indexers
"action", "save_class"
,"class_id", class_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these attributes