@@ -41,13 +41,12 @@ type EIP2930ValuesArray = [
41
41
export default class AccessListEIP2930Transaction extends BaseTransaction < AccessListEIP2930Transaction > {
42
42
public readonly chainId : BN
43
43
public readonly accessList : AccessListBuffer
44
+ public readonly AccessListJSON : AccessList
44
45
45
46
get transactionType ( ) : number {
46
47
return 1
47
48
}
48
49
49
- public readonly AccessListJSON : AccessList
50
-
51
50
// EIP-2930 alias for `s`
52
51
get senderS ( ) {
53
52
return this . s
@@ -59,16 +58,22 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
59
58
}
60
59
61
60
// EIP-2930 alias for `v`
62
-
63
61
get yParity ( ) {
64
62
return this . v
65
63
}
66
64
65
+ /**
66
+ * Instantiate a transaction from a data dictionary
67
+ */
67
68
public static fromTxData ( txData : AccessListEIP2930TxData , opts : TxOptions = { } ) {
68
69
return new AccessListEIP2930Transaction ( txData , opts )
69
70
}
70
71
71
- // Instantiate a transaction from the serialized tx. This means that the Buffer should start with 0x01.
72
+ /**
73
+ * Instantiate a transaction from the serialized tx.
74
+ *
75
+ * Note: this means that the Buffer should start with 0x01.
76
+ */
72
77
public static fromSerializedTx ( serialized : Buffer , opts : TxOptions = { } ) {
73
78
if ( serialized [ 0 ] !== 1 ) {
74
79
throw new Error (
@@ -84,14 +89,25 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
84
89
return AccessListEIP2930Transaction . fromValuesArray ( values , opts )
85
90
}
86
91
87
- // Instantiate a transaction from the serialized tx. This means that the Buffer should start with 0x01.
88
- // Alias of fromSerializedTx
92
+ /**
93
+ * Instantiate a transaction from the serialized tx.
94
+ * (alias of fromSerializedTx())
95
+ *
96
+ * Note: This means that the Buffer should start with 0x01.
97
+ *
98
+ * @deprecated this constructor alias is deprecated and will be removed
99
+ * in favor of the from SerializedTx() constructor
100
+ */
89
101
public static fromRlpSerializedTx ( serialized : Buffer , opts : TxOptions = { } ) {
90
102
return AccessListEIP2930Transaction . fromSerializedTx ( serialized , opts )
91
103
}
92
104
93
- // Create a transaction from a values array.
94
- // The format is: chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, [yParity, senderR, senderS]
105
+ /**
106
+ * Create a transaction from a values array.
107
+ *
108
+ * The format is:
109
+ * chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
110
+ */
95
111
public static fromValuesArray ( values : ( Buffer | AccessListBuffer ) [ ] , opts : TxOptions = { } ) {
96
112
if ( values . length == 8 || values . length == 11 ) {
97
113
const [ chainId , nonce , gasPrice , gasLimit , to , value , data , accessList , v , r , s ] = <
@@ -122,6 +138,10 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
122
138
}
123
139
}
124
140
141
+ /**
142
+ * This constructor takes the values, validates them, assigns them and freezes the object.
143
+ * Use the static factory methods to assist in creating a Transaction object from varying data types.
144
+ */
125
145
public constructor ( txData : AccessListEIP2930TxData , opts : TxOptions = { } ) {
126
146
const { chainId, accessList } = txData
127
147
@@ -236,6 +256,16 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
236
256
237
257
/**
238
258
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
259
+ *
260
+ * Note that if you want to use this function in a tx type independent way
261
+ * to then use the raw data output for tx instantiation with
262
+ * `Tx.fromValuesArray()` you should set the `asList` parameter to `true` -
263
+ * which is ignored on a legacy tx but provides the correct format on
264
+ * a typed tx.
265
+ *
266
+ * To prepare a tx to be added as block data with `Block.fromValuesArray()`
267
+ * just use the plain `raw()` method.
268
+ *
239
269
* @param asList - By default, this method returns a concatenated Buffer
240
270
* If this is not desired, then set this to `true`, to get a Buffer array.
241
271
*/
@@ -268,11 +298,17 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
268
298
return < Buffer > this . raw ( )
269
299
}
270
300
301
+ /**
302
+ * Computes a sha3-256 hash of the serialized unsigned tx, which is used to sign the transaction.
303
+ */
271
304
getMessageToSign ( ) {
272
305
const base = this . raw ( true ) . slice ( 0 , 8 )
273
306
return keccak256 ( Buffer . concat ( [ Buffer . from ( '01' , 'hex' ) , rlp . encode ( base ) ] ) )
274
307
}
275
308
309
+ /**
310
+ * Computes a sha3-256 hash of the serialized tx
311
+ */
276
312
public hash ( ) : Buffer {
277
313
if ( ! this . isSigned ( ) ) {
278
314
throw new Error ( 'Cannot call hash method if transaction is not signed' )
@@ -281,10 +317,16 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
281
317
return keccak256 ( this . serialize ( ) )
282
318
}
283
319
320
+ /**
321
+ * Computes a sha3-256 hash which can be used to verify the signature
322
+ */
284
323
public getMessageToVerifySignature ( ) : Buffer {
285
324
return this . getMessageToSign ( )
286
325
}
287
326
327
+ /**
328
+ * Returns the public key of the sender
329
+ */
288
330
public getSenderPublicKey ( ) : Buffer {
289
331
if ( ! this . isSigned ( ) ) {
290
332
throw new Error ( 'Cannot call this method if transaction is not signed' )
0 commit comments