Skip to content

Commit 22d728d

Browse files
committed
Query if we don't have chain ID, then add to events
1 parent 6ec08f2 commit 22d728d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

internal/ethereum/ethereum.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ethConnector struct {
5151
blockListener *blockListener
5252
eventFilterPollingInterval time.Duration
5353
traceTXForRevertReason bool
54+
chainID string
5455

5556
mux sync.Mutex
5657
eventStreams map[fftypes.UUID]*eventStream

internal/ethereum/event_enricher.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ethereum
1919
import (
2020
"bytes"
2121
"context"
22+
"fmt"
2223

2324
"github.com/hyperledger/firefly-common/pkg/fftypes"
2425
"github.com/hyperledger/firefly-common/pkg/i18n"
@@ -54,9 +55,18 @@ func (ee *eventEnricher) filterEnrichEthLog(ctx context.Context, f *eventFilter,
5455
log.L(ctx).Infof("detected event '%s'", protoID)
5556
data, decoded := ee.decodeLogData(ctx, f.Event, ethLog.Topics, ethLog.Data)
5657

58+
if len(ee.connector.chainID) == 0 {
59+
resp, _, err := ee.connector.IsReady(ctx)
60+
if !resp.Ready || err != nil {
61+
return nil, matched, decoded, err
62+
}
63+
}
64+
5765
info := eventInfo{
58-
logJSONRPC: *ethLog,
59-
ChainIdentifier: fftypes.JSONAnyPtr("asd"),
66+
logJSONRPC: *ethLog,
67+
ChainIdentifier: fftypes.JSONAnyPtr(fmt.Sprintf(`{
68+
"chainId": "%s"
69+
}`, ee.connector.chainID)),
6070
}
6171

6272
var timestamp *fftypes.FFTime

internal/ethereum/statuses.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ func (c *ethConnector) IsLive(_ context.Context) (*ffcapi.LiveResponse, ffcapi.E
3030
}
3131

3232
func (c *ethConnector) IsReady(ctx context.Context) (*ffcapi.ReadyResponse, ffcapi.ErrorReason, error) {
33-
var chainID string
34-
err := c.backend.CallRPC(ctx, &chainID, "net_version")
33+
err := c.backend.CallRPC(ctx, &c.chainID, "net_version")
3534
if err != nil {
3635
return &ffcapi.ReadyResponse{
3736
Ready: false,
3837
}, mapError(netVersionRPCMethods, err.Error()), err.Error()
3938
}
4039

4140
details := &fftypes.JSONObject{
42-
"chainID": chainID,
41+
"chainID": c.chainID,
4342
}
4443

4544
return &ffcapi.ReadyResponse{

0 commit comments

Comments
 (0)