Skip to content

Commit be84e77

Browse files
authored
Merge pull request #821 from onflow/mpeter/display-set-code-tx-auth-list
Return authorization list for `SetCodeTx` type
2 parents ae4a2c6 + 3ceea86 commit be84e77

File tree

4 files changed

+175
-46
lines changed

4 files changed

+175
-46
lines changed

eth/types/types.go

+53-22
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,29 @@ type StorageResult struct {
274274

275275
// Transaction represents a transaction that will serialize to the RPC representation of a transaction
276276
type Transaction struct {
277-
BlockHash *common.Hash `json:"blockHash"`
278-
BlockNumber *hexutil.Big `json:"blockNumber"`
279-
From common.MixedcaseAddress `json:"from"`
280-
Gas hexutil.Uint64 `json:"gas"`
281-
GasPrice *hexutil.Big `json:"gasPrice"`
282-
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
283-
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
284-
MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
285-
Hash common.Hash `json:"hash"`
286-
Input hexutil.Bytes `json:"input"`
287-
Nonce hexutil.Uint64 `json:"nonce"`
288-
To *common.MixedcaseAddress `json:"to"`
289-
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
290-
Value *hexutil.Big `json:"value"`
291-
Type hexutil.Uint64 `json:"type"`
292-
Accesses *types.AccessList `json:"accessList,omitempty"`
293-
ChainID *hexutil.Big `json:"chainId,omitempty"`
294-
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
295-
V *hexutil.Big `json:"v"`
296-
R *hexutil.Big `json:"r"`
297-
S *hexutil.Big `json:"s"`
298-
YParity *hexutil.Uint64 `json:"yParity,omitempty"`
277+
BlockHash *common.Hash `json:"blockHash"`
278+
BlockNumber *hexutil.Big `json:"blockNumber"`
279+
From common.MixedcaseAddress `json:"from"`
280+
Gas hexutil.Uint64 `json:"gas"`
281+
GasPrice *hexutil.Big `json:"gasPrice"`
282+
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
283+
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
284+
MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
285+
Hash common.Hash `json:"hash"`
286+
Input hexutil.Bytes `json:"input"`
287+
Nonce hexutil.Uint64 `json:"nonce"`
288+
To *common.MixedcaseAddress `json:"to"`
289+
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
290+
Value *hexutil.Big `json:"value"`
291+
Type hexutil.Uint64 `json:"type"`
292+
Accesses *types.AccessList `json:"accessList,omitempty"`
293+
ChainID *hexutil.Big `json:"chainId,omitempty"`
294+
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
295+
AuthorizationList []types.SetCodeAuthorization `json:"authorizationList,omitempty"`
296+
V *hexutil.Big `json:"v"`
297+
R *hexutil.Big `json:"r"`
298+
S *hexutil.Big `json:"s"`
299+
YParity *hexutil.Uint64 `json:"yParity,omitempty"`
299300

300301
size uint64
301302
}
@@ -344,6 +345,7 @@ func NewTransaction(
344345

345346
v, r, s := tx.RawSignatureValues()
346347

348+
// These are the common fields through all the transaction types
347349
result := &Transaction{
348350
Type: hexutil.Uint64(tx.Type()),
349351
From: from,
@@ -361,6 +363,29 @@ func NewTransaction(
361363
size: tx.Size(),
362364
}
363365

366+
// After the Pectra hard-fork, the full list of supported tx types is:
367+
// LegacyTxType = 0x00
368+
// AccessListTxType = 0x01
369+
// DynamicFeeTxType = 0x02
370+
// BlobTxType = 0x03
371+
// SetCodeTxType = 0x04
372+
373+
// Each newly-added tx type, is backwards-compatible.
374+
// It supports the fields of previous tx types and it
375+
// introduces its own fields as well. By comparing
376+
// with `if tx.Type() > SomeTxType`, we are
377+
// able to save some duplicated lines of code, and
378+
// incrementally apply the extra fields to their
379+
// respective tx type. For example, when:
380+
// `tx.Type()` is `DynamicFeeTxType`, the
381+
// following conditions are true:
382+
// `tx.Type() > LegacyTxType`
383+
// `tx.Type() > AccessListTxType`
384+
// but the rest are not.
385+
// A `DynamicFeeTxType` supports the fields of
386+
// `LegacyTxType` & `AccessListTxType`, but not
387+
// the fields of `SetCodeTxType`.
388+
364389
if tx.Type() > types.LegacyTxType {
365390
al := tx.AccessList()
366391
yparity := hexutil.Uint64(v.Sign())
@@ -381,6 +406,12 @@ func NewTransaction(
381406
result.BlobVersionedHashes = tx.BlobHashes()
382407
}
383408

409+
// The `AuthorizationList` field became available with the introduction
410+
// of https://eip7702.io/#specification, under the `SetCodeTxType`
411+
if tx.Type() > types.BlobTxType {
412+
result.AuthorizationList = tx.SetCodeAuthorizations()
413+
}
414+
384415
return result, nil
385416
}
386417

models/transaction.go

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Transaction interface {
4949
BlobHashes() []common.Hash
5050
Size() uint64
5151
AccessList() gethTypes.AccessList
52+
SetCodeAuthorizations() []gethTypes.SetCodeAuthorization
5253
MarshalBinary() ([]byte, error)
5354
}
5455

@@ -140,6 +141,10 @@ func (dc DirectCall) AccessList() gethTypes.AccessList {
140141
return gethTypes.AccessList{}
141142
}
142143

144+
func (dc DirectCall) SetCodeAuthorizations() []gethTypes.SetCodeAuthorization {
145+
return []gethTypes.SetCodeAuthorization{}
146+
}
147+
143148
func (dc DirectCall) MarshalBinary() ([]byte, error) {
144149
return dc.DirectCall.Encode()
145150
}

tests/web3js/eth_eip_7702_contract_write_test.js

+61-12
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,31 @@ it('should perform contract writes with relay account', async () => {
5454
})
5555

5656
await new Promise((res) => setTimeout(() => res(), 1500))
57-
let transaction = await publicClient.getTransactionReceipt({
57+
58+
let transaction = await publicClient.getTransaction({ hash: hash })
59+
assert.equal(transaction.from, relay.address)
60+
assert.equal(transaction.type, 'eip7702')
61+
assert.equal(transaction.input, '0x8129fc1c')
62+
assert.deepEqual(
63+
transaction.authorizationList,
64+
[
65+
{
66+
address: '0x313af46a48eeb56d200fae0edb741628255d379f',
67+
chainId: 646,
68+
nonce: 1,
69+
r: '0xa79ca044cfc5754e1fcd7e0007755dc1a98894f40a2a60436fd007fe3e0298d1',
70+
s: '0x2897829f726104b4175474d2100d6b11d7a26498debb1917d24fae324e91275c',
71+
yParity: 0
72+
}
73+
]
74+
)
75+
76+
let txReceipt = await publicClient.getTransactionReceipt({
5877
hash: hash
5978
})
60-
assert.equal(transaction.status, 'success')
61-
assert.equal(transaction.type, 'eip7702')
79+
assert.equal(txReceipt.from, relay.address)
80+
assert.equal(txReceipt.status, 'success')
81+
assert.equal(txReceipt.type, 'eip7702')
6282

6383
hash = await walletClient.writeContract({
6484
abi,
@@ -67,11 +87,18 @@ it('should perform contract writes with relay account', async () => {
6787
})
6888

6989
await new Promise((res) => setTimeout(() => res(), 1500))
70-
transaction = await publicClient.getTransactionReceipt({
90+
91+
transaction = await publicClient.getTransaction({ hash: hash })
92+
assert.equal(transaction.from, relay.address)
93+
assert.equal(transaction.type, 'eip1559')
94+
assert.equal(transaction.input, '0x5c36b186')
95+
96+
txReceipt = await publicClient.getTransactionReceipt({
7197
hash: hash
7298
})
73-
assert.equal(transaction.status, 'success')
74-
assert.equal(transaction.type, 'eip1559')
99+
assert.equal(txReceipt.from, relay.address)
100+
assert.equal(txReceipt.status, 'success')
101+
assert.equal(txReceipt.type, 'eip1559')
75102
})
76103

77104
it('should perform contract writes with self-execution', async () => {
@@ -90,11 +117,31 @@ it('should perform contract writes with self-execution', async () => {
90117
})
91118

92119
await new Promise((res) => setTimeout(() => res(), 1500))
93-
transaction = await publicClient.getTransactionReceipt({
120+
121+
let transaction = await publicClient.getTransaction({ hash: hash })
122+
assert.equal(transaction.from, relay.address)
123+
assert.equal(transaction.type, 'eip7702')
124+
assert.equal(transaction.input, '0x8129fc1c')
125+
assert.deepEqual(
126+
transaction.authorizationList,
127+
[
128+
{
129+
address: '0x313af46a48eeb56d200fae0edb741628255d379f',
130+
chainId: 646,
131+
nonce: 4,
132+
r: '0xf4bc19cca28390f3628cfcda9076a8744b77cc87fa4f7745efa83b7a06cc3514',
133+
s: '0x1d736fecc68ee92ab6fd805d91a3e3dbf27097d3578561402d7105eeeee00bb7',
134+
yParity: 0
135+
}
136+
]
137+
)
138+
139+
let txReceipt = await publicClient.getTransactionReceipt({
94140
hash: hash
95141
})
96-
assert.equal(transaction.status, 'success')
97-
assert.equal(transaction.type, 'eip7702')
142+
assert.equal(txReceipt.from, relay.address)
143+
assert.equal(txReceipt.status, 'success')
144+
assert.equal(txReceipt.type, 'eip7702')
98145

99146
hash = await walletClient.writeContract({
100147
abi,
@@ -103,9 +150,11 @@ it('should perform contract writes with self-execution', async () => {
103150
})
104151

105152
await new Promise((res) => setTimeout(() => res(), 1500))
106-
transaction = await publicClient.getTransactionReceipt({
153+
154+
txReceipt = await publicClient.getTransactionReceipt({
107155
hash: hash
108156
})
109-
assert.equal(transaction.status, 'success')
110-
assert.equal(transaction.type, 'eip1559')
157+
assert.equal(txReceipt.from, relay.address)
158+
assert.equal(txReceipt.status, 'success')
159+
assert.equal(txReceipt.type, 'eip1559')
111160
})

tests/web3js/eth_eip_7702_sending_transactions_test.js

+56-12
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,31 @@ it('should send transactions with relay account', async () => {
5757
})
5858

5959
await new Promise((res) => setTimeout(() => res(), 1500))
60-
let transaction = await publicClient.getTransactionReceipt({
60+
61+
let transaction = await publicClient.getTransaction({ hash: hash })
62+
assert.equal(transaction.from, relay.address)
63+
assert.equal(transaction.type, 'eip7702')
64+
assert.equal(transaction.input, '0x8129fc1c')
65+
assert.deepEqual(
66+
transaction.authorizationList,
67+
[
68+
{
69+
address: '0x313af46a48eeb56d200fae0edb741628255d379f',
70+
chainId: 646,
71+
nonce: 1,
72+
r: '0xa79ca044cfc5754e1fcd7e0007755dc1a98894f40a2a60436fd007fe3e0298d1',
73+
s: '0x2897829f726104b4175474d2100d6b11d7a26498debb1917d24fae324e91275c',
74+
yParity: 0
75+
}
76+
]
77+
)
78+
79+
let txReceipt = await publicClient.getTransactionReceipt({
6180
hash: hash
6281
})
63-
assert.equal(transaction.status, 'success')
64-
assert.equal(transaction.type, 'eip7702')
82+
assert.equal(txReceipt.from, relay.address)
83+
assert.equal(txReceipt.status, 'success')
84+
assert.equal(txReceipt.type, 'eip7702')
6585

6686
hash = await walletClient.sendTransaction({
6787
data: encodeFunctionData({
@@ -72,11 +92,13 @@ it('should send transactions with relay account', async () => {
7292
})
7393

7494
await new Promise((res) => setTimeout(() => res(), 1500))
75-
transaction = await publicClient.getTransactionReceipt({
95+
96+
txReceipt = await publicClient.getTransactionReceipt({
7697
hash: hash
7798
})
78-
assert.equal(transaction.status, 'success')
79-
assert.equal(transaction.type, 'eip1559')
99+
assert.equal(txReceipt.from, relay.address)
100+
assert.equal(txReceipt.status, 'success')
101+
assert.equal(txReceipt.type, 'eip1559')
80102
})
81103

82104
it('should send self-executing transactions', async () => {
@@ -97,11 +119,31 @@ it('should send self-executing transactions', async () => {
97119
})
98120

99121
await new Promise((res) => setTimeout(() => res(), 1500))
100-
let transaction = await publicClient.getTransactionReceipt({
122+
123+
let transaction = await publicClient.getTransaction({ hash: hash })
124+
assert.equal(transaction.from, relay.address)
125+
assert.equal(transaction.type, 'eip7702')
126+
assert.equal(transaction.input, '0x8129fc1c')
127+
assert.deepEqual(
128+
transaction.authorizationList,
129+
[
130+
{
131+
address: '0x313af46a48eeb56d200fae0edb741628255d379f',
132+
chainId: 646,
133+
nonce: 4,
134+
r: '0xf4bc19cca28390f3628cfcda9076a8744b77cc87fa4f7745efa83b7a06cc3514',
135+
s: '0x1d736fecc68ee92ab6fd805d91a3e3dbf27097d3578561402d7105eeeee00bb7',
136+
yParity: 0
137+
}
138+
]
139+
)
140+
141+
let txReceipt = await publicClient.getTransactionReceipt({
101142
hash: hash
102143
})
103-
assert.equal(transaction.status, 'success')
104-
assert.equal(transaction.type, 'eip7702')
144+
assert.equal(txReceipt.from, relay.address)
145+
assert.equal(txReceipt.status, 'success')
146+
assert.equal(txReceipt.type, 'eip7702')
105147

106148
hash = await walletClient.sendTransaction({
107149
data: encodeFunctionData({
@@ -112,9 +154,11 @@ it('should send self-executing transactions', async () => {
112154
})
113155

114156
await new Promise((res) => setTimeout(() => res(), 1500))
115-
transaction = await publicClient.getTransactionReceipt({
157+
158+
txReceipt = await publicClient.getTransactionReceipt({
116159
hash: hash
117160
})
118-
assert.equal(transaction.status, 'success')
119-
assert.equal(transaction.type, 'eip1559')
161+
assert.equal(txReceipt.from, relay.address)
162+
assert.equal(txReceipt.status, 'success')
163+
assert.equal(txReceipt.type, 'eip1559')
120164
})

0 commit comments

Comments
 (0)