@@ -20,6 +20,7 @@ import (
2020// Each record is output as a single line of JSON (newline-delimited JSON).
2121type JSONDatabase struct {
2222 sensorID string
23+ chainID * big.Int
2324 shouldWriteBlocks bool
2425 shouldWriteBlockEvents bool
2526 shouldWriteTransactions bool
@@ -30,6 +31,7 @@ type JSONDatabase struct {
3031// JSONDatabaseOptions is used when creating a NewJSONDatabase.
3132type JSONDatabaseOptions struct {
3233 SensorID string
34+ ChainID uint64
3335 MaxConcurrency int
3436 ShouldWriteBlocks bool
3537 ShouldWriteBlockEvents bool
@@ -42,6 +44,7 @@ type JSONDatabaseOptions struct {
4244func NewJSONDatabase (opts JSONDatabaseOptions ) Database {
4345 return & JSONDatabase {
4446 sensorID : opts .SensorID ,
47+ chainID : new (big.Int ).SetUint64 (opts .ChainID ),
4548 shouldWriteBlocks : opts .ShouldWriteBlocks ,
4649 shouldWriteBlockEvents : opts .ShouldWriteBlockEvents ,
4750 shouldWriteTransactions : opts .ShouldWriteTransactions ,
@@ -252,14 +255,22 @@ func (j *JSONDatabase) writeTxs(txs []*types.Transaction, tfs time.Time) {
252255 }
253256
254257 for _ , tx := range txs {
255- var from common.Address
256- from , _ = types .Sender (types .LatestSignerForChainID (tx .ChainId ()), tx )
258+ chainID := tx .ChainId ()
259+ if tx .ChainId () == nil || tx .ChainId ().Sign () <= 0 {
260+ chainID = j .chainID
261+ }
262+
263+ var from string
264+ addr , err := types .Sender (types .LatestSignerForChainID (chainID ), tx )
265+ if err == nil {
266+ from = addr .Hex ()
267+ }
257268
258269 jsonTx := JSONTransaction {
259270 Type : "transaction" ,
260271 SensorID : j .sensorID ,
261272 Hash : tx .Hash ().Hex (),
262- From : from . Hex () ,
273+ From : from ,
263274 Value : tx .Value ().String (),
264275 Gas : tx .Gas (),
265276 GasPrice : tx .GasPrice ().String (),
0 commit comments