@mysten/sui 2.39.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +162 -0
- package/README.md +5 -188
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/bcs.mjs +49 -22
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/effects.mjs +49 -20
- package/dist/bcs/effects.mjs.map +1 -1
- package/dist/bcs/index.d.mts +1441 -624
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/bcs/index.mjs +2 -1
- package/dist/bcs/index.mjs.map +1 -1
- package/dist/bcs/transactions.d.mts +1059 -0
- package/dist/bcs/transactions.d.mts.map +1 -0
- package/dist/bcs/transactions.mjs +33 -14
- package/dist/bcs/transactions.mjs.map +1 -1
- package/dist/bcs/types.d.mts +6 -1
- package/dist/bcs/types.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +4 -4
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +55 -4
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +98 -1
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/errors.mjs +11 -1
- package/dist/client/errors.mjs.map +1 -1
- package/dist/client/index.d.mts +4 -2
- package/dist/client/index.mjs +5 -2
- package/dist/client/mvr.d.mts +12 -2
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/mvr.mjs +34 -13
- package/dist/client/mvr.mjs.map +1 -1
- package/dist/client/query-filters.mjs +80 -76
- package/dist/client/query-filters.mjs.map +1 -1
- package/dist/client/stream/adapter.d.mts +102 -0
- package/dist/client/stream/adapter.d.mts.map +1 -0
- package/dist/client/stream/errors.d.mts +14 -0
- package/dist/client/stream/errors.d.mts.map +1 -0
- package/dist/client/stream/errors.mjs +25 -0
- package/dist/client/stream/errors.mjs.map +1 -0
- package/dist/client/stream/filter.mjs +18 -0
- package/dist/client/stream/filter.mjs.map +1 -0
- package/dist/client/stream/follow.mjs +48 -0
- package/dist/client/stream/follow.mjs.map +1 -0
- package/dist/client/stream/index.d.mts +4 -0
- package/dist/client/stream/pager.mjs +123 -0
- package/dist/client/stream/pager.mjs.map +1 -0
- package/dist/client/stream/plan.mjs +79 -0
- package/dist/client/stream/plan.mjs.map +1 -0
- package/dist/client/stream/position.d.mts +30 -0
- package/dist/client/stream/position.d.mts.map +1 -0
- package/dist/client/stream/position.mjs +121 -0
- package/dist/client/stream/position.mjs.map +1 -0
- package/dist/client/stream/run.d.mts +2 -0
- package/dist/client/stream/run.mjs +99 -0
- package/dist/client/stream/run.mjs.map +1 -0
- package/dist/client/stream/session.mjs +205 -0
- package/dist/client/stream/session.mjs.map +1 -0
- package/dist/client/stream/status.mjs +47 -0
- package/dist/client/stream/status.mjs.map +1 -0
- package/dist/client/stream/token.mjs +80 -0
- package/dist/client/stream/token.mjs.map +1 -0
- package/dist/client/transaction-data.d.mts +12 -0
- package/dist/client/transaction-data.d.mts.map +1 -0
- package/dist/client/transaction-data.mjs +469 -0
- package/dist/client/transaction-data.mjs.map +1 -0
- package/dist/client/transaction-resolver.mjs +102 -58
- package/dist/client/transaction-resolver.mjs.map +1 -1
- package/dist/client/types.d.mts +560 -240
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts +3 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +91 -26
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/index.d.mts +1 -1
- package/dist/cryptography/keypair.d.mts +1 -1
- package/dist/cryptography/publickey.d.mts +11 -0
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +12 -1
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +8 -8
- package/dist/cryptography/signature.mjs +18 -7
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/graphql/client.d.mts +51 -35
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +125 -69
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +14 -9
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +293 -117
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/errors.d.mts +20 -0
- package/dist/graphql/errors.d.mts.map +1 -0
- package/dist/graphql/errors.mjs +19 -0
- package/dist/graphql/errors.mjs.map +1 -0
- package/dist/graphql/filters.mjs +32 -0
- package/dist/graphql/filters.mjs.map +1 -0
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +1216 -208
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +820 -11
- package/dist/graphql/index.d.mts +2 -1
- package/dist/graphql/index.mjs +2 -1
- package/dist/graphql/sse-parser.mjs +82 -0
- package/dist/graphql/sse-parser.mjs.map +1 -0
- package/dist/graphql/stream/families.mjs +306 -0
- package/dist/graphql/stream/families.mjs.map +1 -0
- package/dist/graphql/stream/index.mjs +38 -0
- package/dist/graphql/stream/index.mjs.map +1 -0
- package/dist/graphql/stream/live.mjs +60 -0
- package/dist/graphql/stream/live.mjs.map +1 -0
- package/dist/graphql/stream/page.mjs +38 -0
- package/dist/graphql/stream/page.mjs.map +1 -0
- package/dist/graphql/stream/query.mjs +47 -0
- package/dist/graphql/stream/query.mjs.map +1 -0
- package/dist/graphql/subscribe.mjs +70 -0
- package/dist/graphql/subscribe.mjs.map +1 -0
- package/dist/grpc/client.d.mts +31 -27
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +42 -46
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +13 -6
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +254 -166
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/filters.mjs +44 -34
- package/dist/grpc/filters.mjs.map +1 -1
- package/dist/grpc/grpc-web-pull.mjs +245 -0
- package/dist/grpc/grpc-web-pull.mjs.map +1 -0
- package/dist/grpc/index.d.mts +2 -1
- package/dist/grpc/index.mjs +1 -1
- package/dist/grpc/network-error.mjs +31 -0
- package/dist/grpc/network-error.mjs.map +1 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs +306 -0
- package/dist/grpc/proto/google/rpc/error_details.mjs.map +1 -0
- package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts +176 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs +175 -0
- package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +2 -2
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +111 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs +46 -0
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +24 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs +25 -7
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/object.mjs +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts +111 -9
- package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs +63 -19
- package/dist/grpc/proto/sui/rpc/v2/query_options.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +5 -5
- package/dist/grpc/proto/sui/rpc/v2/signature.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +5 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs +4 -0
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +20 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs +30 -13
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +20 -14
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs +8 -5
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +11 -5
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs +6 -0
- package/dist/grpc/proto/sui/rpc/v2/transaction.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +6 -2
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +7 -7
- package/dist/grpc/proto/types.mjs +3 -2
- package/dist/grpc/pull-call.d.mts +20 -0
- package/dist/grpc/pull-call.d.mts.map +1 -0
- package/dist/grpc/pull-call.mjs +28 -0
- package/dist/grpc/pull-call.mjs.map +1 -0
- package/dist/grpc/stream/call.mjs +238 -0
- package/dist/grpc/stream/call.mjs.map +1 -0
- package/dist/grpc/stream/families.d.mts +26 -0
- package/dist/grpc/stream/families.d.mts.map +1 -0
- package/dist/grpc/stream/families.mjs +145 -0
- package/dist/grpc/stream/families.mjs.map +1 -0
- package/dist/grpc/stream/index.d.mts +41 -0
- package/dist/grpc/stream/index.d.mts.map +1 -0
- package/dist/grpc/stream/index.mjs +127 -0
- package/dist/grpc/stream/index.mjs.map +1 -0
- package/dist/grpc/stream/live.mjs +31 -0
- package/dist/grpc/stream/live.mjs.map +1 -0
- package/dist/grpc/stream/page.mjs +120 -0
- package/dist/grpc/stream/page.mjs.map +1 -0
- package/dist/grpc/stream-types.d.mts +28 -0
- package/dist/grpc/stream-types.d.mts.map +1 -0
- package/dist/grpc/transport.d.mts +8 -3
- package/dist/grpc/transport.d.mts.map +1 -1
- package/dist/grpc/transport.mjs +88 -45
- package/dist/grpc/transport.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +34 -12
- package/dist/jsonRpc/index.d.mts.map +1 -0
- package/dist/jsonRpc/index.mjs +39 -5
- package/dist/jsonRpc/index.mjs.map +1 -0
- package/dist/jsonRpc/types.d.mts +420 -0
- package/dist/jsonRpc/types.d.mts.map +1 -0
- package/dist/keypairs/passkey/keypair.d.mts +1 -1
- package/dist/multisig/publickey.d.mts +12 -4
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +5 -5
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.d.mts +1 -1
- package/dist/transactions/ObjectCache.d.mts +1 -1
- package/dist/transactions/ObjectCache.mjs +5 -5
- package/dist/transactions/ObjectCache.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +14 -13
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +17 -6
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +135 -133
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/internal.mjs +2 -1
- package/dist/transactions/data/internal.mjs.map +1 -1
- package/dist/transactions/data/v1.d.mts +239 -239
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +2 -2
- package/dist/transactions/executor/serial.d.mts +1 -1
- package/dist/transactions/executor/serial.mjs +2 -2
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/transactions/index.d.mts +3 -2
- package/dist/transactions/index.mjs +4 -3
- package/dist/transactions/intents/AllowanceBalance.mjs +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +1 -1
- package/dist/transactions/resolve.d.mts +6 -0
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/transactions/restricted-move-calls.d.mts +25 -0
- package/dist/transactions/restricted-move-calls.d.mts.map +1 -0
- package/dist/transactions/restricted-move-calls.mjs +47 -0
- package/dist/transactions/restricted-move-calls.mjs.map +1 -0
- package/dist/transactions/serializer.d.mts +1 -4
- package/dist/transactions/serializer.d.mts.map +1 -1
- package/dist/transactions/serializer.mjs +1 -44
- package/dist/transactions/serializer.mjs.map +1 -1
- package/dist/transactions/utils.d.mts +0 -1
- package/dist/transactions/utils.d.mts.map +1 -1
- package/dist/transactions/utils.mjs.map +1 -1
- package/dist/utils/abort.mjs +89 -0
- package/dist/utils/abort.mjs.map +1 -0
- package/dist/utils/coin-reservation.mjs +1 -4
- package/dist/utils/coin-reservation.mjs.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/sui-types.mjs +1 -1
- package/dist/verify/index.d.mts +2 -2
- package/dist/verify/verify.d.mts +74 -24
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/verify/verify.mjs +128 -42
- package/dist/verify/verify.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/publickey.mjs +15 -20
- package/dist/zklogin/publickey.mjs.map +1 -1
- package/docs/bcs.md +2 -2
- package/docs/clients/core.md +19 -18
- package/docs/clients/executing.md +53 -8
- package/docs/clients/graphql.md +81 -11
- package/docs/clients/grpc.md +31 -15
- package/docs/clients/index.md +8 -7
- package/docs/clients/querying.md +134 -30
- package/docs/clients/streaming.md +324 -0
- package/docs/cryptography/index.md +85 -58
- package/docs/llms-index.md +4 -2
- package/docs/migrations/sui-2.0/dapp-kit.md +3 -2
- package/docs/migrations/sui-2.0/json-rpc-migration.md +106 -79
- package/docs/migrations/sui-3.0/index.md +250 -0
- package/docs/plugins.md +10 -10
- package/docs/sdk-building.md +3 -4
- package/docs/transactions/coins-and-balances.md +6 -11
- package/docs/transactions/reference.md +36 -1
- package/package.json +3 -4
- package/src/bcs/bcs.ts +80 -41
- package/src/bcs/effects.ts +61 -25
- package/src/bcs/index.ts +2 -0
- package/src/bcs/transactions.ts +36 -17
- package/src/bcs/types.ts +10 -4
- package/src/client/core-resolver.ts +3 -5
- package/src/client/core.ts +180 -8
- package/src/client/errors.ts +12 -0
- package/src/client/index.ts +4 -1
- package/src/client/mvr.ts +37 -10
- package/src/client/query-filters.ts +151 -97
- package/src/client/stream/adapter.ts +110 -0
- package/src/client/stream/errors.ts +40 -0
- package/src/client/stream/filter.ts +17 -0
- package/src/client/stream/follow.ts +63 -0
- package/src/client/stream/index.ts +9 -0
- package/src/client/stream/pager.ts +158 -0
- package/src/client/stream/plan.ts +147 -0
- package/src/client/stream/position.ts +143 -0
- package/src/client/stream/run.ts +147 -0
- package/src/client/stream/session.ts +259 -0
- package/src/client/stream/status.ts +44 -0
- package/src/client/stream/token.ts +104 -0
- package/src/client/transaction-data.ts +587 -0
- package/src/client/transaction-resolver.ts +158 -69
- package/src/client/types.ts +530 -115
- package/src/client/utils.ts +147 -50
- package/src/cryptography/publickey.ts +12 -1
- package/src/cryptography/signature.ts +6 -3
- package/src/graphql/client.ts +204 -135
- package/src/graphql/core.ts +446 -139
- package/src/graphql/errors.ts +24 -0
- package/src/graphql/filters.ts +48 -0
- package/src/graphql/generated/queries.ts +1455 -277
- package/src/graphql/generated/schema.graphql +282 -9
- package/src/graphql/generated/tada-env.ts +933 -4
- package/src/graphql/queries/checkpoints.graphql +34 -0
- package/src/graphql/queries/getDynamicFields.graphql +1 -0
- package/src/graphql/queries/listEvents.graphql +16 -24
- package/src/graphql/queries/streams.graphql +212 -0
- package/src/graphql/queries/transactions.graphql +71 -28
- package/src/graphql/queries/verifySignature.graphql +17 -0
- package/src/graphql/sse-parser.ts +99 -0
- package/src/graphql/stream/families.ts +515 -0
- package/src/graphql/stream/index.ts +55 -0
- package/src/graphql/stream/live.ts +70 -0
- package/src/graphql/stream/page.ts +47 -0
- package/src/graphql/stream/query.ts +52 -0
- package/src/graphql/subscribe.ts +83 -0
- package/src/grpc/client.ts +81 -79
- package/src/grpc/core.ts +388 -274
- package/src/grpc/filters.ts +59 -60
- package/src/grpc/grpc-web-pull.ts +360 -0
- package/src/grpc/index.ts +5 -0
- package/src/grpc/network-error.ts +33 -0
- package/src/grpc/proto/sui/rpc/v2/error_reason.ts +175 -0
- package/src/grpc/proto/sui/rpc/v2/ledger_service.ts +145 -0
- package/src/grpc/proto/sui/rpc/v2/move_package_service.ts +43 -1
- package/src/grpc/proto/sui/rpc/v2/query_options.ts +132 -8
- package/src/grpc/proto/sui/rpc/v2/signature.ts +4 -4
- package/src/grpc/proto/sui/rpc/v2/signature_scheme.ts +4 -0
- package/src/grpc/proto/sui/rpc/v2/signature_verification_service.ts +30 -0
- package/src/grpc/proto/sui/rpc/v2/subscription_service.client.ts +16 -10
- package/src/grpc/proto/sui/rpc/v2/transaction.ts +6 -0
- package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +5 -1
- package/src/grpc/pull-call.ts +54 -0
- package/src/grpc/stream/call.ts +317 -0
- package/src/grpc/stream/families.ts +228 -0
- package/src/grpc/stream/index.ts +182 -0
- package/src/grpc/stream/live.ts +33 -0
- package/src/grpc/stream/page.ts +161 -0
- package/src/grpc/stream-types.ts +33 -0
- package/src/grpc/transport.ts +116 -59
- package/src/jsonRpc/index.ts +60 -17
- package/src/jsonRpc/types.ts +421 -0
- package/src/multisig/publickey.ts +19 -7
- package/src/transactions/ObjectCache.ts +6 -6
- package/src/transactions/Transaction.ts +30 -6
- package/src/transactions/data/internal.ts +2 -0
- package/src/transactions/executor/serial.ts +2 -2
- package/src/transactions/index.ts +8 -1
- package/src/transactions/resolve.ts +6 -0
- package/src/transactions/restricted-move-calls.ts +87 -0
- package/src/transactions/serializer.ts +0 -70
- package/src/transactions/utils.ts +0 -37
- package/src/utils/abort.ts +101 -0
- package/src/verify/index.ts +1 -0
- package/src/verify/verify.ts +190 -62
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +18 -34
- package/dist/client/core-resolver.d.mts +0 -9
- package/dist/client/core-resolver.d.mts.map +0 -1
- package/dist/jsonRpc/client.d.mts +0 -507
- package/dist/jsonRpc/client.d.mts.map +0 -1
- package/dist/jsonRpc/client.mjs +0 -868
- package/dist/jsonRpc/client.mjs.map +0 -1
- package/dist/jsonRpc/core.d.mts +0 -168
- package/dist/jsonRpc/core.d.mts.map +0 -1
- package/dist/jsonRpc/core.mjs +0 -1054
- package/dist/jsonRpc/core.mjs.map +0 -1
- package/dist/jsonRpc/errors.d.mts +0 -27
- package/dist/jsonRpc/errors.d.mts.map +0 -1
- package/dist/jsonRpc/errors.mjs +0 -50
- package/dist/jsonRpc/errors.mjs.map +0 -1
- package/dist/jsonRpc/http-transport.d.mts +0 -62
- package/dist/jsonRpc/http-transport.d.mts.map +0 -1
- package/dist/jsonRpc/http-transport.mjs +0 -60
- package/dist/jsonRpc/http-transport.mjs.map +0 -1
- package/dist/jsonRpc/network.d.mts +0 -9
- package/dist/jsonRpc/network.d.mts.map +0 -1
- package/dist/jsonRpc/network.mjs +0 -18
- package/dist/jsonRpc/network.mjs.map +0 -1
- package/dist/jsonRpc/types/chain.d.mts +0 -169
- package/dist/jsonRpc/types/chain.d.mts.map +0 -1
- package/dist/jsonRpc/types/changes.d.mts +0 -48
- package/dist/jsonRpc/types/changes.d.mts.map +0 -1
- package/dist/jsonRpc/types/coins.d.mts +0 -15
- package/dist/jsonRpc/types/coins.d.mts.map +0 -1
- package/dist/jsonRpc/types/common.d.mts +0 -9
- package/dist/jsonRpc/types/common.d.mts.map +0 -1
- package/dist/jsonRpc/types/generated.d.mts +0 -1976
- package/dist/jsonRpc/types/generated.d.mts.map +0 -1
- package/dist/jsonRpc/types/index.d.mts +0 -6
- package/dist/jsonRpc/types/params.d.mts +0 -898
- package/dist/jsonRpc/types/params.d.mts.map +0 -1
- package/src/graphql/generated/tsconfig.tada.json +0 -11
- package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -15
- package/src/jsonRpc/client.ts +0 -1252
- package/src/jsonRpc/core.ts +0 -1557
- package/src/jsonRpc/errors.ts +0 -57
- package/src/jsonRpc/http-transport.ts +0 -118
- package/src/jsonRpc/network.ts +0 -21
- package/src/jsonRpc/types/chain.ts +0 -190
- package/src/jsonRpc/types/changes.ts +0 -35
- package/src/jsonRpc/types/coins.ts +0 -14
- package/src/jsonRpc/types/common.ts +0 -8
- package/src/jsonRpc/types/generated.ts +0 -2165
- package/src/jsonRpc/types/index.ts +0 -9
- package/src/jsonRpc/types/params.ts +0 -908
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { MethodInfo, ServiceType } from '@protobuf-ts/runtime-rpc';
|
|
5
|
+
|
|
6
|
+
import type { ItemFrame, StreamFamily, StreamPosition } from '../../client/stream/index.js';
|
|
7
|
+
import { boundaryPosition, itemPosition, SuiStreamError } from '../../client/stream/index.js';
|
|
8
|
+
import type { SuiClientTypes } from '../../client/types.js';
|
|
9
|
+
import {
|
|
10
|
+
CHECKPOINT_READ_MASK_PATHS,
|
|
11
|
+
EVENT_READ_MASK_PATHS,
|
|
12
|
+
parseGrpcCheckpoint,
|
|
13
|
+
parseGrpcEvent,
|
|
14
|
+
parseGrpcTransactionResponse,
|
|
15
|
+
transactionReadMaskPaths,
|
|
16
|
+
} from '../core.js';
|
|
17
|
+
import type { FieldMask } from '../proto/google/protobuf/field_mask.js';
|
|
18
|
+
import type { Checkpoint } from '../proto/sui/rpc/v2/checkpoint.js';
|
|
19
|
+
import type { Event } from '../proto/sui/rpc/v2/event.js';
|
|
20
|
+
import type { ExecutedTransaction } from '../proto/sui/rpc/v2/executed_transaction.js';
|
|
21
|
+
import type { EventFilter, TransactionFilter } from '../proto/sui/rpc/v2/filter.js';
|
|
22
|
+
import { LedgerService } from '../proto/sui/rpc/v2/ledger_service.js';
|
|
23
|
+
import type { QueryEnd, QueryOptions, Watermark } from '../proto/sui/rpc/v2/query_options.js';
|
|
24
|
+
import { SubscriptionService } from '../proto/sui/rpc/v2/subscription_service.js';
|
|
25
|
+
|
|
26
|
+
/** The ledger item a frame carries. */
|
|
27
|
+
export type GrpcItem =
|
|
28
|
+
| { $kind: 'Checkpoint'; checkpoint: Checkpoint }
|
|
29
|
+
| { $kind: 'Transaction'; transaction: ExecutedTransaction }
|
|
30
|
+
| { $kind: 'Event'; event: Event };
|
|
31
|
+
|
|
32
|
+
export type NativeFilter = TransactionFilter | EventFilter;
|
|
33
|
+
|
|
34
|
+
/** The fields every `List*Request` shares. */
|
|
35
|
+
export interface ListRequest {
|
|
36
|
+
readMask: FieldMask;
|
|
37
|
+
filter?: NativeFilter;
|
|
38
|
+
startCheckpoint?: bigint;
|
|
39
|
+
endCheckpoint?: bigint;
|
|
40
|
+
options: QueryOptions;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The fields every `Subscribe*Request` shares. */
|
|
44
|
+
export interface SubscribeRequest {
|
|
45
|
+
readMask: FieldMask;
|
|
46
|
+
filter?: NativeFilter;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A `List*Response`: each family sets only its own item field. */
|
|
50
|
+
export interface ListFrame {
|
|
51
|
+
checkpoint?: Checkpoint;
|
|
52
|
+
transaction?: ExecutedTransaction;
|
|
53
|
+
event?: Event;
|
|
54
|
+
watermark?: Watermark;
|
|
55
|
+
end?: QueryEnd;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A `Subscribe*Response`. Checkpoint subscriptions report `cursor` instead of a watermark. */
|
|
59
|
+
export interface LiveFrame {
|
|
60
|
+
checkpoint?: Checkpoint;
|
|
61
|
+
transaction?: ExecutedTransaction;
|
|
62
|
+
event?: Event;
|
|
63
|
+
watermark?: Watermark;
|
|
64
|
+
cursor?: bigint;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What differs between the three streams. Everything else is shared. */
|
|
68
|
+
export interface GrpcFamily {
|
|
69
|
+
readonly list: MethodInfo<ListRequest, ListFrame>;
|
|
70
|
+
readonly subscribe: MethodInfo<SubscribeRequest, LiveFrame>;
|
|
71
|
+
readMask(include: SuiClientTypes.TransactionInclude | undefined): string[];
|
|
72
|
+
item(frame: ListFrame | LiveFrame): GrpcItem | undefined;
|
|
73
|
+
/** The position of a List item, or of any subscription frame. */
|
|
74
|
+
position(
|
|
75
|
+
frame: { watermark?: Watermark; cursor?: bigint },
|
|
76
|
+
item: GrpcItem | undefined,
|
|
77
|
+
): StreamPosition;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const GRPC_FAMILIES: Record<StreamFamily, GrpcFamily> = {
|
|
81
|
+
checkpoints: {
|
|
82
|
+
list: streamingMethod(LedgerService, 'ListCheckpoints'),
|
|
83
|
+
subscribe: streamingMethod(SubscriptionService, 'SubscribeCheckpoints'),
|
|
84
|
+
// With included transactions, the checkpoint frame carries every one of them.
|
|
85
|
+
readMask: (include) =>
|
|
86
|
+
include
|
|
87
|
+
? [...CHECKPOINT_READ_MASK_PATHS, ...transactionReadMaskPaths(include, 'transactions.')]
|
|
88
|
+
: CHECKPOINT_READ_MASK_PATHS,
|
|
89
|
+
item: (frame) => frame.checkpoint && { $kind: 'Checkpoint', checkpoint: frame.checkpoint },
|
|
90
|
+
// A checkpoint is positioned by its sequence number alone; streams resume after it by number.
|
|
91
|
+
position(frame, item) {
|
|
92
|
+
if (item) return itemPosition(sequenceNumber(item));
|
|
93
|
+
if (frame.cursor === undefined) {
|
|
94
|
+
throw new SuiStreamError('Protocol', 'Checkpoint subscription frame is missing its cursor');
|
|
95
|
+
}
|
|
96
|
+
return boundaryPosition(frame.cursor + 1n);
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
transactions: {
|
|
100
|
+
list: streamingMethod(LedgerService, 'ListTransactions'),
|
|
101
|
+
subscribe: streamingMethod(SubscriptionService, 'SubscribeTransactions'),
|
|
102
|
+
// `transaction_index` orders transactions within a checkpoint.
|
|
103
|
+
readMask: (include) => [...transactionReadMaskPaths(include), 'transaction_index'],
|
|
104
|
+
item: (frame) => frame.transaction && { $kind: 'Transaction', transaction: frame.transaction },
|
|
105
|
+
position: framePosition,
|
|
106
|
+
},
|
|
107
|
+
events: {
|
|
108
|
+
list: streamingMethod(LedgerService, 'ListEvents'),
|
|
109
|
+
subscribe: streamingMethod(SubscriptionService, 'SubscribeEvents'),
|
|
110
|
+
readMask: () => [...EVENT_READ_MASK_PATHS, 'transaction_index'],
|
|
111
|
+
item: (frame) => frame.event && { $kind: 'Event', event: frame.event },
|
|
112
|
+
position: framePosition,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** A generated method by name; its messages share the fields `ListRequest` and friends name. */
|
|
117
|
+
function streamingMethod<I extends object, O extends object>(
|
|
118
|
+
service: ServiceType,
|
|
119
|
+
name: string,
|
|
120
|
+
): MethodInfo<I, O> {
|
|
121
|
+
const method = service.methods.find((candidate) => candidate.name === name);
|
|
122
|
+
if (!method?.serverStreaming) {
|
|
123
|
+
throw new Error(`${service.typeName}/${name} is not a server-streaming method`);
|
|
124
|
+
}
|
|
125
|
+
return method;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The position a watermarked frame reports. */
|
|
129
|
+
export function framePosition(
|
|
130
|
+
frame: { watermark?: Watermark },
|
|
131
|
+
item: GrpcItem | undefined,
|
|
132
|
+
): StreamPosition {
|
|
133
|
+
const position = watermarkPosition(frame.watermark);
|
|
134
|
+
if (!item) return position;
|
|
135
|
+
const { checkpoint, ...indexes } = itemCoordinates(item);
|
|
136
|
+
return itemPosition(checkpoint, {
|
|
137
|
+
...indexes,
|
|
138
|
+
cursor: frame.watermark!.cursor!,
|
|
139
|
+
nextUncovered: position.nextUncovered,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The resume point a watermark reports, as the boundary at its `cursor_position`. */
|
|
144
|
+
export function watermarkPosition(watermark: Watermark | undefined): StreamPosition {
|
|
145
|
+
if (!watermark?.cursor?.length) {
|
|
146
|
+
throw new SuiStreamError('Protocol', 'Ledger response is missing its watermark cursor');
|
|
147
|
+
}
|
|
148
|
+
const at = watermark.cursorPosition;
|
|
149
|
+
if (at?.checkpoint === undefined) {
|
|
150
|
+
throw new SuiStreamError('Protocol', 'Ledger watermark is missing its cursor position');
|
|
151
|
+
}
|
|
152
|
+
return boundaryPosition(at.checkpoint, {
|
|
153
|
+
cursor: watermark.cursor,
|
|
154
|
+
// Unset indexes read as 0, as on the server.
|
|
155
|
+
transactionIndex: at.transactionIndex ?? 0n,
|
|
156
|
+
eventIndex: at.eventIndex ?? null,
|
|
157
|
+
nextUncovered: watermark.checkpoint === undefined ? null : watermark.checkpoint + 1n,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function sequenceNumber(item: GrpcItem): bigint {
|
|
162
|
+
const checkpoint = item.$kind === 'Checkpoint' ? item.checkpoint.sequenceNumber : undefined;
|
|
163
|
+
if (checkpoint === undefined) {
|
|
164
|
+
throw new SuiStreamError('Protocol', 'Checkpoint is missing its sequence number');
|
|
165
|
+
}
|
|
166
|
+
return checkpoint;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Where an item sits in the ledger. Transactions and events must report their indexes. */
|
|
170
|
+
function itemCoordinates(item: GrpcItem) {
|
|
171
|
+
const none = { transactionIndex: null, eventIndex: null };
|
|
172
|
+
const missing = (field: string) =>
|
|
173
|
+
new SuiStreamError('Protocol', `Ledger item is missing its ${field}`);
|
|
174
|
+
switch (item.$kind) {
|
|
175
|
+
case 'Checkpoint':
|
|
176
|
+
throw new SuiStreamError('Protocol', 'A checkpoint is positioned by its sequence number');
|
|
177
|
+
case 'Transaction': {
|
|
178
|
+
const { checkpoint, transactionIndex } = item.transaction;
|
|
179
|
+
if (checkpoint === undefined) throw missing('checkpoint');
|
|
180
|
+
if (transactionIndex === undefined) throw missing('transaction index');
|
|
181
|
+
return { ...none, checkpoint, transactionIndex };
|
|
182
|
+
}
|
|
183
|
+
case 'Event': {
|
|
184
|
+
const { checkpoint, transactionIndex, eventIndex } = item.event;
|
|
185
|
+
if (checkpoint === undefined) throw missing('checkpoint');
|
|
186
|
+
if (transactionIndex === undefined) throw missing('transaction index');
|
|
187
|
+
if (eventIndex === undefined) throw missing('event index');
|
|
188
|
+
return { checkpoint, transactionIndex, eventIndex };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function parseTransaction(
|
|
194
|
+
transaction: ExecutedTransaction,
|
|
195
|
+
include: SuiClientTypes.TransactionInclude | undefined,
|
|
196
|
+
source: string,
|
|
197
|
+
) {
|
|
198
|
+
if (!transaction.digest || !transaction.effects?.status) {
|
|
199
|
+
throw new SuiStreamError('Protocol', `${source} response is incomplete`);
|
|
200
|
+
}
|
|
201
|
+
return parseGrpcTransactionResponse(transaction, { include });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
type WithoutToken<Frame> = Frame extends unknown ? Omit<Frame, 'resumeToken'> : never;
|
|
205
|
+
|
|
206
|
+
/** The public frame for an item, without its token. */
|
|
207
|
+
export function mapGrpcItem(
|
|
208
|
+
item: GrpcItem,
|
|
209
|
+
include: SuiClientTypes.TransactionInclude | undefined,
|
|
210
|
+
): WithoutToken<ItemFrame> {
|
|
211
|
+
switch (item.$kind) {
|
|
212
|
+
case 'Checkpoint': {
|
|
213
|
+
const checkpoint = parseGrpcCheckpoint(item.checkpoint, 'Checkpoint stream');
|
|
214
|
+
if (!include) return { $kind: 'Checkpoint', checkpoint };
|
|
215
|
+
const transactions = item.checkpoint.transactions.map((transaction) =>
|
|
216
|
+
parseTransaction(transaction, include, 'Checkpoint stream'),
|
|
217
|
+
);
|
|
218
|
+
return { $kind: 'Checkpoint', checkpoint: { ...checkpoint, transactions } };
|
|
219
|
+
}
|
|
220
|
+
case 'Transaction':
|
|
221
|
+
return {
|
|
222
|
+
$kind: 'Transaction',
|
|
223
|
+
transaction: parseTransaction(item.transaction, include, 'Transaction stream'),
|
|
224
|
+
};
|
|
225
|
+
case 'Event':
|
|
226
|
+
return { $kind: 'Event', event: parseGrpcEvent(item.event, 'Event stream') };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { RpcError } from '@protobuf-ts/runtime-rpc';
|
|
5
|
+
import type { RpcTransport } from '@protobuf-ts/runtime-rpc';
|
|
6
|
+
|
|
7
|
+
import type { LedgerStreamRequest } from '../../client/core.js';
|
|
8
|
+
import { resolveEventFilter, resolveTransactionFilter } from '../../client/query-filters.js';
|
|
9
|
+
import type {
|
|
10
|
+
Bound,
|
|
11
|
+
ItemFrame,
|
|
12
|
+
LedgerStreamAdapter,
|
|
13
|
+
PageRequest,
|
|
14
|
+
StreamFamily,
|
|
15
|
+
} from '../../client/stream/index.js';
|
|
16
|
+
import { SuiStreamError } from '../../client/stream/index.js';
|
|
17
|
+
import type { SuiClientTypes } from '../../client/types.js';
|
|
18
|
+
import { toGrpcEventFilter, toGrpcTransactionFilter } from '../filters.js';
|
|
19
|
+
import { isNonRetryable } from '../pull-call.js';
|
|
20
|
+
import { openLedgerCall, type LedgerCall } from './call.js';
|
|
21
|
+
import {
|
|
22
|
+
GRPC_FAMILIES,
|
|
23
|
+
mapGrpcItem,
|
|
24
|
+
type GrpcFamily,
|
|
25
|
+
type GrpcItem,
|
|
26
|
+
type ListFrame,
|
|
27
|
+
type LiveFrame,
|
|
28
|
+
type NativeFilter,
|
|
29
|
+
} from './families.js';
|
|
30
|
+
import { liveSubscription } from './live.js';
|
|
31
|
+
import { fetchListPage, readIndexedTip, type ListQuery } from './page.js';
|
|
32
|
+
|
|
33
|
+
/** What the adapter needs from `GrpcCoreClient`. */
|
|
34
|
+
export interface GrpcStreamContext {
|
|
35
|
+
transport: RpcTransport;
|
|
36
|
+
mvr: SuiClientTypes.MvrMethods;
|
|
37
|
+
chainIdentifier(signal: AbortSignal): Promise<string>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A core stream request; `SuiGrpcClient` may pass a native `grpcFilter` through its options. */
|
|
41
|
+
export type GrpcLedgerStreamRequest = LedgerStreamRequest & {
|
|
42
|
+
options: { grpcFilter?: NativeFilter };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** This stream's calls, with its resolved filter and read mask fixed. */
|
|
46
|
+
interface GrpcStreamCalls {
|
|
47
|
+
readonly family: GrpcFamily;
|
|
48
|
+
list(query: ListQuery, signal: AbortSignal): LedgerCall<ListFrame>;
|
|
49
|
+
subscribe(signal: AbortSignal): LedgerCall<LiveFrame>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A ledger stream over gRPC: List calls for pages, Subscribe calls for live delivery. */
|
|
53
|
+
export class GrpcLedgerStreamAdapter implements LedgerStreamAdapter<GrpcItem, ItemFrame> {
|
|
54
|
+
readonly transport = 'grpc' as const;
|
|
55
|
+
readonly family: StreamFamily;
|
|
56
|
+
/** Subscriptions take no start: the core pages history and replays the gap itself. */
|
|
57
|
+
readonly live = 'fromTip';
|
|
58
|
+
readonly #context: GrpcStreamContext;
|
|
59
|
+
readonly #request: GrpcLedgerStreamRequest;
|
|
60
|
+
#calls: GrpcStreamCalls | undefined;
|
|
61
|
+
|
|
62
|
+
constructor(context: GrpcStreamContext, request: GrpcLedgerStreamRequest) {
|
|
63
|
+
if (request.options.grpcFilter && 'filter' in request.options && request.options.filter) {
|
|
64
|
+
throw new SuiStreamError('InvalidOptions', 'Use either filter or grpcFilter, not both');
|
|
65
|
+
}
|
|
66
|
+
this.#context = context;
|
|
67
|
+
this.#request = request;
|
|
68
|
+
this.family = request.family;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async initialize(signal: AbortSignal) {
|
|
72
|
+
const { grpcFilter } = this.#request.options;
|
|
73
|
+
const shared = grpcFilter ? undefined : await this.#sharedFilter(signal);
|
|
74
|
+
const chain = await this.#context.chainIdentifier(signal);
|
|
75
|
+
this.#calls = this.#streamCalls(grpcFilter ?? shared?.native);
|
|
76
|
+
// Tokens bind to the resolved shared filter, not to its protobuf conversion.
|
|
77
|
+
return { chain, filter: grpcFilter ?? shared?.resolved ?? null };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
indexedTip(signal: AbortSignal) {
|
|
81
|
+
return readIndexedTip(this.#context.transport, signal);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fetchPage(request: PageRequest) {
|
|
85
|
+
const { family, list } = this.#initializedCalls();
|
|
86
|
+
return fetchListPage(family, list, request);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
subscribe(_from: Bound | undefined, signal: AbortSignal) {
|
|
90
|
+
const { family, subscribe } = this.#initializedCalls();
|
|
91
|
+
return liveSubscription(subscribe(signal), family);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
mapItem(item: GrpcItem) {
|
|
95
|
+
return mapGrpcItem(item, this.#transactionInclude());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
retryReason(error: unknown): SuiClientTypes.RetryReason | undefined {
|
|
99
|
+
if (!(error instanceof RpcError) || isNonRetryable(error)) return undefined;
|
|
100
|
+
switch (error.code) {
|
|
101
|
+
case 'UNAVAILABLE':
|
|
102
|
+
// Upstream's `serverStreaming` codes a truncated stream as DATA_LOSS.
|
|
103
|
+
case 'DATA_LOSS':
|
|
104
|
+
case 'CANCELLED':
|
|
105
|
+
case 'ABORTED':
|
|
106
|
+
return 'Unavailable';
|
|
107
|
+
case 'RESOURCE_EXHAUSTED':
|
|
108
|
+
return 'RateLimited';
|
|
109
|
+
case 'DEADLINE_EXCEEDED':
|
|
110
|
+
case 'UNKNOWN':
|
|
111
|
+
// sui reports transient storage failures as INTERNAL.
|
|
112
|
+
case 'INTERNAL':
|
|
113
|
+
return 'ServerError';
|
|
114
|
+
default:
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async #sharedFilter(
|
|
120
|
+
signal: AbortSignal,
|
|
121
|
+
): Promise<{ resolved: unknown; native: NativeFilter | undefined } | undefined> {
|
|
122
|
+
const { mvr } = this.#context;
|
|
123
|
+
const request = this.#request;
|
|
124
|
+
switch (request.family) {
|
|
125
|
+
case 'checkpoints':
|
|
126
|
+
return undefined;
|
|
127
|
+
case 'transactions': {
|
|
128
|
+
if (!request.options.filter) return undefined;
|
|
129
|
+
const resolved = await resolveTransactionFilter(mvr, request.options.filter, signal);
|
|
130
|
+
return { resolved, native: toGrpcTransactionFilter(resolved) };
|
|
131
|
+
}
|
|
132
|
+
case 'events': {
|
|
133
|
+
if (!request.options.filter) return undefined;
|
|
134
|
+
const resolved = await resolveEventFilter(mvr, request.options.filter, signal);
|
|
135
|
+
return { resolved, native: toGrpcEventFilter(resolved) };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#streamCalls(filter: NativeFilter | undefined): GrpcStreamCalls {
|
|
141
|
+
const { transport } = this.#context;
|
|
142
|
+
const family = GRPC_FAMILIES[this.family];
|
|
143
|
+
const readMask = { paths: family.readMask(this.#transactionInclude()) };
|
|
144
|
+
const isItem = (frame: object) => family.item(frame) !== undefined;
|
|
145
|
+
return {
|
|
146
|
+
family,
|
|
147
|
+
// Push transports buffer a whole page (at most 1,000 items); a cap would force reconnects.
|
|
148
|
+
list: (query, signal) =>
|
|
149
|
+
openLedgerCall(
|
|
150
|
+
transport,
|
|
151
|
+
family.list,
|
|
152
|
+
{ ...query, readMask, filter },
|
|
153
|
+
{ signal, isItem, maxResponses: Infinity },
|
|
154
|
+
),
|
|
155
|
+
subscribe: (signal) =>
|
|
156
|
+
openLedgerCall(
|
|
157
|
+
transport,
|
|
158
|
+
family.subscribe,
|
|
159
|
+
{ readMask, filter },
|
|
160
|
+
{
|
|
161
|
+
signal,
|
|
162
|
+
isItem,
|
|
163
|
+
coalesceProgress: true,
|
|
164
|
+
validate: (frame) => family.position(frame, family.item(frame)),
|
|
165
|
+
},
|
|
166
|
+
),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The fields of each streamed transaction, or of each checkpoint's transactions. */
|
|
171
|
+
#transactionInclude(): SuiClientTypes.TransactionInclude | undefined {
|
|
172
|
+
const request = this.#request;
|
|
173
|
+
if (request.family === 'transactions') return request.options.include ?? {};
|
|
174
|
+
if (request.family === 'checkpoints') return request.options.include?.transactions;
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#initializedCalls(): GrpcStreamCalls {
|
|
179
|
+
if (!this.#calls) throw new Error('gRPC ledger stream used before initialize');
|
|
180
|
+
return this.#calls;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { LiveEvent, LiveSubscription } from '../../client/stream/index.js';
|
|
5
|
+
import type { LedgerCall } from './call.js';
|
|
6
|
+
import type { GrpcFamily, GrpcItem, LiveFrame } from './families.js';
|
|
7
|
+
|
|
8
|
+
/** A subscription call as live events. gRPC subscriptions start at the live tip. */
|
|
9
|
+
export function liveSubscription(
|
|
10
|
+
call: LedgerCall<LiveFrame>,
|
|
11
|
+
family: GrpcFamily,
|
|
12
|
+
): LiveSubscription<GrpcItem> {
|
|
13
|
+
return {
|
|
14
|
+
[Symbol.asyncIterator]: () => liveEvents(call, family),
|
|
15
|
+
readAhead: (enabled) => call.readAhead(enabled),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @yields one Item or Progress event per frame. */
|
|
20
|
+
async function* liveEvents(
|
|
21
|
+
call: LedgerCall<LiveFrame>,
|
|
22
|
+
family: GrpcFamily,
|
|
23
|
+
): AsyncGenerator<LiveEvent<GrpcItem>> {
|
|
24
|
+
try {
|
|
25
|
+
for await (const frame of call) {
|
|
26
|
+
const item = family.item(frame);
|
|
27
|
+
const position = family.position(frame, item);
|
|
28
|
+
yield item ? { $kind: 'Item', position, item } : { $kind: 'Progress', position };
|
|
29
|
+
}
|
|
30
|
+
} finally {
|
|
31
|
+
await call.return();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { base64decode } from '@protobuf-ts/runtime';
|
|
5
|
+
import { RpcError } from '@protobuf-ts/runtime-rpc';
|
|
6
|
+
import type { RpcTransport } from '@protobuf-ts/runtime-rpc';
|
|
7
|
+
|
|
8
|
+
import type { Page, PageRequest } from '../../client/stream/index.js';
|
|
9
|
+
import { SuiStreamError } from '../../client/stream/index.js';
|
|
10
|
+
import { ErrorInfo } from '../proto/google/rpc/error_details.js';
|
|
11
|
+
import { Status } from '../proto/google/rpc/status.js';
|
|
12
|
+
import { Ordering, QueryEndReason } from '../proto/sui/rpc/v2/query_options.js';
|
|
13
|
+
import { openLedgerCall, type LedgerCall } from './call.js';
|
|
14
|
+
import {
|
|
15
|
+
GRPC_FAMILIES,
|
|
16
|
+
type GrpcFamily,
|
|
17
|
+
type GrpcItem,
|
|
18
|
+
type ListFrame,
|
|
19
|
+
type ListRequest,
|
|
20
|
+
watermarkPosition,
|
|
21
|
+
} from './families.js';
|
|
22
|
+
|
|
23
|
+
/** Servers clamp larger limits to their own maximum for each method. */
|
|
24
|
+
const PAGE_LIMIT = 1000;
|
|
25
|
+
|
|
26
|
+
/** A List request without the stream's filter and read mask. */
|
|
27
|
+
export type ListQuery = Omit<ListRequest, 'readMask' | 'filter'>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One List call as a page. The call streams its items and ends with a QueryEnd frame, whose
|
|
31
|
+
* watermark says where the scan stopped. The call opens on the first read.
|
|
32
|
+
*/
|
|
33
|
+
export async function* fetchListPage(
|
|
34
|
+
family: GrpcFamily,
|
|
35
|
+
list: (query: ListQuery, signal: AbortSignal) => LedgerCall<ListFrame>,
|
|
36
|
+
request: PageRequest,
|
|
37
|
+
): Page<GrpcItem> {
|
|
38
|
+
const { order, range } = request;
|
|
39
|
+
const call = list(listQuery(request), request.signal);
|
|
40
|
+
let end: ListFrame | undefined;
|
|
41
|
+
try {
|
|
42
|
+
for await (const frame of call) {
|
|
43
|
+
const item = family.item(frame);
|
|
44
|
+
if (frame.end) end = frame;
|
|
45
|
+
if (item) yield { position: family.position(frame, item), item };
|
|
46
|
+
// A filtered scan reports its frontier between items.
|
|
47
|
+
else if (!frame.end && frame.watermark)
|
|
48
|
+
yield { position: watermarkPosition(frame.watermark) };
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (!(error instanceof RpcError && error.code === 'OUT_OF_RANGE')) throw error;
|
|
52
|
+
const marker = ledgerErrorInfo(error);
|
|
53
|
+
if (marker?.reason === 'ABOVE_LATEST_AVAILABLE') {
|
|
54
|
+
return { next: { more: false }, notIndexed: true };
|
|
55
|
+
}
|
|
56
|
+
const floor = marker?.metadata.lowestAvailableCheckpoint;
|
|
57
|
+
// A descending read with no low end of its own stops at the floor, after its items.
|
|
58
|
+
if (
|
|
59
|
+
marker?.reason === 'BELOW_EARLIEST_AVAILABLE' &&
|
|
60
|
+
order === 'descending' &&
|
|
61
|
+
range.start === undefined &&
|
|
62
|
+
/^\d+$/.test(floor ?? '')
|
|
63
|
+
) {
|
|
64
|
+
return { next: { more: false }, retainedFrom: BigInt(floor!) };
|
|
65
|
+
}
|
|
66
|
+
throw new SuiStreamError('HistoryUnavailable', error.message, { cause: error });
|
|
67
|
+
} finally {
|
|
68
|
+
await call.return();
|
|
69
|
+
}
|
|
70
|
+
const reason = end?.end?.reason;
|
|
71
|
+
if (reason === undefined) throw protocol('List RPC completed without QueryEnd');
|
|
72
|
+
if (reason === QueryEndReason.UNKNOWN || !(reason in QueryEndReason)) {
|
|
73
|
+
throw protocol('Unknown QueryEnd reason');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const { watermark } = end!;
|
|
77
|
+
const more = reason === QueryEndReason.ITEM_LIMIT || reason === QueryEndReason.SCAN_LIMIT;
|
|
78
|
+
const checkpoint = watermark?.checkpoint;
|
|
79
|
+
// An empty scan at the tip reports no checkpoint: nothing past the start is indexed yet, which
|
|
80
|
+
// only a read with an end has to wait for.
|
|
81
|
+
if (
|
|
82
|
+
order === 'ascending' &&
|
|
83
|
+
checkpoint === undefined &&
|
|
84
|
+
reason === QueryEndReason.LEDGER_TIP &&
|
|
85
|
+
range.end !== undefined
|
|
86
|
+
) {
|
|
87
|
+
return { next: { more: false }, notIndexed: true };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
next: more
|
|
91
|
+
? {
|
|
92
|
+
more,
|
|
93
|
+
cursor: watermark?.cursor,
|
|
94
|
+
// An ITEM_LIMIT end is the last item's frame, which already placed the stream.
|
|
95
|
+
...(reason === QueryEndReason.SCAN_LIMIT && { position: watermarkPosition(watermark) }),
|
|
96
|
+
}
|
|
97
|
+
: { more },
|
|
98
|
+
covered: order === 'ascending' ? checkpoint : undefined,
|
|
99
|
+
// Without a low end, a descending read stops at the oldest checkpoint the server keeps.
|
|
100
|
+
retainedFrom:
|
|
101
|
+
order === 'descending' && !more && range.start === undefined ? checkpoint : undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The indexed tip: the newest checkpoint a List call can read. */
|
|
106
|
+
export async function readIndexedTip(transport: RpcTransport, signal: AbortSignal) {
|
|
107
|
+
const call = openLedgerCall(
|
|
108
|
+
transport,
|
|
109
|
+
GRPC_FAMILIES.checkpoints.list,
|
|
110
|
+
{
|
|
111
|
+
readMask: { paths: ['sequence_number'] },
|
|
112
|
+
options: { limit: 1, ordering: Ordering.DESCENDING },
|
|
113
|
+
},
|
|
114
|
+
{ signal, isItem: (frame) => frame.checkpoint !== undefined },
|
|
115
|
+
);
|
|
116
|
+
try {
|
|
117
|
+
for await (const frame of call) {
|
|
118
|
+
const checkpoint = frame.checkpoint?.sequenceNumber;
|
|
119
|
+
if (checkpoint !== undefined) return checkpoint;
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
await call.return();
|
|
123
|
+
}
|
|
124
|
+
// A new network has nothing indexed for a moment; retry.
|
|
125
|
+
throw new RpcError('No checkpoint is indexed yet', 'UNAVAILABLE');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function listQuery({ range, after, before, order }: PageRequest): ListQuery {
|
|
129
|
+
return {
|
|
130
|
+
startCheckpoint: range.start,
|
|
131
|
+
endCheckpoint: range.end,
|
|
132
|
+
options: {
|
|
133
|
+
limit: PAGE_LIMIT,
|
|
134
|
+
ordering: order === 'ascending' ? Ordering.ASCENDING : Ordering.DESCENDING,
|
|
135
|
+
after,
|
|
136
|
+
before,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The `ErrorInfo` a server marks a ledger OUT_OF_RANGE with, if any. */
|
|
142
|
+
function ledgerErrorInfo(error: RpcError): ErrorInfo | undefined {
|
|
143
|
+
const details = error.meta['grpc-status-details-bin'];
|
|
144
|
+
const encoded = Array.isArray(details) ? details[0] : details;
|
|
145
|
+
if (!encoded) return undefined;
|
|
146
|
+
try {
|
|
147
|
+
const status = Status.fromBinary(base64decode(encoded));
|
|
148
|
+
// Servers send the type URL `/google.rpc.ErrorInfo`, with no host, which `Any.contains` rejects.
|
|
149
|
+
const detail = status.details.find(
|
|
150
|
+
({ typeUrl }) => typeUrl.slice(typeUrl.lastIndexOf('/') + 1) === ErrorInfo.typeName,
|
|
151
|
+
);
|
|
152
|
+
const info = detail && ErrorInfo.fromBinary(detail.value);
|
|
153
|
+
return info?.domain === 'sui.io' ? info : undefined;
|
|
154
|
+
} catch {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function protocol(message: string) {
|
|
160
|
+
return new SuiStreamError('Protocol', message);
|
|
161
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { SuiClientTypes } from '../client/types.js';
|
|
5
|
+
import type { EventFilter, TransactionFilter } from './proto/sui/rpc/v2/filter.js';
|
|
6
|
+
|
|
7
|
+
type Frames = SuiClientTypes.StreamFrameOptions;
|
|
8
|
+
|
|
9
|
+
/** `grpcFilter` streams only checkpoints containing a matching transaction. */
|
|
10
|
+
export type GrpcStreamCheckpointsOptions<
|
|
11
|
+
Include extends SuiClientTypes.StreamCheckpointInclude = {},
|
|
12
|
+
F extends Frames = {},
|
|
13
|
+
> = SuiClientTypes.StreamCheckpointsOptions<Include, F> & { grpcFilter?: TransactionFilter };
|
|
14
|
+
|
|
15
|
+
/** `grpcFilter` is a native gRPC filter, used instead of the shared `filter`. */
|
|
16
|
+
export type GrpcStreamTransactionsOptions<
|
|
17
|
+
Include extends SuiClientTypes.TransactionInclude = {},
|
|
18
|
+
F extends Frames = {},
|
|
19
|
+
> = Omit<SuiClientTypes.StreamTransactionsOptions<Include, F>, 'filter'> &
|
|
20
|
+
(
|
|
21
|
+
| { filter?: SuiClientTypes.TransactionFilter; grpcFilter?: never }
|
|
22
|
+
| { filter?: never; grpcFilter: TransactionFilter }
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/** `grpcFilter` is a native gRPC filter, used instead of the shared `filter`. */
|
|
26
|
+
export type GrpcStreamEventsOptions<F extends Frames = {}> = Omit<
|
|
27
|
+
SuiClientTypes.StreamEventsOptions<F>,
|
|
28
|
+
'filter'
|
|
29
|
+
> &
|
|
30
|
+
(
|
|
31
|
+
| { filter?: SuiClientTypes.EventFilter; grpcFilter?: never }
|
|
32
|
+
| { filter?: never; grpcFilter: EventFilter }
|
|
33
|
+
);
|