-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dan Sover <[email protected]>
- Loading branch information
Showing
2 changed files
with
170 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,83 @@ | ||
use wasmlanche_sdk::{public, store::State}; | ||
|
||
//! A basic ERC-721 compatible contract. | ||
//! Serves as a non-fungible token with the ability to mint, burn, and pause. | ||
//! Only supports whole units with no decimal places. | ||
//! | ||
//! NOTE: The NFT must support the common NFT metadata format. | ||
//! This JSON encoded file provides all the necessary metadata about the NFT. | ||
use metadata::{Properties, TypeDescription, NFT}; | ||
use wasmlanche_sdk::{program::Program, public, state::State, state_keys, types::Address}; | ||
pub mod metadata; | ||
|
||
/// A basic ERC-721 compatible contract. | ||
/// Serves as a non-fungible token with the ability to mint, burn, and pause. | ||
/// Only supports whole units with no decimal places. | ||
/// | ||
/// NOTE: The NFT must support the common NFT metadata format. | ||
/// This JSON encoded file provides all the necessary metadata about the NFT. | ||
const NFT_NAME: &str = "My NFT"; | ||
const NFT_SYMBOL: &str = "MNFT"; | ||
|
||
/// Initializes the program with a name, symbol, and total supply | ||
/// Returns whether the initialization was successful. | ||
// TODO: Parametrize string inputs | ||
#[public] | ||
pub fn init(state: State) -> bool { | ||
state | ||
.store_value("total_supply", &10000_i64) | ||
.store_value("name", "NFToken") | ||
.store_value("symbol", "NFT") | ||
.is_ok() | ||
pub fn init(program: Program) -> bool { | ||
// set token name | ||
program | ||
.state() | ||
.store(StateKey::Name.to_vec(), &NFT_NAME.as_bytes()) | ||
.expect("failed to store coin name"); | ||
|
||
// set token symbol | ||
program | ||
.state() | ||
.store(StateKey::Symbol.to_vec(), &NFT_SYMBOL.as_bytes()) | ||
.expect("failed to store symbol"); | ||
|
||
let nft_metadata = metadata::NFT::new() | ||
.with_title("My NFT".to_string()) | ||
.with_type("object".to_string()) | ||
.with_properties(Properties::new() | ||
.with_name(TypeDescription::new() | ||
.with_type(NFT_SYMBOL.to_string()) | ||
.with_description("Identifies the asset to which this NFT represents".to_string()) | ||
) | ||
.with_description(TypeDescription::new() | ||
.with_type(NFT_NAME.to_string()) | ||
.with_description("Describes the asset to which this NFT represents".to_string()) | ||
) | ||
.with_image(TypeDescription::new() | ||
.with_type("ipfs://bafybeidlkqhddsjrdue7y3dy27pu5d7ydyemcls4z24szlyik3we7vqvam/nft-image.png".to_string()) | ||
.with_description("A URI pointing to a resource with mime type image".to_string()) | ||
)); | ||
|
||
// set total supply | ||
program | ||
.state() | ||
.store(StateKey::TotalSupply.to_vec(), &20) | ||
.expect("failed to store total supply"); | ||
|
||
// TODO: convert nft_metadata struct into bytes to persist to storage. | ||
// program | ||
// .state() | ||
// .store(StateKey::Metadata.to_vec(), nft_metadata) | ||
// .expect("failed to store total supply"); | ||
|
||
true | ||
} | ||
|
||
/// Returns the total supply of the token. | ||
#[public] | ||
pub fn get_total_supply(state: State) -> i64 { | ||
state.get_value("total_supply").unwrap_or(0) | ||
pub fn get_total_supply(program: Program) -> i64 { | ||
0 | ||
} | ||
|
||
/// The program state keys. | ||
#[state_keys] | ||
enum StateKey { | ||
/// The total supply of the token. Key prefix 0x0. | ||
TotalSupply, | ||
/// The name of the token. Key prefix 0x1. | ||
Name, | ||
/// The symbol of the token. Key prefix 0x2. | ||
Symbol, | ||
/// Metadata of the token | ||
Metadata, | ||
/// Owner address | ||
Owner, | ||
/// Edition (for example, edition 1 of 10) | ||
Edition, | ||
} |
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