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

Remove pagingToken and add cursor to getEvents response. #1067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export namespace Api {

export interface GetEventsResponse {
latestLedger: number;
cursor: string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm, no requirement for backwards compat to older rpc versions?

events: EventResponse[];
}

Expand All @@ -202,6 +203,7 @@ export namespace Api {

export interface RawGetEventsResponse {
latestLedger: number;
cursor: string;
events: RawEventResponse[];
}

Expand All @@ -210,7 +212,6 @@ export namespace Api {
type: EventType;
ledger: number;
ledgerClosedAt: string;
pagingToken: string;
inSuccessfulContractCall: boolean;
txHash: string;
}
Expand Down
1 change: 1 addition & 0 deletions src/rpc/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function parseRawEvents(
): Api.GetEventsResponse {
return {
latestLedger: r.latestLedger,
cursor: r.cursor,
events: (r.events ?? []).map((evt) => {
const clone: Omit<Api.RawEventResponse, 'contractId'> = { ...evt };
delete (clone as any).contractId; // `as any` hack because contractId field isn't optional
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ export class Server {
* are combined only in a logical OR fashion, and all of the fields in each
* filter are optional.
*
* To page through events, use the `pagingToken` field on the relevant
* {@link Api.EventResponse} object to set the `cursor` parameter.
* To page through events, use the `cursor` field on the relevant
* {@link Api.GetEventsResponse} object to set the `cursor` parameter.
*
* @param {Server.GetEventsRequest} request event filters
* @returns {Promise<Api.GetEventsResponse>} a paginatable set of the
Expand Down
10 changes: 5 additions & 5 deletions test/unit/server/soroban/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Server#getEvents", function () {
});

it("requests the correct endpoint", function (done) {
let result = { latestLedger: 0, events: [] };
let result = { latestLedger: 0, cursor:'', events: [] };
setupMock(
this.axiosMock,
{
Expand All @@ -38,6 +38,7 @@ describe("Server#getEvents", function () {
it("can build wildcard filters", function (done) {
let result = {
latestLedger: 1,
cursor:"0000000171798695936-0000000001",
events: filterEvents(getEventsResponseFixture, "*/*"),
};
expect(result.events).to.not.have.lengthOf(0, JSON.stringify(result));
Expand Down Expand Up @@ -76,6 +77,7 @@ describe("Server#getEvents", function () {
it("can build matching filters", function (done) {
let result = {
latestLedger: 1,
cursor:"0000000171798695936-0000000001",
events: filterEvents(
getEventsResponseFixture,
`${topicVals[0]}/${topicVals[1]}`,
Expand Down Expand Up @@ -116,6 +118,7 @@ describe("Server#getEvents", function () {
it("can build mixed filters", function (done) {
let result = {
latestLedger: 3,
cursor:"0000000171798695936-0000000001",
events: filterEventsByLedger(
filterEvents(getEventsResponseFixture, `${topicVals[0]}/*`),
2,
Expand Down Expand Up @@ -156,6 +159,7 @@ describe("Server#getEvents", function () {
it("can paginate", function (done) {
let result = {
latestLedger: 3,
cursor:"0000000171798695936-0000000001",
events: filterEventsByLedger(
filterEvents(getEventsResponseFixture, "*/*"),
2,
Expand Down Expand Up @@ -242,7 +246,6 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId: "",
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
Expand All @@ -254,7 +257,6 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId,
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
Expand All @@ -266,7 +268,6 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId,
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: [topicVals[0]],
value: eventVal,
Expand All @@ -278,7 +279,6 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-12-14T01:01:20Z",
contractId,
id: "0000000171798695936-0000000001",
pagingToken: "0000000171798695936-0000000001",
inSuccessfulContractCall: true,
topic: topicVals,
value: eventVal,
Expand Down