Skip to content

Commit 7a673bb

Browse files
committed
decode all events
1 parent 97b9e51 commit 7a673bb

File tree

4 files changed

+51
-25
lines changed

4 files changed

+51
-25
lines changed

seth/contract_store.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ func (c *ContractStore) GetABI(name string) (*abi.ABI, bool) {
4444
return &abi, ok
4545
}
4646

47+
func (c *ContractStore) GetAllABIs() []*abi.ABI {
48+
c.mu.Lock()
49+
defer c.mu.Unlock()
50+
51+
var allABIs []*abi.ABI
52+
for _, a := range c.ABIs {
53+
allABIs = append(allABIs, &a)
54+
}
55+
56+
return allABIs
57+
}
58+
4759
func (c *ContractStore) AddABI(name string, abi abi.ABI) {
4860
if !strings.HasSuffix(name, ".abi") {
4961
name = name + ".abi"

seth/examples_wasp/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ require (
109109
github.com/hashicorp/golang-lru v0.6.0 // indirect
110110
github.com/hashicorp/memberlist v0.5.0 // indirect
111111
github.com/hashicorp/serf v0.10.1 // indirect
112-
github.com/holiman/uint256 v1.2.4 // indirect
112+
github.com/holiman/uint256 v1.3.1 // indirect
113113
github.com/huandu/xstrings v1.3.3 // indirect
114114
github.com/imdario/mergo v0.3.16 // indirect
115115
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -141,7 +141,7 @@ require (
141141
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
142142
github.com/opentracing/opentracing-go v1.2.0 // indirect
143143
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
144-
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
144+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
145145
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
146146
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
147147
github.com/prometheus/alertmanager v0.26.0 // indirect
@@ -152,7 +152,7 @@ require (
152152
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 // indirect
153153
github.com/prometheus/procfs v0.12.0 // indirect
154154
github.com/prometheus/prometheus v0.47.2-0.20231010075449-4b9c19fe5510 // indirect
155-
github.com/rs/zerolog v1.30.0 // indirect
155+
github.com/rs/zerolog v1.33.0 // indirect
156156
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
157157
github.com/sercand/kuberesolver/v5 v5.1.1 // indirect
158158
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
@@ -183,7 +183,7 @@ require (
183183
go.uber.org/atomic v1.11.0 // indirect
184184
go.uber.org/goleak v1.2.1 // indirect
185185
go.uber.org/multierr v1.11.0 // indirect
186-
go.uber.org/ratelimit v0.3.0 // indirect
186+
go.uber.org/ratelimit v0.3.1 // indirect
187187
go.uber.org/zap v1.26.0 // indirect
188188
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f // indirect
189189
golang.org/x/arch v0.4.0 // indirect
@@ -192,7 +192,7 @@ require (
192192
golang.org/x/mod v0.17.0 // indirect
193193
golang.org/x/net v0.27.0 // indirect
194194
golang.org/x/oauth2 v0.15.0 // indirect
195-
golang.org/x/sync v0.7.0 // indirect
195+
golang.org/x/sync v0.8.0 // indirect
196196
golang.org/x/sys v0.22.0 // indirect
197197
golang.org/x/term v0.22.0 // indirect
198198
golang.org/x/text v0.16.0 // indirect

seth/examples_wasp/go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ
530530
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
531531
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
532532
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
533+
github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
533534
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
534535
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
535536
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
@@ -697,6 +698,7 @@ github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhM
697698
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
698699
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
699700
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
701+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
700702
github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ=
701703
github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
702704
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
@@ -761,6 +763,7 @@ github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
761763
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
762764
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
763765
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
766+
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
764767
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
765768
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
766769
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
@@ -898,6 +901,7 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
898901
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
899902
go.uber.org/ratelimit v0.3.0 h1:IdZd9wqvFXnvLvSEBo0KPcGfkoBGNkpTHlrE3Rcjkjw=
900903
go.uber.org/ratelimit v0.3.0/go.mod h1:So5LG7CV1zWpY1sHe+DXTJqQvOx+FFPFaAs2SnoyBaI=
904+
go.uber.org/ratelimit v0.3.1/go.mod h1:6euWsTB6U/Nb3X++xEUXA8ciPJvr19Q/0h1+oDcJhRk=
901905
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
902906
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
903907
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f h1:ketMxHg+vWm3yccyYiq+uK8D3fRmna2Fcj+awpQp84s=
@@ -1034,6 +1038,7 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
10341038
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
10351039
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
10361040
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1041+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
10371042
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10381043
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
10391044
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

seth/tracing.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,14 @@ func (t *Tracer) decodeCall(byteSignature []byte, rawCall Call) (*DecodedCall, e
461461

462462
}
463463

464-
txEvents, err = t.decodeContractLogs(L, rawCall.Logs, abiResult.ABI)
464+
var allABIs []*abi.ABI
465+
if t.ABIFinder.ContractStore == nil {
466+
allABIs = append(allABIs, &abiResult.ABI)
467+
} else {
468+
allABIs = t.ABIFinder.ContractStore.GetAllABIs()
469+
}
470+
471+
txEvents, err = t.decodeContractLogs(L, rawCall.Logs, allABIs)
465472
if err != nil {
466473
L.Debug().Err(err).Msg("Failed to decode logs")
467474
} else {
@@ -602,27 +609,29 @@ func (t *Tracer) SaveDecodedCallsAsJson(dirname string) error {
602609
return nil
603610
}
604611

605-
func (t *Tracer) decodeContractLogs(l zerolog.Logger, logs []TraceLog, a abi.ABI) ([]DecodedCommonLog, error) {
606-
l.Trace().Msg("Decoding events")
612+
func (t *Tracer) decodeContractLogs(l zerolog.Logger, logs []TraceLog, allABIs []*abi.ABI) ([]DecodedCommonLog, error) {
613+
l.Trace().Msg("Decoding ALL events")
607614
var eventsParsed []DecodedCommonLog
608615
for _, lo := range logs {
609-
for _, evSpec := range a.Events {
610-
if evSpec.ID.Hex() == lo.Topics[0] {
611-
l.Trace().Str("Name", evSpec.RawName).Str("Signature", evSpec.Sig).Msg("Unpacking event")
612-
eventsMap, topicsMap, err := decodeEventFromLog(l, a, evSpec, lo)
613-
if err != nil {
614-
return nil, errors.Wrap(err, ErrDecodeLog)
615-
}
616-
parsedEvent := decodedLogFromMaps(&DecodedCommonLog{}, eventsMap, topicsMap)
617-
if decodedLog, ok := parsedEvent.(*DecodedCommonLog); ok {
618-
decodedLog.Signature = evSpec.Sig
619-
t.mergeLogMeta(decodedLog, lo)
620-
eventsParsed = append(eventsParsed, *decodedLog)
621-
l.Trace().Interface("Log", parsedEvent).Msg("Transaction log")
622-
} else {
623-
l.Trace().
624-
Str("Actual type", fmt.Sprintf("%T", decodedLog)).
625-
Msg("Failed to cast decoded event to DecodedCommonLog")
616+
for _, singleAbi := range allABIs {
617+
for _, evSpec := range singleAbi.Events {
618+
if evSpec.ID.Hex() == lo.Topics[0] {
619+
l.Trace().Str("Name", evSpec.RawName).Str("Signature", evSpec.Sig).Msg("Unpacking event")
620+
eventsMap, topicsMap, err := decodeEventFromLog(l, *singleAbi, evSpec, lo)
621+
if err != nil {
622+
return nil, errors.Wrap(err, ErrDecodeLog)
623+
}
624+
parsedEvent := decodedLogFromMaps(&DecodedCommonLog{}, eventsMap, topicsMap)
625+
if decodedLog, ok := parsedEvent.(*DecodedCommonLog); ok {
626+
decodedLog.Signature = evSpec.Sig
627+
t.mergeLogMeta(decodedLog, lo)
628+
eventsParsed = append(eventsParsed, *decodedLog)
629+
l.Trace().Interface("Log", parsedEvent).Msg("Transaction log")
630+
} else {
631+
l.Trace().
632+
Str("Actual type", fmt.Sprintf("%T", decodedLog)).
633+
Msg("Failed to cast decoded event to DecodedCommonLog")
634+
}
626635
}
627636
}
628637
}

0 commit comments

Comments
 (0)