Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add get_token_transactions func from root #21

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/declarations/cap/root.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type DetailValue =
| { U64: bigint }
| { Vec: Array<DetailValue> }
| { Slice: Array<number> }
| { TokenIdU64: bigint }
| { Text: string }
| { True: null }
| { False: null }
Expand All @@ -24,6 +25,11 @@ export interface GetNextCanistersResponse {
witness: [] | [Witness];
canisters: Array<Principal>;
}
export interface GetTokenTransactionsArg {
token_id: bigint;
page: [] | [number];
witness: boolean;
}
export type GetTransactionResponse =
| {
Delegate: [Principal, [] | [Witness]];
Expand Down Expand Up @@ -60,11 +66,15 @@ export interface Witness {
tree: Array<number>;
}
export default interface _SERVICE {
balance: () => Promise<bigint>;
contract_id: () => Promise<Principal>;
get_bucket_for: (arg_0: WithIdArg) => Promise<GetBucketResponse>;
get_next_canisters: (
arg_0: WithWitnessArg
) => Promise<GetNextCanistersResponse>;
get_token_transactions: (
arg_0: GetTokenTransactionsArg
) => Promise<GetTransactionsResponseBorrowed>;
get_transaction: (arg_0: WithIdArg) => Promise<GetTransactionResponse>;
get_transactions: (
arg_0: GetTransactionsArg
Expand Down
10 changes: 10 additions & 0 deletions src/declarations/cap/root.did
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type DetailValue = variant {
U64 : nat64;
Vec : vec DetailValue;
Slice : vec nat8;
TokenIdU64 : nat64;
Text : text;
True;
False;
Expand All @@ -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 };
Expand All @@ -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,
Expand Down
22 changes: 17 additions & 5 deletions src/declarations/cap/root.did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)),
Expand All @@ -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,
Expand All @@ -57,13 +63,19 @@ 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(
[WithWitnessArg],
[GetNextCanistersResponse],
["query"]
),
get_token_transactions: IDL.Func(
[GetTokenTransactionsArg],
[GetTransactionsResponseBorrowed],
["query"]
),
get_transaction: IDL.Func([WithIdArg], [GetTransactionResponse], ["query"]),
get_transactions: IDL.Func(
[GetTransactionsArg],
Expand Down
20 changes: 20 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export class CapRoot extends CapBase<_ROOT_SERVICE> {
return this.actor.contract_id();
}

public async balance(): Promise<bigint> {
return this.actor.balance();
}

public async get_transaction(
id: bigint,
witness = false
Expand Down Expand Up @@ -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<GetTransactionsResponseBorrowed> {
return this.actor.get_token_transactions({
page: typeof page === "number" ? [page] : [],
token_id,
witness,
});
}

public async insert({
operation,
details,
Expand Down