Skip to content

Commit

Permalink
feat(relayer): Event filter (#13318)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Mar 15, 2023
1 parent 9d215cf commit f20d419
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 31 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ go 1.19

require (
github.com/cyberhorsey/errors v0.0.0-20220929234051-087d6d8bb841
github.com/cyberhorsey/webutils v0.0.0-20230119185838-43865c417a79
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7
github.com/ethereum/go-ethereum v1.10.26
github.com/joho/godotenv v1.4.0
github.com/labstack/echo-contrib v0.13.0
github.com/labstack/echo/v4 v4.9.1
github.com/labstack/gommon v0.4.0
github.com/morkid/paginate v1.1.6
github.com/pkg/errors v0.9.1
github.com/pressly/goose v2.7.0+incompatible
github.com/pressly/goose/v3 v3.7.0
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.0
github.com/testcontainers/testcontainers-go v0.15.0
Expand Down Expand Up @@ -72,13 +74,11 @@ require (
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/morkid/gocache v1.0.0 // indirect
github.com/morkid/paginate v1.1.6 // indirect
github.com/neko-neko/echo-logrus/v2 v2.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/opencontainers/runc v1.1.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
Expand Down
24 changes: 2 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand Down Expand Up @@ -269,8 +267,8 @@ github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyberhorsey/errors v0.0.0-20220929234051-087d6d8bb841 h1:FaPua89k9KmkkiptlTAmYzcTsn1IFdQsqneuFO6IAu8=
github.com/cyberhorsey/errors v0.0.0-20220929234051-087d6d8bb841/go.mod h1:qSH/IvpdArCjfny4ODMko/7U0z4JoNIWctgCnUrapnI=
github.com/cyberhorsey/webutils v0.0.0-20230119185838-43865c417a79 h1:kYxc139hoCg00VynxRxAY4D1ypMrWz83TqchNljIgMM=
github.com/cyberhorsey/webutils v0.0.0-20230119185838-43865c417a79/go.mod h1:bNNUHadsCy1HleNUToQ/t11vmKI9/+9Taw8K6GyxERo=
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7 h1:KYOh2RfWAltxYsfD/Ar5D3zB4+AuNQejXW5BvMlGor4=
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7/go.mod h1:bNNUHadsCy1HleNUToQ/t11vmKI9/+9Taw8K6GyxERo=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=
Expand All @@ -283,9 +281,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/denisenkom/go-mssqldb v0.12.0/go.mod h1:iiK0YP1ZeepvmBQk/QpLEhhTNJgfzrpArPY/aFvc9yU=
Expand Down Expand Up @@ -332,8 +327,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.10.25 h1:5dFrKJDnYf8L6/5o42abCE6a9yJm9cs4EJVRyYMr55s=
github.com/ethereum/go-ethereum v1.10.25/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s=
github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand Down Expand Up @@ -793,15 +786,12 @@ github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQ
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34=
github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
Expand Down Expand Up @@ -1004,8 +994,6 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1089,8 +1077,6 @@ golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
Expand Down Expand Up @@ -1208,8 +1194,6 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand All @@ -1223,7 +1207,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
Expand Down Expand Up @@ -1396,7 +1379,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down Expand Up @@ -1454,8 +1436,6 @@ gorm.io/gorm v1.21.3/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.6/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.0 h1:j/CoiSm6xpRpmzbFJsQHYj+I8bGYWLXVHeYEyyKlF74=
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.24.6 h1:wy98aq9oFEetsc4CAbKD2SoBCdMzsbSIvSUUFJuHi5s=
gorm.io/gorm v1.24.6/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
Expand Down
9 changes: 5 additions & 4 deletions packages/relayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ Filter params:
Mandatory:
`address`: user's ethereum address who sent the message.

Optional:
`chainID`: chain ID of the source chain. Default: all chains.
`msgHash`: filter events by message hash. Default: all msgHashs.
`eventType`: filter events by event typoe. Default: all eventType.
Optional:
`chainID`: chain ID of the source chain. Default: all chains. Options: any integer.
`msgHash`: filter events by message hash. Default: all msgHashs. Options: any hash.
`eventType`: filter events by event type. Default: all eventType. Options: Enum value, `0` for sendETH, `1` for sendERC20.
`event`: filter events by event name. Default: all event names. Options: `MessageSent`, `MessageStatusChanged`

Pagination:
`page`: page number to retrive. Default: 0.
Expand Down
3 changes: 3 additions & 0 deletions packages/relayer/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Event struct {
Amount string `json:"amount"`
MsgHash string `json:"msgHash"`
MessageOwner string `json:"messageOwner"`
Event string `json:"event"`
}

// SaveEventOpts
Expand All @@ -75,11 +76,13 @@ type SaveEventOpts struct {
Amount string
MsgHash string
MessageOwner string
Event string
}

type FindAllByAddressOpts struct {
Address common.Address
EventType *EventType
Event *string
MsgHash *string
ChainID *big.Int
}
Expand Down
3 changes: 3 additions & 0 deletions packages/relayer/http/get_events_by_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func (srv *Server) GetEventsByAddress(c echo.Context) error {

eventTypeParam := html.EscapeString(c.QueryParam("eventType"))

event := html.EscapeString(c.QueryParam("event"))

var eventType *relayer.EventType

if eventTypeParam != "" {
Expand All @@ -42,6 +44,7 @@ func (srv *Server) GetEventsByAddress(c echo.Context) error {
MsgHash: &msgHash,
EventType: eventType,
ChainID: chainID,
Event: &event,
},
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/indexer/handle_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (svc *Service) handleEvent(
Amount: amount.String(),
MsgHash: common.Hash(event.MsgHash).Hex(),
MessageOwner: event.Message.Owner.Hex(),
Event: relayer.EventNameMessageSent,
})
if err != nil {
return errors.Wrap(err, "svc.eventRepo.Save")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (svc *Service) saveMessageStatusChangedEvent(
Status: relayer.EventStatus(event.Status),
MessageOwner: previousEvents[0].MessageOwner,
MsgHash: common.Hash(event.MsgHash).Hex(),
Event: relayer.EventNameMessageStatusChanged,
})
if err != nil {
return errors.Wrap(err, "svc.eventRepo.Save")
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/message/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (p *Processor) saveMessageStatusChangedEvent(
Status: relayer.EventStatus(m["status"].(uint8)),
MsgHash: e.MsgHash,
MessageOwner: e.MessageOwner,
Event: relayer.EventNameMessageStatusChanged,
})
if err != nil {
return errors.Wrap(err, "svc.eventRepo.Save")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS events (
name VARCHAR(255) NOT NULL,
status int NOT NULL DEFAULT 0,
event_type int NOT NULL DEFAULT 0,
event VARCHAR(255) NOT NULL DEFAULT "",
chain_id int NOT NULL,
data JSON NOT NULL,
canonical_token_address VARCHAR(255) DEFAULT "",
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/mock/event_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts)
Name: opts.Name,
MessageOwner: opts.MessageOwner,
MsgHash: opts.MsgHash,
EventType: opts.EventType,
})

return nil, nil
Expand Down
7 changes: 5 additions & 2 deletions packages/relayer/repo/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts)
Amount: opts.Amount,
MsgHash: opts.MsgHash,
MessageOwner: opts.MessageOwner,
Event: opts.Event,
}

if err := r.db.GormDB().Create(e).Error; err != nil {
Expand Down Expand Up @@ -74,8 +75,6 @@ func (r *EventRepository) FindAllByMsgHash(
return nil, errors.Wrap(err, "r.db.Find")
}

// find all message status changed events

return e, nil
}

Expand Down Expand Up @@ -103,6 +102,10 @@ func (r *EventRepository) FindAllByAddress(
q = q.Where("chain_id = ?", opts.ChainID.Int64())
}

if opts.Event != nil && *opts.Event != "" {
q = q.Where("event = ?", *opts.Event)
}

reqCtx := pg.With(q)

page := reqCtx.Request(req).Response(&[]relayer.Event{})
Expand Down
47 changes: 47 additions & 0 deletions packages/relayer/repo/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var testEvents = []relayer.Event{
Amount: "1",
MsgHash: testMsgHash,
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageSent,
},
{
ID: 2,
Expand All @@ -54,6 +55,7 @@ var testEvents = []relayer.Event{
Amount: "1",
MsgHash: testMsgHash,
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageSent,
},
{
ID: 3,
Expand All @@ -70,6 +72,7 @@ var testEvents = []relayer.Event{
Amount: "1",
MsgHash: testSecondMsgHash,
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageStatusChanged,
},
}

Expand Down Expand Up @@ -126,6 +129,7 @@ func TestIntegration_Event_Save(t *testing.T) {
Amount: "1",
MsgHash: "0x1",
MessageOwner: "0x1",
Event: relayer.EventNameMessageSent,
},
nil,
},
Expand Down Expand Up @@ -184,6 +188,7 @@ func TestIntegration_Event_UpdateStatus(t *testing.T) {
Amount: "1",
MsgHash: "0x1",
MessageOwner: "0x1",
Event: relayer.EventNameMessageSent,
},
)
assert.Equal(t, nil, err)
Expand Down Expand Up @@ -218,6 +223,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) {
Amount: "1",
MsgHash: "0x1",
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageSent,
})
assert.Equal(t, nil, err)

Expand All @@ -234,6 +240,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) {
Amount: "1",
MsgHash: "0x1",
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageSent,
})
assert.Equal(t, nil, err)

Expand All @@ -250,6 +257,7 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) {
Amount: "1",
MsgHash: "0x2",
MessageOwner: addr.Hex(),
Event: relayer.EventNameMessageStatusChanged,
})
assert.Equal(t, nil, err)

Expand Down Expand Up @@ -277,6 +285,25 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) {
},
nil,
},
{
"successJustAddressAndEvent",
relayer.FindAllByAddressOpts{
Address: addr,
Event: &relayer.EventNameMessageSent,
},
paginate.Page{
Items: testEvents[:2],
Page: 0,
Size: 100,
MaxPage: 1,
TotalPages: 1,
Total: 1,
Last: false,
First: true,
Visible: 1,
},
nil,
},
{
"successAddressAndMsgHash",
relayer.FindAllByAddressOpts{
Expand Down Expand Up @@ -335,6 +362,26 @@ func TestIntegration_Event_FindAllByAddress(t *testing.T) {
},
nil,
},
{
"successAddressMsgHashAndEvent",
relayer.FindAllByAddressOpts{
Address: addr,
MsgHash: &testSecondMsgHash,
Event: &relayer.EventNameMessageStatusChanged,
},
paginate.Page{
Items: testEvents[2:],
Page: 0,
Size: 100,
MaxPage: 1,
TotalPages: 1,
Total: 1,
Last: false,
First: true,
Visible: 1,
},
nil,
},
{
"noneByAddr",
relayer.FindAllByAddressOpts{
Expand Down

0 comments on commit f20d419

Please sign in to comment.