Skip to content
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

feat: move to namespace and snake case methods #65

Merged
merged 9 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pr-integration-test-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
env:
CI: 1
DEBUG: 0
DFX_VERSION: 0.9.3
DFX_VERSION: 0.11.1
DFX_WARNING: -version_check
NODE_ENV: ci
DFX_CANDID_RELEASE: 2022-01-06
Expand Down Expand Up @@ -48,9 +48,9 @@ jobs:
override: true
target: wasm32-unknown-unknown

- name: Install ic-cdk-optimizer
if: steps.cache-rust.outputs.cache-hit != 'true'
run: cargo install ic-cdk-optimizer
# - name: Install ic-cdk-optimizer
# if: steps.cache-rust.outputs.cache-hit != 'true'
# run: cargo install ic-cdk-optimizer

- name: Cache Dfx
id: cache-dfx
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

LOCAL_CUSTODIAN_PRINCIPAL = $(shell dfx identity get-principal)
TEST_CUSTODIAN_PRINCIPAL = $(shell cat test/custodian-test-principal)
CAP_ID ?= $(shell cd cap && dfx canister id ic-history-router)
CAP_ID ?= $(shell dfx canister id cap-router)

cap-local:
# Verifying cap... $(shell [ -z "$(CAP_ID)" ] && cd cap && dfx deploy ic-history-router)
# Verifying cap... $(shell [ -z "$(CAP_ID)" ] && dfx deploy cap-router)
@echo "cap local canister id: $(CAP_ID)"

init:
Expand Down Expand Up @@ -52,4 +52,4 @@ clean: clean-dfx
npm --prefix test run clean

clean-dfx: stop-replica
rm -rf .dfx cap/.dfx
rm -rf .dfx cap/.dfx
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
[DIP-721](spec.md) is an ERC-721 style non-fungible token standard built mirroring its Ethereum counterpart and adapting it to the Internet Computer, maintaining the same interface.

This standard aims to adopt the EIP-721 to the Internet Computer; providing a
simple, non-ambiguous, extendable API for the transfer and tracking ownership of NFTs and expanding/building upon the EXT standard with partial compatibility.
simple, non-ambiguous, extendable API for the transfer and tracking ownership of NFTs

## 📒 Table of Contents

- [Specification](#-specification)
- [Community](#-community)
- [NFT Implementation example](#-nft-implementation-example)
- [Contribution guideline](#-contributing)
- [💎 DIP-721](#-dip-721)
- [📒 Table of Contents](#-table-of-contents)
- [🎓 Specification](#-specification)
- [👋 Community](#-community)
- [👩 NFT Implementation example](#-nft-implementation-example)
- [🙏 Contributing](#-contributing)

## 🎓 Specification

The document for the [DIP-721](spec.md) is available [here](spec.md).

There are 2 versions of the v2 spec. One with namespace and snakecase, and one non namespaced and camel case. The legacy.rs provides the initial v2 spec without namespace, but the final version that should be used and integrated against has the namespace.

⚠️ This is an an in-development standard, consider it a work in progress as we finalize details in its design and gather feedback from the community.

## 👋 Community
Expand Down
7 changes: 6 additions & 1 deletion dfx.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"version": 1,
"dfx": "0.9.3",
"dfx": "0.11.1",
"canisters": {
"nft": {
"package": "nft",
"candid": "nft.did",
"type": "rust"
},
"cap-router": {
"type": "custom",
"wasm": "cap/wasm/cap_router.wasm",
"candid": "cap/candid/router.did"
}
},
"defaults": {
Expand Down
36 changes: 33 additions & 3 deletions nft.did
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,38 @@ service : (opt InitArgs) -> {
burn : (nat) -> (Result);
custodians : () -> (vec principal) query;
cycles : () -> (nat) query;
dfxInfo : () -> (text) query;
gitCommitHash : () -> (text) query;
dfx_info : () -> (text) query;
dip721_approve : (principal, nat) -> (Result);
dip721_balance_of : (principal) -> (Result) query;
dip721_burn : (nat) -> (Result);
dip721_custodians : () -> (vec principal) query;
dip721_cycles : () -> (nat) query;
dip721_is_approved_for_all : (principal, principal) -> (Result_1) query;
dip721_logo : () -> (opt text) query;
dip721_metadata : () -> (ManualReply) query;
dip721_mint : (principal, nat, vec record { text; GenericValue }) -> (Result);
dip721_name : () -> (opt text) query;
dip721_operator_of : (nat) -> (Result_2) query;
dip721_operator_token_identifiers : (principal) -> (ManualReply_1) query;
dip721_operator_token_metadata : (principal) -> (ManualReply_2) query;
dip721_owner_of : (nat) -> (Result_2) query;
dip721_owner_token_identifiers : (principal) -> (ManualReply_1) query;
dip721_owner_token_metadata : (principal) -> (ManualReply_2) query;
dip721_set_approval_for_all : (principal, bool) -> (Result);
dip721_set_custodians : (vec principal) -> ();
dip721_set_logo : (text) -> ();
dip721_set_name : (text) -> ();
dip721_set_symbol : (text) -> ();
dip721_stats : () -> (Stats) query;
dip721_supported_interfaces : () -> (vec SupportedInterface) query;
dip721_symbol : () -> (opt text) query;
dip721_token_metadata : (nat) -> (ManualReply_3) query;
dip721_total_supply : () -> (nat) query;
dip721_total_transactions : () -> (nat) query;
dip721_total_unique_holders : () -> (nat) query;
dip721_transfer : (principal, nat) -> (Result);
dip721_transfer_from : (principal, principal, nat) -> (Result);
git_commit_hash : () -> (text) query;
isApprovedForAll : (principal, principal) -> (Result_1) query;
logo : () -> (opt text) query;
metadata : () -> (ManualReply) query;
Expand All @@ -109,7 +139,7 @@ service : (opt InitArgs) -> {
ownerOf : (nat) -> (Result_2) query;
ownerTokenIdentifiers : (principal) -> (ManualReply_1) query;
ownerTokenMetadata : (principal) -> (ManualReply_2) query;
rustToolchainInfo : () -> (text) query;
rust_toolchain_info : () -> (text) query;
setApprovalForAll : (principal, bool) -> (Result);
setCustodians : (vec principal) -> ();
setLogo : (text) -> ();
Expand Down
204 changes: 204 additions & 0 deletions src/legacy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
use crate::*;

// ======================
// QUERY CALLS
// ======================

#[query(manual_reply = true)]
#[candid_method(query)]
fn name() -> ManualReply<Option<String>> {
dip721_name()
}

#[query(manual_reply = true)]
#[candid_method(query)]
fn logo() -> ManualReply<Option<String>> {
dip721_logo()
}

#[query(manual_reply = true)]
#[candid_method(query)]
fn symbol() -> ManualReply<Option<String>> {
dip721_symbol()
}

#[query(manual_reply = true)]
#[candid_method(query)]
fn custodians() -> ManualReply<HashSet<Principal>> {
dip721_custodians()
}

#[query(manual_reply = true)]
#[candid_method(query)]
fn metadata() -> ManualReply<Metadata> {
dip721_metadata()
}

#[update(name = "setName", guard = "is_canister_custodian")]
#[candid_method(update, rename = "setName")]
fn set_name(name: String) {
dip721_set_name(name)
}

#[update(name = "setLogo", guard = "is_canister_custodian")]
#[candid_method(update, rename = "setLogo")]
fn set_logo(logo: String) {
dip721_set_logo(logo)
}

#[update(name = "setSymbol", guard = "is_canister_custodian")]
#[candid_method(update, rename = "setSymbol")]
fn set_symbol(symbol: String) {
dip721_set_symbol(symbol)
}
#[update(name = "setCustodians", guard = "is_canister_custodian")]
#[candid_method(update, rename = "setCustodians")]
fn set_custodians(custodians: HashSet<Principal>) {
dip721_set_custodians(custodians)
}

#[query(name = "totalSupply")]
#[candid_method(query, rename = "totalSupply")]
fn total_supply() -> Nat {
dip721_total_supply()
}

#[query(name = "totalTransactions")]
#[candid_method(query, rename = "totalTransactions")]
fn total_transactions() -> Nat {
dip721_total_transactions()
}

#[query()]
#[candid_method(query)]
fn cycles() -> Nat {
dip721_cycles()
}

#[query(name = "totalUniqueHolders")]
#[candid_method(query, rename = "totalUniqueHolders")]
fn total_unique_holders() -> Nat {
dip721_total_unique_holders()
}

#[query()]
#[candid_method(query)]
fn stats() -> Stats {
dip721_stats()
}

#[query(name = "supportedInterfaces")]
#[candid_method(query, rename = "supportedInterfaces")]
fn supported_interfaces() -> Vec<SupportedInterface> {
dip721_supported_interfaces()
}

#[query(name = "balanceOf")]
#[candid_method(query, rename = "balanceOf")]
fn balance_of(owner: Principal) -> Result<Nat, NftError> {
dip721_balance_of(owner)
}

#[query(name = "ownerOf")]
#[candid_method(query, rename = "ownerOf")]
fn owner_of(token_identifier: TokenIdentifier) -> Result<Option<Principal>, NftError> {
dip721_owner_of(token_identifier)
}

#[query(name = "operatorOf")]
#[candid_method(query, rename = "operatorOf")]
fn operator_of(token_identifier: TokenIdentifier) -> Result<Option<Principal>, NftError> {
dip721_operator_of(token_identifier)
}

#[query(name = "ownerTokenMetadata", manual_reply = true)]
#[candid_method(query, rename = "ownerTokenMetadata")]
fn owner_token_metadata(owner: Principal) -> ManualReply<Result<Vec<TokenMetadata>, NftError>> {
dip721_owner_token_metadata(owner)
}

#[query(name = "operatorTokenMetadata", manual_reply = true)]
#[candid_method(query, rename = "operatorTokenMetadata")]
fn operator_token_metadata(
operator: Principal,
) -> ManualReply<Result<Vec<TokenMetadata>, NftError>> {
dip721_operator_token_metadata(operator)
}

#[query(name = "ownerTokenIdentifiers", manual_reply = true)]
#[candid_method(query, rename = "ownerTokenIdentifiers")]
fn owner_token_identifiers(
owner: Principal,
) -> ManualReply<Result<Vec<TokenIdentifier>, NftError>> {
dip721_owner_token_identifiers(owner)
}

#[query(name = "operatorTokenIdentifiers", manual_reply = true)]
#[candid_method(query, rename = "operatorTokenIdentifiers")]
fn operator_token_identifiers(
operator: Principal,
) -> ManualReply<Result<Vec<TokenIdentifier>, NftError>> {
dip721_operator_token_identifiers(operator)
}

#[query(name = "tokenMetadata", manual_reply = true)]
#[candid_method(query, rename = "tokenMetadata")]
fn token_metadata(
token_identifier: TokenIdentifier,
) -> ManualReply<Result<TokenMetadata, NftError>> {
dip721_token_metadata(token_identifier)
}

#[query(name = "isApprovedForAll")]
#[candid_method(query, rename = "isApprovedForAll")]
fn is_approved_for_all(owner: Principal, operator: Principal) -> Result<bool, NftError> {
dip721_is_approved_for_all(owner, operator)
}

// ======================
// UPDATE CALLS
// ======================

#[update(name = "approve")]
#[candid_method(update, rename = "approve")]
fn approve(operator: Principal, token_identifier: TokenIdentifier) -> Result<Nat, NftError> {
dip721_approve(operator, token_identifier)
}

#[update(name = "setApprovalForAll")]
#[candid_method(update, rename = "setApprovalForAll")]
fn set_approval_for_all(operator: Principal, is_approved: bool) -> Result<Nat, NftError> {
dip721_set_approval_for_all(operator, is_approved)
}

#[update(name = "transfer")]
#[candid_method(update, rename = "transfer")]
fn transfer(to: Principal, token_identifier: TokenIdentifier) -> Result<Nat, NftError> {
dip721_transfer(to, token_identifier)
}

#[update(name = "transferFrom")]
#[candid_method(update, rename = "transferFrom")]
fn transfer_from(
owner: Principal,
to: Principal,
token_identifier: TokenIdentifier,
) -> Result<Nat, NftError> {
dip721_transfer_from(owner, to, token_identifier)
}

#[update(name = "mint", guard = "is_canister_custodian")]
#[candid_method(update, rename = "mint")]
fn mint(
to: Principal,
token_identifier: TokenIdentifier,
properties: Vec<(String, GenericValue)>,
) -> Result<Nat, NftError> {
dip721_mint(to, token_identifier, properties)
}

#[update(name = "burn")]
#[candid_method(update, rename = "burn")]
fn burn(token_identifier: TokenIdentifier) -> Result<Nat, NftError> {
dip721_burn(token_identifier)
}
Loading