viem 0.0.1-alpha.19 → 0.0.1-alpha.20
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/{rpc-858670f1.d.ts → chain-32f56cfa.d.ts} +68 -18
- package/dist/chain-f12cdc7f.d.ts +5 -0
- package/dist/chains.d.ts +757 -170
- package/dist/chains.js +80 -86
- package/dist/chains.js.map +1 -1
- package/dist/chains.mjs +120 -126
- package/dist/chains.mjs.map +1 -1
- package/dist/{chunk-PHSAQQGZ.mjs → chunk-5Q6FSUU2.mjs} +75 -37
- package/dist/chunk-5Q6FSUU2.mjs.map +1 -0
- package/dist/{chunk-24EKKMUO.js → chunk-FHXXG7I6.js} +12 -12
- package/dist/chunk-FHXXG7I6.js.map +1 -0
- package/dist/{chunk-HRE6LYF3.js → chunk-IAQPMSGJ.js} +13 -13
- package/dist/chunk-IAQPMSGJ.js.map +1 -0
- package/dist/{chunk-IVWG22RQ.mjs → chunk-MYQNZSWD.mjs} +69 -12
- package/dist/chunk-MYQNZSWD.mjs.map +1 -0
- package/dist/{chunk-NYMS65YI.js → chunk-NHAKUPTF.js} +124 -67
- package/dist/chunk-NHAKUPTF.js.map +1 -0
- package/dist/{chunk-BZFF747V.js → chunk-SF4I2NKC.js} +81 -43
- package/dist/chunk-SF4I2NKC.js.map +1 -0
- package/dist/{chunk-VAT5CEF7.mjs → chunk-T7CBAKLI.mjs} +2 -2
- package/dist/chunk-T7CBAKLI.mjs.map +1 -0
- package/dist/{chunk-CTU4PQLY.js → chunk-YFKR74XG.js} +14 -14
- package/dist/{chunk-CTU4PQLY.js.map → chunk-YFKR74XG.js.map} +0 -0
- package/dist/{chunk-NSRORL3O.mjs → chunk-YODUQCHJ.mjs} +2 -2
- package/dist/{chunk-NSRORL3O.mjs.map → chunk-YODUQCHJ.mjs.map} +0 -0
- package/dist/{chunk-E7LH5H76.mjs → chunk-ZVGTYLKU.mjs} +2 -2
- package/dist/chunk-ZVGTYLKU.mjs.map +1 -0
- package/dist/clients/index.d.ts +7 -8
- package/dist/clients/index.js +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/{transactionReceipt-aed524b4.d.ts → contract-9af4608b.d.ts} +30 -18
- package/dist/{createClient-03ba79e8.d.ts → createClient-5d316c7e.d.ts} +2 -2
- package/dist/{createPublicClient-818241ba.d.ts → createPublicClient-9d2b42e1.d.ts} +3 -3
- package/dist/{createTestClient-24eb7be8.d.ts → createTestClient-79498dab.d.ts} +3 -3
- package/dist/{createWalletClient-7cbd6ad1.d.ts → createWalletClient-f69a5230.d.ts} +3 -3
- package/dist/{eip1193-71d8e27d.d.ts → eip1193-6c485d63.d.ts} +1 -1
- package/dist/index.d.ts +45 -23
- package/dist/index.js +10 -6
- package/dist/index.mjs +9 -5
- package/dist/{parseGwei-dbd12305.d.ts → parseGwei-4308ad80.d.ts} +17 -4
- package/dist/public.d.ts +9 -10
- package/dist/public.js +4 -4
- package/dist/public.mjs +3 -3
- package/dist/{sendTransaction-d09961a7.d.ts → sendTransaction-1c8290a9.d.ts} +3 -4
- package/dist/{stopImpersonatingAccount-c8a00be7.d.ts → stopImpersonatingAccount-7781842a.d.ts} +2 -2
- package/dist/test.d.ts +5 -6
- package/dist/test.js +3 -3
- package/dist/test.mjs +2 -2
- package/dist/transactionRequest-341b6ed2.d.ts +15 -0
- package/dist/utils/index.d.ts +9 -8
- package/dist/utils/index.js +22 -2
- package/dist/utils/index.mjs +25 -5
- package/dist/wallet.d.ts +7 -8
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/{watchAsset-c39645b7.d.ts → watchAsset-afaad3c7.d.ts} +3 -4
- package/dist/{watchPendingTransactions-01e6be4f.d.ts → watchPendingTransactions-3b722547.d.ts} +21 -16
- package/dist/{webSocket-3a00015b.d.ts → webSocket-b180e679.d.ts} +2 -2
- package/dist/window.d.ts +3 -2
- package/package.json +3 -3
- package/src/_test/abis.ts +188 -0
- package/src/_test/constants.ts +0 -3
- package/src/_test/index.ts +5 -2
- package/src/actions/index.test.ts +2 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/public/call.ts +2 -1
- package/src/actions/public/createContractEventFilter.test.ts +119 -0
- package/src/actions/public/createContractEventFilter.ts +69 -0
- package/src/actions/public/createEventFilter.ts +5 -8
- package/src/actions/public/deployContract.ts +1 -2
- package/src/actions/public/getBlock.test.ts +3 -3
- package/src/actions/public/getBlock.ts +1 -2
- package/src/actions/public/getBlockTransactionCount.ts +1 -2
- package/src/actions/public/getFilterChanges.test.ts +9 -7
- package/src/actions/public/getFilterLogs.test.ts +7 -5
- package/src/actions/public/getLogs.test.ts +7 -5
- package/src/actions/public/getLogs.ts +3 -2
- package/src/actions/public/getTransaction.ts +1 -2
- package/src/actions/public/getTransactionConfirmations.ts +1 -2
- package/src/actions/public/getTransactionReceipt.test.ts +24 -62
- package/src/actions/public/getTransactionReceipt.ts +1 -2
- package/src/actions/public/index.test.ts +4 -0
- package/src/actions/public/index.ts +18 -0
- package/src/actions/public/readContract.ts +1 -1
- package/src/actions/public/simulateContract.ts +1 -1
- package/src/actions/public/waitForTransactionReceipt.ts +1 -2
- package/src/actions/public/watchBlocks.test.ts +27 -2
- package/src/actions/public/watchBlocks.ts +33 -14
- package/src/actions/public/watchContractEvent.test.ts +301 -0
- package/src/actions/public/watchContractEvent.ts +108 -0
- package/src/actions/public/watchEvent.test.ts +190 -0
- package/src/actions/public/watchEvent.ts +95 -0
- package/src/actions/public/watchPendingTransactions.ts +1 -0
- package/src/actions/wallet/addChain.ts +1 -1
- package/src/actions/wallet/sendTransaction.ts +2 -1
- package/src/actions/wallet/switchChain.ts +1 -1
- package/src/actions/wallet/writeContract.ts +1 -1
- package/src/chains.test.ts +830 -52
- package/src/chains.ts +90 -158
- package/src/clients/createClient.ts +1 -1
- package/src/clients/createPublicClient.ts +1 -1
- package/src/clients/createTestClient.ts +1 -1
- package/src/clients/createWalletClient.ts +1 -1
- package/src/clients/transports/createTransport.ts +1 -1
- package/src/index.test.ts +2 -0
- package/src/index.ts +10 -2
- package/src/types/chain.ts +6 -0
- package/src/types/contract.ts +17 -2
- package/src/types/formatter.ts +23 -0
- package/src/types/index.ts +6 -0
- package/src/types/transaction.ts +1 -1
- package/src/utils/abi/decodeErrorResult.ts +2 -2
- package/src/utils/abi/decodeFunctionData.ts +2 -2
- package/src/utils/abi/encodeErrorResult.ts +2 -2
- package/src/utils/abi/encodeEventTopics.ts +4 -4
- package/src/utils/abi/encodeFunctionData.ts +2 -2
- package/src/utils/abi/{formatAbiItemWithParams.test.ts → formatAbiItem.test.ts} +11 -11
- package/src/utils/abi/{formatAbiItemWithParams.ts → formatAbiItem.ts} +1 -1
- package/src/utils/abi/index.test.ts +1 -1
- package/src/utils/abi/index.ts +1 -1
- package/src/utils/chain.test.ts +43 -0
- package/src/utils/chain.ts +8 -0
- package/src/utils/contract/getContractError.ts +2 -6
- package/src/utils/formatters/block.ts +4 -3
- package/src/utils/formatters/extract.ts +1 -1
- package/src/utils/formatters/format.ts +39 -2
- package/src/utils/formatters/index.test.ts +10 -0
- package/src/utils/formatters/index.ts +15 -5
- package/src/utils/formatters/transaction.ts +16 -4
- package/src/utils/formatters/transactionReceipt.ts +13 -4
- package/src/utils/formatters/transactionRequest.ts +12 -3
- package/src/utils/hash/getEventSignature.ts +2 -2
- package/src/utils/index.test.ts +24 -1
- package/src/utils/index.ts +12 -1
- package/src/{constants.test.ts → utils/unit/constants.test.ts} +0 -5
- package/src/{constants.ts → utils/unit/constants.ts} +0 -6
- package/src/utils/unit/formatEther.ts +1 -1
- package/src/utils/unit/formatGwei.ts +1 -1
- package/src/utils/unit/index.test.ts +12 -0
- package/src/utils/unit/index.ts +1 -0
- package/src/utils/unit/parseEther.ts +1 -1
- package/src/utils/unit/parseGwei.ts +1 -1
- package/dist/chunk-24EKKMUO.js.map +0 -1
- package/dist/chunk-BZFF747V.js.map +0 -1
- package/dist/chunk-E7LH5H76.mjs.map +0 -1
- package/dist/chunk-HRE6LYF3.js.map +0 -1
- package/dist/chunk-IVWG22RQ.mjs.map +0 -1
- package/dist/chunk-NYMS65YI.js.map +0 -1
- package/dist/chunk-PHSAQQGZ.mjs.map +0 -1
- package/dist/chunk-VAT5CEF7.mjs.map +0 -1
- package/dist/transactionRequest-8e970b0e.d.ts +0 -33
@@ -1,11 +1,11 @@
|
|
1
1
|
import { expect, test } from 'vitest'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { formatAbiItem } from './formatAbiItem'
|
4
4
|
|
5
5
|
test('foo()', () => {
|
6
6
|
expect(
|
7
7
|
// @ts-expect-error
|
8
|
-
|
8
|
+
formatAbiItem({
|
9
9
|
name: 'foo',
|
10
10
|
outputs: [],
|
11
11
|
stateMutability: 'nonpayable',
|
@@ -13,7 +13,7 @@ test('foo()', () => {
|
|
13
13
|
}),
|
14
14
|
).toEqual('foo()')
|
15
15
|
expect(
|
16
|
-
|
16
|
+
formatAbiItem({
|
17
17
|
inputs: [],
|
18
18
|
name: 'foo',
|
19
19
|
outputs: [],
|
@@ -25,7 +25,7 @@ test('foo()', () => {
|
|
25
25
|
|
26
26
|
test('foo(uint256)', () => {
|
27
27
|
expect(
|
28
|
-
|
28
|
+
formatAbiItem({
|
29
29
|
inputs: [
|
30
30
|
{
|
31
31
|
internalType: 'uint256',
|
@@ -40,7 +40,7 @@ test('foo(uint256)', () => {
|
|
40
40
|
}),
|
41
41
|
).toEqual('foo(uint256)')
|
42
42
|
expect(
|
43
|
-
|
43
|
+
formatAbiItem(
|
44
44
|
{
|
45
45
|
inputs: [
|
46
46
|
{
|
@@ -61,7 +61,7 @@ test('foo(uint256)', () => {
|
|
61
61
|
|
62
62
|
test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
|
63
63
|
expect(
|
64
|
-
|
64
|
+
formatAbiItem({
|
65
65
|
inputs: [
|
66
66
|
{
|
67
67
|
components: [
|
@@ -108,7 +108,7 @@ test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
|
|
108
108
|
}),
|
109
109
|
).toEqual('getVoter((uint256,bool,address,uint256),string[],bytes)')
|
110
110
|
expect(
|
111
|
-
|
111
|
+
formatAbiItem(
|
112
112
|
{
|
113
113
|
inputs: [
|
114
114
|
{
|
@@ -163,7 +163,7 @@ test('getVoter((uint256,bool,address,uint256),string[],bytes)', () => {
|
|
163
163
|
|
164
164
|
test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
|
165
165
|
expect(
|
166
|
-
|
166
|
+
formatAbiItem({
|
167
167
|
inputs: [
|
168
168
|
{
|
169
169
|
components: [
|
@@ -210,7 +210,7 @@ test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
|
|
210
210
|
}),
|
211
211
|
).toEqual('VoterEvent((uint256,bool,address,uint256),string[],bytes)')
|
212
212
|
expect(
|
213
|
-
|
213
|
+
formatAbiItem(
|
214
214
|
{
|
215
215
|
inputs: [
|
216
216
|
{
|
@@ -265,7 +265,7 @@ test('VoterEvent((uint256,bool,address,uint256),string[],bytes)', () => {
|
|
265
265
|
|
266
266
|
test('VoterError((uint256,bool,address,uint256),string[],bytes)', () => {
|
267
267
|
expect(
|
268
|
-
|
268
|
+
formatAbiItem({
|
269
269
|
inputs: [
|
270
270
|
{
|
271
271
|
components: [
|
@@ -315,7 +315,7 @@ test('VoterError((uint256,bool,address,uint256),string[],bytes)', () => {
|
|
315
315
|
|
316
316
|
test('error: invalid type', () => {
|
317
317
|
expect(() =>
|
318
|
-
|
318
|
+
formatAbiItem({
|
319
319
|
inputs: [
|
320
320
|
{
|
321
321
|
internalType: 'bytes32[]',
|
@@ -3,7 +3,7 @@ import { AbiParameter } from 'abitype'
|
|
3
3
|
import { InvalidDefinitionTypeError } from '../../errors'
|
4
4
|
import { AbiItem } from '../../types'
|
5
5
|
|
6
|
-
export function
|
6
|
+
export function formatAbiItem(
|
7
7
|
abiItem: AbiItem,
|
8
8
|
{ includeName = false }: { includeName?: boolean } = {},
|
9
9
|
) {
|
@@ -15,8 +15,8 @@ test('exports utils', () => {
|
|
15
15
|
"encodeEventTopics": [Function],
|
16
16
|
"encodeFunctionData": [Function],
|
17
17
|
"encodeFunctionResult": [Function],
|
18
|
+
"formatAbiItem": [Function],
|
18
19
|
"formatAbiItemWithArgs": [Function],
|
19
|
-
"formatAbiItemWithParams": [Function],
|
20
20
|
"getAbiItem": [Function],
|
21
21
|
}
|
22
22
|
`)
|
package/src/utils/abi/index.ts
CHANGED
@@ -33,6 +33,6 @@ export { encodeFunctionResult } from './encodeFunctionResult'
|
|
33
33
|
|
34
34
|
export { formatAbiItemWithArgs } from './formatAbiItemWithArgs'
|
35
35
|
|
36
|
-
export {
|
36
|
+
export { formatAbiItem } from './formatAbiItem'
|
37
37
|
|
38
38
|
export { getAbiItem } from './getAbiItem'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
2
|
+
import { celo } from '../chains'
|
3
|
+
import { defineChain } from './chain'
|
4
|
+
|
5
|
+
describe('defineChain', () => {
|
6
|
+
test('default', () => {
|
7
|
+
expect(
|
8
|
+
defineChain({
|
9
|
+
id: 42220,
|
10
|
+
name: 'Celo',
|
11
|
+
network: 'celo',
|
12
|
+
nativeCurrency: { name: 'Celo', symbol: 'CELO', decimals: 18 },
|
13
|
+
rpcUrls: {
|
14
|
+
public: { http: ['https://rpc.ankr.com/celo'] },
|
15
|
+
default: { http: ['https://rpc.ankr.com/celo'] },
|
16
|
+
},
|
17
|
+
}),
|
18
|
+
).toMatchInlineSnapshot(`
|
19
|
+
{
|
20
|
+
"id": 42220,
|
21
|
+
"name": "Celo",
|
22
|
+
"nativeCurrency": {
|
23
|
+
"decimals": 18,
|
24
|
+
"name": "Celo",
|
25
|
+
"symbol": "CELO",
|
26
|
+
},
|
27
|
+
"network": "celo",
|
28
|
+
"rpcUrls": {
|
29
|
+
"default": {
|
30
|
+
"http": [
|
31
|
+
"https://rpc.ankr.com/celo",
|
32
|
+
],
|
33
|
+
},
|
34
|
+
"public": {
|
35
|
+
"http": [
|
36
|
+
"https://rpc.ankr.com/celo",
|
37
|
+
],
|
38
|
+
},
|
39
|
+
},
|
40
|
+
}
|
41
|
+
`)
|
42
|
+
})
|
43
|
+
})
|
@@ -5,11 +5,7 @@ import {
|
|
5
5
|
ContractMethodZeroDataError,
|
6
6
|
} from '../../errors'
|
7
7
|
import { Address } from '../../types'
|
8
|
-
import {
|
9
|
-
formatAbiItemWithArgs,
|
10
|
-
formatAbiItemWithParams,
|
11
|
-
getAbiItem,
|
12
|
-
} from '../abi'
|
8
|
+
import { formatAbiItemWithArgs, formatAbiItem, getAbiItem } from '../abi'
|
13
9
|
|
14
10
|
export function getContractError(
|
15
11
|
err: unknown,
|
@@ -40,7 +36,7 @@ export function getContractError(
|
|
40
36
|
})
|
41
37
|
: undefined
|
42
38
|
const functionWithParams = abiItem
|
43
|
-
?
|
39
|
+
? formatAbiItem(abiItem, { includeName: true })
|
44
40
|
: undefined
|
45
41
|
|
46
42
|
if (err instanceof AbiDecodingZeroDataError) {
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import type { Chain, Formatter, Formatters } from '../../
|
2
|
-
import
|
3
|
-
import type { ExtractFormatter, Formatted } from './format'
|
1
|
+
import type { Chain, Block, Formatter, Formatters, RpcBlock } from '../../types'
|
2
|
+
import { defineFormatter, ExtractFormatter, Formatted } from './format'
|
4
3
|
import { formatTransaction } from './transaction'
|
5
4
|
|
6
5
|
export type BlockFormatter<TChain extends Chain = Chain> = ExtractFormatter<
|
@@ -34,3 +33,5 @@ export function formatBlock(block: Partial<RpcBlock>) {
|
|
34
33
|
: null,
|
35
34
|
} as Block
|
36
35
|
}
|
36
|
+
|
37
|
+
export const defineBlock = defineFormatter({ format: formatBlock })
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import type { Chain, Formatter } from '../../
|
2
|
-
import type { OptionalNullable } from '../../types'
|
1
|
+
import type { Chain, Formatter, OptionalNullable } from '../../types'
|
3
2
|
|
4
3
|
export type ExtractFormatter<
|
5
4
|
TChain extends Chain,
|
@@ -51,3 +50,41 @@ export function format<
|
|
51
50
|
>(data: TSource, { formatter }: FormatOptions<TSource, TTarget>) {
|
52
51
|
return formatter(data) as Formatted<TFormatter, TTarget>
|
53
52
|
}
|
53
|
+
|
54
|
+
export function defineFormatter<
|
55
|
+
TSource extends Record<string, unknown>,
|
56
|
+
TFormatted,
|
57
|
+
>({
|
58
|
+
format,
|
59
|
+
}: {
|
60
|
+
format: (data: TSource) => TFormatted
|
61
|
+
}) {
|
62
|
+
return <
|
63
|
+
TFormat extends Formatter<
|
64
|
+
TSource,
|
65
|
+
Partial<TFormatted> & { [key: string]: unknown }
|
66
|
+
>,
|
67
|
+
TExclude extends (keyof TSource)[] = [],
|
68
|
+
>({
|
69
|
+
exclude,
|
70
|
+
format: formatOverride,
|
71
|
+
}: {
|
72
|
+
exclude?: TExclude
|
73
|
+
format?: TFormat
|
74
|
+
}) =>
|
75
|
+
(data: TSource & { [key: string]: unknown }) => {
|
76
|
+
const formatted = format(data)
|
77
|
+
if (exclude) {
|
78
|
+
for (const key of exclude) {
|
79
|
+
delete (formatted as any)[key]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
return {
|
83
|
+
...formatted,
|
84
|
+
...formatOverride?.(data),
|
85
|
+
} as TFormatted &
|
86
|
+
ReturnType<TFormat> & {
|
87
|
+
[K in TExclude[number]]: never
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
@@ -5,6 +5,11 @@ import * as formatters from './index'
|
|
5
5
|
test('exports formatters', () => {
|
6
6
|
expect(formatters).toMatchInlineSnapshot(`
|
7
7
|
{
|
8
|
+
"defineBlock": [Function],
|
9
|
+
"defineFormatter": [Function],
|
10
|
+
"defineTransaction": [Function],
|
11
|
+
"defineTransactionReceipt": [Function],
|
12
|
+
"defineTransactionRequest": [Function],
|
8
13
|
"extract": [Function],
|
9
14
|
"format": [Function],
|
10
15
|
"formatBlock": [Function],
|
@@ -12,6 +17,11 @@ test('exports formatters', () => {
|
|
12
17
|
"formatTransaction": [Function],
|
13
18
|
"formatTransactionReceipt": [Function],
|
14
19
|
"formatTransactionRequest": [Function],
|
20
|
+
"transactionType": {
|
21
|
+
"0x0": "legacy",
|
22
|
+
"0x1": "eip2930",
|
23
|
+
"0x2": "eip1559",
|
24
|
+
},
|
15
25
|
}
|
16
26
|
`)
|
17
27
|
})
|
@@ -1,24 +1,34 @@
|
|
1
1
|
export type { BlockFormatter, FormattedBlock } from './block'
|
2
|
-
export { formatBlock } from './block'
|
2
|
+
export { defineBlock, formatBlock } from './block'
|
3
3
|
|
4
4
|
export { extract } from './extract'
|
5
5
|
|
6
6
|
export { formatFeeHistory } from './feeHistory'
|
7
7
|
|
8
8
|
export type { ExtractFormatter, FormatOptions, Formatted } from './format'
|
9
|
-
export { format } from './format'
|
9
|
+
export { defineFormatter, format } from './format'
|
10
10
|
|
11
11
|
export type { FormattedTransaction, TransactionFormatter } from './transaction'
|
12
|
-
export {
|
12
|
+
export {
|
13
|
+
defineTransaction,
|
14
|
+
formatTransaction,
|
15
|
+
transactionType,
|
16
|
+
} from './transaction'
|
13
17
|
|
14
18
|
export type {
|
15
19
|
FormattedTransactionReceipt,
|
16
20
|
TransactionReceiptFormatter,
|
17
21
|
} from './transactionReceipt'
|
18
|
-
export {
|
22
|
+
export {
|
23
|
+
defineTransactionReceipt,
|
24
|
+
formatTransactionReceipt,
|
25
|
+
} from './transactionReceipt'
|
19
26
|
|
20
27
|
export type {
|
21
28
|
FormattedTransactionRequest,
|
22
29
|
TransactionRequestFormatter,
|
23
30
|
} from './transactionRequest'
|
24
|
-
export {
|
31
|
+
export {
|
32
|
+
defineTransactionRequest,
|
33
|
+
formatTransactionRequest,
|
34
|
+
} from './transactionRequest'
|
@@ -1,8 +1,12 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
1
|
+
import type {
|
2
|
+
Chain,
|
3
|
+
Formatter,
|
4
|
+
Formatters,
|
5
|
+
RpcTransaction,
|
6
|
+
Transaction,
|
7
|
+
} from '../../types'
|
4
8
|
import { hexToNumber } from '../encoding'
|
5
|
-
import
|
9
|
+
import { defineFormatter, ExtractFormatter, Formatted } from './format'
|
6
10
|
|
7
11
|
export type TransactionFormatter<TChain extends Chain = Chain> =
|
8
12
|
ExtractFormatter<
|
@@ -15,6 +19,12 @@ export type FormattedTransaction<
|
|
15
19
|
TFormatter extends Formatter | undefined = Formatter,
|
16
20
|
> = Formatted<TFormatter, Transaction>
|
17
21
|
|
22
|
+
export const transactionType = {
|
23
|
+
'0x0': 'legacy',
|
24
|
+
'0x1': 'eip2930',
|
25
|
+
'0x2': 'eip1559',
|
26
|
+
} as const
|
27
|
+
|
18
28
|
export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
19
29
|
const transaction_ = {
|
20
30
|
...transaction,
|
@@ -49,3 +59,5 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
|
49
59
|
}
|
50
60
|
return transaction_ as Transaction
|
51
61
|
}
|
62
|
+
|
63
|
+
export const defineTransaction = defineFormatter({ format: formatTransaction })
|
@@ -1,9 +1,14 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
1
|
+
import type {
|
2
|
+
Chain,
|
3
|
+
Formatter,
|
4
|
+
Formatters,
|
5
|
+
RpcTransactionReceipt,
|
6
|
+
TransactionReceipt,
|
7
|
+
} from '../../types'
|
4
8
|
import { hexToNumber } from '../encoding'
|
5
|
-
import
|
9
|
+
import { defineFormatter, ExtractFormatter, Formatted } from './format'
|
6
10
|
import { formatLog } from './log'
|
11
|
+
import { transactionType } from './transaction'
|
7
12
|
|
8
13
|
export type TransactionReceiptFormatter<TChain extends Chain = Chain> =
|
9
14
|
ExtractFormatter<
|
@@ -52,3 +57,7 @@ export function formatTransactionReceipt(
|
|
52
57
|
: null,
|
53
58
|
} as TransactionReceipt
|
54
59
|
}
|
60
|
+
|
61
|
+
export const defineTransactionReceipt = defineFormatter({
|
62
|
+
format: formatTransactionReceipt,
|
63
|
+
})
|
@@ -1,6 +1,11 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
|
1
|
+
import type {
|
2
|
+
Chain,
|
3
|
+
Formatter,
|
4
|
+
Formatters,
|
5
|
+
RpcTransactionRequest,
|
6
|
+
TransactionRequest,
|
7
|
+
} from '../../types'
|
8
|
+
import { defineFormatter, ExtractFormatter, Formatted } from './format'
|
4
9
|
import { numberToHex } from '../encoding'
|
5
10
|
|
6
11
|
export type TransactionRequestFormatter<TChain extends Chain = Chain> =
|
@@ -45,3 +50,7 @@ export function formatTransactionRequest(
|
|
45
50
|
: undefined,
|
46
51
|
} as RpcTransactionRequest
|
47
52
|
}
|
53
|
+
|
54
|
+
export const defineTransactionRequest = defineFormatter({
|
55
|
+
format: formatTransactionRequest,
|
56
|
+
})
|
@@ -1,4 +1,4 @@
|
|
1
|
+
import { EventDefinition } from '../../types'
|
1
2
|
import { hashFunction } from './hashFunction'
|
2
3
|
|
3
|
-
export const getEventSignature = (event:
|
4
|
-
hashFunction(event)
|
4
|
+
export const getEventSignature = (event: EventDefinition) => hashFunction(event)
|
package/src/utils/index.test.ts
CHANGED
@@ -20,6 +20,12 @@ test('exports utils', () => {
|
|
20
20
|
"decodeFunctionResult": [Function],
|
21
21
|
"decodeHex": [Function],
|
22
22
|
"decodeRlp": [Function],
|
23
|
+
"defineBlock": [Function],
|
24
|
+
"defineChain": [Function],
|
25
|
+
"defineFormatter": [Function],
|
26
|
+
"defineTransaction": [Function],
|
27
|
+
"defineTransactionReceipt": [Function],
|
28
|
+
"defineTransactionRequest": [Function],
|
23
29
|
"encodeAbi": [Function],
|
24
30
|
"encodeBytes": [Function],
|
25
31
|
"encodeDeployData": [Function],
|
@@ -29,14 +35,18 @@ test('exports utils', () => {
|
|
29
35
|
"encodeFunctionResult": [Function],
|
30
36
|
"encodeHex": [Function],
|
31
37
|
"encodeRlp": [Function],
|
38
|
+
"etherUnits": {
|
39
|
+
"gwei": 9,
|
40
|
+
"wei": 18,
|
41
|
+
},
|
32
42
|
"extract": [Function],
|
33
43
|
"extractFunctionName": [Function],
|
34
44
|
"extractFunctionParams": [Function],
|
35
45
|
"extractFunctionParts": [Function],
|
36
46
|
"extractFunctionType": [Function],
|
37
47
|
"format": [Function],
|
48
|
+
"formatAbiItem": [Function],
|
38
49
|
"formatAbiItemWithArgs": [Function],
|
39
|
-
"formatAbiItemWithParams": [Function],
|
40
50
|
"formatBlock": [Function],
|
41
51
|
"formatEther": [Function],
|
42
52
|
"formatGwei": [Function],
|
@@ -51,6 +61,10 @@ test('exports utils', () => {
|
|
51
61
|
"getCreateAddress": [Function],
|
52
62
|
"getEventSignature": [Function],
|
53
63
|
"getFunctionSignature": [Function],
|
64
|
+
"gweiUnits": {
|
65
|
+
"ether": -9,
|
66
|
+
"wei": 9,
|
67
|
+
},
|
54
68
|
"hexToBigInt": [Function],
|
55
69
|
"hexToBool": [Function],
|
56
70
|
"hexToBytes": [Function],
|
@@ -81,7 +95,16 @@ test('exports utils', () => {
|
|
81
95
|
"stringToBytes": [Function],
|
82
96
|
"stringToHex": [Function],
|
83
97
|
"stringify": [Function],
|
98
|
+
"transactionType": {
|
99
|
+
"0x0": "legacy",
|
100
|
+
"0x1": "eip2930",
|
101
|
+
"0x2": "eip1559",
|
102
|
+
},
|
84
103
|
"trim": [Function],
|
104
|
+
"weiUnits": {
|
105
|
+
"ether": -18,
|
106
|
+
"gwei": -9,
|
107
|
+
},
|
85
108
|
}
|
86
109
|
`)
|
87
110
|
})
|
package/src/utils/index.ts
CHANGED
@@ -23,7 +23,7 @@ export {
|
|
23
23
|
encodeFunctionData,
|
24
24
|
encodeFunctionResult,
|
25
25
|
formatAbiItemWithArgs,
|
26
|
-
|
26
|
+
formatAbiItem,
|
27
27
|
getAbiItem,
|
28
28
|
} from './abi'
|
29
29
|
|
@@ -43,6 +43,8 @@ export {
|
|
43
43
|
|
44
44
|
export { buildRequest } from './buildRequest'
|
45
45
|
|
46
|
+
export { defineChain } from './chain'
|
47
|
+
|
46
48
|
export {
|
47
49
|
extractFunctionName,
|
48
50
|
extractFunctionParams,
|
@@ -77,11 +79,17 @@ export type {
|
|
77
79
|
TransactionRequestFormatter,
|
78
80
|
} from './formatters'
|
79
81
|
export {
|
82
|
+
defineBlock,
|
83
|
+
defineFormatter,
|
84
|
+
defineTransaction,
|
85
|
+
defineTransactionReceipt,
|
86
|
+
defineTransactionRequest,
|
80
87
|
extract,
|
81
88
|
format,
|
82
89
|
formatBlock,
|
83
90
|
formatTransaction,
|
84
91
|
formatTransactionRequest,
|
92
|
+
transactionType,
|
85
93
|
} from './formatters'
|
86
94
|
|
87
95
|
export type { EncodeRlpResponse } from './encoding'
|
@@ -117,10 +125,13 @@ export { rpc } from './rpc'
|
|
117
125
|
export { stringify } from './stringify'
|
118
126
|
|
119
127
|
export {
|
128
|
+
etherUnits,
|
120
129
|
formatEther,
|
121
130
|
formatGwei,
|
122
131
|
formatUnit,
|
132
|
+
gweiUnits,
|
123
133
|
parseUnit,
|
124
134
|
parseEther,
|
125
135
|
parseGwei,
|
136
|
+
weiUnits,
|
126
137
|
} from './unit'
|
@@ -5,12 +5,24 @@ import * as value from './index'
|
|
5
5
|
test('exports value utils', () => {
|
6
6
|
expect(value).toMatchInlineSnapshot(`
|
7
7
|
{
|
8
|
+
"etherUnits": {
|
9
|
+
"gwei": 9,
|
10
|
+
"wei": 18,
|
11
|
+
},
|
8
12
|
"formatEther": [Function],
|
9
13
|
"formatGwei": [Function],
|
10
14
|
"formatUnit": [Function],
|
15
|
+
"gweiUnits": {
|
16
|
+
"ether": -9,
|
17
|
+
"wei": 9,
|
18
|
+
},
|
11
19
|
"parseEther": [Function],
|
12
20
|
"parseGwei": [Function],
|
13
21
|
"parseUnit": [Function],
|
22
|
+
"weiUnits": {
|
23
|
+
"ether": -18,
|
24
|
+
"gwei": -9,
|
25
|
+
},
|
14
26
|
}
|
15
27
|
`)
|
16
28
|
})
|
package/src/utils/unit/index.ts
CHANGED