viem 0.0.0-main.20230603T024327 → 0.0.0-main.20230604T221342
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/dist/cjs/actions/ens/getEnsAddress.js +34 -23
- package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/public/call.js +1 -1
- package/dist/cjs/actions/public/call.js.map +1 -1
- package/dist/cjs/actions/public/createContractEventFilter.js +2 -1
- package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/createEventFilter.js +2 -1
- package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/cjs/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/cjs/actions/public/getChainId.js +3 -1
- package/dist/cjs/actions/public/getChainId.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js +11 -3
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js +10 -2
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/getGasPrice.js.map +1 -1
- package/dist/cjs/actions/public/getLogs.js +11 -3
- package/dist/cjs/actions/public/getLogs.js.map +1 -1
- package/dist/cjs/actions/public/getTransactionCount.js.map +1 -1
- package/dist/cjs/clients/createClient.js +1 -1
- package/dist/cjs/clients/createClient.js.map +1 -1
- package/dist/cjs/clients/createPublicClient.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/createWalletClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/transports/createTransport.js.map +1 -1
- package/dist/cjs/clients/transports/custom.js.map +1 -1
- package/dist/cjs/clients/transports/fallback.js.map +1 -1
- package/dist/cjs/clients/transports/http.js +25 -7
- package/dist/cjs/clients/transports/http.js.map +1 -1
- package/dist/cjs/clients/transports/webSocket.js +22 -14
- package/dist/cjs/clients/transports/webSocket.js.map +1 -1
- package/dist/cjs/errors/abi.js +15 -1
- package/dist/cjs/errors/abi.js.map +1 -1
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/abi/decodeEventLog.js +10 -2
- package/dist/cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/cjs/utils/ens/encodeLabelhash.js +8 -0
- package/dist/cjs/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +18 -0
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/cjs/utils/ens/labelhash.js +2 -1
- package/dist/cjs/utils/ens/labelhash.js.map +1 -1
- package/dist/cjs/utils/ens/namehash.js +5 -1
- package/dist/cjs/utils/ens/namehash.js.map +1 -1
- package/dist/cjs/utils/ens/packetToBytes.js +10 -9
- package/dist/cjs/utils/ens/packetToBytes.js.map +1 -1
- package/dist/cjs/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/cjs/utils/formatters/log.js +2 -2
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/rpc.js +12 -17
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js +34 -23
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/public/call.js +1 -1
- package/dist/esm/actions/public/call.js.map +1 -1
- package/dist/esm/actions/public/createContractEventFilter.js +2 -1
- package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/esm/actions/public/createEventFilter.js +2 -1
- package/dist/esm/actions/public/createEventFilter.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js +1 -1
- package/dist/esm/actions/public/getBlockTransactionCount.js.map +1 -1
- package/dist/esm/actions/public/getChainId.js +3 -1
- package/dist/esm/actions/public/getChainId.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js +11 -3
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js +10 -2
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/getGasPrice.js.map +1 -1
- package/dist/esm/actions/public/getLogs.js +11 -3
- package/dist/esm/actions/public/getLogs.js.map +1 -1
- package/dist/esm/actions/public/getTransactionCount.js.map +1 -1
- package/dist/esm/clients/createClient.js +1 -1
- package/dist/esm/clients/createClient.js.map +1 -1
- package/dist/esm/clients/createPublicClient.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/createWalletClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/transports/createTransport.js.map +1 -1
- package/dist/esm/clients/transports/custom.js.map +1 -1
- package/dist/esm/clients/transports/fallback.js.map +1 -1
- package/dist/esm/clients/transports/http.js +25 -7
- package/dist/esm/clients/transports/http.js.map +1 -1
- package/dist/esm/clients/transports/webSocket.js +22 -14
- package/dist/esm/clients/transports/webSocket.js.map +1 -1
- package/dist/esm/errors/abi.js +15 -1
- package/dist/esm/errors/abi.js.map +1 -1
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/abi/decodeEventLog.js +10 -2
- package/dist/esm/utils/abi/decodeEventLog.js.map +1 -1
- package/dist/esm/utils/ens/encodeLabelhash.js +4 -0
- package/dist/esm/utils/ens/encodeLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +14 -0
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -0
- package/dist/esm/utils/ens/labelhash.js +2 -1
- package/dist/esm/utils/ens/labelhash.js.map +1 -1
- package/dist/esm/utils/ens/namehash.js +6 -2
- package/dist/esm/utils/ens/namehash.js.map +1 -1
- package/dist/esm/utils/ens/packetToBytes.js +10 -9
- package/dist/esm/utils/ens/packetToBytes.js.map +1 -1
- package/dist/esm/utils/filters/createFilterRequestScope.js.map +1 -1
- package/dist/esm/utils/formatters/log.js +2 -2
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/rpc.js +13 -18
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +8 -3
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +17 -5
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/getChainId.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +4 -4
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +10 -4
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/chains.d.ts +4 -4
- package/dist/types/clients/createClient.d.ts +5 -5
- package/dist/types/clients/createClient.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +3 -3
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +5 -5
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/transports/createTransport.d.ts +5 -8
- package/dist/types/clients/transports/createTransport.d.ts.map +1 -1
- package/dist/types/clients/transports/custom.d.ts +2 -2
- package/dist/types/clients/transports/custom.d.ts.map +1 -1
- package/dist/types/clients/transports/http.d.ts +11 -0
- package/dist/types/clients/transports/http.d.ts.map +1 -1
- package/dist/types/clients/transports/webSocket.d.ts.map +1 -1
- package/dist/types/errors/abi.d.ts +6 -4
- package/dist/types/errors/abi.d.ts.map +1 -1
- package/dist/types/errors/request.d.ts +16 -8
- package/dist/types/errors/request.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +6 -3
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +1037 -872
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/filter.d.ts +12 -3
- package/dist/types/types/filter.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +10 -7
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +11 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +3 -0
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -0
- package/dist/types/utils/ens/labelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/namehash.d.ts.map +1 -1
- package/dist/types/utils/ens/packetToBytes.d.ts.map +1 -1
- package/dist/types/utils/filters/createFilterRequestScope.d.ts +6 -2
- package/dist/types/utils/filters/createFilterRequestScope.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/rpc.d.ts +18 -10
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/package.json +2 -11
- package/src/actions/ens/getEnsAddress.ts +37 -22
- package/src/actions/public/call.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +21 -4
- package/src/actions/public/createEventFilter.ts +34 -13
- package/src/actions/public/estimateGas.ts +1 -1
- package/src/actions/public/getBlock.ts +2 -2
- package/src/actions/public/getBlockTransactionCount.ts +1 -1
- package/src/actions/public/getChainId.ts +3 -1
- package/src/actions/public/getFilterChanges.ts +27 -7
- package/src/actions/public/getFilterLogs.ts +29 -8
- package/src/actions/public/getGasPrice.ts +1 -1
- package/src/actions/public/getLogs.ts +34 -10
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/clients/createClient.ts +13 -11
- package/src/clients/createPublicClient.ts +3 -4
- package/src/clients/createTestClient.ts +2 -3
- package/src/clients/createWalletClient.ts +2 -3
- package/src/clients/decorators/public.ts +33 -14
- package/src/clients/transports/createTransport.ts +5 -9
- package/src/clients/transports/custom.ts +1 -2
- package/src/clients/transports/fallback.ts +1 -1
- package/src/clients/transports/http.ts +44 -7
- package/src/clients/transports/webSocket.ts +23 -15
- package/src/errors/abi.ts +16 -4
- package/src/errors/request.ts +4 -4
- package/src/errors/version.ts +1 -1
- package/src/index.ts +10 -5
- package/src/types/contract.ts +17 -7
- package/src/types/eip1193.ts +1079 -872
- package/src/types/filter.ts +15 -3
- package/src/types/log.ts +18 -9
- package/src/types/utils.ts +15 -0
- package/src/utils/abi/decodeEventLog.ts +10 -2
- package/src/utils/ens/encodeLabelhash.ts +5 -0
- package/src/utils/ens/encodedLabelToLabelhash.ts +11 -0
- package/src/utils/ens/labelhash.ts +2 -1
- package/src/utils/ens/namehash.ts +6 -2
- package/src/utils/ens/packetToBytes.ts +12 -8
- package/src/utils/filters/createFilterRequestScope.ts +12 -4
- package/src/utils/formatters/log.ts +2 -2
- package/src/utils/index.ts +6 -0
- package/src/utils/rpc.ts +52 -52
- package/dist/cjs/adapters/ethers.js +0 -56
- package/dist/cjs/adapters/ethers.js.map +0 -1
- package/dist/cjs/ethers.js +0 -6
- package/dist/cjs/ethers.js.map +0 -1
- package/dist/esm/adapters/ethers.js +0 -52
- package/dist/esm/adapters/ethers.js.map +0 -1
- package/dist/esm/ethers.js +0 -2
- package/dist/esm/ethers.js.map +0 -1
- package/dist/types/adapters/ethers.d.ts +0 -27
- package/dist/types/adapters/ethers.d.ts.map +0 -1
- package/dist/types/ethers.d.ts +0 -2
- package/dist/types/ethers.d.ts.map +0 -1
- package/ethers/package.json +0 -5
- package/src/adapters/ethers.ts +0 -99
- package/src/ethers.ts +0 -1
@@ -1,22 +1,18 @@
|
|
1
1
|
import type { Chain } from '../../types/chain.js'
|
2
|
-
import type {
|
2
|
+
import type { EIP1193RequestFn } from '../../types/eip1193.js'
|
3
3
|
import { buildRequest } from '../../utils/buildRequest.js'
|
4
4
|
import type { ClientConfig } from '../createClient.js'
|
5
5
|
|
6
|
-
export type BaseRpcRequests = {
|
7
|
-
request(...args: any): Promise<any>
|
8
|
-
}
|
9
|
-
|
10
6
|
export type TransportConfig<
|
11
7
|
TType extends string = string,
|
12
|
-
|
8
|
+
TEIP1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn,
|
13
9
|
> = {
|
14
10
|
/** The name of the transport. */
|
15
11
|
name: string
|
16
12
|
/** The key of the transport. */
|
17
13
|
key: string
|
18
14
|
/** The JSON-RPC request function that matches the EIP-1193 request spec. */
|
19
|
-
request:
|
15
|
+
request: TEIP1193RequestFn
|
20
16
|
/** The base delay (in ms) between retries. */
|
21
17
|
retryDelay?: number
|
22
18
|
/** The max number of times to retry. */
|
@@ -30,7 +26,7 @@ export type TransportConfig<
|
|
30
26
|
export type Transport<
|
31
27
|
TType extends string = string,
|
32
28
|
TRpcAttributes = Record<string, any>,
|
33
|
-
|
29
|
+
TEIP1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn,
|
34
30
|
> = <TChain extends Chain | undefined = Chain>({
|
35
31
|
chain,
|
36
32
|
}: {
|
@@ -40,7 +36,7 @@ export type Transport<
|
|
40
36
|
timeout?: TransportConfig['timeout']
|
41
37
|
}) => {
|
42
38
|
config: TransportConfig<TType>
|
43
|
-
request:
|
39
|
+
request: TEIP1193RequestFn
|
44
40
|
value?: TRpcAttributes
|
45
41
|
}
|
46
42
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import {
|
2
|
-
type BaseRpcRequests,
|
3
2
|
type Transport,
|
4
3
|
type TransportConfig,
|
5
4
|
createTransport,
|
6
5
|
} from './createTransport.js'
|
7
6
|
|
8
|
-
type EthereumProvider = { request:
|
7
|
+
type EthereumProvider = { request(...args: any): Promise<any> }
|
9
8
|
|
10
9
|
export type CustomTransportConfig = {
|
11
10
|
/** The key of the transport. */
|
@@ -102,7 +102,7 @@ export function fallback(
|
|
102
102
|
key,
|
103
103
|
name,
|
104
104
|
async request({ method, params }) {
|
105
|
-
const fetch = async (i
|
105
|
+
const fetch = async (i = 0): Promise<any> => {
|
106
106
|
const transport = transports[i]({ chain, retryCount: 0, timeout })
|
107
107
|
try {
|
108
108
|
const response = await transport.request({
|
@@ -1,5 +1,7 @@
|
|
1
|
+
import { RpcRequestError } from '../../errors/request.js'
|
1
2
|
import { UrlRequiredError } from '../../errors/transport.js'
|
2
|
-
import {
|
3
|
+
import { createBatchScheduler } from '../../utils/promise/createBatchScheduler.js'
|
4
|
+
import { type HttpOptions, type RpcRequest, rpc } from '../../utils/rpc.js'
|
3
5
|
|
4
6
|
import {
|
5
7
|
type Transport,
|
@@ -7,7 +9,19 @@ import {
|
|
7
9
|
createTransport,
|
8
10
|
} from './createTransport.js'
|
9
11
|
|
12
|
+
export type BatchOptions = {
|
13
|
+
/** The maximum number of JSON-RPC requests to send in a batch. @default 1_000 */
|
14
|
+
batchSize?: number
|
15
|
+
/** The maximum number of milliseconds to wait before sending a batch. @default 0 */
|
16
|
+
wait?: number
|
17
|
+
}
|
18
|
+
|
10
19
|
export type HttpTransportConfig = {
|
20
|
+
/**
|
21
|
+
* Whether to enable Batch JSON-RPC.
|
22
|
+
* @link https://www.jsonrpc.org/specification#batch
|
23
|
+
*/
|
24
|
+
batch?: boolean | BatchOptions
|
11
25
|
/**
|
12
26
|
* Request configuration to pass to `fetch`.
|
13
27
|
* @link https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
@@ -41,12 +55,15 @@ export function http(
|
|
41
55
|
config: HttpTransportConfig = {},
|
42
56
|
): HttpTransport {
|
43
57
|
const {
|
58
|
+
batch,
|
44
59
|
fetchOptions,
|
45
60
|
key = 'http',
|
46
61
|
name = 'HTTP JSON-RPC',
|
47
62
|
retryDelay,
|
48
63
|
} = config
|
49
64
|
return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
|
65
|
+
const { batchSize = 1000, wait = 0 } =
|
66
|
+
typeof batch === 'object' ? batch : {}
|
50
67
|
const retryCount = config.retryCount ?? retryCount_
|
51
68
|
const timeout = timeout_ ?? config.timeout ?? 10_000
|
52
69
|
const url_ = url || chain?.rpcUrls.default.http[0]
|
@@ -56,14 +73,34 @@ export function http(
|
|
56
73
|
key,
|
57
74
|
name,
|
58
75
|
async request({ method, params }) {
|
59
|
-
const
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
const body = { method, params }
|
77
|
+
|
78
|
+
const { schedule } = createBatchScheduler({
|
79
|
+
id: `${url}`,
|
80
|
+
wait,
|
81
|
+
shouldSplitBatch(requests) {
|
82
|
+
return requests.length > batchSize
|
63
83
|
},
|
64
|
-
|
65
|
-
|
84
|
+
fn: (body: RpcRequest[]) =>
|
85
|
+
rpc.http(url_, {
|
86
|
+
body,
|
87
|
+
fetchOptions,
|
88
|
+
timeout,
|
89
|
+
}),
|
66
90
|
})
|
91
|
+
|
92
|
+
const fn = async (body: RpcRequest) =>
|
93
|
+
batch
|
94
|
+
? schedule(body)
|
95
|
+
: [await rpc.http(url_, { body, fetchOptions, timeout })]
|
96
|
+
|
97
|
+
const [{ error, result }] = await fn(body)
|
98
|
+
if (error)
|
99
|
+
throw new RpcRequestError({
|
100
|
+
body,
|
101
|
+
error,
|
102
|
+
url: url_,
|
103
|
+
})
|
67
104
|
return result
|
68
105
|
},
|
69
106
|
retryCount,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { WebSocket } from 'isomorphic-ws'
|
2
2
|
|
3
|
+
import { RpcRequestError } from '../../errors/request.js'
|
3
4
|
import { UrlRequiredError } from '../../errors/transport.js'
|
4
5
|
import type { Hash } from '../../types/misc.js'
|
5
6
|
import { type RpcResponse, getSocket, rpc } from '../../utils/rpc.js'
|
6
|
-
|
7
7
|
import {
|
8
8
|
type Transport,
|
9
9
|
type TransportConfig,
|
@@ -72,11 +72,18 @@ export function webSocket(
|
|
72
72
|
key,
|
73
73
|
name,
|
74
74
|
async request({ method, params }) {
|
75
|
+
const body = { method, params }
|
75
76
|
const socket = await getSocket(url_)
|
76
|
-
const { result } = await rpc.webSocketAsync(socket, {
|
77
|
-
body
|
77
|
+
const { error, result } = await rpc.webSocketAsync(socket, {
|
78
|
+
body,
|
78
79
|
timeout,
|
79
80
|
})
|
81
|
+
if (error)
|
82
|
+
throw new RpcRequestError({
|
83
|
+
body,
|
84
|
+
error,
|
85
|
+
url: url_,
|
86
|
+
})
|
80
87
|
return result
|
81
88
|
},
|
82
89
|
retryCount,
|
@@ -97,31 +104,32 @@ export function webSocket(
|
|
97
104
|
method: 'eth_subscribe',
|
98
105
|
params,
|
99
106
|
},
|
100
|
-
|
101
|
-
if (
|
102
|
-
|
107
|
+
onResponse(response) {
|
108
|
+
if (response.error) {
|
109
|
+
reject(response.error)
|
110
|
+
onError?.(response.error)
|
103
111
|
return
|
104
112
|
}
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
113
|
+
|
114
|
+
if (typeof response.id === 'number') {
|
115
|
+
resolve(response)
|
116
|
+
return
|
117
|
+
}
|
118
|
+
if (response.method !== 'eth_subscription') return
|
119
|
+
onData(response.params)
|
111
120
|
},
|
112
121
|
}),
|
113
122
|
)
|
114
123
|
return {
|
115
124
|
subscriptionId,
|
116
125
|
async unsubscribe() {
|
117
|
-
return new Promise<any>((resolve
|
126
|
+
return new Promise<any>((resolve) =>
|
118
127
|
rpc.webSocket(socket, {
|
119
128
|
body: {
|
120
129
|
method: 'eth_unsubscribe',
|
121
130
|
params: [subscriptionId],
|
122
131
|
},
|
123
|
-
|
124
|
-
onError: reject,
|
132
|
+
onResponse: resolve,
|
125
133
|
}),
|
126
134
|
)
|
127
135
|
},
|
package/src/errors/abi.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import type { AbiParameter } from 'abitype'
|
1
|
+
import type { AbiEvent, AbiParameter } from 'abitype'
|
2
2
|
|
3
|
-
import type { AbiItem } from '../types/contract.js'
|
4
3
|
import type { Hex } from '../types/misc.js'
|
5
4
|
import { formatAbiItem, formatAbiParams } from '../utils/abi/formatAbiItem.js'
|
6
5
|
import { size } from '../utils/data/size.js'
|
@@ -278,15 +277,22 @@ export class BytesSizeMismatchError extends BaseError {
|
|
278
277
|
export class DecodeLogDataMismatch extends BaseError {
|
279
278
|
override name = 'DecodeLogDataMismatch'
|
280
279
|
|
280
|
+
abiItem: AbiEvent
|
281
281
|
data: Hex
|
282
282
|
params: readonly AbiParameter[]
|
283
283
|
size: number
|
284
284
|
|
285
285
|
constructor({
|
286
|
+
abiItem,
|
286
287
|
data,
|
287
288
|
params,
|
288
289
|
size,
|
289
|
-
}: {
|
290
|
+
}: {
|
291
|
+
abiItem: AbiEvent
|
292
|
+
data: Hex
|
293
|
+
params: readonly AbiParameter[]
|
294
|
+
size: number
|
295
|
+
}) {
|
290
296
|
super(
|
291
297
|
[
|
292
298
|
`Data size of ${size} bytes is too small for non-indexed event parameters.`,
|
@@ -299,6 +305,7 @@ export class DecodeLogDataMismatch extends BaseError {
|
|
299
305
|
},
|
300
306
|
)
|
301
307
|
|
308
|
+
this.abiItem = abiItem
|
302
309
|
this.data = data
|
303
310
|
this.params = params
|
304
311
|
this.size = size
|
@@ -307,11 +314,14 @@ export class DecodeLogDataMismatch extends BaseError {
|
|
307
314
|
|
308
315
|
export class DecodeLogTopicsMismatch extends BaseError {
|
309
316
|
override name = 'DecodeLogTopicsMismatch'
|
317
|
+
|
318
|
+
abiItem: AbiEvent
|
319
|
+
|
310
320
|
constructor({
|
311
321
|
abiItem,
|
312
322
|
param,
|
313
323
|
}: {
|
314
|
-
abiItem:
|
324
|
+
abiItem: AbiEvent
|
315
325
|
param: AbiParameter & { indexed: boolean }
|
316
326
|
}) {
|
317
327
|
super(
|
@@ -321,6 +331,8 @@ export class DecodeLogTopicsMismatch extends BaseError {
|
|
321
331
|
} on event "${formatAbiItem(abiItem, { includeName: true })}".`,
|
322
332
|
].join('\n'),
|
323
333
|
)
|
334
|
+
|
335
|
+
this.abiItem = abiItem
|
324
336
|
}
|
325
337
|
}
|
326
338
|
|
package/src/errors/request.ts
CHANGED
@@ -6,7 +6,7 @@ import { getUrl } from './utils.js'
|
|
6
6
|
export class HttpRequestError extends BaseError {
|
7
7
|
override name = 'HttpRequestError'
|
8
8
|
|
9
|
-
body?: { [
|
9
|
+
body?: { [x: string]: unknown } | { [y: string]: unknown }[]
|
10
10
|
headers?: Headers
|
11
11
|
status?: number
|
12
12
|
url: string
|
@@ -18,7 +18,7 @@ export class HttpRequestError extends BaseError {
|
|
18
18
|
status,
|
19
19
|
url,
|
20
20
|
}: {
|
21
|
-
body?: { [
|
21
|
+
body?: { [x: string]: unknown } | { [y: string]: unknown }[]
|
22
22
|
details?: string
|
23
23
|
headers?: Headers
|
24
24
|
status?: number
|
@@ -68,7 +68,7 @@ export class RpcRequestError extends BaseError {
|
|
68
68
|
error,
|
69
69
|
url,
|
70
70
|
}: {
|
71
|
-
body: { [
|
71
|
+
body: { [x: string]: unknown } | { [y: string]: unknown }[]
|
72
72
|
error: { code: number; message: string }
|
73
73
|
url: string
|
74
74
|
}) {
|
@@ -88,7 +88,7 @@ export class TimeoutError extends BaseError {
|
|
88
88
|
body,
|
89
89
|
url,
|
90
90
|
}: {
|
91
|
-
body: { [
|
91
|
+
body: { [x: string]: unknown } | { [y: string]: unknown }[]
|
92
92
|
url: string
|
93
93
|
}) {
|
94
94
|
super('The request took too long to respond.', {
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.0.0-main.
|
1
|
+
export const version = '0.0.0-main.20230604T221342'
|
package/src/index.ts
CHANGED
@@ -447,19 +447,24 @@ export {
|
|
447
447
|
} from './types/misc.js'
|
448
448
|
export type { Chain } from './types/chain.js'
|
449
449
|
export type {
|
450
|
+
AddEthereumChainParameter,
|
451
|
+
EIP1193Events,
|
452
|
+
EIP1193Parameters,
|
450
453
|
EIP1193Provider,
|
454
|
+
EIP1193RequestFn,
|
455
|
+
EIP1474Methods,
|
451
456
|
ProviderRpcError as EIP1193ProviderRpcError,
|
452
457
|
ProviderConnectInfo,
|
453
458
|
ProviderMessage,
|
454
|
-
|
459
|
+
PublicRpcSchema,
|
455
460
|
NetworkSync,
|
456
|
-
|
457
|
-
|
458
|
-
|
461
|
+
RpcSchema,
|
462
|
+
RpcSchemaOverride,
|
463
|
+
TestRpcSchema,
|
459
464
|
WatchAssetParams,
|
460
465
|
WalletPermissionCaveat,
|
461
466
|
WalletPermission,
|
462
|
-
|
467
|
+
WalletRpcSchema,
|
463
468
|
} from './types/eip1193.js'
|
464
469
|
export {
|
465
470
|
type FeeHistory,
|
package/src/types/contract.ts
CHANGED
@@ -20,7 +20,7 @@ import type {
|
|
20
20
|
|
21
21
|
import type { Hex, LogTopic } from './misc.js'
|
22
22
|
import type { TransactionRequest } from './transaction.js'
|
23
|
-
import type { Filter, NoUndefined } from './utils.js'
|
23
|
+
import type { Filter, MaybeRequired, NoUndefined, Prettify } from './utils.js'
|
24
24
|
|
25
25
|
export type AbiItem = Abi[number]
|
26
26
|
|
@@ -238,7 +238,7 @@ export type GetEventArgsFromTopics<
|
|
238
238
|
: AbiEvent & { type: 'event' },
|
239
239
|
TArgs = AbiEventParametersToPrimitiveTypes<
|
240
240
|
TAbiEvent['inputs'],
|
241
|
-
{ EnableUnion: false; IndexedOnly: false }
|
241
|
+
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
242
242
|
>,
|
243
243
|
> = TTopics extends readonly []
|
244
244
|
? TData extends undefined
|
@@ -252,10 +252,12 @@ export type GetEventArgsFromTopics<
|
|
252
252
|
type EventParameterOptions = {
|
253
253
|
EnableUnion?: boolean
|
254
254
|
IndexedOnly?: boolean
|
255
|
+
Required?: boolean
|
255
256
|
}
|
256
257
|
type DefaultEventParameterOptions = {
|
257
258
|
EnableUnion: true
|
258
259
|
IndexedOnly: true
|
260
|
+
Required: false
|
259
261
|
}
|
260
262
|
|
261
263
|
type HashedEventTypes = 'bytes' | 'string' | 'tuple' | `${string}[${string}]`
|
@@ -328,10 +330,13 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
328
330
|
},
|
329
331
|
]
|
330
332
|
// Distribute over tuple to represent optional parameters
|
331
|
-
| (
|
332
|
-
|
333
|
-
|
334
|
-
|
333
|
+
| (Options['Required'] extends true
|
334
|
+
? never
|
335
|
+
: // Distribute over tuple to represent optional parameters
|
336
|
+
Filtered extends readonly [
|
337
|
+
...infer Head extends readonly AbiParameter[],
|
338
|
+
infer _,
|
339
|
+
]
|
335
340
|
? AbiEventParametersToPrimitiveTypes<
|
336
341
|
readonly [...{ [K in keyof Head]: Omit<Head[K], 'name'> }],
|
337
342
|
Options
|
@@ -346,6 +351,11 @@ export type AbiEventParametersToPrimitiveTypes<
|
|
346
351
|
? Name
|
347
352
|
: never]?: AbiEventParameterToPrimitiveType<Parameter, Options>
|
348
353
|
} extends infer Mapped
|
349
|
-
?
|
354
|
+
? Prettify<
|
355
|
+
MaybeRequired<
|
356
|
+
Mapped,
|
357
|
+
Options['Required'] extends boolean ? Options['Required'] : false
|
358
|
+
>
|
359
|
+
>
|
350
360
|
: never
|
351
361
|
: never
|