Skip to content

Commit 6530945

Browse files
authored
internal/ethapi: Add timestamp to eth_getTransactionByHash (#33709)
Implements ethereum/execution-apis#729 and fixes #33491. It adds blockTimestamp to transaction objects returned by the RPC.
1 parent a951aac commit 6530945

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

internal/ethapi/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
974974
type RPCTransaction struct {
975975
BlockHash *common.Hash `json:"blockHash"`
976976
BlockNumber *hexutil.Big `json:"blockNumber"`
977+
BlockTimestamp *hexutil.Uint64 `json:"blockTimestamp"`
977978
From common.Address `json:"from"`
978979
Gas hexutil.Uint64 `json:"gas"`
979980
GasPrice *hexutil.Big `json:"gasPrice"`
@@ -1020,6 +1021,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
10201021
if blockHash != (common.Hash{}) {
10211022
result.BlockHash = &blockHash
10221023
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
1024+
result.BlockTimestamp = (*hexutil.Uint64)(&blockTime)
10231025
result.TransactionIndex = (*hexutil.Uint64)(&index)
10241026
}
10251027

internal/ethapi/api_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
140140
Want: `{
141141
"blockHash": null,
142142
"blockNumber": null,
143+
"blockTimestamp": null,
143144
"from": "0x71562b71999873db5b286df957af199ec94617f7",
144145
"gas": "0x7",
145146
"gasPrice": "0x6",
@@ -170,6 +171,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
170171
Want: `{
171172
"blockHash": null,
172173
"blockNumber": null,
174+
"blockTimestamp": null,
173175
"from": "0x71562b71999873db5b286df957af199ec94617f7",
174176
"gas": "0x7",
175177
"gasPrice": "0x6",
@@ -208,6 +210,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
208210
Want: `{
209211
"blockHash": null,
210212
"blockNumber": null,
213+
"blockTimestamp": null,
211214
"from": "0x71562b71999873db5b286df957af199ec94617f7",
212215
"gas": "0x7",
213216
"gasPrice": "0x6",
@@ -254,6 +257,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
254257
Want: `{
255258
"blockHash": null,
256259
"blockNumber": null,
260+
"blockTimestamp": null,
257261
"from": "0x71562b71999873db5b286df957af199ec94617f7",
258262
"gas": "0x7",
259263
"gasPrice": "0x6",
@@ -301,6 +305,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
301305
Want: `{
302306
"blockHash": null,
303307
"blockNumber": null,
308+
"blockTimestamp": null,
304309
"from": "0x71562b71999873db5b286df957af199ec94617f7",
305310
"gas": "0x7",
306311
"gasPrice": "0x9",
@@ -345,6 +350,7 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []txDa
345350
Want: `{
346351
"blockHash": null,
347352
"blockNumber": null,
353+
"blockTimestamp": null,
348354
"from": "0x71562b71999873db5b286df957af199ec94617f7",
349355
"gas": "0x7",
350356
"gasPrice": "0x9",
@@ -387,6 +393,7 @@ func allBlobTxs(addr common.Address, config *params.ChainConfig) []txData {
387393
Want: `{
388394
"blockHash": null,
389395
"blockNumber": null,
396+
"blockTimestamp": null,
390397
"from": "0x71562b71999873db5b286df957af199ec94617f7",
391398
"gas": "0x6",
392399
"gasPrice": "0x5",
@@ -3138,6 +3145,7 @@ func TestRPCMarshalBlock(t *testing.T) {
31383145
{
31393146
"blockHash": "0x9b73c83b25d0faf7eab854e3684c7e394336d6e135625aafa5c183f27baa8fee",
31403147
"blockNumber": "0x64",
3148+
"blockTimestamp": "0x0",
31413149
"from": "0x0000000000000000000000000000000000000000",
31423150
"gas": "0x457",
31433151
"gasPrice": "0x2b67",
@@ -3158,6 +3166,7 @@ func TestRPCMarshalBlock(t *testing.T) {
31583166
{
31593167
"blockHash": "0x9b73c83b25d0faf7eab854e3684c7e394336d6e135625aafa5c183f27baa8fee",
31603168
"blockNumber": "0x64",
3169+
"blockTimestamp": "0x0",
31613170
"from": "0x0000000000000000000000000000000000000000",
31623171
"gas": "0x457",
31633172
"gasPrice": "0x2b67",
@@ -3176,6 +3185,7 @@ func TestRPCMarshalBlock(t *testing.T) {
31763185
{
31773186
"blockHash": "0x9b73c83b25d0faf7eab854e3684c7e394336d6e135625aafa5c183f27baa8fee",
31783187
"blockNumber": "0x64",
3188+
"blockTimestamp": "0x0",
31793189
"from": "0x0000000000000000000000000000000000000000",
31803190
"gas": "0x457",
31813191
"gasPrice": "0x2b67",
@@ -3196,6 +3206,7 @@ func TestRPCMarshalBlock(t *testing.T) {
31963206
{
31973207
"blockHash": "0x9b73c83b25d0faf7eab854e3684c7e394336d6e135625aafa5c183f27baa8fee",
31983208
"blockNumber": "0x64",
3209+
"blockTimestamp": "0x0",
31993210
"from": "0x0000000000000000000000000000000000000000",
32003211
"gas": "0x457",
32013212
"gasPrice": "0x2b67",

internal/ethapi/testdata/eth_getBlockByHash-hash-latest-1-fullTx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{
2121
"blockHash": "0xedb9ccf3a85f67c095ad48abfb0fa09d47179bb0f902078d289042d12428aca5",
2222
"blockNumber": "0x9",
23+
"blockTimestamp": "0x5a",
2324
"from": "0x703c4b2bd70c169f5717101caee543299fc946c7",
2425
"gas": "0x5208",
2526
"gasPrice": "0x121a9cca",

internal/ethapi/testdata/eth_getBlockByNumber-number-latest-1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{
2121
"blockHash": "0xedb9ccf3a85f67c095ad48abfb0fa09d47179bb0f902078d289042d12428aca5",
2222
"blockNumber": "0x9",
23+
"blockTimestamp": "0x5a",
2324
"from": "0x703c4b2bd70c169f5717101caee543299fc946c7",
2425
"gas": "0x5208",
2526
"gasPrice": "0x121a9cca",

internal/ethapi/testdata/eth_getBlockByNumber-tag-pending-fullTx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{
2121
"blockHash": "0xfda6c7cb7a3a712e0c424909a7724cab0448e89e286617fa8d5fd27f63f28bd2",
2222
"blockNumber": "0xb",
23+
"blockTimestamp": "0x6e",
2324
"from": "0x703c4b2bd70c169f5717101caee543299fc946c7",
2425
"gas": "0x5208",
2526
"gasPrice": "0xde56ab3",

0 commit comments

Comments
 (0)