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

Switch consumers over to events_v2 #65

Merged
merged 1 commit into from
Mar 20, 2024
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
1 change: 1 addition & 0 deletions rs/canister/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type WhitelistedPrincipals = record {
};
service : (InitArgs) -> {
events : (EventsArgs) -> (EventsResponse) query;
events_v2 : (EventsArgs) -> (EventsResponse) query;
push_events : (PushEventsArgs) -> ();
push_events_v2 : (PushEventsArgs) -> ();
whitelisted_principals : () -> (WhitelistedPrincipals) query;
Expand Down
2 changes: 1 addition & 1 deletion rs/consumer/agent_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl AgentRuntime {
) -> Result<EventsResponse, (i32, String)> {
match self
.agent
.query(&canister_id, "events")
.query(&canister_id, "events_v2")
.with_arg(candid::encode_one(args).unwrap())
.call()
.await
Expand Down
2 changes: 1 addition & 1 deletion rs/consumer/cdk_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl CdkRuntime {
canister_id: Principal,
args: EventsArgs,
) -> Result<EventsResponse, (i32, String)> {
match ic_cdk::call(canister_id, "events", (args,)).await {
match ic_cdk::call(canister_id, "events_v2", (args,)).await {
Ok((response,)) => Ok(response),
Err((code, msg)) => Err((code as i32, msg)),
}
Expand Down
12 changes: 10 additions & 2 deletions ts/consumer/src/candid/idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const idlFactory = ({ IDL }) => {
const InitArgs = IDL.Record({
'push_events_whitelist' : IDL.Vec(IDL.Principal),
'read_events_whitelist' : IDL.Vec(IDL.Principal),
'time_granularity' : IDL.Opt(IDL.Nat64),
});
const EventsArgs = IDL.Record({ 'start' : IDL.Nat64, 'length' : IDL.Nat64 });
const IndexedEvent = IDL.Record({
Expand All @@ -16,10 +17,14 @@ export const idlFactory = ({ IDL }) => {
'events' : IDL.Vec(IndexedEvent),
'latest_event_index' : IDL.Opt(IDL.Nat64),
});
const Anonymizable = IDL.Variant({
'Anonymize' : IDL.Text,
'Public' : IDL.Text,
});
const IdempotentEvent = IDL.Record({
'source' : IDL.Opt(IDL.Text),
'source' : IDL.Opt(Anonymizable),
'name' : IDL.Text,
'user' : IDL.Opt(IDL.Text),
'user' : IDL.Opt(Anonymizable),
'timestamp' : IDL.Nat64,
'payload' : IDL.Vec(IDL.Nat8),
'idempotency_key' : IDL.Nat,
Expand All @@ -31,14 +36,17 @@ export const idlFactory = ({ IDL }) => {
});
return IDL.Service({
'events' : IDL.Func([EventsArgs], [EventsResponse], ['query']),
'events_v2' : IDL.Func([EventsArgs], [EventsResponse], ['query']),
'push_events' : IDL.Func([PushEventsArgs], [], []),
'push_events_v2' : IDL.Func([PushEventsArgs], [], []),
'whitelisted_principals' : IDL.Func([], [WhitelistedPrincipals], ['query']),
});
};
export const init = ({ IDL }) => {
const InitArgs = IDL.Record({
'push_events_whitelist' : IDL.Vec(IDL.Principal),
'read_events_whitelist' : IDL.Vec(IDL.Principal),
'time_granularity' : IDL.Opt(IDL.Nat64),
});
return [InitArgs];
};
9 changes: 7 additions & 2 deletions ts/consumer/src/candid/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';

export type Anonymizable = { 'Anonymize' : string } |
{ 'Public' : string };
export interface EventsArgs { 'start' : bigint, 'length' : bigint }
export interface EventsResponse {
'events' : Array<IndexedEvent>,
'latest_event_index' : [] | [bigint],
}
export interface IdempotentEvent {
'source' : [] | [string],
'source' : [] | [Anonymizable],
'name' : string,
'user' : [] | [string],
'user' : [] | [Anonymizable],
'timestamp' : bigint,
'payload' : Uint8Array | number[],
'idempotency_key' : bigint,
Expand All @@ -25,6 +27,7 @@ export interface IndexedEvent {
export interface InitArgs {
'push_events_whitelist' : Array<Principal>,
'read_events_whitelist' : Array<Principal>,
'time_granularity' : [] | [bigint],
}
export interface PushEventsArgs { 'events' : Array<IdempotentEvent> }
export interface WhitelistedPrincipals {
Expand All @@ -33,6 +36,8 @@ export interface WhitelistedPrincipals {
}
export interface _SERVICE {
'events' : ActorMethod<[EventsArgs], EventsResponse>,
'events_v2' : ActorMethod<[EventsArgs], EventsResponse>,
'push_events' : ActorMethod<[PushEventsArgs], undefined>,
'push_events_v2' : ActorMethod<[PushEventsArgs], undefined>,
'whitelisted_principals' : ActorMethod<[], WhitelistedPrincipals>,
}
2 changes: 1 addition & 1 deletion ts/consumer/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Client {
}

public async events(start: bigint, length: bigint): Promise<EventsResponse> {
const candid = await this.canister.events({
const candid = await this.canister.events_v2({
start,
length,
});
Expand Down
Loading