viem 1.4.2 → 1.5.2
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/accounts/index.js +1 -1
- package/dist/cjs/accounts/index.js.map +1 -1
- package/dist/cjs/accounts/utils/signMessage.js +1 -1
- package/dist/cjs/accounts/utils/signMessage.js.map +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js.map +1 -1
- package/dist/cjs/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/createEventFilter.js +16 -8
- package/dist/cjs/actions/public/createEventFilter.js.map +1 -1
- package/dist/cjs/actions/public/getBlock.js +3 -1
- package/dist/cjs/actions/public/getBlock.js.map +1 -1
- package/dist/cjs/actions/public/getBlockNumber.js +2 -2
- package/dist/cjs/actions/public/getBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/getLogs.js +16 -10
- package/dist/cjs/actions/public/getLogs.js.map +1 -1
- package/dist/cjs/actions/public/getTransaction.js +2 -1
- package/dist/cjs/actions/public/getTransaction.js.map +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js +1 -1
- package/dist/cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/cjs/actions/public/watchBlocks.js +2 -1
- package/dist/cjs/actions/public/watchBlocks.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +3 -0
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js +7 -2
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/clients/createClient.js +2 -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/constants/number.js +101 -0
- package/dist/cjs/constants/number.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +110 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/formatters/block.js.map +1 -1
- package/dist/cjs/utils/formatters/formatter.js +1 -0
- package/dist/cjs/utils/formatters/formatter.js.map +1 -1
- package/dist/cjs/utils/formatters/transaction.js.map +1 -1
- package/dist/cjs/utils/hash/hashFunction.js +3 -2
- package/dist/cjs/utils/hash/hashFunction.js.map +1 -1
- package/dist/cjs/utils/promise/withCache.js +3 -3
- package/dist/cjs/utils/promise/withCache.js.map +1 -1
- package/dist/cjs/utils/signature/hexToSignature.js +12 -0
- package/dist/cjs/utils/signature/hexToSignature.js.map +1 -0
- package/dist/cjs/utils/signature/signatureToHex.js.map +1 -0
- package/dist/esm/accounts/index.js +1 -1
- package/dist/esm/accounts/index.js.map +1 -1
- package/dist/esm/accounts/utils/signMessage.js +1 -1
- package/dist/esm/accounts/utils/signMessage.js.map +1 -1
- package/dist/esm/accounts/utils/signTypedData.js +1 -1
- package/dist/esm/accounts/utils/signTypedData.js.map +1 -1
- package/dist/esm/actions/public/createContractEventFilter.js.map +1 -1
- package/dist/esm/actions/public/createEventFilter.js +16 -8
- package/dist/esm/actions/public/createEventFilter.js.map +1 -1
- package/dist/esm/actions/public/getBlock.js +3 -1
- package/dist/esm/actions/public/getBlock.js.map +1 -1
- package/dist/esm/actions/public/getBlockNumber.js +2 -2
- package/dist/esm/actions/public/getBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js +1 -1
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/getLogs.js +16 -10
- package/dist/esm/actions/public/getLogs.js.map +1 -1
- package/dist/esm/actions/public/getTransaction.js +2 -1
- package/dist/esm/actions/public/getTransaction.js.map +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js +1 -1
- package/dist/esm/actions/public/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/public/watchBlocks.js +2 -1
- package/dist/esm/actions/public/watchBlocks.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +5 -0
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js +9 -2
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/clients/createClient.js +2 -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/constants/number.js +97 -0
- package/dist/esm/constants/number.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/formatters/block.js.map +1 -1
- package/dist/esm/utils/formatters/formatter.js +1 -0
- package/dist/esm/utils/formatters/formatter.js.map +1 -1
- package/dist/esm/utils/formatters/transaction.js.map +1 -1
- package/dist/esm/utils/hash/hashFunction.js +3 -2
- package/dist/esm/utils/hash/hashFunction.js.map +1 -1
- package/dist/esm/utils/promise/withCache.js +3 -3
- package/dist/esm/utils/promise/withCache.js.map +1 -1
- package/dist/esm/utils/signature/hexToSignature.js +18 -0
- package/dist/esm/utils/signature/hexToSignature.js.map +1 -0
- package/dist/esm/utils/signature/signatureToHex.js +21 -0
- package/dist/esm/utils/signature/signatureToHex.js.map +1 -0
- package/dist/types/accounts/index.d.ts +1 -1
- package/dist/types/accounts/index.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +5 -5
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +20 -7
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/getBlock.d.ts +5 -5
- package/dist/types/actions/public/getBlock.d.ts.map +1 -1
- package/dist/types/actions/public/getBlockNumber.d.ts +4 -2
- package/dist/types/actions/public/getBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +5 -8
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +5 -4
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +17 -6
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getTransaction.d.ts +4 -4
- package/dist/types/actions/public/getTransaction.d.ts.map +1 -1
- package/dist/types/actions/public/watchBlocks.d.ts +10 -10
- package/dist/types/actions/public/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +19 -8
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/chains/formatters/celo.d.ts +4 -0
- package/dist/types/chains/formatters/celo.d.ts.map +1 -1
- package/dist/types/chains/formatters/optimism.d.ts +5 -3
- package/dist/types/chains/formatters/optimism.d.ts.map +1 -1
- package/dist/types/chains/index.d.ts +44 -12
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/clients/createClient.d.ts +7 -0
- package/dist/types/clients/createClient.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +1 -1
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +1 -1
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +10 -9
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/constants/number.d.ts +97 -0
- package/dist/types/constants/number.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/block.d.ts +7 -7
- package/dist/types/types/block.d.ts.map +1 -1
- package/dist/types/types/contract.d.ts +1 -1
- package/dist/types/types/contract.d.ts.map +1 -1
- package/dist/types/types/filter.d.ts +7 -3
- package/dist/types/types/filter.d.ts.map +1 -1
- package/dist/types/types/formatter.d.ts +3 -0
- package/dist/types/types/formatter.d.ts.map +1 -1
- package/dist/types/types/log.d.ts +8 -8
- package/dist/types/types/log.d.ts.map +1 -1
- package/dist/types/types/misc.d.ts.map +1 -1
- package/dist/types/types/rpc.d.ts +3 -3
- package/dist/types/types/rpc.d.ts.map +1 -1
- package/dist/types/types/transaction.d.ts +8 -8
- package/dist/types/types/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/block.d.ts +13 -3
- package/dist/types/utils/formatters/block.d.ts.map +1 -1
- package/dist/types/utils/formatters/formatter.d.ts +1 -0
- package/dist/types/utils/formatters/formatter.d.ts.map +1 -1
- package/dist/types/utils/formatters/transaction.d.ts +10 -3
- package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionReceipt.d.ts +1 -0
- package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +1 -0
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/hash/hashFunction.d.ts +1 -1
- package/dist/types/utils/hash/hashFunction.d.ts.map +1 -1
- package/dist/types/utils/promise/withCache.d.ts +3 -3
- package/dist/types/utils/promise/withCache.d.ts.map +1 -1
- package/dist/types/utils/signature/hexToSignature.d.ts +13 -0
- package/dist/types/utils/signature/hexToSignature.d.ts.map +1 -0
- package/dist/types/utils/signature/signatureToHex.d.ts +17 -0
- package/dist/types/utils/signature/signatureToHex.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/accounts/index.ts +1 -1
- package/src/accounts/utils/signMessage.ts +1 -1
- package/src/accounts/utils/signTypedData.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +30 -7
- package/src/actions/public/createEventFilter.ts +78 -24
- package/src/actions/public/getBlock.ts +18 -8
- package/src/actions/public/getBlockNumber.ts +5 -3
- package/src/actions/public/getFilterChanges.ts +46 -10
- package/src/actions/public/getFilterLogs.ts +26 -10
- package/src/actions/public/getLogs.ts +73 -18
- package/src/actions/public/getTransaction.ts +15 -8
- package/src/actions/public/watchBlockNumber.ts +1 -1
- package/src/actions/public/watchBlocks.ts +37 -18
- package/src/actions/public/watchContractEvent.ts +9 -5
- package/src/actions/public/watchEvent.ts +54 -17
- package/src/clients/createClient.ts +9 -0
- package/src/clients/createPublicClient.ts +7 -1
- package/src/clients/createTestClient.ts +7 -1
- package/src/clients/createWalletClient.ts +7 -1
- package/src/clients/decorators/public.ts +114 -25
- package/src/constants/number.ts +98 -0
- package/src/errors/version.ts +1 -1
- package/src/index.ts +101 -1
- package/src/types/block.ts +25 -10
- package/src/types/contract.ts +7 -3
- package/src/types/filter.ts +32 -26
- package/src/types/formatter.ts +9 -0
- package/src/types/log.ts +13 -8
- package/src/types/misc.ts +3 -0
- package/src/types/rpc.ts +20 -6
- package/src/types/transaction.ts +22 -11
- package/src/utils/formatters/block.ts +31 -4
- package/src/utils/formatters/formatter.ts +1 -0
- package/src/utils/formatters/transaction.ts +25 -2
- package/src/utils/hash/hashFunction.ts +3 -2
- package/src/utils/promise/withCache.ts +5 -5
- package/src/utils/signature/hexToSignature.ts +20 -0
- package/src/utils/signature/signatureToHex.ts +26 -0
- package/dist/cjs/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/esm/accounts/utils/signatureToHex.js +0 -7
- package/dist/esm/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/types/accounts/utils/signatureToHex.d.ts +0 -3
- package/dist/types/accounts/utils/signatureToHex.d.ts.map +0 -1
- package/src/accounts/utils/signatureToHex.ts +0 -12
- /package/dist/cjs/{accounts/utils → utils/signature}/signatureToHex.js +0 -0
package/src/types/log.ts
CHANGED
@@ -15,9 +15,12 @@ import type { Hash, Hex } from './misc.js'
|
|
15
15
|
export type Log<
|
16
16
|
TQuantity = bigint,
|
17
17
|
TIndex = number,
|
18
|
+
TPending extends boolean = boolean,
|
18
19
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
19
20
|
TStrict extends boolean | undefined = undefined,
|
20
|
-
TAbi extends Abi | readonly unknown[] =
|
21
|
+
TAbi extends Abi | readonly unknown[] | undefined = TAbiEvent extends AbiEvent
|
22
|
+
? [TAbiEvent]
|
23
|
+
: undefined,
|
21
24
|
TEventName extends string | undefined = TAbiEvent extends AbiEvent
|
22
25
|
? TAbiEvent['name']
|
23
26
|
: undefined,
|
@@ -25,17 +28,17 @@ export type Log<
|
|
25
28
|
/** The address from which this log originated */
|
26
29
|
address: Address
|
27
30
|
/** Hash of block containing this log or `null` if pending */
|
28
|
-
blockHash:
|
31
|
+
blockHash: TPending extends true ? null : Hash
|
29
32
|
/** Number of block containing this log or `null` if pending */
|
30
|
-
blockNumber:
|
33
|
+
blockNumber: TPending extends true ? null : TQuantity
|
31
34
|
/** Contains the non-indexed arguments of the log */
|
32
35
|
data: Hex
|
33
36
|
/** Index of this log within its block or `null` if pending */
|
34
|
-
logIndex:
|
37
|
+
logIndex: TPending extends true ? null : TIndex
|
35
38
|
/** Hash of the transaction that created this log or `null` if pending */
|
36
|
-
transactionHash:
|
39
|
+
transactionHash: TPending extends true ? null : Hash
|
37
40
|
/** Index of the transaction that created this log or `null` if pending */
|
38
|
-
transactionIndex:
|
41
|
+
transactionIndex: TPending extends true ? null : TIndex
|
39
42
|
/** `true` if this filter has been destroyed and is invalid */
|
40
43
|
removed: boolean
|
41
44
|
} & GetInferredLogValues<TAbiEvent, TAbi, TEventName, TStrict>
|
@@ -79,7 +82,9 @@ type GetTopics<
|
|
79
82
|
|
80
83
|
type GetInferredLogValues<
|
81
84
|
TAbiEvent extends AbiEvent | undefined = undefined,
|
82
|
-
TAbi extends Abi | readonly unknown[] =
|
85
|
+
TAbi extends Abi | readonly unknown[] | undefined = TAbiEvent extends AbiEvent
|
86
|
+
? [TAbiEvent]
|
87
|
+
: undefined,
|
83
88
|
TEventName extends string | undefined = TAbiEvent extends AbiEvent
|
84
89
|
? TAbiEvent['name']
|
85
90
|
: undefined,
|
@@ -110,7 +115,7 @@ type GetInferredLogValues<
|
|
110
115
|
[TName in _EventNames]: {
|
111
116
|
args: GetEventArgs<
|
112
117
|
TAbi,
|
113
|
-
|
118
|
+
TName,
|
114
119
|
{
|
115
120
|
EnableUnion: false
|
116
121
|
IndexedOnly: false
|
package/src/types/misc.ts
CHANGED
package/src/types/rpc.ts
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
Block,
|
3
|
+
BlockIdentifier,
|
4
|
+
BlockNumber,
|
5
|
+
BlockTag,
|
6
|
+
Uncle,
|
7
|
+
} from './block.js'
|
2
8
|
import type { FeeHistory, FeeValues } from './fee.js'
|
3
9
|
import type { Log } from './log.js'
|
4
10
|
import type {
|
@@ -17,7 +23,15 @@ export type Quantity = `0x${string}`
|
|
17
23
|
export type Status = '0x0' | '0x1'
|
18
24
|
export type TransactionType = '0x0' | '0x1' | '0x2' | (string & {})
|
19
25
|
|
20
|
-
export type RpcBlock
|
26
|
+
export type RpcBlock<
|
27
|
+
TBlockTag extends BlockTag = BlockTag,
|
28
|
+
TIncludeTransactions extends boolean = boolean,
|
29
|
+
> = Block<
|
30
|
+
Quantity,
|
31
|
+
TIncludeTransactions,
|
32
|
+
TBlockTag,
|
33
|
+
RpcTransaction<TBlockTag extends 'pending' ? true : false>
|
34
|
+
>
|
21
35
|
export type RpcBlockNumber = BlockNumber<Quantity>
|
22
36
|
export type RpcBlockIdentifier = BlockIdentifier<Quantity>
|
23
37
|
export type RpcUncle = Uncle<Quantity>
|
@@ -34,9 +48,9 @@ export type RpcTransactionRequest =
|
|
34
48
|
| TransactionRequestLegacy<Quantity, Index, '0x0'>
|
35
49
|
| TransactionRequestEIP2930<Quantity, Index, '0x1'>
|
36
50
|
| TransactionRequestEIP1559<Quantity, Index, '0x2'>
|
37
|
-
export type RpcTransaction = UnionOmit<
|
38
|
-
| TransactionLegacy<Quantity, Index, '0x0'>
|
39
|
-
| TransactionEIP2930<Quantity, Index, '0x1'>
|
40
|
-
| TransactionEIP1559<Quantity, Index, '0x2'>,
|
51
|
+
export type RpcTransaction<TPending extends boolean = boolean> = UnionOmit<
|
52
|
+
| TransactionLegacy<Quantity, Index, TPending, '0x0'>
|
53
|
+
| TransactionEIP2930<Quantity, Index, TPending, '0x1'>
|
54
|
+
| TransactionEIP1559<Quantity, Index, TPending, '0x2'>,
|
41
55
|
'typeHex'
|
42
56
|
>
|
package/src/types/transaction.ts
CHANGED
@@ -47,11 +47,15 @@ export type TransactionReceipt<
|
|
47
47
|
type: TType
|
48
48
|
}
|
49
49
|
|
50
|
-
export type TransactionBase<
|
50
|
+
export type TransactionBase<
|
51
|
+
TQuantity = bigint,
|
52
|
+
TIndex = number,
|
53
|
+
TPending extends boolean = boolean,
|
54
|
+
> = {
|
51
55
|
/** Hash of block containing this transaction or `null` if pending */
|
52
|
-
blockHash:
|
56
|
+
blockHash: TPending extends true ? null : Hash
|
53
57
|
/** Number of block containing this transaction or `null` if pending */
|
54
|
-
blockNumber:
|
58
|
+
blockNumber: TPending extends true ? null : TQuantity
|
55
59
|
/** Transaction sender */
|
56
60
|
from: Address
|
57
61
|
/** Gas provided for transaction execution */
|
@@ -69,7 +73,7 @@ export type TransactionBase<TQuantity = bigint, TIndex = number> = {
|
|
69
73
|
/** Transaction recipient or `null` if deploying a contract */
|
70
74
|
to: Address | null
|
71
75
|
/** Index of this transaction in the block or `null` if pending */
|
72
|
-
transactionIndex:
|
76
|
+
transactionIndex: TPending extends true ? null : TIndex
|
73
77
|
/** The type represented as hex. */
|
74
78
|
typeHex: Hex | null
|
75
79
|
/** ECDSA recovery ID */
|
@@ -80,8 +84,9 @@ export type TransactionBase<TQuantity = bigint, TIndex = number> = {
|
|
80
84
|
export type TransactionLegacy<
|
81
85
|
TQuantity = bigint,
|
82
86
|
TIndex = number,
|
87
|
+
TPending extends boolean = boolean,
|
83
88
|
TType = 'legacy',
|
84
|
-
> = TransactionBase<TQuantity, TIndex> &
|
89
|
+
> = TransactionBase<TQuantity, TIndex, TPending> &
|
85
90
|
FeeValuesLegacy<TQuantity> & {
|
86
91
|
accessList?: never
|
87
92
|
chainId?: TIndex
|
@@ -90,8 +95,9 @@ export type TransactionLegacy<
|
|
90
95
|
export type TransactionEIP2930<
|
91
96
|
TQuantity = bigint,
|
92
97
|
TIndex = number,
|
98
|
+
TPending extends boolean = boolean,
|
93
99
|
TType = 'eip2930',
|
94
|
-
> = TransactionBase<TQuantity, TIndex> &
|
100
|
+
> = TransactionBase<TQuantity, TIndex, TPending> &
|
95
101
|
FeeValuesLegacy<TQuantity> & {
|
96
102
|
accessList: AccessList
|
97
103
|
chainId: TIndex
|
@@ -100,17 +106,22 @@ export type TransactionEIP2930<
|
|
100
106
|
export type TransactionEIP1559<
|
101
107
|
TQuantity = bigint,
|
102
108
|
TIndex = number,
|
109
|
+
TPending extends boolean = boolean,
|
103
110
|
TType = 'eip1559',
|
104
|
-
> = TransactionBase<TQuantity, TIndex> &
|
111
|
+
> = TransactionBase<TQuantity, TIndex, TPending> &
|
105
112
|
FeeValuesEIP1559<TQuantity> & {
|
106
113
|
accessList: AccessList
|
107
114
|
chainId: TIndex
|
108
115
|
type: TType
|
109
116
|
}
|
110
|
-
export type Transaction<
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
export type Transaction<
|
118
|
+
TQuantity = bigint,
|
119
|
+
TIndex = number,
|
120
|
+
TPending extends boolean = boolean,
|
121
|
+
> =
|
122
|
+
| TransactionLegacy<TQuantity, TIndex, TPending>
|
123
|
+
| TransactionEIP2930<TQuantity, TIndex, TPending>
|
124
|
+
| TransactionEIP1559<TQuantity, TIndex, TPending>
|
114
125
|
|
115
126
|
export type TransactionRequestBase<TQuantity = bigint, TIndex = number> = {
|
116
127
|
/** Contract code or a hashed method call with encoded args */
|
@@ -1,14 +1,41 @@
|
|
1
|
-
import type { Block } from '../../types/block.js'
|
1
|
+
import type { Block, BlockTag } from '../../types/block.js'
|
2
2
|
import type { Chain } from '../../types/chain.js'
|
3
|
-
import type {
|
3
|
+
import type {
|
4
|
+
ExtractFormatterExclude,
|
5
|
+
ExtractFormatterReturnType,
|
6
|
+
} from '../../types/formatter.js'
|
7
|
+
import type { Hash } from '../../types/misc.js'
|
4
8
|
import type { RpcBlock } from '../../types/rpc.js'
|
9
|
+
import type { Prettify } from '../../types/utils.js'
|
5
10
|
|
6
11
|
import { defineFormatter } from './formatter.js'
|
7
|
-
import { formatTransaction } from './transaction.js'
|
12
|
+
import { type FormattedTransaction, formatTransaction } from './transaction.js'
|
13
|
+
|
14
|
+
type BlockPendingDependencies = 'hash' | 'logsBloom' | 'nonce' | 'number'
|
8
15
|
|
9
16
|
export type FormattedBlock<
|
10
17
|
TChain extends Chain | undefined = Chain | undefined,
|
11
|
-
|
18
|
+
TIncludeTransactions extends boolean = boolean,
|
19
|
+
TBlockTag extends BlockTag = BlockTag,
|
20
|
+
_FormatterReturnType = ExtractFormatterReturnType<
|
21
|
+
TChain,
|
22
|
+
'block',
|
23
|
+
Block<bigint, TIncludeTransactions>
|
24
|
+
>,
|
25
|
+
_ExcludedPendingDependencies extends string = BlockPendingDependencies &
|
26
|
+
ExtractFormatterExclude<TChain, 'block'>,
|
27
|
+
_Formatted = Omit<_FormatterReturnType, BlockPendingDependencies> & {
|
28
|
+
[K in _ExcludedPendingDependencies]: never
|
29
|
+
} & Pick<
|
30
|
+
Block<bigint, TIncludeTransactions, TBlockTag>,
|
31
|
+
BlockPendingDependencies
|
32
|
+
>,
|
33
|
+
_Transactions = TIncludeTransactions extends true
|
34
|
+
? Prettify<FormattedTransaction<TChain, TBlockTag>>[]
|
35
|
+
: Hash[],
|
36
|
+
> = Omit<_Formatted, 'transactions'> & {
|
37
|
+
transactions: _Transactions
|
38
|
+
}
|
12
39
|
|
13
40
|
export function formatBlock(block: Partial<RpcBlock>) {
|
14
41
|
const transactions = block.transactions?.map((transaction) => {
|
@@ -16,6 +16,7 @@ export function defineFormatter<TType extends string, TParameters, TReturnType>(
|
|
16
16
|
format: (_: TOverrideParameters) => TOverrideReturnType
|
17
17
|
}) => {
|
18
18
|
return {
|
19
|
+
exclude,
|
19
20
|
format: (args: TParameters & TOverrideParameters) => {
|
20
21
|
const formatted = format(args)
|
21
22
|
if (exclude) {
|
@@ -1,13 +1,36 @@
|
|
1
|
+
import type { BlockTag } from '../../types/block.js'
|
1
2
|
import type { Chain } from '../../types/chain.js'
|
2
|
-
import type {
|
3
|
+
import type {
|
4
|
+
ExtractFormatterExclude,
|
5
|
+
ExtractFormatterReturnType,
|
6
|
+
} from '../../types/formatter.js'
|
3
7
|
import type { RpcTransaction } from '../../types/rpc.js'
|
4
8
|
import type { Transaction } from '../../types/transaction.js'
|
9
|
+
import type { UnionOmit } from '../../types/utils.js'
|
5
10
|
import { hexToNumber } from '../encoding/fromHex.js'
|
6
11
|
import { defineFormatter } from './formatter.js'
|
7
12
|
|
13
|
+
type TransactionPendingDependencies =
|
14
|
+
| 'blockHash'
|
15
|
+
| 'blockNumber'
|
16
|
+
| 'transactionIndex'
|
17
|
+
|
8
18
|
export type FormattedTransaction<
|
9
19
|
TChain extends Chain | undefined = Chain | undefined,
|
10
|
-
|
20
|
+
TBlockTag extends BlockTag = BlockTag,
|
21
|
+
_FormatterReturnType = ExtractFormatterReturnType<
|
22
|
+
TChain,
|
23
|
+
'transaction',
|
24
|
+
Transaction
|
25
|
+
>,
|
26
|
+
_ExcludedPendingDependencies extends string = TransactionPendingDependencies &
|
27
|
+
ExtractFormatterExclude<TChain, 'transaction'>,
|
28
|
+
> = UnionOmit<_FormatterReturnType, TransactionPendingDependencies> & {
|
29
|
+
[K in _ExcludedPendingDependencies]: never
|
30
|
+
} & Pick<
|
31
|
+
Transaction<bigint, number, TBlockTag extends 'pending' ? true : false>,
|
32
|
+
TransactionPendingDependencies
|
33
|
+
>
|
11
34
|
|
12
35
|
export const transactionType = {
|
13
36
|
'0x0': 'legacy',
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { formatAbiItem } from '../abi/formatAbiItem.js'
|
1
2
|
import {
|
2
3
|
extractFunctionName,
|
3
4
|
extractFunctionParams,
|
@@ -15,6 +16,6 @@ export function hashFunction(def: string) {
|
|
15
16
|
return hash(`${name}(${params.map(({ type }) => type).join(',')})`)
|
16
17
|
}
|
17
18
|
|
18
|
-
export function hashAbiItem(
|
19
|
-
return hash(
|
19
|
+
export function hashAbiItem(abiItem: AbiFunction | AbiEvent) {
|
20
|
+
return hash(formatAbiItem(abiItem))
|
20
21
|
}
|
@@ -27,8 +27,8 @@ export function getCache<TData>(cacheKey: string) {
|
|
27
27
|
export type WithCacheParameters = {
|
28
28
|
/** The key to cache the data against. */
|
29
29
|
cacheKey: string
|
30
|
-
/** The
|
31
|
-
|
30
|
+
/** The time that cached data will remain in memory. Default: Infinity (no expiry) */
|
31
|
+
cacheTime?: number
|
32
32
|
}
|
33
33
|
|
34
34
|
/**
|
@@ -37,7 +37,7 @@ export type WithCacheParameters = {
|
|
37
37
|
*/
|
38
38
|
export async function withCache<TData>(
|
39
39
|
fn: () => Promise<TData>,
|
40
|
-
{ cacheKey,
|
40
|
+
{ cacheKey, cacheTime = Infinity }: WithCacheParameters,
|
41
41
|
) {
|
42
42
|
const cache = getCache<TData>(cacheKey)
|
43
43
|
|
@@ -45,9 +45,9 @@ export async function withCache<TData>(
|
|
45
45
|
// and do not invoke the promise.
|
46
46
|
// If the max age is 0, the cache is disabled.
|
47
47
|
const response = cache.response.get()
|
48
|
-
if (response &&
|
48
|
+
if (response && cacheTime > 0) {
|
49
49
|
const age = new Date().getTime() - response.created.getTime()
|
50
|
-
if (age <
|
50
|
+
if (age < cacheTime) return response.data
|
51
51
|
}
|
52
52
|
|
53
53
|
let promise = cache.promise.get()
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
+
|
3
|
+
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
+
import { numberToHex } from '../../utils/encoding/toHex.js'
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @description Parses a hex formatted signature into a structured signature.
|
8
|
+
*
|
9
|
+
* @param signatureHex Signature in hex format.
|
10
|
+
* @returns The structured signature.
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* hexToSignature('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')
|
14
|
+
* // { r: '0x...', s: '0x...', v: 28n }
|
15
|
+
*/
|
16
|
+
export function hexToSignature(signatureHex: Hex): Signature {
|
17
|
+
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
|
18
|
+
const v = BigInt(`0x${signatureHex.slice(130)}`)
|
19
|
+
return { r: numberToHex(r), s: numberToHex(s), v }
|
20
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
+
|
3
|
+
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
5
|
+
import { toHex } from '../../utils/encoding/toHex.js'
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @description Converts a signature into hex format.
|
9
|
+
*
|
10
|
+
* @param signature The signature to convert.
|
11
|
+
* @returns The signature in hex format.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* signatureToHex({
|
15
|
+
* r: '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf',
|
16
|
+
* s: '0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8',
|
17
|
+
* v: 28n
|
18
|
+
* })
|
19
|
+
* // "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"
|
20
|
+
*/
|
21
|
+
export function signatureToHex({ r, s, v }: Signature): Hex {
|
22
|
+
return `0x${new secp256k1.Signature(
|
23
|
+
hexToBigInt(r),
|
24
|
+
hexToBigInt(s),
|
25
|
+
).toCompactHex()}${toHex(v).slice(2)}`
|
26
|
+
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.js","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAGnD,gEAA6D;AAC7D,4DAAqD;AAErD,SAAgB,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAa;IACnD,OAAO,KAAK,IAAI,qBAAS,CAAC,SAAS,CACjC,IAAA,wBAAW,EAAC,CAAC,CAAC,EACd,IAAA,wBAAW,EAAC,CAAC,CAAC,CACf,CAAC,YAAY,EAAE,GAAG,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AACxC,CAAC;AALD,wCAKC"}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
2
|
-
import { hexToBigInt } from '../../utils/encoding/fromHex.js';
|
3
|
-
import { toHex } from '../../utils/encoding/toHex.js';
|
4
|
-
export function signatureToHex({ r, s, v }) {
|
5
|
-
return `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${toHex(v).slice(2)}`;
|
6
|
-
}
|
7
|
-
//# sourceMappingURL=signatureToHex.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.js","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,MAAM,UAAU,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAa;IACnD,OAAO,KAAK,IAAI,SAAS,CAAC,SAAS,CACjC,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,CAAC,CACf,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AACxC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.d.ts","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIzD,wBAAgB,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,GAAG,GAAG,CAK1D"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
-
|
3
|
-
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
-
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
5
|
-
import { toHex } from '../../utils/encoding/toHex.js'
|
6
|
-
|
7
|
-
export function signatureToHex({ r, s, v }: Signature): Hex {
|
8
|
-
return `0x${new secp256k1.Signature(
|
9
|
-
hexToBigInt(r),
|
10
|
-
hexToBigInt(s),
|
11
|
-
).toCompactHex()}${toHex(v).slice(2)}`
|
12
|
-
}
|
File without changes
|