Skip to content

Commit 8f8173d

Browse files
committed
add blob fields to transactions
1 parent 7421489 commit 8f8173d

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed

internal/common/transaction.go

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Transaction struct {
2828
FunctionSelector string `json:"function_selector" ch:"function_selector"`
2929
MaxFeePerGas *big.Int `json:"max_fee_per_gas" ch:"max_fee_per_gas" swaggertype:"string"`
3030
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"`
3133
TransactionType uint8 `json:"transaction_type" ch:"transaction_type"`
3234
R *big.Int `json:"r" ch:"r" swaggertype:"string"`
3335
S *big.Int `json:"s" ch:"s" swaggertype:"string"`
@@ -58,35 +60,37 @@ type DecodedTransaction struct {
5860

5961
// TransactionModel represents a simplified Transaction structure for Swagger documentation
6062
type TransactionModel struct {
61-
ChainId string `json:"chain_id"`
62-
Hash string `json:"hash"`
63-
Nonce uint64 `json:"nonce"`
64-
BlockHash string `json:"block_hash"`
65-
BlockNumber uint64 `json:"block_number"`
66-
BlockTimestamp uint64 `json:"block_timestamp"`
67-
TransactionIndex uint64 `json:"transaction_index"`
68-
FromAddress string `json:"from_address"`
69-
ToAddress string `json:"to_address"`
70-
Value string `json:"value"`
71-
Gas uint64 `json:"gas"`
72-
GasPrice string `json:"gas_price"`
73-
Data string `json:"data"`
74-
FunctionSelector string `json:"function_selector"`
75-
MaxFeePerGas string `json:"max_fee_per_gas"`
76-
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas"`
77-
TransactionType uint8 `json:"transaction_type"`
78-
R string `json:"r"`
79-
S string `json:"s"`
80-
V string `json:"v"`
81-
AccessListJson *string `json:"access_list_json"`
82-
ContractAddress *string `json:"contract_address"`
83-
GasUsed *uint64 `json:"gas_used"`
84-
CumulativeGasUsed *uint64 `json:"cumulative_gas_used"`
85-
EffectiveGasPrice *string `json:"effective_gas_price"`
86-
BlobGasUsed *uint64 `json:"blob_gas_used"`
87-
BlobGasPrice *string `json:"blob_gas_price"`
88-
LogsBloom *string `json:"logs_bloom"`
89-
Status *uint64 `json:"status"`
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"`
80+
BlobVersionedHashes *[]string `json:"blob_versioned_hashes"`
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"`
9094
}
9195

9296
type DecodedTransactionDataModel struct {
@@ -188,6 +192,8 @@ func (t *Transaction) Serialize() TransactionModel {
188192
FunctionSelector: t.FunctionSelector,
189193
MaxFeePerGas: t.MaxFeePerGas.String(),
190194
MaxPriorityFeePerGas: t.MaxPriorityFeePerGas.String(),
195+
MaxFeePerBlobGas: t.MaxFeePerBlobGas.String(),
196+
BlobVersionedHashes: t.BlobVersionedHashes,
191197
TransactionType: t.TransactionType,
192198
R: t.R.String(),
193199
S: t.S.String(),

internal/rpc/serializer.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,18 @@ func serializeTransaction(chainId *big.Int, tx map[string]interface{}, blockTime
189189
FunctionSelector: ExtractFunctionSelector(interfaceToString(tx["input"])),
190190
MaxFeePerGas: hexToBigInt(tx["maxFeePerGas"]),
191191
MaxPriorityFeePerGas: hexToBigInt(tx["maxPriorityFeePerGas"]),
192-
TransactionType: uint8(hexToUint64(tx["type"])),
193-
R: hexToBigInt(tx["r"]),
194-
S: hexToBigInt(tx["s"]),
195-
V: hexToBigInt(tx["v"]),
192+
MaxFeePerBlobGas: hexToBigInt(tx["maxFeePerBlobGas"]),
193+
BlobVersionedHashes: func() *[]string {
194+
if tx["blobVersionedHashes"] != nil {
195+
hashes := interfaceToStringSlice(tx["blobVersionedHashes"])
196+
return &hashes
197+
}
198+
return nil
199+
}(),
200+
TransactionType: uint8(hexToUint64(tx["type"])),
201+
R: hexToBigInt(tx["r"]),
202+
S: hexToBigInt(tx["s"]),
203+
V: hexToBigInt(tx["v"]),
196204
AccessListJson: func() *string {
197205
if tx["accessList"] != nil {
198206
jsonString := interfaceToJsonString(tx["accessList"])
@@ -429,6 +437,28 @@ func interfaceToString(value interface{}) string {
429437
return res
430438
}
431439

440+
func interfaceToStringSlice(value interface{}) []string {
441+
if value == nil {
442+
return []string{}
443+
}
444+
445+
// Handle []string case
446+
if res, ok := value.([]string); ok {
447+
return res
448+
}
449+
450+
// Handle []interface{} case
451+
if res, ok := value.([]interface{}); ok {
452+
strings := make([]string, len(res))
453+
for i, v := range res {
454+
strings[i] = interfaceToString(v)
455+
}
456+
return strings
457+
}
458+
459+
return []string{}
460+
}
461+
432462
func interfaceToJsonString(value interface{}) string {
433463
if value == nil {
434464
return ""

internal/storage/clickhouse.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (c *ClickHouseConnector) insertTransactions(txs []common.Transaction, opt I
194194
tableName := c.getTableName(txs[0].ChainId, "transactions")
195195
columns := []string{
196196
"chain_id", "hash", "nonce", "block_hash", "block_number", "block_timestamp", "transaction_index", "from_address", "to_address", "value", "gas",
197-
"gas_price", "data", "function_selector", "max_fee_per_gas", "max_priority_fee_per_gas", "transaction_type", "r", "s", "v", "access_list",
197+
"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",
198198
"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 {
@@ -230,6 +230,8 @@ func (c *ClickHouseConnector) insertTransactions(txs []common.Transaction, opt I
230230
tx.FunctionSelector,
231231
tx.MaxFeePerGas,
232232
tx.MaxPriorityFeePerGas,
233+
tx.MaxFeePerBlobGas,
234+
tx.BlobVersionedHashes,
233235
tx.TransactionType,
234236
tx.R,
235237
tx.S,

internal/tools/clickhouse_create_transactions_table.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ CREATE TABLE IF NOT EXISTS transactions (
1515
`function_selector` FixedString(10),
1616
`max_fee_per_gas` UInt128,
1717
`max_priority_fee_per_gas` UInt128,
18+
`max_fee_per_blob_gas` UInt256,
19+
`blob_versioned_hashes` Array(String),
1820
`transaction_type` UInt8,
1921
`r` UInt256,
2022
`s` UInt256,

0 commit comments

Comments
 (0)