diff --git a/Cargo.lock b/Cargo.lock index b7191a2..8825dc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,9 +290,9 @@ dependencies = [ [[package]] name = "dip721-rs" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b145a95894c59eb7fb9d094389cb2cfb347db9f9af7f64d015c921c591328969" +checksum = "5f30dec47955de459de2c1f81b105f4de22cade14de9063e0e03f6cf213eb88b" dependencies = [ "async-trait", "candid", diff --git a/Cargo.toml b/Cargo.toml index a147315..3d6006b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ version = "0.1.0" [workspace.dependencies] async-trait = "0.1" candid = "0.10" -dip721-rs = "0.1" +dip721-rs = "0.2" getrandom = { version = "0.2", features = ["custom"] } ic-cdk = "0.12" ic-cdk-macros = "0.8" diff --git a/integration-tests/src/client/dip721.rs b/integration-tests/src/client/dip721.rs index b139e82..223147f 100644 --- a/integration-tests/src/client/dip721.rs +++ b/integration-tests/src/client/dip721.rs @@ -21,7 +21,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "metadata", + "dip721_metadata", Encode!(&()).unwrap(), ) .expect("query failed") @@ -29,13 +29,23 @@ impl<'a> Dip721Client<'a> { pub fn stats(&self) -> Stats { self.env - .query(self.env.dip721_id, alice(), "stats", Encode!(&()).unwrap()) + .query( + self.env.dip721_id, + alice(), + "dip721_stats", + Encode!(&()).unwrap(), + ) .expect("query failed") } pub fn logo(&self) -> Option { self.env - .query(self.env.dip721_id, alice(), "logo", Encode!(&()).unwrap()) + .query( + self.env.dip721_id, + alice(), + "dip721_logo", + Encode!(&()).unwrap(), + ) .expect("query failed") } @@ -44,7 +54,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "set_logo", + "dip721_set_logo", Encode!(&logo).unwrap(), ) .expect("update failed") @@ -52,7 +62,12 @@ impl<'a> Dip721Client<'a> { pub fn name(&self) -> Option { self.env - .query(self.env.dip721_id, alice(), "name", Encode!(&()).unwrap()) + .query( + self.env.dip721_id, + alice(), + "dip721_name", + Encode!(&()).unwrap(), + ) .expect("query failed") } @@ -61,7 +76,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "set_name", + "dip721_set_name", Encode!(&name).unwrap(), ) .expect("update failed") @@ -69,7 +84,12 @@ impl<'a> Dip721Client<'a> { pub fn symbol(&self) -> Option { self.env - .query(self.env.dip721_id, alice(), "symbol", Encode!(&()).unwrap()) + .query( + self.env.dip721_id, + alice(), + "dip721_symbol", + Encode!(&()).unwrap(), + ) .expect("query failed") } @@ -78,7 +98,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "set_symbol", + "dip721_set_symbol", Encode!(&symbol).unwrap(), ) .expect("update failed") @@ -89,7 +109,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "custodians", + "dip721_custodians", Encode!(&()).unwrap(), ) .expect("query failed") @@ -100,7 +120,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "set_custodians", + "dip721_set_custodians", Encode!(&(custodians,)).unwrap(), ) .expect("update failed") @@ -108,7 +128,12 @@ impl<'a> Dip721Client<'a> { pub fn cycles(&self) -> Nat { self.env - .query(self.env.dip721_id, alice(), "cycles", Encode!(&()).unwrap()) + .query( + self.env.dip721_id, + alice(), + "dip721_cycles", + Encode!(&()).unwrap(), + ) .expect("query failed") } @@ -117,7 +142,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "total_unique_holders", + "dip721_total_unique_holders", Encode!(&()).unwrap(), ) .expect("query failed") @@ -131,7 +156,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "token_metadata", + "dip721_token_metadata", Encode!(&token_identifier).unwrap(), ) .expect("query failed") @@ -142,7 +167,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "balance_of", + "dip721_balance_of", Encode!(&owner).unwrap(), ) .expect("query failed") @@ -156,7 +181,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "owner_of", + "dip721_owner_of", Encode!(&token_identifier).unwrap(), ) .expect("query failed") @@ -170,7 +195,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "owner_token_identifiers", + "dip721_owner_token_identifiers", Encode!(&owner).unwrap(), ) .expect("query failed") @@ -181,7 +206,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "owner_token_metadata", + "dip721_owner_token_metadata", Encode!(&owner).unwrap(), ) .expect("query failed") @@ -192,7 +217,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "operator_of", + "dip721_operator_of", Encode!(&owner).unwrap(), ) .expect("query failed") @@ -206,7 +231,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "operator_token_identifiers", + "dip721_operator_token_identifiers", Encode!(&operator).unwrap(), ) .expect("query failed") @@ -220,7 +245,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "operator_token_metadata", + "dip721_operator_token_metadata", Encode!(&operator).unwrap(), ) .expect("query failed") @@ -231,7 +256,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "supported_interfaces", + "dip721_supported_interfaces", Encode!(&()).unwrap(), ) .expect("query failed") @@ -242,7 +267,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "total_supply", + "dip721_total_supply", Encode!(&()).unwrap(), ) .expect("query failed") @@ -258,7 +283,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "approve", + "dip721_approve", Encode!(&operator, &token_identifier).unwrap(), ) .expect("update failed") @@ -274,7 +299,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "set_approval_for_all", + "dip721_set_approval_for_all", Encode!(&(operator, approved)).unwrap(), ) .expect("query failed") @@ -289,7 +314,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "is_approved_for_all", + "dip721_is_approved_for_all", Encode!(&(owner, operator)).unwrap(), ) .expect("query failed") @@ -305,7 +330,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "transfer", + "dip721_transfer", Encode!(&to, &token_identifier).unwrap(), ) .expect("query failed") @@ -322,7 +347,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "transfer_from", + "dip721_transfer_from", Encode!(&owner, &to, &token_identifier).unwrap(), ) .expect("query failed") @@ -339,7 +364,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "mint", + "dip721_mint", Encode!(&to, &token_identifier, &properties).unwrap(), ) .expect("query failed") @@ -354,7 +379,7 @@ impl<'a> Dip721Client<'a> { .update( self.env.dip721_id, caller, - "burn", + "dip721_burn", Encode!(&token_identifier).unwrap(), ) .expect("query failed") @@ -365,7 +390,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "transaction", + "dip721_transaction", Encode!(&tx_id).unwrap(), ) .expect("query failed") @@ -376,7 +401,7 @@ impl<'a> Dip721Client<'a> { .query( self.env.dip721_id, alice(), - "total_transactions", + "dip721_total_transactions", Encode!(&()).unwrap(), ) .expect("query failed") diff --git a/integration-tests/tests/inspect.rs b/integration-tests/tests/inspect.rs index d7775e5..667f2ee 100644 --- a/integration-tests/tests/inspect.rs +++ b/integration-tests/tests/inspect.rs @@ -11,7 +11,7 @@ fn test_should_inspect_is_custodian() { .update::<()>( env.dip721_id, admin(), - "set_name", + "dip721_set_name", Encode!(&"test").unwrap() ) .is_ok()); @@ -20,7 +20,7 @@ fn test_should_inspect_is_custodian() { .update::<()>( env.dip721_id, alice(), - "set_name", + "dip721_set_name", Encode!(&"test").unwrap() ) .is_err()); diff --git a/src/declarations/dip721-canister/dip721-canister.did b/src/declarations/dip721-canister/dip721-canister.did deleted file mode 100644 index f01cad5..0000000 --- a/src/declarations/dip721-canister/dip721-canister.did +++ /dev/null @@ -1,115 +0,0 @@ -type CanisterInitData = record { - logo : opt text; - name : text; - custodians : vec principal; - symbol : text; - supported_interfaces : vec SupportedInterface; -}; -type GenericValue = variant { - Nat64Content : nat64; - Nat32Content : nat32; - BoolContent : bool; - Nat8Content : nat8; - Int64Content : int64; - IntContent : int; - NatContent : nat; - Nat16Content : nat16; - Int32Content : int32; - Int8Content : int8; - FloatContent : float64; - Int16Content : int16; - BlobContent : blob; - NestedContent : vec record { text; GenericValue }; - Principal : principal; - TextContent : text; -}; -type Metadata = record { - logo : opt text; - name : opt text; - created_at : nat64; - upgraded_at : nat64; - custodians : vec principal; - symbol : opt text; -}; -type NftError = variant { - UnauthorizedOperator; - SelfTransfer; - TokenNotFound; - UnauthorizedOwner; - TxNotFound; - SelfApprove; - OperatorNotFound; - ExistedNFT; - OwnerNotFound; - Other : text; -}; -type Result = variant { Ok : nat; Err : NftError }; -type Result_1 = variant { Ok : bool; Err : NftError }; -type Result_2 = variant { Ok : opt principal; Err : NftError }; -type Result_3 = variant { Ok : vec nat; Err : NftError }; -type Result_4 = variant { Ok : vec TokenMetadata; Err : NftError }; -type Result_5 = variant { Ok; Err : NftError }; -type Result_6 = variant { Ok : TokenMetadata; Err : NftError }; -type Result_7 = variant { Ok : TxEvent; Err : NftError }; -type Stats = record { - cycles : nat; - total_transactions : nat; - total_unique_holders : nat; - total_supply : nat; -}; -type SupportedInterface = variant { Burn; Mint; Approval; TransactionHistory }; -type TokenMetadata = record { - transferred_at : opt nat64; - transferred_by : opt principal; - owner : opt principal; - operator : opt principal; - approved_at : opt nat64; - approved_by : opt principal; - properties : vec record { text; GenericValue }; - is_burned : bool; - token_identifier : nat; - burned_at : opt nat64; - burned_by : opt principal; - minted_at : nat64; - minted_by : principal; -}; -type TxEvent = record { - time : nat64; - operation : text; - details : vec record { text; GenericValue }; - caller : principal; -}; -service : (CanisterInitData) -> { - approve : (principal, nat) -> (Result); - balance_of : (principal) -> (Result) query; - burn : (nat) -> (Result); - custodians : () -> (vec principal) query; - cycles : () -> (nat) query; - is_approved_for_all : (principal, principal) -> (Result_1); - logo : () -> (opt text) query; - metadata : () -> (Metadata) query; - mint : (principal, nat, vec record { text; GenericValue }) -> (Result); - name : () -> (opt text) query; - operator_of : (nat) -> (Result_2) query; - operator_token_identifiers : (principal) -> (Result_3) query; - operator_token_metadata : (principal) -> (Result_4) query; - owner_of : (nat) -> (Result_2) query; - owner_token_identifiers : (principal) -> (Result_3) query; - owner_token_metadata : (principal) -> (Result_4) query; - set_approval_for_all : (principal, bool) -> (Result); - set_custodians : (vec principal) -> (); - set_logo : (text) -> (); - set_name : (text) -> (); - set_symbol : (text) -> (); - set_token_property : (nat, text, GenericValue) -> (Result_5); - stats : () -> (Stats) query; - supported_interfaces : () -> (vec SupportedInterface) query; - symbol : () -> (opt text) query; - token_metadata : (nat) -> (Result_6) query; - total_supply : () -> (nat) query; - total_transactions : () -> (nat) query; - total_unique_holders : () -> (nat) query; - transaction : (nat) -> (Result_7) query; - transfer : (principal, nat) -> (Result); - transfer_from : (principal, principal, nat) -> (Result); -} \ No newline at end of file diff --git a/src/declarations/dip721-canister/dip721-canister.did.d.ts b/src/declarations/dip721-canister/dip721-canister.did.d.ts index a5c2098..4bc81fc 100644 --- a/src/declarations/dip721-canister/dip721-canister.did.d.ts +++ b/src/declarations/dip721-canister/dip721-canister.did.d.ts @@ -53,11 +53,11 @@ export type Result_3 = { 'Ok' : Array } | { 'Err' : NftError }; export type Result_4 = { 'Ok' : Array } | { 'Err' : NftError }; -export type Result_5 = { 'Ok' : null } | +export type Result_5 = { 'Ok' : TokenMetadata } | { 'Err' : NftError }; -export type Result_6 = { 'Ok' : TokenMetadata } | +export type Result_6 = { 'Ok' : TxEvent } | { 'Err' : NftError }; -export type Result_7 = { 'Ok' : TxEvent } | +export type Result_7 = { 'Ok' : null } | { 'Err' : NftError }; export interface Stats { 'cycles' : bigint, @@ -91,41 +91,41 @@ export interface TxEvent { 'caller' : Principal, } export interface _SERVICE { - 'approve' : ActorMethod<[Principal, bigint], Result>, - 'balance_of' : ActorMethod<[Principal], Result>, - 'burn' : ActorMethod<[bigint], Result>, - 'custodians' : ActorMethod<[], Array>, - 'cycles' : ActorMethod<[], bigint>, - 'is_approved_for_all' : ActorMethod<[Principal, Principal], Result_1>, - 'logo' : ActorMethod<[], [] | [string]>, - 'metadata' : ActorMethod<[], Metadata>, - 'mint' : ActorMethod< + 'dip721_approve' : ActorMethod<[Principal, bigint], Result>, + 'dip721_balance_of' : ActorMethod<[Principal], Result>, + 'dip721_burn' : ActorMethod<[bigint], Result>, + 'dip721_custodians' : ActorMethod<[], Array>, + 'dip721_cycles' : ActorMethod<[], bigint>, + 'dip721_is_approved_for_all' : ActorMethod<[Principal, Principal], Result_1>, + 'dip721_logo' : ActorMethod<[], [] | [string]>, + 'dip721_metadata' : ActorMethod<[], Metadata>, + 'dip721_mint' : ActorMethod< [Principal, bigint, Array<[string, GenericValue]>], Result >, - 'name' : ActorMethod<[], [] | [string]>, - 'operator_of' : ActorMethod<[bigint], Result_2>, - 'operator_token_identifiers' : ActorMethod<[Principal], Result_3>, - 'operator_token_metadata' : ActorMethod<[Principal], Result_4>, - 'owner_of' : ActorMethod<[bigint], Result_2>, - 'owner_token_identifiers' : ActorMethod<[Principal], Result_3>, - 'owner_token_metadata' : ActorMethod<[Principal], Result_4>, - 'set_approval_for_all' : ActorMethod<[Principal, boolean], Result>, - 'set_custodians' : ActorMethod<[Array], undefined>, - 'set_logo' : ActorMethod<[string], undefined>, - 'set_name' : ActorMethod<[string], undefined>, - 'set_symbol' : ActorMethod<[string], undefined>, - 'set_token_property' : ActorMethod<[bigint, string, GenericValue], Result_5>, - 'stats' : ActorMethod<[], Stats>, - 'supported_interfaces' : ActorMethod<[], Array>, - 'symbol' : ActorMethod<[], [] | [string]>, - 'token_metadata' : ActorMethod<[bigint], Result_6>, - 'total_supply' : ActorMethod<[], bigint>, - 'total_transactions' : ActorMethod<[], bigint>, - 'total_unique_holders' : ActorMethod<[], bigint>, - 'transaction' : ActorMethod<[bigint], Result_7>, - 'transfer' : ActorMethod<[Principal, bigint], Result>, - 'transfer_from' : ActorMethod<[Principal, Principal, bigint], Result>, + 'dip721_name' : ActorMethod<[], [] | [string]>, + 'dip721_operator_of' : ActorMethod<[bigint], Result_2>, + 'dip721_operator_token_identifiers' : ActorMethod<[Principal], Result_3>, + 'dip721_operator_token_metadata' : ActorMethod<[Principal], Result_4>, + 'dip721_owner_of' : ActorMethod<[bigint], Result_2>, + 'dip721_owner_token_identifiers' : ActorMethod<[Principal], Result_3>, + 'dip721_owner_token_metadata' : ActorMethod<[Principal], Result_4>, + 'dip721_set_approval_for_all' : ActorMethod<[Principal, boolean], Result>, + 'dip721_set_custodians' : ActorMethod<[Array], undefined>, + 'dip721_set_logo' : ActorMethod<[string], undefined>, + 'dip721_set_name' : ActorMethod<[string], undefined>, + 'dip721_set_symbol' : ActorMethod<[string], undefined>, + 'dip721_stats' : ActorMethod<[], Stats>, + 'dip721_supported_interfaces' : ActorMethod<[], Array>, + 'dip721_symbol' : ActorMethod<[], [] | [string]>, + 'dip721_token_metadata' : ActorMethod<[bigint], Result_5>, + 'dip721_total_supply' : ActorMethod<[], bigint>, + 'dip721_total_transactions' : ActorMethod<[], bigint>, + 'dip721_total_unique_holders' : ActorMethod<[], bigint>, + 'dip721_transaction' : ActorMethod<[bigint], Result_6>, + 'dip721_transfer' : ActorMethod<[Principal, bigint], Result>, + 'dip721_transfer_from' : ActorMethod<[Principal, Principal, bigint], Result>, + 'set_token_property' : ActorMethod<[bigint, string, GenericValue], Result_7>, } export declare const idlFactory: IDL.InterfaceFactory; -export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; +export declare const init: ({ IDL }: { IDL: IDL }) => IDL.Type[]; diff --git a/src/declarations/dip721-canister/dip721-canister.did.js b/src/declarations/dip721-canister/dip721-canister.did.js index 0e000b3..da10c5c 100644 --- a/src/declarations/dip721-canister/dip721-canister.did.js +++ b/src/declarations/dip721-canister/dip721-canister.did.js @@ -79,86 +79,94 @@ export const idlFactory = ({ IDL }) => { 'Ok' : IDL.Vec(TokenMetadata), 'Err' : NftError, }); - const Result_5 = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : NftError }); const Stats = IDL.Record({ 'cycles' : IDL.Nat, 'total_transactions' : IDL.Nat, 'total_unique_holders' : IDL.Nat, 'total_supply' : IDL.Nat, }); - const Result_6 = IDL.Variant({ 'Ok' : TokenMetadata, 'Err' : NftError }); + const Result_5 = IDL.Variant({ 'Ok' : TokenMetadata, 'Err' : NftError }); const TxEvent = IDL.Record({ 'time' : IDL.Nat64, 'operation' : IDL.Text, 'details' : IDL.Vec(IDL.Tuple(IDL.Text, GenericValue)), 'caller' : IDL.Principal, }); - const Result_7 = IDL.Variant({ 'Ok' : TxEvent, 'Err' : NftError }); + const Result_6 = IDL.Variant({ 'Ok' : TxEvent, 'Err' : NftError }); + const Result_7 = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : NftError }); return IDL.Service({ - 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), - 'balance_of' : IDL.Func([IDL.Principal], [Result], ['query']), - 'burn' : IDL.Func([IDL.Nat], [Result], []), - 'custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), - 'cycles' : IDL.Func([], [IDL.Nat], ['query']), - 'is_approved_for_all' : IDL.Func( + 'dip721_approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), + 'dip721_balance_of' : IDL.Func([IDL.Principal], [Result], ['query']), + 'dip721_burn' : IDL.Func([IDL.Nat], [Result], []), + 'dip721_custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), + 'dip721_cycles' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_is_approved_for_all' : IDL.Func( [IDL.Principal, IDL.Principal], [Result_1], [], ), - 'logo' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), - 'metadata' : IDL.Func([], [Metadata], ['query']), - 'mint' : IDL.Func( + 'dip721_logo' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_metadata' : IDL.Func([], [Metadata], ['query']), + 'dip721_mint' : IDL.Func( [IDL.Principal, IDL.Nat, IDL.Vec(IDL.Tuple(IDL.Text, GenericValue))], [Result], [], ), - 'name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), - 'operator_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), - 'operator_token_identifiers' : IDL.Func( + 'dip721_name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_operator_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), + 'dip721_operator_token_identifiers' : IDL.Func( [IDL.Principal], [Result_3], ['query'], ), - 'operator_token_metadata' : IDL.Func( + 'dip721_operator_token_metadata' : IDL.Func( [IDL.Principal], [Result_4], ['query'], ), - 'owner_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), - 'owner_token_identifiers' : IDL.Func( + 'dip721_owner_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), + 'dip721_owner_token_identifiers' : IDL.Func( [IDL.Principal], [Result_3], ['query'], ), - 'owner_token_metadata' : IDL.Func([IDL.Principal], [Result_4], ['query']), - 'set_approval_for_all' : IDL.Func([IDL.Principal, IDL.Bool], [Result], []), - 'set_custodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), - 'set_logo' : IDL.Func([IDL.Text], [], []), - 'set_name' : IDL.Func([IDL.Text], [], []), - 'set_symbol' : IDL.Func([IDL.Text], [], []), - 'set_token_property' : IDL.Func( - [IDL.Nat, IDL.Text, GenericValue], - [Result_5], + 'dip721_owner_token_metadata' : IDL.Func( + [IDL.Principal], + [Result_4], + ['query'], + ), + 'dip721_set_approval_for_all' : IDL.Func( + [IDL.Principal, IDL.Bool], + [Result], [], ), - 'stats' : IDL.Func([], [Stats], ['query']), - 'supported_interfaces' : IDL.Func( + 'dip721_set_custodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), + 'dip721_set_logo' : IDL.Func([IDL.Text], [], []), + 'dip721_set_name' : IDL.Func([IDL.Text], [], []), + 'dip721_set_symbol' : IDL.Func([IDL.Text], [], []), + 'dip721_stats' : IDL.Func([], [Stats], ['query']), + 'dip721_supported_interfaces' : IDL.Func( [], [IDL.Vec(SupportedInterface)], ['query'], ), - 'symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), - 'token_metadata' : IDL.Func([IDL.Nat], [Result_6], ['query']), - 'total_supply' : IDL.Func([], [IDL.Nat], ['query']), - 'total_transactions' : IDL.Func([], [IDL.Nat], ['query']), - 'total_unique_holders' : IDL.Func([], [IDL.Nat], ['query']), - 'transaction' : IDL.Func([IDL.Nat], [Result_7], ['query']), - 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), - 'transfer_from' : IDL.Func( + 'dip721_symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_token_metadata' : IDL.Func([IDL.Nat], [Result_5], ['query']), + 'dip721_total_supply' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_total_transactions' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_total_unique_holders' : IDL.Func([], [IDL.Nat], ['query']), + 'dip721_transaction' : IDL.Func([IDL.Nat], [Result_6], ['query']), + 'dip721_transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), + 'dip721_transfer_from' : IDL.Func( [IDL.Principal, IDL.Principal, IDL.Nat], [Result], [], ), + 'set_token_property' : IDL.Func( + [IDL.Nat, IDL.Text, GenericValue], + [Result_7], + [], + ), }); }; export const init = ({ IDL }) => { diff --git a/src/declarations/dip721-canister/index.js b/src/declarations/dip721-canister/index.js index a6f010a..150cdce 100644 --- a/src/declarations/dip721-canister/index.js +++ b/src/declarations/dip721-canister/index.js @@ -10,7 +10,8 @@ export { idlFactory } from "./dip721-canister.did.js"; * beginning in dfx 0.15.0 */ export const canisterId = - process.env.CANISTER_ID_DIP721-CANISTER; + process.env.CANISTER_ID_DIP721-CANISTER || + process.env.DIP721-CANISTER_CANISTER_ID; export const createActor = (canisterId, options = {}) => { const agent = options.agent || new HttpAgent({ ...options.agentOptions }); diff --git a/src/dip721_canister/dip721-canister.did b/src/dip721_canister/dip721-canister.did index f01cad5..54d6fd0 100644 --- a/src/dip721_canister/dip721-canister.did +++ b/src/dip721_canister/dip721-canister.did @@ -48,9 +48,9 @@ type Result_1 = variant { Ok : bool; Err : NftError }; type Result_2 = variant { Ok : opt principal; Err : NftError }; type Result_3 = variant { Ok : vec nat; Err : NftError }; type Result_4 = variant { Ok : vec TokenMetadata; Err : NftError }; -type Result_5 = variant { Ok; Err : NftError }; -type Result_6 = variant { Ok : TokenMetadata; Err : NftError }; -type Result_7 = variant { Ok : TxEvent; Err : NftError }; +type Result_5 = variant { Ok : TokenMetadata; Err : NftError }; +type Result_6 = variant { Ok : TxEvent; Err : NftError }; +type Result_7 = variant { Ok; Err : NftError }; type Stats = record { cycles : nat; total_transactions : nat; @@ -80,36 +80,36 @@ type TxEvent = record { caller : principal; }; service : (CanisterInitData) -> { - approve : (principal, nat) -> (Result); - balance_of : (principal) -> (Result) query; - burn : (nat) -> (Result); - custodians : () -> (vec principal) query; - cycles : () -> (nat) query; - is_approved_for_all : (principal, principal) -> (Result_1); - logo : () -> (opt text) query; - metadata : () -> (Metadata) query; - mint : (principal, nat, vec record { text; GenericValue }) -> (Result); - name : () -> (opt text) query; - operator_of : (nat) -> (Result_2) query; - operator_token_identifiers : (principal) -> (Result_3) query; - operator_token_metadata : (principal) -> (Result_4) query; - owner_of : (nat) -> (Result_2) query; - owner_token_identifiers : (principal) -> (Result_3) query; - owner_token_metadata : (principal) -> (Result_4) query; - set_approval_for_all : (principal, bool) -> (Result); - set_custodians : (vec principal) -> (); - set_logo : (text) -> (); - set_name : (text) -> (); - set_symbol : (text) -> (); - set_token_property : (nat, text, GenericValue) -> (Result_5); - stats : () -> (Stats) query; - supported_interfaces : () -> (vec SupportedInterface) query; - symbol : () -> (opt text) query; - token_metadata : (nat) -> (Result_6) query; - total_supply : () -> (nat) query; - total_transactions : () -> (nat) query; - total_unique_holders : () -> (nat) query; - transaction : (nat) -> (Result_7) query; - transfer : (principal, nat) -> (Result); - transfer_from : (principal, principal, nat) -> (Result); + 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); + dip721_logo : () -> (opt text) query; + dip721_metadata : () -> (Metadata) 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) -> (Result_3) query; + dip721_operator_token_metadata : (principal) -> (Result_4) query; + dip721_owner_of : (nat) -> (Result_2) query; + dip721_owner_token_identifiers : (principal) -> (Result_3) query; + dip721_owner_token_metadata : (principal) -> (Result_4) 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) -> (Result_5) query; + dip721_total_supply : () -> (nat) query; + dip721_total_transactions : () -> (nat) query; + dip721_total_unique_holders : () -> (nat) query; + dip721_transaction : (nat) -> (Result_6) query; + dip721_transfer : (principal, nat) -> (Result); + dip721_transfer_from : (principal, principal, nat) -> (Result); + set_token_property : (nat, text, GenericValue) -> (Result_7); } \ No newline at end of file diff --git a/src/dip721_canister/src/app.rs b/src/dip721_canister/src/app.rs index e67dc18..3d253fd 100644 --- a/src/dip721_canister/src/app.rs +++ b/src/dip721_canister/src/app.rs @@ -61,35 +61,35 @@ impl App { #[async_trait] impl Dip721 for App { /// Returns the Metadata of the NFT canister which includes custodians, logo, name, symbol. - fn metadata() -> Metadata { + fn dip721_metadata() -> Metadata { Metadata { created_at: Configuration::get_created_at(), - custodians: Self::custodians(), - logo: Self::logo(), - name: Self::name(), - symbol: Self::symbol(), + custodians: Self::dip721_custodians(), + logo: Self::dip721_logo(), + name: Self::dip721_name(), + symbol: Self::dip721_symbol(), upgraded_at: Configuration::get_upgraded_at(), } } /// Returns the Stats of the NFT canister which includes cycles, totalSupply, totalTransactions, totalUniqueHolders. - fn stats() -> Stats { + fn dip721_stats() -> Stats { Stats { - cycles: Self::cycles(), - total_supply: Self::total_supply(), - total_transactions: Self::total_transactions(), - total_unique_holders: Self::total_unique_holders(), + cycles: Self::dip721_cycles(), + total_supply: Self::dip721_total_supply(), + total_transactions: Self::dip721_total_transactions(), + total_unique_holders: Self::dip721_total_unique_holders(), } } /// Returns the logo of the NFT contract as Base64 encoded text. - fn logo() -> Option { + fn dip721_logo() -> Option { Configuration::get_logo() } /// Sets the logo of the NFT canister. Base64 encoded text is recommended. /// Caller must be the custodian of NFT canister. - fn set_logo(logo: String) { + fn dip721_set_logo(logo: String) { if !Inspect::inspect_is_custodian(caller()) { ic_cdk::trap("Unauthorized"); } @@ -97,13 +97,13 @@ impl Dip721 for App { } /// Returns the name of the NFT canister. - fn name() -> Option { + fn dip721_name() -> Option { Configuration::get_name() } /// Sets the name of the NFT contract. /// Caller must be the custodian of NFT canister. - fn set_name(name: String) { + fn dip721_set_name(name: String) { if !Inspect::inspect_is_custodian(caller()) { ic_cdk::trap("Unauthorized"); } @@ -111,13 +111,13 @@ impl Dip721 for App { } /// Returns the symbol of the NFT contract. - fn symbol() -> Option { + fn dip721_symbol() -> Option { Configuration::get_symbol() } /// Set symbol /// Caller must be the custodian of NFT canister. - fn set_symbol(symbol: String) { + fn dip721_set_symbol(symbol: String) { if !Inspect::inspect_is_custodian(caller()) { ic_cdk::trap("Unauthorized"); } @@ -125,13 +125,13 @@ impl Dip721 for App { } /// Returns a list of the canister custodians - fn custodians() -> Vec { + fn dip721_custodians() -> Vec { Configuration::get_custodians() } /// Set canister custodians /// Caller must be the custodian of NFT canister. - fn set_custodians(custodians: Vec) { + fn dip721_set_custodians(custodians: Vec) { if !Inspect::inspect_is_custodian(caller()) { ic_cdk::trap("Unauthorized"); } @@ -139,23 +139,23 @@ impl Dip721 for App { } /// Returns canister cycles - fn cycles() -> Nat { + fn dip721_cycles() -> Nat { crate::utils::cycles() } /// Returns total unique holders of tokens - fn total_unique_holders() -> Nat { + fn dip721_total_unique_holders() -> Nat { TokensStorage::total_unique_holders().into() } /// Returns metadata for token - fn token_metadata(token_identifier: TokenIdentifier) -> Result { + fn dip721_token_metadata(token_identifier: TokenIdentifier) -> Result { TokensStorage::get_token(&token_identifier) } /// Returns the count of NFTs owned by user. /// If the user does not own any NFTs, returns an error containing NftError. - fn balance_of(owner: Principal) -> Result { + fn dip721_balance_of(owner: Principal) -> Result { match TokensStorage::tokens_by_owner(owner) { tokens if tokens.is_empty() => Err(NftError::OwnerNotFound), tokens => Ok(tokens.len().into()), @@ -164,13 +164,13 @@ impl Dip721 for App { /// Returns the owner of the token. /// Returns an error containing NftError if token_identifier is invalid. - fn owner_of(token_identifier: TokenIdentifier) -> Result, NftError> { + fn dip721_owner_of(token_identifier: TokenIdentifier) -> Result, NftError> { TokensStorage::get_token(&token_identifier).map(|token| token.owner) } /// Returns the list of the token_identifier of the NFT associated with owner. /// Returns an error containing NftError if principal is invalid. - fn owner_token_identifiers(owner: Principal) -> Result, NftError> { + fn dip721_owner_token_identifiers(owner: Principal) -> Result, NftError> { match TokensStorage::tokens_by_owner(owner) { tokens if tokens.is_empty() => Err(NftError::OwnerNotFound), tokens => Ok(tokens), @@ -179,11 +179,11 @@ impl Dip721 for App { /// Returns the list of the token_metadata of the NFT associated with owner. /// Returns an error containing NftError if principal is invalid. - fn owner_token_metadata(owner: Principal) -> Result, NftError> { - let tokens = Self::owner_token_identifiers(owner)?; + fn dip721_owner_token_metadata(owner: Principal) -> Result, NftError> { + let tokens = Self::dip721_owner_token_identifiers(owner)?; let mut metadata = Vec::with_capacity(tokens.len()); for token in tokens { - metadata.push(Self::token_metadata(token)?); + metadata.push(Self::dip721_token_metadata(token)?); } if metadata.is_empty() { @@ -194,12 +194,16 @@ impl Dip721 for App { } /// Returns the Principal of the operator of the NFT associated with token_identifier. - fn operator_of(token_identifier: TokenIdentifier) -> Result, NftError> { + fn dip721_operator_of( + token_identifier: TokenIdentifier, + ) -> Result, NftError> { TokensStorage::get_token(&token_identifier).map(|token| token.operator) } /// Returns the list of the token_identifier of the NFT associated with operator. - fn operator_token_identifiers(operator: Principal) -> Result, NftError> { + fn dip721_operator_token_identifiers( + operator: Principal, + ) -> Result, NftError> { match TokensStorage::tokens_by_operator(operator) { tokens if tokens.is_empty() => Err(NftError::OperatorNotFound), tokens => Ok(tokens), @@ -207,11 +211,11 @@ impl Dip721 for App { } /// Returns the list of the token_metadata of the NFT associated with operator. - fn operator_token_metadata(operator: Principal) -> Result, NftError> { - let tokens = Self::operator_token_identifiers(operator)?; + fn dip721_operator_token_metadata(operator: Principal) -> Result, NftError> { + let tokens = Self::dip721_operator_token_identifiers(operator)?; let mut metadata = Vec::with_capacity(tokens.len()); for token in tokens { - metadata.push(Self::token_metadata(token)?); + metadata.push(Self::dip721_token_metadata(token)?); } if metadata.is_empty() { @@ -222,13 +226,13 @@ impl Dip721 for App { } /// Returns the list of the interfaces supported by this canister - fn supported_interfaces() -> Vec { + fn dip721_supported_interfaces() -> Vec { Configuration::get_supported_interfaces() } /// Returns the total supply of the NFT. /// NFTs that are minted and later burned explicitly or sent to the zero address should also count towards totalSupply. - fn total_supply() -> Nat { + fn dip721_total_supply() -> Nat { TokensStorage::total_supply().into() } @@ -237,7 +241,10 @@ impl Dip721 for App { // // If the approval goes through, returns a nat that represents the CAP History transaction ID that can be used at the transaction method. /// Interface: approval - fn approve(operator: Principal, token_identifier: TokenIdentifier) -> Result { + fn dip721_approve( + operator: Principal, + token_identifier: TokenIdentifier, + ) -> Result { if !Inspect::inspect_is_owner(caller(), &token_identifier) { return Err(NftError::UnauthorizedOwner); } @@ -253,9 +260,9 @@ impl Dip721 for App { /// Approvals granted by the approve function are independent from the approvals granted by setApprovalForAll function. /// If the approval goes through, returns a nat that represents the CAP History transaction ID that can be used at the transaction method. /// Interface: approval - fn set_approval_for_all(operator: Principal, approved: bool) -> Result { + fn dip721_set_approval_for_all(operator: Principal, approved: bool) -> Result { if Configuration::has_interface(SupportedInterface::Approval) { - let tokens_by_owner = Self::owner_token_identifiers(caller())?; + let tokens_by_owner = Self::dip721_owner_token_identifiers(caller())?; let mut tx_id = None; for token in tokens_by_owner { if approved { @@ -276,9 +283,9 @@ impl Dip721 for App { /// Returns true if the given operator is an approved operator for all the tokens owned by the caller through the use of the setApprovalForAll method, returns false otherwise. /// Interface: approval - fn is_approved_for_all(owner: Principal, operator: Principal) -> Result { + fn dip721_is_approved_for_all(owner: Principal, operator: Principal) -> Result { if Configuration::has_interface(SupportedInterface::Approval) { - for token in Self::owner_token_identifiers(owner)? { + for token in Self::dip721_owner_token_identifiers(owner)? { let token = TokensStorage::get_token(&token)?; if token.operator != Some(operator) { return Ok(false); @@ -293,8 +300,11 @@ impl Dip721 for App { /// Sends the callers nft token_identifier to `to`` and returns a nat that represents a /// transaction id that can be used at the transaction method. - async fn transfer(to: Principal, token_identifier: TokenIdentifier) -> Result { - Self::transfer_from(caller(), to, token_identifier).await + async fn dip721_transfer( + to: Principal, + token_identifier: TokenIdentifier, + ) -> Result { + Self::dip721_transfer_from(caller(), to, token_identifier).await } /// Caller of this method is able to transfer the NFT token_identifier that is in from's balance to to's balance @@ -302,7 +312,7 @@ impl Dip721 for App { /// /// If the transfer goes through, returns a nat that represents the CAP History transaction ID /// that can be used at the transaction method. - async fn transfer_from( + async fn dip721_transfer_from( owner: Principal, to: Principal, token_identifier: TokenIdentifier, @@ -321,7 +331,7 @@ impl Dip721 for App { TokensStorage::transfer(&token_identifier, to) } - fn mint( + fn dip721_mint( to: Principal, token_identifier: TokenIdentifier, properties: Vec<(String, GenericValue)>, @@ -342,7 +352,7 @@ impl Dip721 for App { /// Implementations are encouraged to only allow burning by the owner of the token_identifier. /// /// The burn will also reduce the contract value by the token value - fn burn(token_identifier: TokenIdentifier) -> Result { + fn dip721_burn(token_identifier: TokenIdentifier) -> Result { Inspect::inspect_is_owner_or_operator(caller(), &token_identifier)?; if Configuration::has_interface(SupportedInterface::Burn) { @@ -354,7 +364,7 @@ impl Dip721 for App { /// Returns the TxEvent that corresponds with tx_id. /// If there is no TxEvent that corresponds with the tx_id entered, returns a NftError.TxNotFound. - fn transaction(tx_id: Nat) -> Result { + fn dip721_transaction(tx_id: Nat) -> Result { if Configuration::has_interface(SupportedInterface::TransactionHistory) { match TxHistory::get_transaction_by_id(tx_id) { Some(ev) => Ok(ev), @@ -366,7 +376,7 @@ impl Dip721 for App { } /// Returns a nat that represents the total number of transactions that have occurred on the NFT canister. - fn total_transactions() -> Nat { + fn dip721_total_transactions() -> Nat { TxHistory::count().into() } } @@ -386,7 +396,7 @@ mod test { fn test_should_init_canister() { init_canister(); - assert_eq!(App::custodians(), vec![caller()]); + assert_eq!(App::dip721_custodians(), vec![caller()]); assert_eq!(Configuration::get_logo().as_deref(), Some("logo")); assert_eq!(Configuration::get_name().as_deref(), Some("nft")); assert_eq!(Configuration::get_symbol().as_deref(), Some("NFT")); @@ -404,18 +414,18 @@ mod test { #[test] fn test_should_set_upgrade_time_on_post_upgrade() { init_canister(); - let metadata: Metadata = App::metadata(); + let metadata: Metadata = App::dip721_metadata(); assert!(metadata.upgraded_at == metadata.created_at); std::thread::sleep(Duration::from_millis(100)); App::post_upgrade(); - let metadata = App::metadata(); + let metadata = App::dip721_metadata(); assert!(metadata.upgraded_at > metadata.created_at); } #[test] fn test_should_get_metadata() { init_canister(); - let metadata = App::metadata(); + let metadata = App::dip721_metadata(); assert_eq!(metadata.custodians, vec![caller()]); assert_eq!(metadata.logo.as_deref(), Some("logo")); assert_eq!(metadata.name.as_deref(), Some("nft")); @@ -425,7 +435,7 @@ mod test { #[test] fn test_should_get_stats() { init_canister(); - let stats = App::stats(); + let stats = App::dip721_stats(); assert_eq!(stats.cycles, crate::utils::cycles()); assert_eq!(stats.total_supply, 0_u64); assert_eq!(stats.total_transactions, 0_u64); @@ -436,73 +446,73 @@ mod test { fn test_should_set_logo() { init_canister(); let logo = "logo"; - App::set_logo(logo.to_string()); - assert_eq!(App::logo().as_deref(), Some(logo)); + App::dip721_set_logo(logo.to_string()); + assert_eq!(App::dip721_logo().as_deref(), Some(logo)); } #[test] fn test_should_set_name() { init_canister(); let name = "name"; - App::set_name(name.to_string()); - assert_eq!(App::name().as_deref(), Some(name)); + App::dip721_set_name(name.to_string()); + assert_eq!(App::dip721_name().as_deref(), Some(name)); } #[test] fn test_should_set_symbol() { init_canister(); let symbol = "symbol"; - App::set_symbol(symbol.to_string()); - assert_eq!(App::symbol().as_deref(), Some(symbol)); + App::dip721_set_symbol(symbol.to_string()); + assert_eq!(App::dip721_symbol().as_deref(), Some(symbol)); } #[test] fn test_should_set_custodians() { init_canister(); let custodians = vec![caller(), Principal::management_canister()]; - App::set_custodians(custodians.clone()); - assert_eq!(App::custodians().len(), custodians.len()); + App::dip721_set_custodians(custodians.clone()); + assert_eq!(App::dip721_custodians().len(), custodians.len()); } #[test] fn test_should_get_cycles() { init_canister(); - assert_eq!(App::cycles(), crate::utils::cycles()); + assert_eq!(App::dip721_cycles(), crate::utils::cycles()); } #[test] fn test_should_get_unique_holders() { init_canister(); store_mock_token(1); - assert_eq!(App::total_unique_holders(), Nat::from(1_u64)); + assert_eq!(App::dip721_total_unique_holders(), Nat::from(1_u64)); } #[test] fn test_should_get_token_metadata() { init_canister(); store_mock_token(1); - let metadata = App::token_metadata(1_u64.into()).unwrap(); + let metadata = App::dip721_token_metadata(1_u64.into()).unwrap(); assert_eq!(metadata.owner, Some(caller())); assert_eq!(metadata.token_identifier, Nat::from(1_u64)); // unexisting token - assert!(App::token_metadata(5_u64.into()).is_err()); + assert!(App::dip721_token_metadata(5_u64.into()).is_err()); } #[test] fn test_should_get_balance_of() { init_canister(); store_mock_token(1); - assert_eq!(App::balance_of(caller()).unwrap(), Nat::from(1_u64)); - assert!(App::balance_of(Principal::management_canister()).is_err()); + assert_eq!(App::dip721_balance_of(caller()).unwrap(), Nat::from(1_u64)); + assert!(App::dip721_balance_of(Principal::management_canister()).is_err()); } #[test] fn test_should_get_owner_of() { init_canister(); store_mock_token(1); - assert_eq!(App::owner_of(1_u64.into()).unwrap(), Some(caller())); - assert!(App::owner_of(5_u64.into()).is_err()); + assert_eq!(App::dip721_owner_of(1_u64.into()).unwrap(), Some(caller())); + assert!(App::dip721_owner_of(5_u64.into()).is_err()); } #[test] @@ -511,10 +521,10 @@ mod test { store_mock_token(1); store_mock_token(2); assert_eq!( - App::owner_token_identifiers(caller()).unwrap(), + App::dip721_owner_token_identifiers(caller()).unwrap(), vec![Nat::from(1_u64), Nat::from(2_u64)] ); - assert!(App::owner_token_identifiers(Principal::management_canister()).is_err()); + assert!(App::dip721_owner_token_identifiers(Principal::management_canister()).is_err()); } #[test] @@ -522,7 +532,7 @@ mod test { init_canister(); store_mock_token(1); store_mock_token(2); - let metadata = App::owner_token_metadata(caller()).unwrap(); + let metadata = App::dip721_owner_token_metadata(caller()).unwrap(); assert_eq!(metadata.len(), 2); assert_eq!(metadata[0].owner, Some(caller())); assert_eq!(metadata[0].token_identifier, Nat::from(1_u64)); @@ -530,24 +540,24 @@ mod test { assert_eq!(metadata[1].token_identifier, Nat::from(2_u64)); // unexisting owner - assert!(App::owner_token_metadata(Principal::management_canister()).is_err()); + assert!(App::dip721_owner_token_metadata(Principal::management_canister()).is_err()); } #[test] fn test_should_get_operator_of() { init_canister(); store_mock_token(1); - assert_eq!(App::operator_of(1_u64.into()).unwrap(), None); + assert_eq!(App::dip721_operator_of(1_u64.into()).unwrap(), None); store_mock_token_with(2, |token| { token.operator = Some(Principal::management_canister()) }); assert_eq!( - App::operator_of(2_u64.into()).unwrap(), + App::dip721_operator_of(2_u64.into()).unwrap(), Some(Principal::management_canister()) ); - assert!(App::operator_of(5_u64.into()).is_err()); + assert!(App::dip721_operator_of(5_u64.into()).is_err()); } #[test] @@ -557,17 +567,17 @@ mod test { store_mock_token_with(1, |token| { token.operator = None; }); - assert!(App::operator_token_identifiers(caller()).is_err()); + assert!(App::dip721_operator_token_identifiers(caller()).is_err()); // with operator store_mock_token_with(2, |token| { token.operator = Some(Principal::management_canister()) }); assert_eq!( - App::operator_token_identifiers(Principal::management_canister()).unwrap(), + App::dip721_operator_token_identifiers(Principal::management_canister()).unwrap(), vec![Nat::from(2_u64)] ); - assert!(App::operator_of(5_u64.into()).is_err()); + assert!(App::dip721_operator_of(5_u64.into()).is_err()); } #[test] @@ -577,25 +587,26 @@ mod test { store_mock_token_with(1, |token| { token.operator = None; }); - assert!(App::operator_token_metadata(caller()).is_err()); + assert!(App::dip721_operator_token_metadata(caller()).is_err()); // with operator store_mock_token_with(2, |token| { token.operator = Some(Principal::management_canister()) }); - let metadata = App::operator_token_metadata(Principal::management_canister()).unwrap(); + let metadata = + App::dip721_operator_token_metadata(Principal::management_canister()).unwrap(); assert_eq!(metadata.len(), 1); assert_eq!(metadata[0].owner, Some(caller())); assert_eq!(metadata[0].token_identifier, Nat::from(2_u64)); - assert!(App::operator_of(5_u64.into()).is_err()); + assert!(App::dip721_operator_of(5_u64.into()).is_err()); } #[test] fn test_should_get_supported_interfaces() { init_canister(); assert_eq!( - App::supported_interfaces(), + App::dip721_supported_interfaces(), vec![ SupportedInterface::Burn, SupportedInterface::TransactionHistory, @@ -610,7 +621,7 @@ mod test { init_canister(); store_mock_token(1); store_mock_token(2); - assert_eq!(App::total_supply(), Nat::from(2_u64)); + assert_eq!(App::dip721_total_supply(), Nat::from(2_u64)); } #[tokio::test] @@ -618,22 +629,22 @@ mod test { init_canister(); store_mock_token(1); // self transfer - assert!(App::transfer(caller(), 1_u64.into()).await.is_err()); + assert!(App::dip721_transfer(caller(), 1_u64.into()).await.is_err()); // transfer assert!( - App::transfer(Principal::management_canister(), 1_u64.into()) + App::dip721_transfer(Principal::management_canister(), 1_u64.into()) .await .is_ok() ); - assert!(App::balance_of(caller()).is_err()); + assert!(App::dip721_balance_of(caller()).is_err()); assert_eq!( - App::balance_of(Principal::management_canister()).unwrap(), + App::dip721_balance_of(Principal::management_canister()).unwrap(), Nat::from(1_u64) ); // transfer unexisting assert!( - App::transfer(Principal::management_canister(), 5_u64.into()) + App::dip721_transfer(Principal::management_canister(), 5_u64.into()) .await .is_err() ); @@ -643,17 +654,17 @@ mod test { fn test_should_burn() { init_canister(); store_mock_token(1); - assert!(App::burn(1_u64.into()).is_ok()); - assert!(App::balance_of(caller()).is_err()); - assert!(App::burn(1_u64.into()).is_err()); - assert!(App::burn(5_u64.into()).is_err()); + assert!(App::dip721_burn(1_u64.into()).is_ok()); + assert!(App::dip721_balance_of(caller()).is_err()); + assert!(App::dip721_burn(1_u64.into()).is_err()); + assert!(App::dip721_burn(5_u64.into()).is_err()); } #[test] fn test_should_approve() { init_canister(); store_mock_token(1); - assert!(App::approve(bob(), 1_u64.into()).is_ok()); + assert!(App::dip721_approve(bob(), 1_u64.into()).is_ok()); let tokens_with_bob_as_op = TokensStorage::tokens_by_operator(bob()); assert_eq!(tokens_with_bob_as_op, vec![Nat::from(1_u64)]); @@ -664,7 +675,7 @@ mod test { init_canister(); store_mock_token(1); store_mock_token(2); - assert!(App::set_approval_for_all(bob(), true).is_ok()); + assert!(App::dip721_set_approval_for_all(bob(), true).is_ok()); let tokens_with_bob_as_op = TokensStorage::tokens_by_operator(bob()); assert_eq!( @@ -672,7 +683,7 @@ mod test { vec![Nat::from(1_u64), Nat::from(2_u64)] ); - assert!(App::set_approval_for_all(bob(), false).is_ok()); + assert!(App::dip721_set_approval_for_all(bob(), false).is_ok()); let tokens_with_bob_as_op = TokensStorage::tokens_by_operator(bob()); assert!(tokens_with_bob_as_op.is_empty()); @@ -683,28 +694,30 @@ mod test { init_canister(); store_mock_token(1); store_mock_token(2); - assert!(App::set_approval_for_all(bob(), true).is_ok()); - assert!(App::is_approved_for_all(caller(), bob()).unwrap()); - assert!(!App::is_approved_for_all(caller(), Principal::management_canister()).unwrap()); + assert!(App::dip721_set_approval_for_all(bob(), true).is_ok()); + assert!(App::dip721_is_approved_for_all(caller(), bob()).unwrap()); + assert!( + !App::dip721_is_approved_for_all(caller(), Principal::management_canister()).unwrap() + ); store_mock_token(3); - assert!(!App::is_approved_for_all(caller(), bob()).unwrap()); + assert!(!App::dip721_is_approved_for_all(caller(), bob()).unwrap()); } #[test] fn test_should_get_tx() { init_canister(); - assert!(App::transaction(Nat::from(1_u64)).is_err()); + assert!(App::dip721_transaction(Nat::from(1_u64)).is_err()); let id = TxHistory::register_token_mint(&mock_token(1)); - assert!(App::transaction(id).is_ok()); + assert!(App::dip721_transaction(id).is_ok()); } #[test] fn test_should_get_total_transactions() { init_canister(); - assert_eq!(App::total_transactions(), Nat::from(0_u64)); + assert_eq!(App::dip721_total_transactions(), Nat::from(0_u64)); let _ = TxHistory::register_token_mint(&mock_token(1)); - assert_eq!(App::total_transactions(), Nat::from(1_u64)); + assert_eq!(App::dip721_total_transactions(), Nat::from(1_u64)); } #[test] @@ -718,7 +731,7 @@ mod test { ) .is_ok()); - let metadata = App::token_metadata(1_u64.into()).unwrap(); + let metadata = App::dip721_token_metadata(1_u64.into()).unwrap(); assert_eq!( metadata.properties, vec![("key".to_string(), GenericValue::BoolContent(true))] diff --git a/src/dip721_canister/src/app/inspect.rs b/src/dip721_canister/src/app/inspect.rs index c9aaa74..552d86c 100644 --- a/src/dip721_canister/src/app/inspect.rs +++ b/src/dip721_canister/src/app/inspect.rs @@ -90,7 +90,7 @@ mod test { token.operator = Some(caller); }); assert!(TokensStorage::transfer(&2_u64.into(), Principal::management_canister()).is_ok()); - assert!(Inspect::inspect_is_owner_or_operator(caller, &2_u64.into()).is_ok()); + assert!(Inspect::inspect_is_owner_or_operator(caller, &2_u64.into()).is_err()); // no operator, no owner test_utils::store_mock_token_with(3, |token| { @@ -114,7 +114,7 @@ mod test { token.operator = Some(caller); }); assert!(TokensStorage::transfer(&2_u64.into(), Principal::management_canister()).is_ok()); - assert!(Inspect::inspect_transfer_from(caller, &2_u64.into()).is_ok()); + assert!(Inspect::inspect_transfer_from(caller, &2_u64.into()).is_err()); // no operator, no owner test_utils::store_mock_token_with(3, |token| { diff --git a/src/dip721_canister/src/app/storage/tokens.rs b/src/dip721_canister/src/app/storage/tokens.rs index 594fbbd..edc81af 100644 --- a/src/dip721_canister/src/app/storage/tokens.rs +++ b/src/dip721_canister/src/app/storage/tokens.rs @@ -89,6 +89,7 @@ impl TokensStorage { token.owner = Some(to); token.transferred_at = Some(crate::utils::time()); token.transferred_by = Some(crate::utils::caller()); + token.operator = None; // register transfer let tx_id = TxHistory::register_transfer(token); @@ -106,6 +107,7 @@ impl TokensStorage { } token.is_burned = true; token.owner = None; + token.operator = None; token.burned_at = Some(crate::utils::time()); token.burned_by = Some(crate::utils::caller()); diff --git a/src/dip721_canister/src/inspect.rs b/src/dip721_canister/src/inspect.rs index 37ff94a..dd7f701 100644 --- a/src/dip721_canister/src/inspect.rs +++ b/src/dip721_canister/src/inspect.rs @@ -20,17 +20,21 @@ fn inspect_message_impl() { let method = api::call::method_name(); let check_result = match method.as_str() { - "mint" | "set_logo" | "set_name" | "set_symbol" | "set_custodians" + "dip721_mint" + | "dip721_set_logo" + | "dip721_set_name" + | "dip721_set_symbol" + | "dip721_set_custodians" | "set_token_property" => Inspect::inspect_is_custodian(caller()), - "burn" => { + "dip721_burn" => { let token_identifier = api::call::arg_data::<(Nat,)>().0; Inspect::inspect_is_owner_or_operator(caller(), &token_identifier).is_ok() } - "approve" => { + "dip721_approve" => { let (_operator, token_identifier) = api::call::arg_data::<(Principal, Nat)>(); Inspect::inspect_is_owner(caller(), &token_identifier) } - "transfer_from" => { + "dip721_transfer_from" => { let (_, _, token_identifier) = api::call::arg_data::<(Principal, Principal, Nat)>(); Inspect::inspect_is_owner_or_operator(caller(), &token_identifier).is_ok() } diff --git a/src/dip721_canister/src/lib.rs b/src/dip721_canister/src/lib.rs index 8bb9569..c7dea5e 100644 --- a/src/dip721_canister/src/lib.rs +++ b/src/dip721_canister/src/lib.rs @@ -37,224 +37,224 @@ pub fn set_token_property( #[query] #[candid_method(query)] -pub fn metadata() -> dip721_rs::Metadata { - App::metadata() +pub fn dip721_metadata() -> dip721_rs::Metadata { + App::dip721_metadata() } #[query] #[candid_method(query)] -pub fn stats() -> dip721_rs::Stats { - App::stats() +pub fn dip721_stats() -> dip721_rs::Stats { + App::dip721_stats() } #[query] #[candid_method(query)] -pub fn logo() -> Option { - App::logo() +pub fn dip721_logo() -> Option { + App::dip721_logo() } #[update] #[candid_method(update)] -pub fn set_logo(logo: String) { - App::set_logo(logo) +pub fn dip721_set_logo(logo: String) { + App::dip721_set_logo(logo) } #[query] #[candid_method(query)] -pub fn name() -> Option { - App::name() +pub fn dip721_name() -> Option { + App::dip721_name() } #[update] #[candid_method(update)] -pub fn set_name(name: String) { - App::set_name(name) +pub fn dip721_set_name(name: String) { + App::dip721_set_name(name) } #[query] #[candid_method(query)] -pub fn symbol() -> Option { - App::symbol() +pub fn dip721_symbol() -> Option { + App::dip721_symbol() } #[update] #[candid_method(update)] -pub fn set_symbol(symbol: String) { - App::set_symbol(symbol) +pub fn dip721_set_symbol(symbol: String) { + App::dip721_set_symbol(symbol) } #[query] #[candid_method(query)] -pub fn custodians() -> Vec { - App::custodians() +pub fn dip721_custodians() -> Vec { + App::dip721_custodians() } #[update] #[candid_method(update)] -pub fn set_custodians(custodians: Vec) { - App::set_custodians(custodians) +pub fn dip721_set_custodians(custodians: Vec) { + App::dip721_set_custodians(custodians) } #[query] #[candid_method(query)] -pub fn cycles() -> Nat { - App::cycles() +pub fn dip721_cycles() -> Nat { + App::dip721_cycles() } #[query] #[candid_method(query)] -pub fn total_unique_holders() -> Nat { - App::total_unique_holders() +pub fn dip721_total_unique_holders() -> Nat { + App::dip721_total_unique_holders() } #[query] #[candid_method(query)] -pub fn token_metadata( +pub fn dip721_token_metadata( token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - App::token_metadata(token_identifier) + App::dip721_token_metadata(token_identifier) } #[query] #[candid_method(query)] -pub fn balance_of(owner: Principal) -> Result { - App::balance_of(owner) +pub fn dip721_balance_of(owner: Principal) -> Result { + App::dip721_balance_of(owner) } #[query] #[candid_method(query)] -pub fn owner_of( +pub fn dip721_owner_of( token_identifier: dip721_rs::TokenIdentifier, ) -> Result, dip721_rs::NftError> { - App::owner_of(token_identifier) + App::dip721_owner_of(token_identifier) } #[query] #[candid_method(query)] -pub fn owner_token_identifiers( +pub fn dip721_owner_token_identifiers( owner: Principal, ) -> Result, dip721_rs::NftError> { - App::owner_token_identifiers(owner) + App::dip721_owner_token_identifiers(owner) } #[query] #[candid_method(query)] -pub fn owner_token_metadata( +pub fn dip721_owner_token_metadata( owner: Principal, ) -> Result, dip721_rs::NftError> { - App::owner_token_metadata(owner) + App::dip721_owner_token_metadata(owner) } #[query] #[candid_method(query)] -pub fn operator_of( +pub fn dip721_operator_of( token_identifier: dip721_rs::TokenIdentifier, ) -> Result, dip721_rs::NftError> { - App::operator_of(token_identifier) + App::dip721_operator_of(token_identifier) } #[query] #[candid_method(query)] -pub fn operator_token_identifiers( +pub fn dip721_operator_token_identifiers( operator: Principal, ) -> Result, dip721_rs::NftError> { - App::operator_token_identifiers(operator) + App::dip721_operator_token_identifiers(operator) } #[query] #[candid_method(query)] -pub fn operator_token_metadata( +pub fn dip721_operator_token_metadata( operator: Principal, ) -> Result, dip721_rs::NftError> { - App::operator_token_metadata(operator) + App::dip721_operator_token_metadata(operator) } #[query] #[candid_method(query)] -pub fn supported_interfaces() -> Vec { - App::supported_interfaces() +pub fn dip721_supported_interfaces() -> Vec { + App::dip721_supported_interfaces() } #[query] #[candid_method(query)] -pub fn total_supply() -> Nat { - App::total_supply() +pub fn dip721_total_supply() -> Nat { + App::dip721_total_supply() } #[update] #[candid_method(update)] -pub fn approve( +pub fn dip721_approve( spender: Principal, token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - App::approve(spender, token_identifier) + App::dip721_approve(spender, token_identifier) } #[update] #[candid_method(update)] -pub fn set_approval_for_all( +pub fn dip721_set_approval_for_all( operator: Principal, approved: bool, ) -> Result { - App::set_approval_for_all(operator, approved) + App::dip721_set_approval_for_all(operator, approved) } #[update] #[candid_method(update)] -pub fn is_approved_for_all( +pub fn dip721_is_approved_for_all( owner: Principal, operator: Principal, ) -> Result { - App::is_approved_for_all(owner, operator) + App::dip721_is_approved_for_all(owner, operator) } #[update] #[candid_method(update)] -pub async fn transfer( +pub async fn dip721_transfer( to: Principal, token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - App::transfer(to, token_identifier).await + App::dip721_transfer(to, token_identifier).await } #[update] #[candid_method(update)] -pub async fn transfer_from( +pub async fn dip721_transfer_from( from: Principal, to: Principal, token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - App::transfer_from(from, to, token_identifier).await + App::dip721_transfer_from(from, to, token_identifier).await } #[update] #[candid_method(update)] -pub fn mint( +pub fn dip721_mint( to: Principal, token_identifier: dip721_rs::TokenIdentifier, properties: Vec<(String, dip721_rs::GenericValue)>, ) -> Result { - App::mint(to, token_identifier, properties) + App::dip721_mint(to, token_identifier, properties) } #[update] #[candid_method(update)] -pub fn burn( +pub fn dip721_burn( token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - App::burn(token_identifier) + App::dip721_burn(token_identifier) } #[query] #[candid_method(query)] -pub fn transaction(tx_id: Nat) -> Result { - App::transaction(tx_id) +pub fn dip721_transaction(tx_id: Nat) -> Result { + App::dip721_transaction(tx_id) } #[query] #[candid_method(query)] -pub fn total_transactions() -> Nat { - App::total_transactions() +pub fn dip721_total_transactions() -> Nat { + App::dip721_total_transactions() } #[allow(dead_code)]