diff --git a/Cargo.lock b/Cargo.lock index 6452c6f..4c2761d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,9 +610,9 @@ dependencies = [ [[package]] name = "dip721-rs" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d28ae0556ac567a6b4d3e27447ac6f5bb16d13607dc6e2cd7943900674f0672c" +checksum = "5f30dec47955de459de2c1f81b105f4de22cade14de9063e0e03f6cf213eb88b" dependencies = [ "async-trait", "candid", diff --git a/Cargo.toml b/Cargo.toml index 20c880c..8f5c511 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ ethers-contract = { version = "2", default-features = false, features = [ ethers-core = "2" ethers-signers = "2" ethnum = "1" -dip721-rs = "0.1" +dip721-rs = "0.2" getrandom = { version = "0.2", features = ["custom"] } hex = "0.4" ic-cdk = "0.12" diff --git a/docs/canisters/deferred.md b/docs/canisters/deferred.md index 4856165..0b6a438 100644 --- a/docs/canisters/deferred.md +++ b/docs/canisters/deferred.md @@ -38,7 +38,7 @@ ## Introduction -Deferred is a canister which provides a **Non-fungible Token (NFT)** which implements the **DIP-721** Standard . +Deferred is a canister which provides a **Non-fungible Token (NFT)** which implements the **DIP-721** Standard with the `dip721_` namespace. The Deferred canister takes care of registering the sell or financing of a real estate between two or more parts, **Buyers** and **Sellers**. This agreement between parts is called **Contract**. diff --git a/integration-tests/src/client/deferred.rs b/integration-tests/src/client/deferred.rs index 54efe16..e498de0 100644 --- a/integration-tests/src/client/deferred.rs +++ b/integration-tests/src/client/deferred.rs @@ -148,7 +148,7 @@ impl<'a> DeferredClient<'a> { .query( self.env.deferred_id, admin(), - "total_supply", + "dip721_total_supply", Encode!(&()).unwrap(), ) .unwrap(); @@ -162,7 +162,7 @@ impl<'a> DeferredClient<'a> { .query( self.env.deferred_id, alice(), - "token_metadata", + "dip721_token_metadata", Encode!(&token_id).unwrap(), ) .unwrap(); @@ -189,7 +189,7 @@ impl<'a> DeferredClient<'a> { .update::<()>( self.env.deferred_id, admin(), - "set_custodians", + "dip721_set_custodians", Encode!(&principals).unwrap(), ) .unwrap(); @@ -206,7 +206,7 @@ impl<'a> DeferredClient<'a> { .update( self.env.deferred_id, caller, - "transfer_from", + "dip721_transfer_from", Encode!(&from, &to, &id).unwrap(), ) .unwrap() diff --git a/integration-tests/tests/inspect/deferred.rs b/integration-tests/tests/inspect/deferred.rs index 798e692..1d0bb5d 100644 --- a/integration-tests/tests/inspect/deferred.rs +++ b/integration-tests/tests/inspect/deferred.rs @@ -50,7 +50,7 @@ fn test_should_inspect_is_custodian() { .update::<()>( env.deferred_id, alice(), - "set_name", + "dip721_set_name", Encode!(&"new name").unwrap(), ) .is_ok()); @@ -68,7 +68,7 @@ fn test_should_inspect_is_custodian_not_custodian() { .update::<()>( env.deferred_id, admin(), - "set_name", + "dip721_set_name", Encode!(&"new name").unwrap(), ) .is_err()); @@ -584,7 +584,7 @@ fn test_should_inspect_burn() { .update::>( env.deferred_id, bob(), - "burn", + "dip721_burn", Encode!(&token_id).unwrap(), ) .is_ok()); diff --git a/src/declarations/deferred/deferred.did.d.ts b/src/declarations/deferred/deferred.did.d.ts index 0e06062..94eda37 100644 --- a/src/declarations/deferred/deferred.did.d.ts +++ b/src/declarations/deferred/deferred.did.d.ts @@ -179,12 +179,12 @@ export type Result_4 = { 'Ok' : Array } | { 'Err' : NftError }; export type Result_5 = { 'Ok' : Array } | { 'Err' : NftError }; -export type Result_6 = { 'Ok' : bigint } | - { 'Err' : DeferredError }; -export type Result_7 = { 'Ok' : TokenMetadata } | +export type Result_6 = { 'Ok' : TokenMetadata } | { 'Err' : NftError }; -export type Result_8 = { 'Ok' : TxEvent } | +export type Result_7 = { 'Ok' : TxEvent } | { 'Err' : NftError }; +export type Result_8 = { 'Ok' : bigint } | + { 'Err' : DeferredError }; export type Role = { 'Custodian' : null } | { 'Agent' : null }; export interface Seller { 'principal' : Principal, 'quota' : number } @@ -282,11 +282,43 @@ export interface _SERVICE { 'admin_set_ekoke_reward_pool_canister' : ActorMethod<[Principal], undefined>, 'admin_set_marketplace_canister' : ActorMethod<[Principal], undefined>, 'admin_set_role' : ActorMethod<[Principal, Role], undefined>, - 'approve' : ActorMethod<[Principal, bigint], Result_1>, - 'balance_of' : ActorMethod<[Principal], Result_1>, - 'burn' : ActorMethod<[bigint], Result_1>, - 'custodians' : ActorMethod<[], Array>, - 'cycles' : ActorMethod<[], bigint>, + 'dip721_approve' : ActorMethod<[Principal, bigint], Result_1>, + 'dip721_balance_of' : ActorMethod<[Principal], Result_1>, + 'dip721_burn' : ActorMethod<[bigint], Result_1>, + 'dip721_custodians' : ActorMethod<[], Array>, + 'dip721_cycles' : ActorMethod<[], bigint>, + 'dip721_is_approved_for_all' : ActorMethod<[Principal, Principal], Result_2>, + 'dip721_logo' : ActorMethod<[], [] | [string]>, + 'dip721_metadata' : ActorMethod<[], Metadata>, + 'dip721_mint' : ActorMethod< + [Principal, bigint, Array<[string, GenericValue]>], + Result_1 + >, + 'dip721_name' : ActorMethod<[], [] | [string]>, + 'dip721_operator_of' : ActorMethod<[bigint], Result_3>, + 'dip721_operator_token_identifiers' : ActorMethod<[Principal], Result_4>, + 'dip721_operator_token_metadata' : ActorMethod<[Principal], Result_5>, + 'dip721_owner_of' : ActorMethod<[bigint], Result_3>, + 'dip721_owner_token_identifiers' : ActorMethod<[Principal], Result_4>, + 'dip721_owner_token_metadata' : ActorMethod<[Principal], Result_5>, + 'dip721_set_approval_for_all' : ActorMethod<[Principal, boolean], Result_1>, + '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_6>, + 'dip721_total_supply' : ActorMethod<[], bigint>, + 'dip721_total_transactions' : ActorMethod<[], bigint>, + 'dip721_total_unique_holders' : ActorMethod<[], bigint>, + 'dip721_transaction' : ActorMethod<[bigint], Result_7>, + 'dip721_transfer' : ActorMethod<[Principal, bigint], Result_1>, + 'dip721_transfer_from' : ActorMethod< + [Principal, Principal, bigint], + Result_1 + >, 'get_agencies' : ActorMethod<[], Array>, 'get_contract' : ActorMethod<[bigint], [] | [Contract]>, 'get_restricted_contract_properties' : ActorMethod< @@ -298,38 +330,9 @@ export interface _SERVICE { 'get_unsigned_contracts' : ActorMethod<[], Array>, 'http_request' : ActorMethod<[HttpRequest], HttpResponse>, 'increment_contract_value' : ActorMethod<[bigint, bigint, bigint], Result>, - 'is_approved_for_all' : ActorMethod<[Principal, Principal], Result_2>, - 'logo' : ActorMethod<[], [] | [string]>, - 'metadata' : ActorMethod<[], Metadata>, - 'mint' : ActorMethod< - [Principal, bigint, Array<[string, GenericValue]>], - Result_1 - >, - 'name' : ActorMethod<[], [] | [string]>, - 'operator_of' : ActorMethod<[bigint], Result_3>, - 'operator_token_identifiers' : ActorMethod<[Principal], Result_4>, - 'operator_token_metadata' : ActorMethod<[Principal], Result_5>, - 'owner_of' : ActorMethod<[bigint], Result_3>, - 'owner_token_identifiers' : ActorMethod<[Principal], Result_4>, - 'owner_token_metadata' : ActorMethod<[Principal], Result_5>, - 'register_contract' : ActorMethod<[ContractRegistration], Result_6>, + 'register_contract' : ActorMethod<[ContractRegistration], Result_8>, 'remove_agency' : ActorMethod<[Principal], Result>, - 'set_approval_for_all' : ActorMethod<[Principal, boolean], Result_1>, - 'set_custodians' : ActorMethod<[Array], undefined>, - 'set_logo' : ActorMethod<[string], undefined>, - 'set_name' : ActorMethod<[string], undefined>, - 'set_symbol' : ActorMethod<[string], undefined>, 'sign_contract' : ActorMethod<[bigint], Result>, - 'stats' : ActorMethod<[], Stats>, - 'supported_interfaces' : ActorMethod<[], Array>, - 'symbol' : ActorMethod<[], [] | [string]>, - 'token_metadata' : ActorMethod<[bigint], Result_7>, - 'total_supply' : ActorMethod<[], bigint>, - 'total_transactions' : ActorMethod<[], bigint>, - 'total_unique_holders' : ActorMethod<[], bigint>, - 'transaction' : ActorMethod<[bigint], Result_8>, - 'transfer' : ActorMethod<[Principal, bigint], Result_1>, - 'transfer_from' : ActorMethod<[Principal, Principal, bigint], Result_1>, 'update_contract_buyers' : ActorMethod<[bigint, Array], Result>, 'update_contract_property' : ActorMethod< [bigint, string, GenericValue], diff --git a/src/declarations/deferred/deferred.did.js b/src/declarations/deferred/deferred.did.js index a5ebf2a..dc497bb 100644 --- a/src/declarations/deferred/deferred.did.js +++ b/src/declarations/deferred/deferred.did.js @@ -168,9 +168,14 @@ export const idlFactory = ({ IDL }) => { }); const Result = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : DeferredError }); const Result_1 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : NftError }); - const ContractType = IDL.Variant({ - 'Sell' : IDL.Null, - 'Financing' : IDL.Null, + const Result_2 = IDL.Variant({ 'Ok' : IDL.Bool, 'Err' : NftError }); + const Metadata = IDL.Record({ + 'logo' : IDL.Opt(IDL.Text), + 'name' : IDL.Opt(IDL.Text), + 'created_at' : IDL.Nat64, + 'upgraded_at' : IDL.Nat64, + 'custodians' : IDL.Vec(IDL.Principal), + 'symbol' : IDL.Opt(IDL.Text), }); GenericValue.fill( IDL.Variant({ @@ -192,6 +197,54 @@ export const idlFactory = ({ IDL }) => { 'TextContent' : IDL.Text, }) ); + const Result_3 = IDL.Variant({ + 'Ok' : IDL.Opt(IDL.Principal), + 'Err' : NftError, + }); + const Result_4 = IDL.Variant({ 'Ok' : IDL.Vec(IDL.Nat), 'Err' : NftError }); + const TokenMetadata = IDL.Record({ + 'transferred_at' : IDL.Opt(IDL.Nat64), + 'transferred_by' : IDL.Opt(IDL.Principal), + 'owner' : IDL.Opt(IDL.Principal), + 'operator' : IDL.Opt(IDL.Principal), + 'approved_at' : IDL.Opt(IDL.Nat64), + 'approved_by' : IDL.Opt(IDL.Principal), + 'properties' : IDL.Vec(IDL.Tuple(IDL.Text, GenericValue)), + 'is_burned' : IDL.Bool, + 'token_identifier' : IDL.Nat, + 'burned_at' : IDL.Opt(IDL.Nat64), + 'burned_by' : IDL.Opt(IDL.Principal), + 'minted_at' : IDL.Nat64, + 'minted_by' : IDL.Principal, + }); + const Result_5 = IDL.Variant({ + 'Ok' : IDL.Vec(TokenMetadata), + 'Err' : NftError, + }); + const Stats = IDL.Record({ + 'cycles' : IDL.Nat, + 'total_transactions' : IDL.Nat, + 'total_unique_holders' : IDL.Nat, + 'total_supply' : IDL.Nat, + }); + const SupportedInterface = IDL.Variant({ + 'Burn' : IDL.Null, + 'Mint' : IDL.Null, + 'Approval' : IDL.Null, + 'TransactionHistory' : IDL.Null, + }); + const Result_6 = 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 ContractType = IDL.Variant({ + 'Sell' : IDL.Null, + 'Financing' : IDL.Null, + }); const RestrictionLevel = IDL.Variant({ 'Buyer' : IDL.Null, 'Seller' : IDL.Null, @@ -251,39 +304,6 @@ export const idlFactory = ({ IDL }) => { 'upgrade' : IDL.Opt(IDL.Bool), 'status_code' : IDL.Nat16, }); - const Result_2 = IDL.Variant({ 'Ok' : IDL.Bool, 'Err' : NftError }); - const Metadata = IDL.Record({ - 'logo' : IDL.Opt(IDL.Text), - 'name' : IDL.Opt(IDL.Text), - 'created_at' : IDL.Nat64, - 'upgraded_at' : IDL.Nat64, - 'custodians' : IDL.Vec(IDL.Principal), - 'symbol' : IDL.Opt(IDL.Text), - }); - const Result_3 = IDL.Variant({ - 'Ok' : IDL.Opt(IDL.Principal), - 'Err' : NftError, - }); - const Result_4 = IDL.Variant({ 'Ok' : IDL.Vec(IDL.Nat), 'Err' : NftError }); - const TokenMetadata = IDL.Record({ - 'transferred_at' : IDL.Opt(IDL.Nat64), - 'transferred_by' : IDL.Opt(IDL.Principal), - 'owner' : IDL.Opt(IDL.Principal), - 'operator' : IDL.Opt(IDL.Principal), - 'approved_at' : IDL.Opt(IDL.Nat64), - 'approved_by' : IDL.Opt(IDL.Principal), - 'properties' : IDL.Vec(IDL.Tuple(IDL.Text, GenericValue)), - 'is_burned' : IDL.Bool, - 'token_identifier' : IDL.Nat, - 'burned_at' : IDL.Opt(IDL.Nat64), - 'burned_by' : IDL.Opt(IDL.Principal), - 'minted_at' : IDL.Nat64, - 'minted_by' : IDL.Principal, - }); - const Result_5 = IDL.Variant({ - 'Ok' : IDL.Vec(TokenMetadata), - 'Err' : NftError, - }); const ContractRegistration = IDL.Record({ 'value' : IDL.Nat64, 'type' : ContractType, @@ -295,115 +315,99 @@ export const idlFactory = ({ IDL }) => { 'installments' : IDL.Nat64, 'buyers' : IDL.Vec(IDL.Principal), }); - const Result_6 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : DeferredError }); - const Stats = IDL.Record({ - 'cycles' : IDL.Nat, - 'total_transactions' : IDL.Nat, - 'total_unique_holders' : IDL.Nat, - 'total_supply' : IDL.Nat, - }); - const SupportedInterface = IDL.Variant({ - 'Burn' : IDL.Null, - 'Mint' : IDL.Null, - 'Approval' : IDL.Null, - 'TransactionHistory' : IDL.Null, - }); - const Result_7 = 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_8 = IDL.Variant({ 'Ok' : TxEvent, 'Err' : NftError }); + const Result_8 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : DeferredError }); return IDL.Service({ 'admin_register_agency' : IDL.Func([IDL.Principal, Agency], [], []), 'admin_remove_role' : IDL.Func([IDL.Principal, Role], [Result], []), 'admin_set_ekoke_reward_pool_canister' : IDL.Func([IDL.Principal], [], []), 'admin_set_marketplace_canister' : IDL.Func([IDL.Principal], [], []), 'admin_set_role' : IDL.Func([IDL.Principal, Role], [], []), - 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result_1], []), - 'balance_of' : IDL.Func([IDL.Principal], [Result_1], ['query']), - 'burn' : IDL.Func([IDL.Nat], [Result_1], []), - 'custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), - 'cycles' : IDL.Func([], [IDL.Nat], ['query']), - 'get_agencies' : IDL.Func([], [IDL.Vec(Agency)], ['query']), - 'get_contract' : IDL.Func([IDL.Nat], [IDL.Opt(Contract)], ['query']), - 'get_restricted_contract_properties' : IDL.Func( - [IDL.Nat], - [IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, RestrictedProperty)))], - ['query'], - ), - 'get_signed_contracts' : IDL.Func([], [IDL.Vec(IDL.Nat)], ['query']), - 'get_token' : IDL.Func([IDL.Nat], [IDL.Opt(TokenInfo)], ['query']), - 'get_unsigned_contracts' : IDL.Func([], [IDL.Vec(IDL.Nat)], ['query']), - 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), - 'increment_contract_value' : IDL.Func( - [IDL.Nat, IDL.Nat64, IDL.Nat64], - [Result], - [], - ), - 'is_approved_for_all' : IDL.Func( + 'dip721_approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result_1], []), + 'dip721_balance_of' : IDL.Func([IDL.Principal], [Result_1], ['query']), + 'dip721_burn' : IDL.Func([IDL.Nat], [Result_1], []), + '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_2], [], ), - '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_1], [], ), - 'name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), - 'operator_of' : IDL.Func([IDL.Nat], [Result_3], ['query']), - 'operator_token_identifiers' : IDL.Func( + 'dip721_name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_operator_of' : IDL.Func([IDL.Nat], [Result_3], ['query']), + 'dip721_operator_token_identifiers' : IDL.Func( [IDL.Principal], [Result_4], ['query'], ), - 'operator_token_metadata' : IDL.Func( + 'dip721_operator_token_metadata' : IDL.Func( [IDL.Principal], [Result_5], ['query'], ), - 'owner_of' : IDL.Func([IDL.Nat], [Result_3], ['query']), - 'owner_token_identifiers' : IDL.Func( + 'dip721_owner_of' : IDL.Func([IDL.Nat], [Result_3], ['query']), + 'dip721_owner_token_identifiers' : IDL.Func( [IDL.Principal], [Result_4], ['query'], ), - 'owner_token_metadata' : IDL.Func([IDL.Principal], [Result_5], ['query']), - 'register_contract' : IDL.Func([ContractRegistration], [Result_6], []), - 'remove_agency' : IDL.Func([IDL.Principal], [Result], []), - 'set_approval_for_all' : IDL.Func( + 'dip721_owner_token_metadata' : IDL.Func( + [IDL.Principal], + [Result_5], + ['query'], + ), + 'dip721_set_approval_for_all' : IDL.Func( [IDL.Principal, IDL.Bool], [Result_1], [], ), - '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], [], []), - 'sign_contract' : IDL.Func([IDL.Nat], [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_7], ['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_8], ['query']), - 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result_1], []), - 'transfer_from' : IDL.Func( + 'dip721_symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + 'dip721_token_metadata' : IDL.Func([IDL.Nat], [Result_6], ['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_7], ['query']), + 'dip721_transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result_1], []), + 'dip721_transfer_from' : IDL.Func( [IDL.Principal, IDL.Principal, IDL.Nat], [Result_1], [], ), + 'get_agencies' : IDL.Func([], [IDL.Vec(Agency)], ['query']), + 'get_contract' : IDL.Func([IDL.Nat], [IDL.Opt(Contract)], ['query']), + 'get_restricted_contract_properties' : IDL.Func( + [IDL.Nat], + [IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, RestrictedProperty)))], + ['query'], + ), + 'get_signed_contracts' : IDL.Func([], [IDL.Vec(IDL.Nat)], ['query']), + 'get_token' : IDL.Func([IDL.Nat], [IDL.Opt(TokenInfo)], ['query']), + 'get_unsigned_contracts' : IDL.Func([], [IDL.Vec(IDL.Nat)], ['query']), + 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), + 'increment_contract_value' : IDL.Func( + [IDL.Nat, IDL.Nat64, IDL.Nat64], + [Result], + [], + ), + 'register_contract' : IDL.Func([ContractRegistration], [Result_8], []), + 'remove_agency' : IDL.Func([IDL.Principal], [Result], []), + 'sign_contract' : IDL.Func([IDL.Nat], [Result], []), 'update_contract_buyers' : IDL.Func( [IDL.Nat, IDL.Vec(IDL.Principal)], [Result], diff --git a/src/deferred/deferred.did b/src/deferred/deferred.did index 64c6d75..fb1a881 100644 --- a/src/deferred/deferred.did +++ b/src/deferred/deferred.did @@ -181,9 +181,9 @@ type Result_2 = variant { Ok : bool; Err : NftError }; type Result_3 = variant { Ok : opt principal; Err : NftError }; type Result_4 = variant { Ok : vec nat; Err : NftError }; type Result_5 = variant { Ok : vec TokenMetadata; Err : NftError }; -type Result_6 = variant { Ok : nat; Err : DeferredError }; -type Result_7 = variant { Ok : TokenMetadata; Err : NftError }; -type Result_8 = variant { Ok : TxEvent; Err : NftError }; +type Result_6 = variant { Ok : TokenMetadata; Err : NftError }; +type Result_7 = variant { Ok : TxEvent; Err : NftError }; +type Result_8 = variant { Ok : nat; Err : DeferredError }; type Role = variant { Custodian; Agent }; type Seller = record { "principal" : principal; quota : nat8 }; type Stats = record { @@ -279,11 +279,39 @@ service : (DeferredInitData) -> { admin_set_ekoke_reward_pool_canister : (principal) -> (); admin_set_marketplace_canister : (principal) -> (); admin_set_role : (principal, Role) -> (); - approve : (principal, nat) -> (Result_1); - balance_of : (principal) -> (Result_1) query; - burn : (nat) -> (Result_1); - custodians : () -> (vec principal) query; - cycles : () -> (nat) query; + dip721_approve : (principal, nat) -> (Result_1); + dip721_balance_of : (principal) -> (Result_1) query; + dip721_burn : (nat) -> (Result_1); + dip721_custodians : () -> (vec principal) query; + dip721_cycles : () -> (nat) query; + dip721_is_approved_for_all : (principal, principal) -> (Result_2); + dip721_logo : () -> (opt text) query; + dip721_metadata : () -> (Metadata) query; + dip721_mint : (principal, nat, vec record { text; GenericValue }) -> ( + Result_1, + ); + dip721_name : () -> (opt text) query; + dip721_operator_of : (nat) -> (Result_3) query; + dip721_operator_token_identifiers : (principal) -> (Result_4) query; + dip721_operator_token_metadata : (principal) -> (Result_5) query; + dip721_owner_of : (nat) -> (Result_3) query; + dip721_owner_token_identifiers : (principal) -> (Result_4) query; + dip721_owner_token_metadata : (principal) -> (Result_5) query; + dip721_set_approval_for_all : (principal, bool) -> (Result_1); + 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_6) query; + dip721_total_supply : () -> (nat) query; + dip721_total_transactions : () -> (nat) query; + dip721_total_unique_holders : () -> (nat) query; + dip721_transaction : (nat) -> (Result_7) query; + dip721_transfer : (principal, nat) -> (Result_1); + dip721_transfer_from : (principal, principal, nat) -> (Result_1); get_agencies : () -> (vec Agency) query; get_contract : (nat) -> (opt Contract) query; get_restricted_contract_properties : (nat) -> ( @@ -294,35 +322,9 @@ service : (DeferredInitData) -> { get_unsigned_contracts : () -> (vec nat) query; http_request : (HttpRequest) -> (HttpResponse) query; increment_contract_value : (nat, nat64, nat64) -> (Result); - is_approved_for_all : (principal, principal) -> (Result_2); - logo : () -> (opt text) query; - metadata : () -> (Metadata) query; - mint : (principal, nat, vec record { text; GenericValue }) -> (Result_1); - name : () -> (opt text) query; - operator_of : (nat) -> (Result_3) query; - operator_token_identifiers : (principal) -> (Result_4) query; - operator_token_metadata : (principal) -> (Result_5) query; - owner_of : (nat) -> (Result_3) query; - owner_token_identifiers : (principal) -> (Result_4) query; - owner_token_metadata : (principal) -> (Result_5) query; - register_contract : (ContractRegistration) -> (Result_6); + register_contract : (ContractRegistration) -> (Result_8); remove_agency : (principal) -> (Result); - set_approval_for_all : (principal, bool) -> (Result_1); - set_custodians : (vec principal) -> (); - set_logo : (text) -> (); - set_name : (text) -> (); - set_symbol : (text) -> (); sign_contract : (nat) -> (Result); - stats : () -> (Stats) query; - supported_interfaces : () -> (vec SupportedInterface) query; - symbol : () -> (opt text) query; - token_metadata : (nat) -> (Result_7) query; - total_supply : () -> (nat) query; - total_transactions : () -> (nat) query; - total_unique_holders : () -> (nat) query; - transaction : (nat) -> (Result_8) query; - transfer : (principal, nat) -> (Result_1); - transfer_from : (principal, principal, nat) -> (Result_1); update_contract_buyers : (nat, vec principal) -> (Result); update_contract_property : (nat, text, GenericValue) -> (Result); update_restricted_contract_property : (nat, text, RestrictedProperty) -> ( diff --git a/src/deferred/src/app.rs b/src/deferred/src/app.rs index ba25501..a29fba8 100644 --- a/src/deferred/src/app.rs +++ b/src/deferred/src/app.rs @@ -316,35 +316,35 @@ impl Deferred { #[async_trait] impl Dip721 for Deferred { /// 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"); } @@ -354,13 +354,13 @@ impl Dip721 for Deferred { } /// 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"); } @@ -370,13 +370,13 @@ impl Dip721 for Deferred { } /// 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"); } @@ -386,13 +386,13 @@ impl Dip721 for Deferred { } /// Returns a list of the canister custodians - fn custodians() -> Vec { + fn dip721_custodians() -> Vec { RolesManager::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"); } @@ -402,23 +402,23 @@ impl Dip721 for Deferred { } /// 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 { ContractStorage::total_unique_holders().into() } /// Returns metadata for token - fn token_metadata(token_identifier: TokenIdentifier) -> Result { + fn dip721_token_metadata(token_identifier: TokenIdentifier) -> Result { ContractStorage::get_token_metadata(&token_identifier).ok_or(NftError::TokenNotFound) } /// 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 ContractStorage::tokens_by_owner(owner) { tokens if tokens.is_empty() => Err(NftError::OwnerNotFound), tokens => Ok(tokens.len().into()), @@ -427,7 +427,7 @@ impl Dip721 for Deferred { /// 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> { match ContractStorage::get_token(&token_identifier).map(|token| token.owner) { Some(owner) => Ok(owner), None => Err(NftError::TokenNotFound), @@ -436,7 +436,7 @@ impl Dip721 for Deferred { /// 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 ContractStorage::tokens_by_owner(owner) { tokens if tokens.is_empty() => Err(NftError::OwnerNotFound), tokens => Ok(tokens), @@ -445,11 +445,11 @@ impl Dip721 for Deferred { /// 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() { @@ -460,7 +460,9 @@ impl Dip721 for Deferred { } /// 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> { match ContractStorage::get_token(&token_identifier) { Some(token) => Ok(token.operator), None => Err(NftError::TokenNotFound), @@ -468,7 +470,9 @@ impl Dip721 for Deferred { } /// 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 ContractStorage::tokens_by_operator(operator) { tokens if tokens.is_empty() => Err(NftError::OperatorNotFound), tokens => Ok(tokens), @@ -476,11 +480,11 @@ impl Dip721 for Deferred { } /// 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() { @@ -491,7 +495,7 @@ impl Dip721 for Deferred { } /// Returns the list of the interfaces supported by this canister - fn supported_interfaces() -> Vec { + fn dip721_supported_interfaces() -> Vec { vec![ SupportedInterface::Burn, SupportedInterface::TransactionHistory, @@ -500,7 +504,7 @@ impl Dip721 for Deferred { /// 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 { ContractStorage::total_supply().into() } @@ -509,7 +513,10 @@ impl Dip721 for Deferred { // // 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 { Err(NftError::Other("Not implemented".to_string())) } @@ -517,20 +524,26 @@ impl Dip721 for Deferred { /// 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 { Err(NftError::Other("Not implemented".to_string())) } /// 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 { Err(NftError::Other("Not implemented".to_string())) } /// 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 @@ -538,7 +551,7 @@ impl Dip721 for Deferred { /// /// 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, @@ -565,7 +578,7 @@ impl Dip721 for Deferred { Ok(tx_id) } - fn mint( + fn dip721_mint( _to: Principal, _token_identifier: TokenIdentifier, _properties: Vec<(String, GenericValue)>, @@ -579,7 +592,7 @@ impl Dip721 for Deferred { /// 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_burn(caller(), &token_identifier)?; match ContractStorage::burn_token(&token_identifier) { @@ -591,7 +604,7 @@ impl Dip721 for Deferred { /// 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 { match TxHistory::get_transaction_by_id(tx_id) { Some(ev) => Ok(ev), None => Err(NftError::TxNotFound), @@ -599,7 +612,7 @@ impl Dip721 for Deferred { } /// 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() } } @@ -626,7 +639,7 @@ mod test { marketplace_canister: caller(), }); - assert_eq!(Deferred::custodians(), vec![caller()]); + assert_eq!(Deferred::dip721_custodians(), vec![caller()]); assert_eq!(Configuration::get_ekoke_reward_pool_canister(), caller()); assert_eq!(Configuration::get_marketplace_canister(), caller()); } @@ -634,11 +647,11 @@ mod test { #[test] fn test_should_set_upgrade_time_on_post_upgrade() { init_canister(); - let metadata = Deferred::metadata(); + let metadata = Deferred::dip721_metadata(); assert!(metadata.upgraded_at == metadata.created_at); std::thread::sleep(Duration::from_millis(100)); Deferred::post_upgrade(); - let metadata = Deferred::metadata(); + let metadata = Deferred::dip721_metadata(); assert!(metadata.upgraded_at > metadata.created_at); } @@ -692,11 +705,11 @@ mod test { }; assert_eq!(Deferred::register_contract(contract).unwrap(), 0_u64); - assert_eq!(Deferred::total_supply(), Nat::from(0_u64)); + assert_eq!(Deferred::dip721_total_supply(), Nat::from(0_u64)); assert_eq!(Deferred::get_unsigned_contracts(), vec![Nat::from(0_u64)]); assert!(Deferred::sign_contract(0_u64.into()).await.is_ok()); assert_eq!(Deferred::get_signed_contracts(), vec![Nat::from(0_u64)]); - assert_eq!(Deferred::total_supply(), Nat::from(10_u64)); + assert_eq!(Deferred::dip721_total_supply(), Nat::from(10_u64)); } #[tokio::test] @@ -723,7 +736,7 @@ mod test { assert!(Deferred::increment_contract_value(0_u64.into(), 50, 10) .await .is_ok()); - assert_eq!(Deferred::total_supply(), Nat::from(20_u64)); + assert_eq!(Deferred::dip721_total_supply(), Nat::from(20_u64)); } #[test] @@ -771,7 +784,7 @@ mod test { #[test] fn test_should_get_metadata() { init_canister(); - let metadata = Deferred::metadata(); + let metadata = Deferred::dip721_metadata(); assert_eq!(metadata.custodians, vec![caller()]); assert_eq!(metadata.logo.as_deref(), Some(DEFAULT_LOGO)); assert_eq!(metadata.name.as_deref(), Some(DEFAULT_NAME)); @@ -781,7 +794,7 @@ mod test { #[test] fn test_should_get_stats() { init_canister(); - let stats = Deferred::stats(); + let stats = Deferred::dip721_stats(); assert_eq!(stats.cycles, crate::utils::cycles()); assert_eq!(stats.total_supply, 0_u64); assert_eq!(stats.total_transactions, 0_u64); @@ -792,73 +805,79 @@ mod test { fn test_should_set_logo() { init_canister(); let logo = "logo"; - Deferred::set_logo(logo.to_string()); - assert_eq!(Deferred::logo().as_deref(), Some(logo)); + Deferred::dip721_set_logo(logo.to_string()); + assert_eq!(Deferred::dip721_logo().as_deref(), Some(logo)); } #[test] fn test_should_set_name() { init_canister(); let name = "name"; - Deferred::set_name(name.to_string()); - assert_eq!(Deferred::name().as_deref(), Some(name)); + Deferred::dip721_set_name(name.to_string()); + assert_eq!(Deferred::dip721_name().as_deref(), Some(name)); } #[test] fn test_should_set_symbol() { init_canister(); let symbol = "symbol"; - Deferred::set_symbol(symbol.to_string()); - assert_eq!(Deferred::symbol().as_deref(), Some(symbol)); + Deferred::dip721_set_symbol(symbol.to_string()); + assert_eq!(Deferred::dip721_symbol().as_deref(), Some(symbol)); } #[test] fn test_should_set_custodians() { init_canister(); let custodians = vec![caller(), Principal::management_canister()]; - Deferred::set_custodians(custodians.clone()); - assert_eq!(Deferred::custodians().len(), custodians.len()); + Deferred::dip721_set_custodians(custodians.clone()); + assert_eq!(Deferred::dip721_custodians().len(), custodians.len()); } #[test] fn test_should_get_cycles() { init_canister(); - assert_eq!(Deferred::cycles(), crate::utils::cycles()); + assert_eq!(Deferred::dip721_cycles(), crate::utils::cycles()); } #[test] fn test_should_get_unique_holders() { init_canister(); store_mock_contract(&[1, 2], 1); - assert_eq!(Deferred::total_unique_holders(), Nat::from(1_u64)); + assert_eq!(Deferred::dip721_total_unique_holders(), Nat::from(1_u64)); } #[test] fn test_should_get_token_metadata() { init_canister(); store_mock_contract(&[1, 2], 1); - let metadata = Deferred::token_metadata(1_u64.into()).unwrap(); + let metadata = Deferred::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!(Deferred::token_metadata(5_u64.into()).is_err()); + assert!(Deferred::dip721_token_metadata(5_u64.into()).is_err()); } #[test] fn test_should_get_balance_of() { init_canister(); store_mock_contract(&[1, 2], 1); - assert_eq!(Deferred::balance_of(caller()).unwrap(), Nat::from(2_u64)); - assert!(Deferred::balance_of(Principal::management_canister()).is_err()); + assert_eq!( + Deferred::dip721_balance_of(caller()).unwrap(), + Nat::from(2_u64) + ); + assert!(Deferred::dip721_balance_of(Principal::management_canister()).is_err()); } #[test] fn test_should_get_owner_of() { init_canister(); store_mock_contract(&[1, 2], 1); - assert_eq!(Deferred::owner_of(1_u64.into()).unwrap(), Some(caller())); - assert!(Deferred::owner_of(5_u64.into()).is_err()); + assert_eq!( + Deferred::dip721_owner_of(1_u64.into()).unwrap(), + Some(caller()) + ); + assert!(Deferred::dip721_owner_of(5_u64.into()).is_err()); } #[test] @@ -866,17 +885,19 @@ mod test { init_canister(); store_mock_contract(&[1, 2], 1); assert_eq!( - Deferred::owner_token_identifiers(caller()).unwrap(), + Deferred::dip721_owner_token_identifiers(caller()).unwrap(), vec![Nat::from(1_u64), Nat::from(2_u64)] ); - assert!(Deferred::owner_token_identifiers(Principal::management_canister()).is_err()); + assert!( + Deferred::dip721_owner_token_identifiers(Principal::management_canister()).is_err() + ); } #[test] fn test_should_get_owner_token_metadata() { init_canister(); store_mock_contract(&[1, 2], 1); - let metadata = Deferred::owner_token_metadata(caller()).unwrap(); + let metadata = Deferred::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)); @@ -884,14 +905,14 @@ mod test { assert_eq!(metadata[1].token_identifier, Nat::from(2_u64)); // unexisting owner - assert!(Deferred::owner_token_metadata(Principal::management_canister()).is_err()); + assert!(Deferred::dip721_owner_token_metadata(Principal::management_canister()).is_err()); } #[test] fn test_should_get_operator_of() { init_canister(); store_mock_contract(&[1, 2], 1); - assert_eq!(Deferred::operator_of(1_u64.into()).unwrap(), None); + assert_eq!(Deferred::dip721_operator_of(1_u64.into()).unwrap(), None); store_mock_contract_with( &[3], 2, @@ -900,11 +921,11 @@ mod test { ); assert_eq!( - Deferred::operator_of(3_u64.into()).unwrap(), + Deferred::dip721_operator_of(3_u64.into()).unwrap(), Some(Principal::management_canister()) ); - assert!(Deferred::operator_of(5_u64.into()).is_err()); + assert!(Deferred::dip721_operator_of(5_u64.into()).is_err()); } #[test] @@ -919,7 +940,7 @@ mod test { token.operator = None; }, ); - assert!(Deferred::operator_token_identifiers(caller()).is_err()); + assert!(Deferred::dip721_operator_token_identifiers(caller()).is_err()); // with operator store_mock_contract_with( @@ -929,10 +950,10 @@ mod test { |token| token.operator = Some(Principal::management_canister()), ); assert_eq!( - Deferred::operator_token_identifiers(Principal::management_canister()).unwrap(), + Deferred::dip721_operator_token_identifiers(Principal::management_canister()).unwrap(), vec![Nat::from(3_u64), Nat::from(4_u64)] ); - assert!(Deferred::operator_of(5_u64.into()).is_err()); + assert!(Deferred::dip721_operator_of(5_u64.into()).is_err()); } #[test] @@ -947,7 +968,7 @@ mod test { token.operator = None; }, ); - assert!(Deferred::operator_token_metadata(caller()).is_err()); + assert!(Deferred::dip721_operator_token_metadata(caller()).is_err()); // with operator store_mock_contract_with( @@ -956,21 +977,22 @@ mod test { |_| {}, |token| token.operator = Some(Principal::management_canister()), ); - let metadata = Deferred::operator_token_metadata(Principal::management_canister()).unwrap(); + let metadata = + Deferred::dip721_operator_token_metadata(Principal::management_canister()).unwrap(); assert_eq!(metadata.len(), 2); assert_eq!(metadata[0].owner, Some(caller())); assert_eq!(metadata[0].token_identifier, Nat::from(3_u64)); assert_eq!(metadata[1].owner, Some(caller())); assert_eq!(metadata[1].token_identifier, Nat::from(4_u64)); - assert!(Deferred::operator_of(5_u64.into()).is_err()); + assert!(Deferred::dip721_operator_of(5_u64.into()).is_err()); } #[test] fn test_should_get_supported_interfaces() { init_canister(); assert_eq!( - Deferred::supported_interfaces(), + Deferred::dip721_supported_interfaces(), vec![ SupportedInterface::Burn, SupportedInterface::TransactionHistory @@ -983,7 +1005,7 @@ mod test { init_canister(); store_mock_contract(&[1, 2], 1); store_mock_contract(&[3, 4], 2); - assert_eq!(Deferred::total_supply(), Nat::from(4_u64)); + assert_eq!(Deferred::dip721_total_supply(), Nat::from(4_u64)); } #[tokio::test] @@ -991,22 +1013,27 @@ mod test { init_canister(); store_mock_contract(&[1, 2], 1); // self transfer - assert!(Deferred::transfer(caller(), 1_u64.into()).await.is_err()); + assert!(Deferred::dip721_transfer(caller(), 1_u64.into()) + .await + .is_err()); // transfer assert!( - Deferred::transfer(Principal::management_canister(), 1_u64.into()) + Deferred::dip721_transfer(Principal::management_canister(), 1_u64.into()) .await .is_ok() ); - assert_eq!(Deferred::balance_of(caller()).unwrap(), Nat::from(1_u64)); assert_eq!( - Deferred::balance_of(Principal::management_canister()).unwrap(), + Deferred::dip721_balance_of(caller()).unwrap(), + Nat::from(1_u64) + ); + assert_eq!( + Deferred::dip721_balance_of(Principal::management_canister()).unwrap(), Nat::from(1_u64) ); // transfer unexisting assert!( - Deferred::transfer(Principal::management_canister(), 5_u64.into()) + Deferred::dip721_transfer(Principal::management_canister(), 5_u64.into()) .await .is_err() ); @@ -1016,24 +1043,27 @@ mod test { fn test_should_burn() { init_canister(); store_mock_contract(&[1, 2], 1); - assert!(Deferred::burn(1_u64.into()).is_ok()); - assert_eq!(Deferred::balance_of(caller()).unwrap(), Nat::from(1_u64)); + assert!(Deferred::dip721_burn(1_u64.into()).is_ok()); + assert_eq!( + Deferred::dip721_balance_of(caller()).unwrap(), + Nat::from(1_u64) + ); - assert!(Deferred::burn(5_u64.into()).is_err()); + assert!(Deferred::dip721_burn(5_u64.into()).is_err()); } #[test] fn test_should_get_tx() { - assert!(Deferred::transaction(Nat::from(1_u64)).is_err()); + assert!(Deferred::dip721_transaction(Nat::from(1_u64)).is_err()); let id = TxHistory::register_token_mint(&mock_token(1, 1)); - assert!(Deferred::transaction(id).is_ok()); + assert!(Deferred::dip721_transaction(id).is_ok()); } #[test] fn test_should_get_total_transactions() { - assert_eq!(Deferred::total_transactions(), Nat::from(0_u64)); + assert_eq!(Deferred::dip721_total_transactions(), Nat::from(0_u64)); let _ = TxHistory::register_token_mint(&mock_token(1, 1)); - assert_eq!(Deferred::total_transactions(), Nat::from(1_u64)); + assert_eq!(Deferred::dip721_total_transactions(), Nat::from(1_u64)); } #[test] @@ -1068,7 +1098,7 @@ mod test { }; assert_eq!(Deferred::register_contract(contract).unwrap(), 0_u64); - assert_eq!(Deferred::total_supply(), Nat::from(0_u64)); + assert_eq!(Deferred::dip721_total_supply(), Nat::from(0_u64)); assert_eq!(Deferred::get_unsigned_contracts(), vec![Nat::from(0_u64)]); assert!(Deferred::sign_contract(0_u64.into()).await.is_ok()); diff --git a/src/deferred/src/lib.rs b/src/deferred/src/lib.rs index 0c5bc90..106f3bf 100644 --- a/src/deferred/src/lib.rs +++ b/src/deferred/src/lib.rs @@ -160,224 +160,224 @@ pub fn admin_register_agency(wallet: Principal, agency: Agency) { #[query] #[candid_method(query)] -pub fn metadata() -> dip721_rs::Metadata { - Deferred::metadata() +pub fn dip721_metadata() -> dip721_rs::Metadata { + Deferred::dip721_metadata() } #[query] #[candid_method(query)] -pub fn stats() -> dip721_rs::Stats { - Deferred::stats() +pub fn dip721_stats() -> dip721_rs::Stats { + Deferred::dip721_stats() } #[query] #[candid_method(query)] -pub fn logo() -> Option { - Deferred::logo() +pub fn dip721_logo() -> Option { + Deferred::dip721_logo() } #[update] #[candid_method(update)] -pub fn set_logo(logo: String) { - Deferred::set_logo(logo) +pub fn dip721_set_logo(logo: String) { + Deferred::dip721_set_logo(logo) } #[query] #[candid_method(query)] -pub fn name() -> Option { - Deferred::name() +pub fn dip721_name() -> Option { + Deferred::dip721_name() } #[update] #[candid_method(update)] -pub fn set_name(name: String) { - Deferred::set_name(name) +pub fn dip721_set_name(name: String) { + Deferred::dip721_set_name(name) } #[query] #[candid_method(query)] -pub fn symbol() -> Option { - Deferred::symbol() +pub fn dip721_symbol() -> Option { + Deferred::dip721_symbol() } #[update] #[candid_method(update)] -pub fn set_symbol(symbol: String) { - Deferred::set_symbol(symbol) +pub fn dip721_set_symbol(symbol: String) { + Deferred::dip721_set_symbol(symbol) } #[query] #[candid_method(query)] -pub fn custodians() -> Vec { - Deferred::custodians() +pub fn dip721_custodians() -> Vec { + Deferred::dip721_custodians() } #[update] #[candid_method(update)] -pub fn set_custodians(custodians: Vec) { - Deferred::set_custodians(custodians) +pub fn dip721_set_custodians(custodians: Vec) { + Deferred::dip721_set_custodians(custodians) } #[query] #[candid_method(query)] -pub fn cycles() -> Nat { - Deferred::cycles() +pub fn dip721_cycles() -> Nat { + Deferred::dip721_cycles() } #[query] #[candid_method(query)] -pub fn total_unique_holders() -> Nat { - Deferred::total_unique_holders() +pub fn dip721_total_unique_holders() -> Nat { + Deferred::dip721_total_unique_holders() } #[query] #[candid_method(query)] -pub fn token_metadata( +pub fn dip721_token_metadata( token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - Deferred::token_metadata(token_identifier) + Deferred::dip721_token_metadata(token_identifier) } #[query] #[candid_method(query)] -pub fn balance_of(owner: Principal) -> Result { - Deferred::balance_of(owner) +pub fn dip721_balance_of(owner: Principal) -> Result { + Deferred::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> { - Deferred::owner_of(token_identifier) + Deferred::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> { - Deferred::owner_token_identifiers(owner) + Deferred::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> { - Deferred::owner_token_metadata(owner) + Deferred::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> { - Deferred::operator_of(token_identifier) + Deferred::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> { - Deferred::operator_token_identifiers(operator) + Deferred::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> { - Deferred::operator_token_metadata(operator) + Deferred::dip721_operator_token_metadata(operator) } #[query] #[candid_method(query)] -pub fn supported_interfaces() -> Vec { - Deferred::supported_interfaces() +pub fn dip721_supported_interfaces() -> Vec { + Deferred::dip721_supported_interfaces() } #[query] #[candid_method(query)] -pub fn total_supply() -> Nat { - Deferred::total_supply() +pub fn dip721_total_supply() -> Nat { + Deferred::dip721_total_supply() } #[update] #[candid_method(update)] -pub fn approve( +pub fn dip721_approve( spender: Principal, token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - Deferred::approve(spender, token_identifier) + Deferred::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 { - Deferred::set_approval_for_all(operator, approved) + Deferred::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 { - Deferred::is_approved_for_all(owner, operator) + Deferred::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 { - Deferred::transfer(to, token_identifier).await + Deferred::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 { - Deferred::transfer_from(from, to, token_identifier).await + Deferred::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 { - Deferred::mint(to, token_identifier, properties) + Deferred::dip721_mint(to, token_identifier, properties) } #[update] #[candid_method(update)] -pub fn burn( +pub fn dip721_burn( token_identifier: dip721_rs::TokenIdentifier, ) -> Result { - Deferred::burn(token_identifier) + Deferred::dip721_burn(token_identifier) } #[query] #[candid_method(query)] -pub fn transaction(tx_id: Nat) -> Result { - Deferred::transaction(tx_id) +pub fn dip721_transaction(tx_id: Nat) -> Result { + Deferred::dip721_transaction(tx_id) } #[query] #[candid_method(query)] -pub fn total_transactions() -> Nat { - Deferred::total_transactions() +pub fn dip721_total_transactions() -> Nat { + Deferred::dip721_total_transactions() } // HTTP endpoint diff --git a/src/marketplace/src/client/deferred.rs b/src/marketplace/src/client/deferred.rs index 3591630..6b8235d 100644 --- a/src/marketplace/src/client/deferred.rs +++ b/src/marketplace/src/client/deferred.rs @@ -106,7 +106,7 @@ impl DeferredClient { { let result: (Result,) = ic_cdk::api::call::call( self.deferred_canister, - "transfer_from", + "dip721_transfer_from", (from, to, token_id), ) .await @@ -126,7 +126,7 @@ impl DeferredClient { #[cfg(target_arch = "wasm32")] { let result: (Result,) = - ic_cdk::api::call::call(self.deferred_canister, "burn", (token_id,)) + ic_cdk::api::call::call(self.deferred_canister, "dip721_burn", (token_id,)) .await .map_err(|(code, err)| MarketplaceError::CanisterCall(code, err))?;