ox 0.9.4 → 0.9.6
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/Abi/package.json +6 -0
- package/AbiConstructor/package.json +6 -0
- package/AbiError/package.json +6 -0
- package/AbiEvent/package.json +6 -0
- package/AbiFunction/package.json +6 -0
- package/AbiItem/package.json +6 -0
- package/AbiParameters/package.json +6 -0
- package/AccessList/package.json +6 -0
- package/AccountProof/package.json +6 -0
- package/Address/package.json +6 -0
- package/AesGcm/package.json +6 -0
- package/Authorization/package.json +6 -0
- package/Base58/package.json +6 -0
- package/Base64/package.json +6 -0
- package/BinaryStateTree/package.json +6 -0
- package/Blobs/package.json +6 -0
- package/Block/package.json +6 -0
- package/BlockOverrides/package.json +6 -0
- package/Bloom/package.json +6 -0
- package/Bls/package.json +6 -0
- package/BlsPoint/package.json +6 -0
- package/Bytes/package.json +6 -0
- package/CHANGELOG.md +28 -0
- package/Caches/package.json +6 -0
- package/ContractAddress/package.json +6 -0
- package/Ed25519/package.json +6 -0
- package/Ens/package.json +6 -0
- package/Errors/package.json +6 -0
- package/Fee/package.json +6 -0
- package/Filter/package.json +6 -0
- package/Hash/package.json +6 -0
- package/HdKey/package.json +6 -0
- package/Hex/package.json +6 -0
- package/Json/package.json +6 -0
- package/Keystore/package.json +6 -0
- package/Kzg/package.json +6 -0
- package/Log/package.json +6 -0
- package/Mnemonic/package.json +6 -0
- package/P256/package.json +6 -0
- package/PersonalMessage/package.json +6 -0
- package/Provider/package.json +6 -0
- package/PublicKey/package.json +6 -0
- package/Rlp/package.json +6 -0
- package/RpcRequest/package.json +6 -0
- package/RpcResponse/package.json +6 -0
- package/RpcSchema/package.json +6 -0
- package/RpcTransport/package.json +6 -0
- package/Secp256k1/package.json +6 -0
- package/Signature/package.json +6 -0
- package/Siwe/package.json +6 -0
- package/Solidity/package.json +6 -0
- package/StateOverrides/package.json +6 -0
- package/Transaction/package.json +6 -0
- package/TransactionEnvelope/package.json +6 -0
- package/TransactionEnvelopeEip1559/package.json +6 -0
- package/TransactionEnvelopeEip2930/package.json +6 -0
- package/TransactionEnvelopeEip4844/package.json +6 -0
- package/TransactionEnvelopeEip7702/package.json +6 -0
- package/TransactionEnvelopeLegacy/package.json +6 -0
- package/TransactionReceipt/package.json +6 -0
- package/TransactionRequest/package.json +6 -0
- package/TypedData/package.json +6 -0
- package/ValidatorData/package.json +6 -0
- package/Value/package.json +6 -0
- package/WebAuthnP256/package.json +6 -0
- package/WebCryptoP256/package.json +6 -0
- package/Withdrawal/package.json +6 -0
- package/X25519/package.json +6 -0
- package/_cjs/core/AbiConstructor.js +16 -2
- package/_cjs/core/AbiConstructor.js.map +1 -1
- package/_cjs/core/AbiError.js +17 -2
- package/_cjs/core/AbiError.js.map +1 -1
- package/_cjs/core/AbiEvent.js +17 -2
- package/_cjs/core/AbiEvent.js.map +1 -1
- package/_cjs/core/AbiFunction.js +35 -8
- package/_cjs/core/AbiFunction.js.map +1 -1
- package/_cjs/core/AbiItem.js +24 -3
- package/_cjs/core/AbiItem.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/Abi.js +2 -2
- package/_esm/core/Abi.js.map +1 -1
- package/_esm/core/AbiConstructor.js +18 -56
- package/_esm/core/AbiConstructor.js.map +1 -1
- package/_esm/core/AbiError.js +19 -54
- package/_esm/core/AbiError.js.map +1 -1
- package/_esm/core/AbiEvent.js +19 -187
- package/_esm/core/AbiEvent.js.map +1 -1
- package/_esm/core/AbiFunction.js +39 -242
- package/_esm/core/AbiFunction.js.map +1 -1
- package/_esm/core/AbiItem.js +27 -93
- package/_esm/core/AbiItem.js.map +1 -1
- package/_esm/erc6492/SignatureErc6492.js +2 -2
- package/_esm/erc6492/index.js +2 -2
- package/_esm/erc8010/SignatureErc8010.js +2 -2
- package/_esm/erc8010/index.js +2 -2
- package/_esm/version.js +1 -1
- package/_types/core/AbiConstructor.d.ts +43 -4
- package/_types/core/AbiConstructor.d.ts.map +1 -1
- package/_types/core/AbiError.d.ts +29 -19
- package/_types/core/AbiError.d.ts.map +1 -1
- package/_types/core/AbiEvent.d.ts +60 -0
- package/_types/core/AbiEvent.d.ts.map +1 -1
- package/_types/core/AbiFunction.d.ts +84 -2
- package/_types/core/AbiFunction.d.ts.map +1 -1
- package/_types/core/AbiItem.d.ts +36 -0
- package/_types/core/AbiItem.d.ts.map +1 -1
- package/_types/erc6492/SignatureErc6492.d.ts +2 -2
- package/_types/erc6492/index.d.ts +2 -2
- package/_types/erc8010/SignatureErc8010.d.ts +2 -2
- package/_types/erc8010/index.d.ts +2 -2
- package/_types/version.d.ts +1 -1
- package/core/Abi.ts +2 -2
- package/core/AbiConstructor.ts +96 -12
- package/core/AbiError.ts +121 -27
- package/core/AbiEvent.ts +145 -1
- package/core/AbiFunction.ts +272 -11
- package/core/AbiItem.ts +87 -3
- package/erc4337/EntryPoint/package.json +6 -0
- package/erc4337/RpcSchema/package.json +6 -0
- package/erc4337/UserOperation/package.json +6 -0
- package/erc4337/UserOperationGas/package.json +6 -0
- package/erc4337/UserOperationReceipt/package.json +6 -0
- package/erc4337/package.json +6 -0
- package/erc6492/SignatureErc6492/package.json +6 -0
- package/erc6492/SignatureErc6492.ts +2 -2
- package/erc6492/index.ts +2 -2
- package/erc6492/package.json +6 -0
- package/erc8010/SignatureErc8010/package.json +6 -0
- package/erc8010/SignatureErc8010.ts +2 -2
- package/erc8010/index.ts +2 -2
- package/erc8010/package.json +6 -0
- package/index.docs/package.json +6 -0
- package/package.json +1 -1
- package/trusted-setups/Paths/package.json +6 -0
- package/trusted-setups/package.json +6 -0
- package/version.ts +1 -1
- package/window/package.json +6 -0
package/core/AbiError.ts
CHANGED
|
@@ -75,6 +75,25 @@ export function decode<
|
|
|
75
75
|
* ```
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
78
|
+
* ### ABI-shorthand
|
|
79
|
+
*
|
|
80
|
+
* You can also specify an entire ABI object as a parameter to {@link ox#AbiError.(decode:function)}:
|
|
81
|
+
*
|
|
82
|
+
* ```ts twoslash
|
|
83
|
+
* // @noErrors
|
|
84
|
+
* import { Abi, AbiError } from 'ox'
|
|
85
|
+
*
|
|
86
|
+
* const abi = Abi.from([...])
|
|
87
|
+
*
|
|
88
|
+
* const value = AbiError.decode(
|
|
89
|
+
* abi, // [!code hl]
|
|
90
|
+
* 'InvalidSignature', // [!code hl]
|
|
91
|
+
* '0x...'
|
|
92
|
+
* )
|
|
93
|
+
* // @log: [420n, 69n, 1]
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
78
97
|
* ### End-to-end
|
|
79
98
|
*
|
|
80
99
|
* Below is an end-to-end example of using `AbiError.decode` to decode the revert error of an `approve` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
|
|
@@ -139,17 +158,58 @@ export function decode<
|
|
|
139
158
|
* @param options - Decoding options.
|
|
140
159
|
* @returns The decoded error.
|
|
141
160
|
*/
|
|
142
|
-
export function decode
|
|
143
|
-
|
|
161
|
+
export function decode<
|
|
162
|
+
const abi extends Abi.Abi | readonly unknown[],
|
|
163
|
+
name extends Name<abi>,
|
|
164
|
+
const args extends
|
|
165
|
+
| AbiItem_internal.ExtractArgs<abi, name>
|
|
166
|
+
| undefined = undefined,
|
|
167
|
+
as extends 'Object' | 'Array' = 'Array',
|
|
168
|
+
//
|
|
169
|
+
abiError extends AbiError = AbiItem.fromAbi.ReturnType<
|
|
170
|
+
abi,
|
|
171
|
+
name,
|
|
172
|
+
args,
|
|
173
|
+
AbiError
|
|
174
|
+
>,
|
|
175
|
+
allNames = Name<abi>,
|
|
176
|
+
>(
|
|
177
|
+
abi: abi | Abi.Abi | readonly unknown[],
|
|
178
|
+
name: Hex.Hex | (name extends allNames ? name : never),
|
|
144
179
|
data: Hex.Hex,
|
|
145
|
-
options?: decode.Options | undefined,
|
|
146
|
-
):
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
180
|
+
options?: decode.Options<as> | undefined,
|
|
181
|
+
): decode.ReturnType<abiError, as>
|
|
182
|
+
export function decode<
|
|
183
|
+
const abiError extends AbiError,
|
|
184
|
+
as extends 'Object' | 'Array' = 'Array',
|
|
185
|
+
>(
|
|
186
|
+
abiError: abiError | AbiError,
|
|
150
187
|
data: Hex.Hex,
|
|
151
|
-
options
|
|
188
|
+
options?: decode.Options<as> | undefined,
|
|
189
|
+
): decode.ReturnType<abiError, as>
|
|
190
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
191
|
+
export function decode(
|
|
192
|
+
...parameters:
|
|
193
|
+
| [
|
|
194
|
+
abi: Abi.Abi | readonly unknown[],
|
|
195
|
+
name: Hex.Hex | string,
|
|
196
|
+
data: Hex.Hex,
|
|
197
|
+
options?: decode.Options | undefined,
|
|
198
|
+
]
|
|
199
|
+
| [abiError: AbiError, data: Hex.Hex, options?: decode.Options | undefined]
|
|
152
200
|
): decode.ReturnType {
|
|
201
|
+
const [abiError, data, options = {}] = (() => {
|
|
202
|
+
if (Array.isArray(parameters[0])) {
|
|
203
|
+
const [abi, name, data, options] = parameters as [
|
|
204
|
+
Abi.Abi | readonly unknown[],
|
|
205
|
+
Hex.Hex | string,
|
|
206
|
+
Hex.Hex,
|
|
207
|
+
decode.Options | undefined,
|
|
208
|
+
]
|
|
209
|
+
return [fromAbi(abi, name), data, options]
|
|
210
|
+
}
|
|
211
|
+
return parameters as [AbiError, Hex.Hex, decode.Options | undefined]
|
|
212
|
+
})()
|
|
153
213
|
if (Hex.size(data) < 4) throw new AbiItem.InvalidSelectorSizeError({ data })
|
|
154
214
|
if (abiError.inputs.length === 0) return undefined
|
|
155
215
|
|
|
@@ -223,42 +283,76 @@ export declare namespace decode {
|
|
|
223
283
|
* ```
|
|
224
284
|
*
|
|
225
285
|
* @example
|
|
226
|
-
*
|
|
286
|
+
* ### ABI-shorthand
|
|
287
|
+
*
|
|
288
|
+
* You can also specify an entire ABI object and an error name as parameters to `AbiError.encode`.
|
|
227
289
|
*
|
|
228
290
|
* ```ts twoslash
|
|
229
291
|
* // @noErrors
|
|
230
292
|
* import { Abi, AbiError } from 'ox'
|
|
231
293
|
*
|
|
232
|
-
* const abi = Abi.from([
|
|
233
|
-
* // ... // [!code hl]
|
|
234
|
-
* { // [!code hl]
|
|
235
|
-
* name: 'InvalidSignature', // [!code hl]
|
|
236
|
-
* type: 'error', // [!code hl]
|
|
237
|
-
* inputs: [ // [!code hl]
|
|
238
|
-
* { name: 'r', type: 'uint256' }, // [!code hl]
|
|
239
|
-
* { name: 's', type: 'uint256' }, // [!code hl]
|
|
240
|
-
* { name: 'yParity', type: 'uint8' }, // [!code hl]
|
|
241
|
-
* ], // [!code hl]
|
|
242
|
-
* }, // [!code hl]
|
|
243
|
-
* // ... // [!code hl]
|
|
244
|
-
* ]) // [!code hl]
|
|
245
|
-
* const error = AbiError.fromAbi(abi, 'InvalidSignature') // [!code hl]
|
|
294
|
+
* const abi = Abi.from([...])
|
|
246
295
|
*
|
|
247
296
|
* const data = AbiError.encode(
|
|
248
|
-
*
|
|
249
|
-
*
|
|
297
|
+
* abi, // [!code hl]
|
|
298
|
+
* 'InvalidSignature', // [!code hl]
|
|
299
|
+
* [1n, 2n, 0]
|
|
250
300
|
* )
|
|
251
|
-
* // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
|
|
252
301
|
* ```
|
|
253
302
|
*
|
|
254
303
|
* @param abiError - ABI Error to encode
|
|
255
304
|
* @param args - Error arguments
|
|
256
305
|
* @returns ABI-encoded error name and arguments
|
|
257
306
|
*/
|
|
307
|
+
export function encode<
|
|
308
|
+
const abi extends Abi.Abi | readonly unknown[],
|
|
309
|
+
name extends Name<abi>,
|
|
310
|
+
const args extends
|
|
311
|
+
| AbiItem_internal.ExtractArgs<abi, name>
|
|
312
|
+
| undefined = undefined,
|
|
313
|
+
//
|
|
314
|
+
abiError extends AbiError = AbiItem.fromAbi.ReturnType<
|
|
315
|
+
abi,
|
|
316
|
+
name,
|
|
317
|
+
args,
|
|
318
|
+
AbiError
|
|
319
|
+
>,
|
|
320
|
+
allNames = Name<abi>,
|
|
321
|
+
>(
|
|
322
|
+
abi: abi | Abi.Abi | readonly unknown[],
|
|
323
|
+
name: Hex.Hex | (name extends allNames ? name : never),
|
|
324
|
+
...args: encode.Args<abiError>
|
|
325
|
+
): encode.ReturnType
|
|
258
326
|
export function encode<const abiError extends AbiError>(
|
|
259
327
|
abiError: abiError,
|
|
260
328
|
...args: encode.Args<abiError>
|
|
261
|
-
): encode.ReturnType
|
|
329
|
+
): encode.ReturnType
|
|
330
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
331
|
+
export function encode(
|
|
332
|
+
...parameters:
|
|
333
|
+
| [
|
|
334
|
+
abi: Abi.Abi | readonly unknown[],
|
|
335
|
+
name: Hex.Hex | string,
|
|
336
|
+
...args: readonly unknown[],
|
|
337
|
+
]
|
|
338
|
+
| [abiError: AbiError, ...args: readonly unknown[]]
|
|
339
|
+
) {
|
|
340
|
+
const [abiError, args] = (() => {
|
|
341
|
+
if (Array.isArray(parameters[0])) {
|
|
342
|
+
const [abi, name, ...args] = parameters as [
|
|
343
|
+
Abi.Abi | readonly unknown[],
|
|
344
|
+
Hex.Hex | string,
|
|
345
|
+
...(readonly unknown[]),
|
|
346
|
+
]
|
|
347
|
+
return [fromAbi(abi, name), args]
|
|
348
|
+
}
|
|
349
|
+
const [abiError, ...args] = parameters as [
|
|
350
|
+
AbiError,
|
|
351
|
+
...(readonly unknown[]),
|
|
352
|
+
]
|
|
353
|
+
return [abiError, args]
|
|
354
|
+
})()
|
|
355
|
+
|
|
262
356
|
const selector = getSelector(abiError)
|
|
263
357
|
|
|
264
358
|
const data =
|
package/core/AbiEvent.ts
CHANGED
|
@@ -237,6 +237,38 @@ export declare namespace assertArgs {
|
|
|
237
237
|
* ```
|
|
238
238
|
*
|
|
239
239
|
* @example
|
|
240
|
+
* ### ABI-shorthand
|
|
241
|
+
*
|
|
242
|
+
* You can also specify an entire ABI object and an event name as parameters to {@link ox#AbiEvent.(decode:function)}:
|
|
243
|
+
*
|
|
244
|
+
* ```ts twoslash
|
|
245
|
+
* // @noErrors
|
|
246
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
247
|
+
*
|
|
248
|
+
* const abi = Abi.from([...])
|
|
249
|
+
* const log = {
|
|
250
|
+
* // ...
|
|
251
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
252
|
+
* topics: [
|
|
253
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
254
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
255
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
256
|
+
* ],
|
|
257
|
+
* } as const
|
|
258
|
+
*
|
|
259
|
+
* const decoded = AbiEvent.decode(
|
|
260
|
+
* abi, // [!code focus]
|
|
261
|
+
* 'Transfer', // [!code focus]
|
|
262
|
+
* log
|
|
263
|
+
* )
|
|
264
|
+
* // @log: {
|
|
265
|
+
* // @log: from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
266
|
+
* // @log: to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
267
|
+
* // @log: value: 1n
|
|
268
|
+
* // @log: }
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
240
272
|
* ### End-to-end
|
|
241
273
|
*
|
|
242
274
|
* Below is an end-to-end example of using `AbiEvent.decode` to decode the topics of a `Transfer` event on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
|
|
@@ -286,10 +318,51 @@ export declare namespace assertArgs {
|
|
|
286
318
|
* @param log - `topics` & `data` to decode.
|
|
287
319
|
* @returns The decoded event.
|
|
288
320
|
*/
|
|
321
|
+
export function decode<
|
|
322
|
+
const abi extends Abi.Abi | readonly unknown[],
|
|
323
|
+
name extends Name<abi>,
|
|
324
|
+
const args extends
|
|
325
|
+
| AbiItem_internal.ExtractArgs<abi, name>
|
|
326
|
+
| undefined = undefined,
|
|
327
|
+
//
|
|
328
|
+
abiEvent extends AbiEvent = AbiItem.fromAbi.ReturnType<
|
|
329
|
+
abi,
|
|
330
|
+
name,
|
|
331
|
+
args,
|
|
332
|
+
AbiEvent
|
|
333
|
+
>,
|
|
334
|
+
allNames = Name<abi>,
|
|
335
|
+
>(
|
|
336
|
+
abi: abi | Abi.Abi | readonly unknown[],
|
|
337
|
+
name: Hex.Hex | (name extends allNames ? name : never),
|
|
338
|
+
log: decode.Log,
|
|
339
|
+
): decode.ReturnType<abiEvent>
|
|
289
340
|
export function decode<const abiEvent extends AbiEvent>(
|
|
290
341
|
abiEvent: abiEvent | AbiEvent,
|
|
291
342
|
log: decode.Log,
|
|
292
|
-
): decode.ReturnType<abiEvent>
|
|
343
|
+
): decode.ReturnType<abiEvent>
|
|
344
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
345
|
+
export function decode(
|
|
346
|
+
...parameters:
|
|
347
|
+
| [
|
|
348
|
+
abi: Abi.Abi | readonly unknown[],
|
|
349
|
+
name: Hex.Hex | string,
|
|
350
|
+
log: decode.Log,
|
|
351
|
+
]
|
|
352
|
+
| [abiEvent: AbiEvent, log: decode.Log]
|
|
353
|
+
): decode.ReturnType {
|
|
354
|
+
const [abiEvent, log] = (() => {
|
|
355
|
+
if (Array.isArray(parameters[0])) {
|
|
356
|
+
const [abi, name, log] = parameters as [
|
|
357
|
+
Abi.Abi | readonly unknown[],
|
|
358
|
+
Hex.Hex | string,
|
|
359
|
+
decode.Log,
|
|
360
|
+
]
|
|
361
|
+
return [fromAbi(abi, name), log]
|
|
362
|
+
}
|
|
363
|
+
return parameters as [AbiEvent, decode.Log]
|
|
364
|
+
})()
|
|
365
|
+
|
|
293
366
|
const { data, topics } = log
|
|
294
367
|
|
|
295
368
|
const [selector_, ...argTopics] = topics
|
|
@@ -449,6 +522,32 @@ export declare namespace decode {
|
|
|
449
522
|
* ```
|
|
450
523
|
*
|
|
451
524
|
* @example
|
|
525
|
+
* ### ABI-shorthand
|
|
526
|
+
*
|
|
527
|
+
* You can also specify an entire ABI object and an event name as parameters to {@link ox#AbiEvent.(encode:function)}:
|
|
528
|
+
*
|
|
529
|
+
* ```ts twoslash
|
|
530
|
+
* // @noErrors
|
|
531
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
532
|
+
*
|
|
533
|
+
* const abi = Abi.from([...])
|
|
534
|
+
*
|
|
535
|
+
* const { topics } = AbiEvent.encode(
|
|
536
|
+
* abi, // [!code focus]
|
|
537
|
+
* 'Transfer', // [!code focus]
|
|
538
|
+
* {
|
|
539
|
+
* from: '0xf39fd6e51aad88f6f4ce6ab882779cfffb92266', // [!code focus]
|
|
540
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
541
|
+
* }
|
|
542
|
+
* )
|
|
543
|
+
* // @log: [
|
|
544
|
+
* // @log: '0x406dade31f7ae4b5dbc276258c28dde5ae6d5c2773c5745802c493a2360e55e0',
|
|
545
|
+
* // @log: '0x00000000000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
546
|
+
* // @log: '0x0000000000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8'
|
|
547
|
+
* // @log: ]
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
452
551
|
* ### End-to-end
|
|
453
552
|
*
|
|
454
553
|
* Below is an end-to-end example of using `AbiEvent.encode` to encode the topics of a `Transfer` event and query for events matching the encoded topics on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
|
|
@@ -496,10 +595,55 @@ export declare namespace decode {
|
|
|
496
595
|
* @param args - The arguments to encode.
|
|
497
596
|
* @returns The encoded event topics.
|
|
498
597
|
*/
|
|
598
|
+
export function encode<
|
|
599
|
+
const abi extends Abi.Abi | readonly unknown[],
|
|
600
|
+
name extends Name<abi>,
|
|
601
|
+
const args extends
|
|
602
|
+
| AbiItem_internal.ExtractArgs<abi, name>
|
|
603
|
+
| undefined = undefined,
|
|
604
|
+
//
|
|
605
|
+
abiEvent extends AbiEvent = AbiItem.fromAbi.ReturnType<
|
|
606
|
+
abi,
|
|
607
|
+
name,
|
|
608
|
+
args,
|
|
609
|
+
AbiEvent
|
|
610
|
+
>,
|
|
611
|
+
allNames = Name<abi>,
|
|
612
|
+
>(
|
|
613
|
+
abi: abi | Abi.Abi | readonly unknown[],
|
|
614
|
+
name: Hex.Hex | (name extends allNames ? name : never),
|
|
615
|
+
...[args]: encode.Args<abiEvent>
|
|
616
|
+
): encode.ReturnType
|
|
499
617
|
export function encode<const abiEvent extends AbiEvent>(
|
|
500
618
|
abiEvent: abiEvent | AbiEvent,
|
|
501
619
|
...[args]: encode.Args<abiEvent>
|
|
620
|
+
): encode.ReturnType
|
|
621
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
622
|
+
export function encode(
|
|
623
|
+
...parameters:
|
|
624
|
+
| [
|
|
625
|
+
abi: Abi.Abi | readonly unknown[],
|
|
626
|
+
name: Hex.Hex | string,
|
|
627
|
+
args?: readonly unknown[] | Record<string, unknown>,
|
|
628
|
+
]
|
|
629
|
+
| [abiEvent: AbiEvent, args?: readonly unknown[] | Record<string, unknown>]
|
|
502
630
|
): encode.ReturnType {
|
|
631
|
+
const [abiEvent, args] = (() => {
|
|
632
|
+
if (Array.isArray(parameters[0])) {
|
|
633
|
+
const [abi, name, args] = parameters as [
|
|
634
|
+
Abi.Abi | readonly unknown[],
|
|
635
|
+
Hex.Hex | string,
|
|
636
|
+
readonly unknown[] | Record<string, unknown> | undefined,
|
|
637
|
+
]
|
|
638
|
+
return [fromAbi(abi, name), args]
|
|
639
|
+
}
|
|
640
|
+
const [abiEvent, args] = parameters as [
|
|
641
|
+
AbiEvent,
|
|
642
|
+
readonly unknown[] | Record<string, unknown> | undefined,
|
|
643
|
+
]
|
|
644
|
+
return [abiEvent, args]
|
|
645
|
+
})()
|
|
646
|
+
|
|
503
647
|
let topics: (Hex.Hex | Hex.Hex[] | null)[] = []
|
|
504
648
|
if (args && abiEvent.inputs) {
|
|
505
649
|
const indexedInputs = abiEvent.inputs.filter(
|