-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More reorganization and cleanup, add comments and basic README
- Loading branch information
1 parent
1d5d038
commit 1411d27
Showing
14 changed files
with
257 additions
and
221 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# cw721-sylvia-base | ||
|
||
This is a basic implementation of a cw721 NFT contract. It implements | ||
the [CW721 spec](../../packages/cw721/README.md) and is designed to | ||
be deployed as is, or imported into other contracts to easily build | ||
cw721-compatible NFTs with custom logic. It uses the [Sylvia](https://github.com/cosmwasm/sylvia) smart contract framework for easier extension. | ||
|
||
Use this as a base to build your own custom NFT contract. |
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,7 @@ | ||
use cosmwasm_schema::cw_serde; | ||
|
||
/// Shows who can mint these tokens | ||
#[cw_serde] | ||
pub struct MinterResponse { | ||
pub minter: Option<String>, | ||
} |
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,48 @@ | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::{Addr, BlockInfo, Empty}; | ||
use cw_ownable::Expiration; | ||
use cw_storage_plus::{Index, IndexList, MultiIndex}; | ||
|
||
#[cw_serde] | ||
pub struct Approval { | ||
/// Account that can transfer/send the token | ||
pub spender: Addr, | ||
/// When the Approval expires (maybe Expiration::never) | ||
pub expires: Expiration, | ||
} | ||
|
||
impl Approval { | ||
pub fn is_expired(&self, block: &BlockInfo) -> bool { | ||
self.expires.is_expired(block) | ||
} | ||
} | ||
|
||
#[cw_serde] | ||
pub struct TokenInfo { | ||
/// The owner of the newly minted NFT | ||
pub owner: Addr, | ||
/// Approvals are stored here, as we clear them all upon transfer and cannot accumulate much | ||
pub approvals: Vec<Approval>, | ||
|
||
/// Universal resource identifier for this NFT | ||
/// Should point to a JSON file that conforms to the ERC721 | ||
/// Metadata JSON Schema | ||
pub token_uri: Option<String>, | ||
|
||
pub extension: Empty, | ||
} | ||
|
||
pub fn token_owner_idx(_pk: &[u8], d: &TokenInfo) -> Addr { | ||
d.owner.clone() | ||
} | ||
|
||
/// Indexed map for NFT tokens by owner | ||
pub struct TokenIndexes<'a> { | ||
pub owner: MultiIndex<'a, Addr, TokenInfo, String>, | ||
} | ||
impl<'a> IndexList<TokenInfo> for TokenIndexes<'a> { | ||
fn get_indexes(&'_ self) -> Box<dyn Iterator<Item = &'_ (dyn Index<TokenInfo> + '_)> + '_> { | ||
let v: Vec<&dyn Index<TokenInfo>> = vec![&self.owner]; | ||
Box::new(v.into_iter()) | ||
} | ||
} |
Oops, something went wrong.