Skip to content

Commit

Permalink
Fixes the relAddresses in the events debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Sep 25, 2023
1 parent 4b2d0e9 commit 8cf7e63
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 88 deletions.
38 changes: 19 additions & 19 deletions go/common/tracers/debug_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

// DebugLogs are the logs returned when using the DebugGetLogs endpoint
type DebugLogs struct {
RelAddress1 *gethcommon.Hash `json:"relAddress1"`
RelAddress2 *gethcommon.Hash `json:"relAddress2"`
RelAddress3 *gethcommon.Hash `json:"relAddress3"`
RelAddress4 *gethcommon.Hash `json:"relAddress4"`
LifecycleEvent bool `json:"lifecycleEvent"`
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
RelAddress4 *gethcommon.Address `json:"relAddress4"`
LifecycleEvent bool `json:"lifecycleEvent"`

gethtypes.Log
}
Expand All @@ -24,20 +24,20 @@ type DebugLogs struct {
// this holds a copy of the gethtypes.Log log marshaller
func (l DebugLogs) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Address string `json:"address" gencodec:"required"`
Topics []gethcommon.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber uint64 `json:"blockNumber"`
TxHash gethcommon.Hash `json:"transactionHash" gencodec:"required"`
TxIndex uint `json:"transactionIndex"`
BlockHash gethcommon.Hash `json:"blockHash"`
Index uint `json:"logIndex"`
Removed bool `json:"removed"`
LifecycleEvent bool `json:"lifecycleEvent"`
RelAddress1 *gethcommon.Hash `json:"relAddress1"`
RelAddress2 *gethcommon.Hash `json:"relAddress2"`
RelAddress3 *gethcommon.Hash `json:"relAddress3"`
RelAddress4 *gethcommon.Hash `json:"relAddress4"`
Address string `json:"address" gencodec:"required"`
Topics []gethcommon.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber uint64 `json:"blockNumber"`
TxHash gethcommon.Hash `json:"transactionHash" gencodec:"required"`
TxIndex uint `json:"transactionIndex"`
BlockHash gethcommon.Hash `json:"blockHash"`
Index uint `json:"logIndex"`
Removed bool `json:"removed"`
LifecycleEvent bool `json:"lifecycleEvent"`
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
RelAddress4 *gethcommon.Address `json:"relAddress4"`
}{
l.Address.Hex(),
l.Topics,
Expand Down
35 changes: 13 additions & 22 deletions go/enclave/storage/enclavedb/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func DebugGetLogs(db *sql.DB, txHash common.TxHash) ([]*tracers.DebugLogs, error
}

var t0, t1, t2, t3, t4 sql.NullString
var relAddress1, relAddress2, relAddress3, relAddress4 sql.NullByte
var relAddress1, relAddress2, relAddress3, relAddress4 []byte
err = rows.Scan(
&relAddress1,
&relAddress2,
Expand All @@ -229,10 +229,10 @@ func DebugGetLogs(db *sql.DB, txHash common.TxHash) ([]*tracers.DebugLogs, error
}
}

l.RelAddress1 = bytesToHash(relAddress1)
l.RelAddress2 = bytesToHash(relAddress2)
l.RelAddress3 = bytesToHash(relAddress3)
l.RelAddress4 = bytesToHash(relAddress4)
l.RelAddress1 = bytesToAddress(relAddress1)
l.RelAddress2 = bytesToAddress(relAddress2)
l.RelAddress3 = bytesToAddress(relAddress3)
l.RelAddress4 = bytesToAddress(relAddress4)

result = append(result, &l)
}
Expand All @@ -244,6 +244,14 @@ func DebugGetLogs(db *sql.DB, txHash common.TxHash) ([]*tracers.DebugLogs, error
return result, nil
}

func bytesToAddress(b []byte) *gethcommon.Address {
if b != nil {
addr := gethcommon.BytesToAddress(b)
return &addr
}
return nil
}

// Of the log's topics, returns those that are (potentially) user addresses. A topic is considered a user address if:
// - It has at least 12 leading zero bytes (since addresses are 20 bytes long, while hashes are 32) and at most 22 leading zero bytes
// - It does not have associated code (meaning it's a smart-contract address)
Expand Down Expand Up @@ -350,23 +358,6 @@ func stringToHash(ns sql.NullString) gethcommon.Hash {
return result
}

func bytesToHash(b sql.NullByte) *gethcommon.Hash {
result := gethcommon.Hash{}

if !b.Valid {
return nil
}

value, err := b.Value()
if err != nil {
return nil
}
s := value.(string)

result.SetBytes([]byte(s))
return &result
}

func byteArrayToHash(b []byte) gethcommon.Hash {
result := gethcommon.Hash{}
result.SetBytes(b)
Expand Down
Loading

0 comments on commit 8cf7e63

Please sign in to comment.