sui icon indicating copy to clipboard operation
sui copied to clipboard

[RPC API Improvement 2/n] - Event query pagination and merge all getEvents* methods

Open patrickkuo opened this issue 3 years ago • 5 comments

RPC API improvement part 2 : Event query pagination

Changes:

  • Merged all getEvents* methods and use EventQuery criteria object instead of separated methods.
pub enum EventQuery {
    /// Return all events.
    All,
    /// Return events emitted by the given transaction.
    Transaction(
        ///digest of the transaction, as base-64 encoded string
        TransactionDigest,
    ),
    /// Return events emitted in a specified Move module
    MoveModule {
        /// the Move package ID
        package: ObjectID,
        /// the module name
        module: String,
    },
    /// Return events with the given move event struct name
    MoveEvent(
        /// the event struct name type, e.g. `0x2::devnet_nft::MintNFTEvent` or `0x2::SUI::test_foo<address, vector<u8>>` with type params
        String,
    ),
    EventType(EventType),
    /// Query by sender address.
    Sender(SuiAddress),
    /// Query by recipient address.
    Recipient(Owner),
    /// Return events associated with the given object
    Object(ObjectID),
    /// Return events emitted in [start_time, end_time] interval
    TimeRange {
        /// left endpoint of time interval, inclusive
        start_time: u64,
        /// right endpoint of time interval, exclusive
        end_time: u64,
    },
}
  • Added a unique ID to Event, the ID is generated automatically by the database during persistent, the ID is being used for pagination.
  • Parse Move event fields.
  • Capped RPC query page size limit to 1000.
  • Added event query method to TS SDK.

Examples

1, Querying all event Request:

curl --location --request POST '127.0.0.1:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sui_getEvents",
  "params": ["All", null, 1, "Descending"]
}'

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "id": 2,
                "timestamp": 1666012833101,
                "txDigest": "/fU42IZ6Bp0mRBwKfOO1iDxD9HtjBNuiQ+9TdNrEVWs=",
                "event": {
                    "moveEvent": {
                        "packageId": "0x0000000000000000000000000000000000000002",
                        "transactionModule": "devnet_nft",
                        "sender": "0xdac9483c5334c3189a740ad1f40fba71327aac5c",
                        "type": "0x2::devnet_nft::MintNFTEvent",
                        "fields": {
                            "creator": "0xdac9483c5334c3189a740ad1f40fba71327aac5c",
                            "name": "Example NFT",
                            "object_id": "0x18b41c66bfc56cc89833adb2fa11efa2f51e1bb7"
                        },
                        "bcs": "GLQcZr/FbMiYM62y+hHvovUeG7fayUg8UzTDGJp0CtH0D7pxMnqsXAtFeGFtcGxlIE5GVA=="
                    }
                }
            }
        ],
        "nextCursor": 1
    },
    "id": 1
}

2, Query by event type request:

curl --location --request POST '127.0.0.1:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sui_getEvents",
  "params": [{"EventType": "NewObject"}, null, null, "Descending"]
}'

response:

{
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "id": 1,
                "timestamp": 1666012833101,
                "txDigest": "/fU42IZ6Bp0mRBwKfOO1iDxD9HtjBNuiQ+9TdNrEVWs=",
                "event": {
                    "newObject": {
                        "packageId": "0x0000000000000000000000000000000000000002",
                        "transactionModule": "devnet_nft",
                        "sender": "0xdac9483c5334c3189a740ad1f40fba71327aac5c",
                        "recipient": {
                            "AddressOwner": "0xdac9483c5334c3189a740ad1f40fba71327aac5c"
                        },
                        "objectId": "0x18b41c66bfc56cc89833adb2fa11efa2f51e1bb7"
                    }
                }
            }
        ],
        "nextCursor": null
    },
    "id": 1
}

TODOs

  • https://github.com/MystenLabs/sui/issues/5501

patrickkuo avatar Oct 11 '22 11:10 patrickkuo

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3387514088#artifacts

github-actions[bot] avatar Oct 11 '22 11:10 github-actions[bot]

this PR is ready for more reviews, thanks!!

patrickkuo avatar Oct 22 '22 02:10 patrickkuo

Friendly nudge :) this PR needs an approval.

patrickkuo avatar Oct 30 '22 11:10 patrickkuo

@stella3d can I get a thumbs up from you?

patrickkuo avatar Nov 02 '22 10:11 patrickkuo

@666lcz do we still have problem lining up TS SDK and Sui release? Do I need to put back the old methods?

patrickkuo avatar Nov 02 '22 10:11 patrickkuo