Skip to content

Commit

Permalink
feat: DIP721 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Nov 9, 2023
1 parent 707d195 commit 638911b
Show file tree
Hide file tree
Showing 8 changed files with 679 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ args = ["fmt", "--all", "--", "--check"]

[tasks.did]
description = "Generate did files"
run_task = [{ name = "sell_contract_did" }, { name = "dfx_generate" }]
dependencies = ["sell_contract_did", "dfx_generate"]
workspace = false

[tasks.sell_contract_did]
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/tests/sell_contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Principal } from "@dfinity/principal";

import { sellContract } from "./actor";

/*
test("should be able to update fly canister principal", async () => {
const principal = Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai");
await sellContract.admin_set_fly_canister(principal);
Expand All @@ -12,3 +13,9 @@ test("should be able to update marketplace canister principal", async () => {
const principal = Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai");
await sellContract.admin_set_marketplace_canister(principal);
});
*/

test("should be able to get the total amount of nfts", async () => {
const totalSupply = await sellContract.total_supply();
expect(totalSupply).toBeGreaterThanOrEqual(0);
});
134 changes: 134 additions & 0 deletions src/declarations/sell_contract/sell_contract.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,56 @@ export interface Contract {
'mfly_reward' : bigint,
}
export type FlyError = { 'StorageError' : null };
export type GenericValue = { 'Nat64Content' : bigint } |
{ 'Nat32Content' : number } |
{ 'BoolContent' : boolean } |
{ 'Nat8Content' : number } |
{ 'Int64Content' : bigint } |
{ 'IntContent' : bigint } |
{ 'NatContent' : bigint } |
{ 'Nat16Content' : number } |
{ 'Int32Content' : number } |
{ 'Int8Content' : number } |
{ 'FloatContent' : number } |
{ 'Int16Content' : number } |
{ 'BlobContent' : Uint8Array | number[] } |
{ 'NestedContent' : Vec } |
{ 'Principal' : Principal } |
{ 'TextContent' : string };
export interface Metadata {
'logo' : [] | [string],
'name' : [] | [string],
'created_at' : bigint,
'upgraded_at' : bigint,
'custodians' : Array<Principal>,
'symbol' : [] | [string],
}
export type NftError = { 'UnauthorizedOperator' : null } |
{ 'SelfTransfer' : null } |
{ 'TokenNotFound' : null } |
{ 'UnauthorizedOwner' : null } |
{ 'TxNotFound' : null } |
{ 'SelfApprove' : null } |
{ 'OperatorNotFound' : null } |
{ 'ExistedNFT' : null } |
{ 'OwnerNotFound' : null } |
{ 'Other' : string };
export type Result = { 'Ok' : null } |
{ 'Err' : SellContractError };
export type Result_1 = { 'Ok' : bigint } |
{ 'Err' : NftError };
export type Result_2 = { 'Ok' : boolean } |
{ 'Err' : NftError };
export type Result_3 = { 'Ok' : [] | [Principal] } |
{ 'Err' : NftError };
export type Result_4 = { 'Ok' : Array<bigint> } |
{ 'Err' : NftError };
export type Result_5 = { 'Ok' : Array<TokenMetadata> } |
{ 'Err' : NftError };
export type Result_6 = { 'Ok' : TokenMetadata } |
{ 'Err' : NftError };
export type Result_7 = { 'Ok' : TxEvent } |
{ 'Err' : NftError };
export type SellContractError = { 'Fly' : FlyError } |
{ 'Configuration' : ConfigurationError } |
{ 'Unauthorized' : null } |
Expand All @@ -27,6 +75,16 @@ export interface SellContractInitData {
'custodians' : Array<Principal>,
'marketplace_canister' : Principal,
}
export interface Stats {
'cycles' : bigint,
'total_transactions' : bigint,
'total_unique_holders' : bigint,
'total_supply' : bigint,
}
export type SupportedInterface = { 'Burn' : null } |
{ 'Mint' : null } |
{ 'Approval' : null } |
{ 'TransactionHistory' : null };
export type TokenError = { 'ContractValueIsNotMultipleOfInstallments' : null } |
{ 'TokenAlreadyExists' : bigint } |
{ 'TokensMismatch' : null } |
Expand All @@ -37,13 +95,89 @@ export type TokenError = { 'ContractValueIsNotMultipleOfInstallments' : null } |
{ 'TokenIsBurned' : bigint } |
{ 'InvalidExpirationDate' : null } |
{ 'BadMintTokenOwner' : bigint };
export interface TokenMetadata {
'transferred_at' : [] | [bigint],
'transferred_by' : [] | [Principal],
'owner' : [] | [Principal],
'operator' : [] | [Principal],
'approved_at' : [] | [bigint],
'approved_by' : [] | [Principal],
'properties' : Array<[string, GenericValue]>,
'is_burned' : boolean,
'token_identifier' : bigint,
'burned_at' : [] | [bigint],
'burned_by' : [] | [Principal],
'minted_at' : bigint,
'minted_by' : Principal,
}
export interface TxEvent {
'time' : bigint,
'operation' : string,
'details' : Array<[string, GenericValue]>,
'caller' : Principal,
}
export type Vec = Array<
[
string,
{ 'Nat64Content' : bigint } |
{ 'Nat32Content' : number } |
{ 'BoolContent' : boolean } |
{ 'Nat8Content' : number } |
{ 'Int64Content' : bigint } |
{ 'IntContent' : bigint } |
{ 'NatContent' : bigint } |
{ 'Nat16Content' : number } |
{ 'Int32Content' : number } |
{ 'Int8Content' : number } |
{ 'FloatContent' : number } |
{ 'Int16Content' : number } |
{ 'BlobContent' : Uint8Array | number[] } |
{ 'NestedContent' : Vec } |
{ 'Principal' : Principal } |
{ 'TextContent' : string },
]
>;
export interface _SERVICE {
'admin_register_contract' : ActorMethod<
[bigint, Principal, Array<Principal>, string, bigint, bigint, BuildingData],
Result
>,
'admin_set_fly_canister' : ActorMethod<[Principal], undefined>,
'admin_set_marketplace_canister' : ActorMethod<[Principal], undefined>,
'approve' : ActorMethod<[Principal, bigint], Result_1>,
'balance_of' : ActorMethod<[Principal], Result_1>,
'burn' : ActorMethod<[bigint], Result_1>,
'custodians' : ActorMethod<[], Array<Principal>>,
'cycles' : ActorMethod<[], bigint>,
'get_contract' : ActorMethod<[bigint], [] | [Contract]>,
'get_contracts' : ActorMethod<[], Array<bigint>>,
'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>,
'set_approval_for_all' : ActorMethod<[Principal, boolean], Result_1>,
'set_custodians' : ActorMethod<[Array<Principal>], undefined>,
'set_logo' : ActorMethod<[string], undefined>,
'set_name' : ActorMethod<[string], undefined>,
'set_symbol' : ActorMethod<[string], undefined>,
'stats' : ActorMethod<[], Stats>,
'supported_interfaces' : ActorMethod<[], Array<SupportedInterface>>,
'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_1>,
'transfer_from' : ActorMethod<[Principal, Principal, bigint], Result_1>,
}
173 changes: 173 additions & 0 deletions src/declarations/sell_contract/sell_contract.did.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const idlFactory = ({ IDL }) => {
const Vec = IDL.Rec();
const SellContractInitData = IDL.Record({
'fly_canister' : IDL.Principal,
'custodians' : IDL.Vec(IDL.Principal),
Expand Down Expand Up @@ -30,6 +31,19 @@ export const idlFactory = ({ IDL }) => {
'StorageError' : IDL.Null,
});
const Result = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : SellContractError });
const NftError = IDL.Variant({
'UnauthorizedOperator' : IDL.Null,
'SelfTransfer' : IDL.Null,
'TokenNotFound' : IDL.Null,
'UnauthorizedOwner' : IDL.Null,
'TxNotFound' : IDL.Null,
'SelfApprove' : IDL.Null,
'OperatorNotFound' : IDL.Null,
'ExistedNFT' : IDL.Null,
'OwnerNotFound' : IDL.Null,
'Other' : IDL.Text,
});
const Result_1 = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : NftError });
const Contract = IDL.Record({
'id' : IDL.Nat,
'value' : IDL.Nat64,
Expand All @@ -40,6 +54,102 @@ export const idlFactory = ({ IDL }) => {
'buyers' : IDL.Vec(IDL.Principal),
'mfly_reward' : IDL.Nat64,
});
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),
});
Vec.fill(
IDL.Vec(
IDL.Tuple(
IDL.Text,
IDL.Variant({
'Nat64Content' : IDL.Nat64,
'Nat32Content' : IDL.Nat32,
'BoolContent' : IDL.Bool,
'Nat8Content' : IDL.Nat8,
'Int64Content' : IDL.Int64,
'IntContent' : IDL.Int,
'NatContent' : IDL.Nat,
'Nat16Content' : IDL.Nat16,
'Int32Content' : IDL.Int32,
'Int8Content' : IDL.Int8,
'FloatContent' : IDL.Float64,
'Int16Content' : IDL.Int16,
'BlobContent' : IDL.Vec(IDL.Nat8),
'NestedContent' : Vec,
'Principal' : IDL.Principal,
'TextContent' : IDL.Text,
}),
)
)
);
const GenericValue = IDL.Variant({
'Nat64Content' : IDL.Nat64,
'Nat32Content' : IDL.Nat32,
'BoolContent' : IDL.Bool,
'Nat8Content' : IDL.Nat8,
'Int64Content' : IDL.Int64,
'IntContent' : IDL.Int,
'NatContent' : IDL.Nat,
'Nat16Content' : IDL.Nat16,
'Int32Content' : IDL.Int32,
'Int8Content' : IDL.Int8,
'FloatContent' : IDL.Float64,
'Int16Content' : IDL.Int16,
'BlobContent' : IDL.Vec(IDL.Nat8),
'NestedContent' : Vec,
'Principal' : IDL.Principal,
'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 });
return IDL.Service({
'admin_register_contract' : IDL.Func(
[
Expand All @@ -56,8 +166,71 @@ export const idlFactory = ({ IDL }) => {
),
'admin_set_fly_canister' : IDL.Func([IDL.Principal], [], []),
'admin_set_marketplace_canister' : IDL.Func([IDL.Principal], [], []),
'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_contract' : IDL.Func([IDL.Nat], [IDL.Opt(Contract)], ['query']),
'get_contracts' : IDL.Func([], [IDL.Vec(IDL.Nat)], ['query']),
'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(
[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(
[IDL.Principal],
[Result_4],
['query'],
),
'operator_token_metadata' : IDL.Func(
[IDL.Principal],
[Result_5],
['query'],
),
'owner_of' : IDL.Func([IDL.Nat], [Result_3], ['query']),
'owner_token_identifiers' : IDL.Func(
[IDL.Principal],
[Result_4],
['query'],
),
'owner_token_metadata' : IDL.Func([IDL.Principal], [Result_5], ['query']),
'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], [], []),
'stats' : IDL.Func([], [Stats], ['query']),
'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_1], []),
'transfer_from' : IDL.Func(
[IDL.Principal, IDL.Principal, IDL.Nat],
[Result_1],
[],
),
});
};
export const init = ({ IDL }) => {
Expand Down
Loading

0 comments on commit 638911b

Please sign in to comment.