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

TS SDK - Event Queries #4503

Merged
merged 122 commits into from
Sep 9, 2022
Merged

TS SDK - Event Queries #4503

merged 122 commits into from
Sep 9, 2022

Conversation

stella3d
Copy link
Contributor

@stella3d stella3d commented Sep 7, 2022

Add historical event queries

New Methods

all new methods are on the rpc Provider.

  • getEventsByTransaction()
  • getEventsByTransactionModule()
  • getEventsByMoveEventStructName()
  • getEventsBySender()
  • getEventsByRecipient()
  • getEventsByObject()
  • getEventsByTimeRange()

Common Parameter Defaults

Parameters shared between many functions have defaults, to allow calling functions without specifying count or time range.

async getEventsBySender(
    sender: SuiAddress,
    count: number = DEFAULT_RESULT_COUNT,
    startTime: number = DEFAULT_START_TIME,
    endTime: number = DEFAULT_END_TIME
  )

allows calling like:

await rpc.getEventsBySender('0x0327d48f4c6e4cd8c7923b5940e3465e8198e9e2');

instead of

await rpc.getEventsBySender('0x0327d48f4c6e4cd8c7923b5940e3465e8198e9e2', 1000, 0, Number.MAX_SAFE_INTEGER);

API Design

The parameters for each method appear exactly as they do in the RPC method, with no abstraction. Initially i had an object that encapsulated a time range & count, but i backed it out in favor of a less opinionated design.

Testing

here's the results of some manual testing.

getEventsByTransaction()

image

getEventsByObject()

image

getEventsBySender()

image

getEventsByRecipient()

image

getEventsByTimeRange

image

getEventsByModule

image

getEventsByMoveEventStructName

image

Base automatically changed from tx-subscribe to main September 8, 2022 21:44
@@ -12,7 +12,7 @@ export type MoveEvent = {
transactionModule: string;
sender: SuiAddress;
type: string;
fields: { [key: string]: any; };
fields?: { [key: string]: any; };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fields should always have been optional, i think. Some transactions turned out to have events without fields, this change unblocked the type guard validation

@@ -67,7 +67,8 @@ function objectContent(label: string, id: ObjectId) {
};
}

function fieldsContent(fields: { [key: string]: any }) {
function fieldsContent(fields: { [key: string]: any } | undefined) {
if (!fields) return [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is related to my other comment about making MoveEvent.fields optional.

@stella3d stella3d added the ts-sdk label Sep 9, 2022
Copy link
Contributor

@666lcz 666lcz left a comment

Choose a reason for hiding this comment

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

Thanks for adding the comprehensive test plan! Overall looks good, requesting changes for some renaming and documentation update(see inline comments). Could you also update the Usage section in https://github.com/MystenLabs/sui/tree/main/sdk/typescript#usage to include the usage of events related API?

sdk/typescript/src/providers/provider.ts Outdated Show resolved Hide resolved
sdk/typescript/src/providers/provider.ts Outdated Show resolved Hide resolved
sdk/typescript/src/types/events.ts Outdated Show resolved Hide resolved
Stella Cannefax and others added 3 commits September 9, 2022 12:51
Co-authored-by: Chris Li <76067158+666lcz@users.noreply.github.com>
Co-authored-by: Chris Li <76067158+666lcz@users.noreply.github.com>
Co-authored-by: Chris Li <76067158+666lcz@users.noreply.github.com>
@stella3d stella3d requested a review from 666lcz September 9, 2022 17:55
@stella3d stella3d enabled auto-merge (squash) September 9, 2022 18:28
@stella3d stella3d merged commit 88ae677 into main Sep 9, 2022
@stella3d stella3d deleted the event-query branch September 9, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants