@@ -32,9 +32,9 @@ import {
32
32
AccessList ,
33
33
AccessListUint8Array ,
34
34
FeeMarketEIP1559TxData ,
35
- FeeMarketEIP1559ValuesArray ,
36
35
JsonTx ,
37
36
TxOptions ,
37
+ TxValuesArray ,
38
38
} from 'web3-eth-accounts' ;
39
39
40
40
const { getAccessListData, getAccessListJSON, getDataFeeEIP2930, verifyAccessList } = txUtils ;
@@ -43,19 +43,40 @@ const MAX_INTEGER = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffff
43
43
export const TRANSACTION_TYPE = 15 ;
44
44
const TRANSACTION_TYPE_UINT8ARRAY = hexToBytes ( TRANSACTION_TYPE . toString ( 16 ) . padStart ( 2 , '0' ) ) ;
45
45
46
+ type CustomFieldTxValuesArray = [
47
+ Uint8Array ,
48
+ Uint8Array ,
49
+ Uint8Array ,
50
+ Uint8Array ,
51
+ Uint8Array ,
52
+ Uint8Array ,
53
+ Uint8Array ,
54
+ Uint8Array ,
55
+ AccessListUint8Array ,
56
+ Uint8Array ,
57
+ Uint8Array ?,
58
+ Uint8Array ?,
59
+ Uint8Array ?,
60
+ ] ;
61
+
62
+ type SomeNewTxTypeTxData = FeeMarketEIP1559TxData & {
63
+ customTestField : bigint ;
64
+ } ;
65
+
46
66
/**
47
67
* Typed transaction with a new gas fee market mechanism
48
68
*
49
69
* - TransactionType: 2
50
70
* - EIP: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
51
71
*/
52
72
// eslint-disable-next-line no-use-before-define
53
- export class SomeNewTxTypeTransaction extends BaseTransaction < FeeMarketEIP1559Transaction > {
73
+ export class SomeNewTxTypeTransaction extends BaseTransaction < SomeNewTxTypeTransaction > {
54
74
public readonly chainId : bigint ;
55
75
public readonly accessList : AccessListUint8Array ;
56
76
public readonly AccessListJSON : AccessList ;
57
77
public readonly maxPriorityFeePerGas : bigint ;
58
78
public readonly maxFeePerGas : bigint ;
79
+ public readonly customTestField : bigint ;
59
80
60
81
public readonly common : Common ;
61
82
@@ -77,7 +98,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
77
98
* - `chainId` will be set automatically if not provided
78
99
* - All parameters are optional and have some basic default values
79
100
*/
80
- public static fromTxData ( txData : FeeMarketEIP1559TxData , opts : TxOptions = { } ) {
101
+ public static fromTxData ( txData : SomeNewTxTypeTxData , opts : TxOptions = { } ) {
81
102
return new SomeNewTxTypeTransaction ( txData , opts ) ;
82
103
}
83
104
@@ -110,10 +131,10 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
110
131
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
111
132
* accessList, signatureYParity, signatureR, signatureS]`
112
133
*/
113
- public static fromValuesArray ( values : FeeMarketEIP1559ValuesArray , opts : TxOptions = { } ) {
114
- if ( values . length !== 9 && values . length !== 12 ) {
134
+ public static fromValuesArray ( values : CustomFieldTxValuesArray , opts : TxOptions = { } ) {
135
+ if ( values . length !== 10 && values . length !== 13 ) {
115
136
throw new Error (
116
- 'Invalid EIP-1559 transaction. Only expecting 9 values (for unsigned tx) or 12 values (for signed tx).' ,
137
+ 'Invalid CUSTOM TEST transaction. Only expecting 10 values (for unsigned tx) or 13 values (for signed tx).' ,
117
138
) ;
118
139
}
119
140
@@ -127,6 +148,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
127
148
value ,
128
149
data ,
129
150
accessList ,
151
+ customTestField ,
130
152
v ,
131
153
r ,
132
154
s ,
@@ -144,7 +166,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
144
166
s,
145
167
} ) ;
146
168
147
- return new FeeMarketEIP1559Transaction (
169
+ return new SomeNewTxTypeTransaction (
148
170
{
149
171
chainId : uint8ArrayToBigInt ( chainId ) ,
150
172
nonce,
@@ -155,6 +177,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
155
177
value,
156
178
data,
157
179
accessList : accessList ?? [ ] ,
180
+ customTestField : uint8ArrayToBigInt ( customTestField ) ,
158
181
v : v !== undefined ? uint8ArrayToBigInt ( v ) : undefined , // EIP2930 supports v's with value 0 (empty Uint8Array)
159
182
r,
160
183
s,
@@ -170,12 +193,13 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
170
193
* the static factory methods to assist in creating a Transaction object from
171
194
* varying data types.
172
195
*/
173
- public constructor ( txData : FeeMarketEIP1559TxData , opts : TxOptions = { } ) {
196
+ public constructor ( txData : SomeNewTxTypeTxData , opts : TxOptions = { } ) {
174
197
super ( { ...txData , type : TRANSACTION_TYPE } , opts ) ;
175
- const { chainId, accessList, maxFeePerGas, maxPriorityFeePerGas } = txData ;
198
+ const { chainId, accessList, maxFeePerGas, maxPriorityFeePerGas, customTestField } = txData ;
176
199
177
200
this . common = this . _getCommon ( opts . common , chainId ) ;
178
201
this . chainId = this . common . chainId ( ) ;
202
+ this . customTestField = customTestField ;
179
203
180
204
if ( ! this . common . isActivatedEIP ( 1559 ) ) {
181
205
throw new Error ( 'EIP-1559 not enabled on Common' ) ;
@@ -272,7 +296,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
272
296
* signature parameters `v`, `r` and `s` for encoding. For an EIP-155 compliant
273
297
* representation for external signing use {@link FeeMarketEIP1559Transaction.getMessageToSign}.
274
298
*/
275
- public raw ( ) : FeeMarketEIP1559ValuesArray {
299
+ public raw ( ) : TxValuesArray {
276
300
return [
277
301
bigIntToUnpaddedUint8Array ( this . chainId ) ,
278
302
bigIntToUnpaddedUint8Array ( this . nonce ) ,
@@ -283,10 +307,11 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
283
307
bigIntToUnpaddedUint8Array ( this . value ) ,
284
308
this . data ,
285
309
this . accessList ,
310
+ bigIntToUnpaddedUint8Array ( this . customTestField ) ,
286
311
this . v !== undefined ? bigIntToUnpaddedUint8Array ( this . v ) : Uint8Array . from ( [ ] ) ,
287
312
this . r !== undefined ? bigIntToUnpaddedUint8Array ( this . r ) : Uint8Array . from ( [ ] ) ,
288
313
this . s !== undefined ? bigIntToUnpaddedUint8Array ( this . s ) : Uint8Array . from ( [ ] ) ,
289
- ] ;
314
+ ] as TxValuesArray ;
290
315
}
291
316
292
317
/**
@@ -384,7 +409,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
384
409
public _processSignature ( v : bigint , r : Uint8Array , s : Uint8Array ) {
385
410
const opts = { ...this . txOptions , common : this . common } ;
386
411
387
- return FeeMarketEIP1559Transaction . fromTxData (
412
+ return SomeNewTxTypeTransaction . fromTxData (
388
413
{
389
414
chainId : this . chainId ,
390
415
nonce : this . nonce ,
@@ -395,6 +420,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction<FeeMarketEIP1559Tr
395
420
value : this . value ,
396
421
data : this . data ,
397
422
accessList : this . accessList ,
423
+ customTestField : this . customTestField ,
398
424
v : v - BigInt ( 27 ) , // This looks extremely hacky: /util actually adds 27 to the value, the recovery bit is either 0 or 1.
399
425
r : uint8ArrayToBigInt ( r ) ,
400
426
s : uint8ArrayToBigInt ( s ) ,
0 commit comments