Skip to content

Commit 210ebd3

Browse files
authored
include auth list in tx data for ERC-7702 (#200)
### TL;DR Added support for transaction authorization lists in the transaction data model. ### What changed? - Added a new `AuthorizationListJson` field to the `Transaction` and `TransactionModel` structs - Updated the serializer to extract and process authorization list data from transactions - Modified ClickHouse database schema to include the new `authorization_list` column - Updated SQL scripts for table creation and data insertion to accommodate the new field - Adjusted database operations to handle the new field during transaction insertions ### How to test? 1. Deploy the updated schema to a test environment 2. Process transactions that include authorization lists 3. Verify that the authorization list data is correctly stored in the database 4. Query transactions with authorization lists to ensure the data is retrievable 5. Check that existing functionality continues to work with the schema changes ### Why make this change? This change adds support for authorization lists in transactions, which is a feature in ERC-7702. By storing this data, the system can now track and analyze transactions that utilize authorization lists, and validate transcation type 4
2 parents 16ce7e8 + dad9f7b commit 210ebd3

File tree

6 files changed

+101
-83
lines changed

6 files changed

+101
-83
lines changed

internal/common/transaction.go

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,40 @@ import (
1212
)
1313

1414
type Transaction struct {
15-
ChainId *big.Int `json:"chain_id" ch:"chain_id" swaggertype:"string"`
16-
Hash string `json:"hash" ch:"hash"`
17-
Nonce uint64 `json:"nonce" ch:"nonce"`
18-
BlockHash string `json:"block_hash" ch:"block_hash"`
19-
BlockNumber *big.Int `json:"block_number" ch:"block_number" swaggertype:"string"`
20-
BlockTimestamp time.Time `json:"block_timestamp" ch:"block_timestamp"`
21-
TransactionIndex uint64 `json:"transaction_index" ch:"transaction_index"`
22-
FromAddress string `json:"from_address" ch:"from_address"`
23-
ToAddress string `json:"to_address" ch:"to_address"`
24-
Value *big.Int `json:"value" ch:"value" swaggertype:"string"`
25-
Gas uint64 `json:"gas" ch:"gas"`
26-
GasPrice *big.Int `json:"gas_price" ch:"gas_price" swaggertype:"string"`
27-
Data string `json:"data" ch:"data"`
28-
FunctionSelector string `json:"function_selector" ch:"function_selector"`
29-
MaxFeePerGas *big.Int `json:"max_fee_per_gas" ch:"max_fee_per_gas" swaggertype:"string"`
30-
MaxPriorityFeePerGas *big.Int `json:"max_priority_fee_per_gas" ch:"max_priority_fee_per_gas" swaggertype:"string"`
31-
MaxFeePerBlobGas *big.Int `json:"max_fee_per_blob_gas" ch:"max_fee_per_blob_gas" swaggertype:"string"`
32-
BlobVersionedHashes []string `json:"blob_versioned_hashes" ch:"blob_versioned_hashes"`
33-
TransactionType uint8 `json:"transaction_type" ch:"transaction_type"`
34-
R *big.Int `json:"r" ch:"r" swaggertype:"string"`
35-
S *big.Int `json:"s" ch:"s" swaggertype:"string"`
36-
V *big.Int `json:"v" ch:"v" swaggertype:"string"`
37-
AccessListJson *string `json:"access_list_json" ch:"access_list"`
38-
ContractAddress *string `json:"contract_address" ch:"contract_address"`
39-
GasUsed *uint64 `json:"gas_used" ch:"gas_used"`
40-
CumulativeGasUsed *uint64 `json:"cumulative_gas_used" ch:"cumulative_gas_used"`
41-
EffectiveGasPrice *big.Int `json:"effective_gas_price" ch:"effective_gas_price" swaggertype:"string"`
42-
BlobGasUsed *uint64 `json:"blob_gas_used" ch:"blob_gas_used"`
43-
BlobGasPrice *big.Int `json:"blob_gas_price" ch:"blob_gas_price" swaggertype:"string"`
44-
LogsBloom *string `json:"logs_bloom" ch:"logs_bloom"`
45-
Status *uint64 `json:"status" ch:"status"`
46-
Sign int8 `json:"sign" ch:"sign"`
47-
InsertTimestamp time.Time `json:"insert_timestamp" ch:"insert_timestamp"`
15+
ChainId *big.Int `json:"chain_id" ch:"chain_id" swaggertype:"string"`
16+
Hash string `json:"hash" ch:"hash"`
17+
Nonce uint64 `json:"nonce" ch:"nonce"`
18+
BlockHash string `json:"block_hash" ch:"block_hash"`
19+
BlockNumber *big.Int `json:"block_number" ch:"block_number" swaggertype:"string"`
20+
BlockTimestamp time.Time `json:"block_timestamp" ch:"block_timestamp"`
21+
TransactionIndex uint64 `json:"transaction_index" ch:"transaction_index"`
22+
FromAddress string `json:"from_address" ch:"from_address"`
23+
ToAddress string `json:"to_address" ch:"to_address"`
24+
Value *big.Int `json:"value" ch:"value" swaggertype:"string"`
25+
Gas uint64 `json:"gas" ch:"gas"`
26+
GasPrice *big.Int `json:"gas_price" ch:"gas_price" swaggertype:"string"`
27+
Data string `json:"data" ch:"data"`
28+
FunctionSelector string `json:"function_selector" ch:"function_selector"`
29+
MaxFeePerGas *big.Int `json:"max_fee_per_gas" ch:"max_fee_per_gas" swaggertype:"string"`
30+
MaxPriorityFeePerGas *big.Int `json:"max_priority_fee_per_gas" ch:"max_priority_fee_per_gas" swaggertype:"string"`
31+
MaxFeePerBlobGas *big.Int `json:"max_fee_per_blob_gas" ch:"max_fee_per_blob_gas" swaggertype:"string"`
32+
BlobVersionedHashes []string `json:"blob_versioned_hashes" ch:"blob_versioned_hashes"`
33+
TransactionType uint8 `json:"transaction_type" ch:"transaction_type"`
34+
R *big.Int `json:"r" ch:"r" swaggertype:"string"`
35+
S *big.Int `json:"s" ch:"s" swaggertype:"string"`
36+
V *big.Int `json:"v" ch:"v" swaggertype:"string"`
37+
AccessListJson *string `json:"access_list_json" ch:"access_list"`
38+
AuthorizationListJson *string `json:"authorization_list_json" ch:"authorization_list"`
39+
ContractAddress *string `json:"contract_address" ch:"contract_address"`
40+
GasUsed *uint64 `json:"gas_used" ch:"gas_used"`
41+
CumulativeGasUsed *uint64 `json:"cumulative_gas_used" ch:"cumulative_gas_used"`
42+
EffectiveGasPrice *big.Int `json:"effective_gas_price" ch:"effective_gas_price" swaggertype:"string"`
43+
BlobGasUsed *uint64 `json:"blob_gas_used" ch:"blob_gas_used"`
44+
BlobGasPrice *big.Int `json:"blob_gas_price" ch:"blob_gas_price" swaggertype:"string"`
45+
LogsBloom *string `json:"logs_bloom" ch:"logs_bloom"`
46+
Status *uint64 `json:"status" ch:"status"`
47+
Sign int8 `json:"sign" ch:"sign"`
48+
InsertTimestamp time.Time `json:"insert_timestamp" ch:"insert_timestamp"`
4849
}
4950

5051
type DecodedTransactionData struct {
@@ -60,37 +61,38 @@ type DecodedTransaction struct {
6061

6162
// TransactionModel represents a simplified Transaction structure for Swagger documentation
6263
type TransactionModel struct {
63-
ChainId string `json:"chain_id"`
64-
Hash string `json:"hash"`
65-
Nonce uint64 `json:"nonce"`
66-
BlockHash string `json:"block_hash"`
67-
BlockNumber uint64 `json:"block_number"`
68-
BlockTimestamp uint64 `json:"block_timestamp"`
69-
TransactionIndex uint64 `json:"transaction_index"`
70-
FromAddress string `json:"from_address"`
71-
ToAddress string `json:"to_address"`
72-
Value string `json:"value"`
73-
Gas uint64 `json:"gas"`
74-
GasPrice string `json:"gas_price"`
75-
Data string `json:"data"`
76-
FunctionSelector string `json:"function_selector"`
77-
MaxFeePerGas string `json:"max_fee_per_gas"`
78-
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas"`
79-
MaxFeePerBlobGas *string `json:"max_fee_per_blob_gas,omitempty"`
80-
BlobVersionedHashes []string `json:"blob_versioned_hashes,omitempty"`
81-
TransactionType uint8 `json:"transaction_type"`
82-
R string `json:"r"`
83-
S string `json:"s"`
84-
V string `json:"v"`
85-
AccessListJson *string `json:"access_list_json"`
86-
ContractAddress *string `json:"contract_address"`
87-
GasUsed *uint64 `json:"gas_used"`
88-
CumulativeGasUsed *uint64 `json:"cumulative_gas_used"`
89-
EffectiveGasPrice *string `json:"effective_gas_price"`
90-
BlobGasUsed *uint64 `json:"blob_gas_used"`
91-
BlobGasPrice *string `json:"blob_gas_price"`
92-
LogsBloom *string `json:"logs_bloom"`
93-
Status *uint64 `json:"status"`
64+
ChainId string `json:"chain_id"`
65+
Hash string `json:"hash"`
66+
Nonce uint64 `json:"nonce"`
67+
BlockHash string `json:"block_hash"`
68+
BlockNumber uint64 `json:"block_number"`
69+
BlockTimestamp uint64 `json:"block_timestamp"`
70+
TransactionIndex uint64 `json:"transaction_index"`
71+
FromAddress string `json:"from_address"`
72+
ToAddress string `json:"to_address"`
73+
Value string `json:"value"`
74+
Gas uint64 `json:"gas"`
75+
GasPrice string `json:"gas_price"`
76+
Data string `json:"data"`
77+
FunctionSelector string `json:"function_selector"`
78+
MaxFeePerGas string `json:"max_fee_per_gas"`
79+
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas"`
80+
MaxFeePerBlobGas *string `json:"max_fee_per_blob_gas,omitempty"`
81+
BlobVersionedHashes []string `json:"blob_versioned_hashes,omitempty"`
82+
TransactionType uint8 `json:"transaction_type"`
83+
R string `json:"r"`
84+
S string `json:"s"`
85+
V string `json:"v"`
86+
AccessListJson *string `json:"access_list_json"`
87+
AuthorizationListJson *string `json:"authorization_list_json"`
88+
ContractAddress *string `json:"contract_address"`
89+
GasUsed *uint64 `json:"gas_used"`
90+
CumulativeGasUsed *uint64 `json:"cumulative_gas_used"`
91+
EffectiveGasPrice *string `json:"effective_gas_price"`
92+
BlobGasUsed *uint64 `json:"blob_gas_used"`
93+
BlobGasPrice *string `json:"blob_gas_price"`
94+
LogsBloom *string `json:"logs_bloom"`
95+
Status *uint64 `json:"status"`
9496
}
9597

9698
type DecodedTransactionDataModel struct {
@@ -199,15 +201,16 @@ func (t *Transaction) Serialize() TransactionModel {
199201
v := t.MaxFeePerBlobGas.String()
200202
return &v
201203
}(),
202-
BlobVersionedHashes: t.BlobVersionedHashes,
203-
TransactionType: t.TransactionType,
204-
R: t.R.String(),
205-
S: t.S.String(),
206-
V: t.V.String(),
207-
AccessListJson: t.AccessListJson,
208-
ContractAddress: t.ContractAddress,
209-
GasUsed: t.GasUsed,
210-
CumulativeGasUsed: t.CumulativeGasUsed,
204+
BlobVersionedHashes: t.BlobVersionedHashes,
205+
TransactionType: t.TransactionType,
206+
R: t.R.String(),
207+
S: t.S.String(),
208+
V: t.V.String(),
209+
AccessListJson: t.AccessListJson,
210+
AuthorizationListJson: t.AuthorizationListJson,
211+
ContractAddress: t.ContractAddress,
212+
GasUsed: t.GasUsed,
213+
CumulativeGasUsed: t.CumulativeGasUsed,
211214
EffectiveGasPrice: func() *string {
212215
if t.EffectiveGasPrice == nil {
213216
return nil

internal/rpc/serializer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ func serializeTransaction(chainId *big.Int, tx map[string]interface{}, blockTime
205205
}
206206
return nil
207207
}(),
208+
AuthorizationListJson: func() *string {
209+
if tx["authorizationList"] != nil {
210+
jsonString := interfaceToJsonString(tx["authorizationList"])
211+
if jsonString == "" {
212+
return nil
213+
}
214+
return &jsonString
215+
}
216+
return nil
217+
}(),
208218
ContractAddress: func() *string {
209219
if receipt != nil {
210220
contractAddress := interfaceToString((*receipt)["contractAddress"])

internal/storage/clickhouse.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var defaultTransactionFields = []string{
4545
"transaction_index", "from_address", "to_address", "value", "gas", "gas_price",
4646
"data", "function_selector", "max_fee_per_gas", "max_priority_fee_per_gas",
4747
"max_fee_per_blob_gas", "blob_versioned_hashes", "transaction_type", "r", "s", "v",
48-
"access_list", "contract_address", "gas_used", "cumulative_gas_used",
48+
"access_list", "authorization_list", "contract_address", "gas_used", "cumulative_gas_used",
4949
"effective_gas_price", "blob_gas_used", "blob_gas_price", "logs_bloom", "status",
5050
}
5151

@@ -195,7 +195,7 @@ func (c *ClickHouseConnector) insertTransactions(txs []common.Transaction, opt I
195195
columns := []string{
196196
"chain_id", "hash", "nonce", "block_hash", "block_number", "block_timestamp", "transaction_index", "from_address", "to_address", "value", "gas",
197197
"gas_price", "data", "function_selector", "max_fee_per_gas", "max_priority_fee_per_gas", "max_fee_per_blob_gas", "blob_versioned_hashes", "transaction_type", "r", "s", "v", "access_list",
198-
"contract_address", "gas_used", "cumulative_gas_used", "effective_gas_price", "blob_gas_used", "blob_gas_price", "logs_bloom", "status", "sign",
198+
"authorization_list", "contract_address", "gas_used", "cumulative_gas_used", "effective_gas_price", "blob_gas_used", "blob_gas_price", "logs_bloom", "status", "sign",
199199
}
200200
if opt.AsDeleted {
201201
columns = append(columns, "insert_timestamp")
@@ -237,6 +237,7 @@ func (c *ClickHouseConnector) insertTransactions(txs []common.Transaction, opt I
237237
tx.S,
238238
tx.V,
239239
tx.AccessListJson,
240+
tx.AuthorizationListJson,
240241
tx.ContractAddress,
241242
tx.GasUsed,
242243
tx.CumulativeGasUsed,
@@ -1228,6 +1229,7 @@ func (c *ClickHouseConnector) InsertBlockData(data []common.BlockData) error {
12281229
tx.S,
12291230
tx.V,
12301231
tx.AccessListJson,
1232+
tx.AuthorizationListJson,
12311233
tx.ContractAddress,
12321234
tx.GasUsed,
12331235
tx.CumulativeGasUsed,

internal/tools/clickhouse_create_insert_mvs.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ SELECT
5555
t.20 AS s,
5656
t.21 AS v,
5757
t.22 AS access_list,
58-
t.23 AS contract_address,
59-
t.24 AS gas_used,
60-
t.25 AS cumulative_gas_used,
61-
t.26 AS effective_gas_price,
62-
t.27 AS blob_gas_used,
63-
t.28 AS blob_gas_price,
64-
t.29 AS logs_bloom,
65-
t.30 AS status,
58+
t.23 AS authorization_list,
59+
t.24 AS contract_address,
60+
t.25 AS gas_used,
61+
t.26 AS cumulative_gas_used,
62+
t.27 AS effective_gas_price,
63+
t.28 AS blob_gas_used,
64+
t.29 AS blob_gas_price,
65+
t.30 AS logs_bloom,
66+
t.31 AS status,
6667
insert_timestamp,
6768
sign
6869
FROM inserts_null_table

internal/tools/clickhouse_create_insert_null_table.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS inserts_null_table (
4646
s UInt256,
4747
v UInt256,
4848
access_list Nullable(String),
49+
authorization_list Nullable(String),
4950
contract_address Nullable(FixedString(42)),
5051
gas_used Nullable(UInt64),
5152
cumulative_gas_used Nullable(UInt64),

internal/tools/clickhouse_create_transactions_table.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CREATE TABLE IF NOT EXISTS transactions (
2222
`s` UInt256,
2323
`v` UInt256,
2424
`access_list` Nullable(String),
25+
`authorization_list` Nullable(String),
2526
`contract_address` Nullable(FixedString(42)),
2627
`gas_used` Nullable(UInt64),
2728
`cumulative_gas_used` Nullable(UInt64),

0 commit comments

Comments
 (0)