diff --git a/src/declarations/cap/root.d.ts b/src/declarations/cap/root.d.ts index 543cac6..4ec1708 100644 --- a/src/declarations/cap/root.d.ts +++ b/src/declarations/cap/root.d.ts @@ -5,6 +5,7 @@ export type DetailValue = | { U64: bigint } | { Vec: Array } | { Slice: Array } + | { TokenIdU64: bigint } | { Text: string } | { True: null } | { False: null } @@ -24,6 +25,11 @@ export interface GetNextCanistersResponse { witness: [] | [Witness]; canisters: Array; } +export interface GetTokenTransactionsArg { + token_id: bigint; + page: [] | [number]; + witness: boolean; +} export type GetTransactionResponse = | { Delegate: [Principal, [] | [Witness]]; @@ -60,11 +66,15 @@ export interface Witness { tree: Array; } export default interface _SERVICE { + balance: () => Promise; contract_id: () => Promise; get_bucket_for: (arg_0: WithIdArg) => Promise; get_next_canisters: ( arg_0: WithWitnessArg ) => Promise; + get_token_transactions: ( + arg_0: GetTokenTransactionsArg + ) => Promise; get_transaction: (arg_0: WithIdArg) => Promise; get_transactions: ( arg_0: GetTransactionsArg diff --git a/src/declarations/cap/root.did b/src/declarations/cap/root.did index f93c1fd..fe8dc5d 100644 --- a/src/declarations/cap/root.did +++ b/src/declarations/cap/root.did @@ -3,6 +3,7 @@ type DetailValue = variant { U64 : nat64; Vec : vec DetailValue; Slice : vec nat8; + TokenIdU64 : nat64; Text : text; True; False; @@ -20,6 +21,11 @@ type GetNextCanistersResponse = record { witness : opt Witness; canisters : vec principal; }; +type GetTokenTransactionsArg = record { + token_id : nat64; + page : opt nat32; + witness : bool; +}; type GetTransactionResponse = variant { Delegate : record { principal; opt Witness }; Found : record { opt Event; opt Witness }; @@ -44,9 +50,13 @@ type WithIdArg = record { id : nat64; witness : bool }; type WithWitnessArg = record { witness : bool }; type Witness = record { certificate : vec nat8; tree : vec nat8 }; service : { + balance : () -> (nat64) query; contract_id : () -> (principal) query; get_bucket_for : (WithIdArg) -> (GetBucketResponse) query; get_next_canisters : (WithWitnessArg) -> (GetNextCanistersResponse) query; + get_token_transactions : (GetTokenTransactionsArg) -> ( + GetTransactionsResponseBorrowed, + ) query; get_transaction : (WithIdArg) -> (GetTransactionResponse) query; get_transactions : (GetTransactionsArg) -> ( GetTransactionsResponseBorrowed, diff --git a/src/declarations/cap/root.did.ts b/src/declarations/cap/root.did.ts index 8e7fe63..4bae39b 100644 --- a/src/declarations/cap/root.did.ts +++ b/src/declarations/cap/root.did.ts @@ -14,12 +14,18 @@ export const rootFactory = ({ IDL }: { IDL: any }) => { witness: IDL.Opt(Witness), canisters: IDL.Vec(IDL.Principal), }); + const GetTokenTransactionsArg = IDL.Record({ + token_id: IDL.Nat64, + page: IDL.Opt(IDL.Nat32), + witness: IDL.Bool, + }); DetailValue.fill( IDL.Variant({ I64: IDL.Int64, U64: IDL.Nat64, Vec: IDL.Vec(DetailValue), Slice: IDL.Vec(IDL.Nat8), + TokenIdU64: IDL.Nat64, Text: IDL.Text, True: IDL.Null, False: IDL.Null, @@ -33,6 +39,11 @@ export const rootFactory = ({ IDL }: { IDL: any }) => { details: IDL.Vec(IDL.Tuple(IDL.Text, DetailValue)), caller: IDL.Principal, }); + const GetTransactionsResponseBorrowed = IDL.Record({ + data: IDL.Vec(Event), + page: IDL.Nat32, + witness: IDL.Opt(Witness), + }); const GetTransactionResponse = IDL.Variant({ Delegate: IDL.Tuple(IDL.Principal, IDL.Opt(Witness)), Found: IDL.Tuple(IDL.Opt(Event), IDL.Opt(Witness)), @@ -41,11 +52,6 @@ export const rootFactory = ({ IDL }: { IDL: any }) => { page: IDL.Opt(IDL.Nat32), witness: IDL.Bool, }); - const GetTransactionsResponseBorrowed = IDL.Record({ - data: IDL.Vec(Event), - page: IDL.Nat32, - witness: IDL.Opt(Witness), - }); const GetUserTransactionsArg = IDL.Record({ page: IDL.Opt(IDL.Nat32), user: IDL.Principal, @@ -57,6 +63,7 @@ export const rootFactory = ({ IDL }: { IDL: any }) => { caller: IDL.Principal, }); return IDL.Service({ + balance: IDL.Func([], [IDL.Nat64], ["query"]), contract_id: IDL.Func([], [IDL.Principal], ["query"]), get_bucket_for: IDL.Func([WithIdArg], [GetBucketResponse], ["query"]), get_next_canisters: IDL.Func( @@ -64,6 +71,11 @@ export const rootFactory = ({ IDL }: { IDL: any }) => { [GetNextCanistersResponse], ["query"] ), + get_token_transactions: IDL.Func( + [GetTokenTransactionsArg], + [GetTransactionsResponseBorrowed], + ["query"] + ), get_transaction: IDL.Func([WithIdArg], [GetTransactionResponse], ["query"]), get_transactions: IDL.Func( [GetTransactionsArg], diff --git a/src/index.ts b/src/index.ts index 4f228eb..08f5c38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -262,6 +262,10 @@ export class CapRoot extends CapBase<_ROOT_SERVICE> { return this.actor.contract_id(); } + public async balance(): Promise { + return this.actor.balance(); + } + public async get_transaction( id: bigint, witness = false @@ -301,6 +305,22 @@ export class CapRoot extends CapBase<_ROOT_SERVICE> { }); } + public async get_token_transactions({ + page, + token_id, + witness = false, + }: { + page?: number; + token_id: bigint; + witness?: boolean; + }): Promise { + return this.actor.get_token_transactions({ + page: typeof page === "number" ? [page] : [], + token_id, + witness, + }); + } + public async insert({ operation, details,