-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from CosmWasm/440-demo-metadata-extension
Demo metadata extension
- Loading branch information
Showing
24 changed files
with
1,353 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib" | ||
schema = "run --example schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "cw721-metadata-uri" | ||
version = "0.9.0" | ||
authors = ["Ethan Frey <[email protected]>"] | ||
edition = "2018" | ||
description = "Example extending CW721 NFT with ERC20 like metadata_uri" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/CosmWasm/cw-plus" | ||
homepage = "https://cosmwasm.com" | ||
documentation = "https://docs.cosmwasm.com" | ||
|
||
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. | ||
"artifacts/*", | ||
] | ||
|
||
# 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 = [] | ||
|
||
[dependencies] | ||
cw0 = { path = "../../packages/cw0", version = "0.9.0" } | ||
cw2 = { path = "../../packages/cw2", version = "0.9.0" } | ||
cw721 = { path = "../../packages/cw721", version = "0.9.0" } | ||
cw721-base = { path = "../cw721-base", version = "0.9.0", features = ["library"] } | ||
cw-storage-plus = { path = "../../packages/storage-plus", version = "0.9.0" } | ||
cosmwasm-std = { version = "0.16.0" } | ||
schemars = "0.8.1" | ||
serde = { version = "1.0.103", default-features = false, features = ["derive"] } | ||
thiserror = { version = "1.0.23" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "0.16.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Cw721_metadata_uri | ||
Copyright (C) 2020 Confio OÜ | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# CW721 Metadata URI | ||
|
||
In Ethereum, the ERC721 standard includes a metadata_uri field to store all metadata offchain. | ||
With CW721-Base in CosmWasm, we allow you to store any data on chain you wish, using a generic `extension: T`. | ||
|
||
In order to provide better "out of the box" compatibility for people migrating from the Ethereum ecosystem, | ||
and to demonstrate how to use the extension ability, we have created this simple contract. There is no business | ||
logic here, but looking at `lib.rs` will show you how do define custom data that is included when minting and | ||
available in all queries. | ||
|
||
In particular, here we define: | ||
|
||
```rust | ||
pub struct Extension { | ||
pub metadata_uri: String, | ||
} | ||
``` | ||
|
||
This means when you query `NftInfo{name: "Enterprise"}`, you will get something like: | ||
|
||
```json | ||
{ | ||
"name": "Enterprise", | ||
"description": "USS Starship Enterprise", | ||
"image": null, | ||
"extension": { | ||
"metadata_uri": "http://starships.example.com/Starships/Enterprise.json" | ||
} | ||
} | ||
``` | ||
|
||
Please look at the test code for an example usage in Rust. | ||
|
||
## Notice | ||
|
||
Feel free to use this contract out of the box, or as inspiration for further customization of cw721-base. | ||
We will not be adding new features or business logic here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for}; | ||
|
||
use cw721::{ | ||
AllNftInfoResponse, ApprovedForAllResponse, ContractInfoResponse, NftInfoResponse, | ||
NumTokensResponse, OwnerOfResponse, TokensResponse, | ||
}; | ||
use cw721_metadata_uri::{ExecuteMsg, Extension, InstantiateMsg, MinterResponse, QueryMsg}; | ||
|
||
fn main() { | ||
let mut out_dir = current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
create_dir_all(&out_dir).unwrap(); | ||
remove_schemas(&out_dir).unwrap(); | ||
|
||
export_schema(&schema_for!(InstantiateMsg), &out_dir); | ||
export_schema_with_title(&schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg"); | ||
export_schema(&schema_for!(QueryMsg), &out_dir); | ||
export_schema_with_title( | ||
&schema_for!(AllNftInfoResponse<Extension>), | ||
&out_dir, | ||
"AllNftInfoResponse", | ||
); | ||
export_schema(&schema_for!(ApprovedForAllResponse), &out_dir); | ||
export_schema(&schema_for!(ContractInfoResponse), &out_dir); | ||
export_schema(&schema_for!(MinterResponse), &out_dir); | ||
export_schema_with_title( | ||
&schema_for!(NftInfoResponse<Extension>), | ||
&out_dir, | ||
"NftInfoResponse", | ||
); | ||
export_schema(&schema_for!(NumTokensResponse), &out_dir); | ||
export_schema(&schema_for!(OwnerOfResponse), &out_dir); | ||
export_schema(&schema_for!(TokensResponse), &out_dir); | ||
} |
Oops, something went wrong.