Skip to content

Commit 6b6d94f

Browse files
authored
decode events (#125)
### TL;DR Added event decoding functionality for Ethereum logs, enabling the parsing and interpretation of indexed and non-indexed event parameters. ### What changed? - Added `ConstructEventABI` function to parse event signatures into ABI format - Implemented log decoding functionality to handle both indexed and non-indexed event parameters - Created new `DecodedLog` and `DecodedLogData` structures to represent decoded event data - Enhanced log handlers to support automatic event decoding when a signature is provided - Added support for converting various data types (bytes, numerics) to hexadecimal format ### How to test? 1. Make a GET request to `/{chainId}/events/{contract}/{signature}` with a valid event signature 2. Verify that the response includes decoded event data with: - Event name and signature - Indexed parameters properly decoded - Non-indexed parameters converted to appropriate formats - All byte and numeric values properly converted to hex ### Why make this change? To improve the readability and usability of event log data by automatically decoding raw event parameters into their proper types and formats. This makes it easier for developers to work with and understand event data without having to manually decode the raw logs.
2 parents cdef621 + 0872cf9 commit 6b6d94f

File tree

10 files changed

+876
-99
lines changed

10 files changed

+876
-99
lines changed

api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func ParseQueryParams(r *http.Request) (QueryParams, error) {
123123
log.Error().Err(err).Msg("Error parsing query params")
124124
return QueryParams{}, err
125125
}
126+
if params.Limit == 0 {
127+
params.Limit = 5
128+
}
126129
return params, nil
127130
}
128131

docs/docs.go

Lines changed: 203 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const docTemplate = `{
7777
},
7878
{
7979
"type": "integer",
80+
"default": 5,
8081
"description": "Number of items per page",
8182
"name": "limit",
8283
"in": "query"
@@ -200,6 +201,7 @@ const docTemplate = `{
200201
},
201202
{
202203
"type": "integer",
204+
"default": 5,
203205
"description": "Number of items per page",
204206
"name": "limit",
205207
"in": "query"
@@ -265,7 +267,7 @@ const docTemplate = `{
265267
"BasicAuth": []
266268
}
267269
],
268-
"description": "Retrieve logs for a specific contract and event signature",
270+
"description": "Retrieve logs for a specific contract and event signature. When a valid event signature is provided, the response includes decoded log data with both indexed and non-indexed parameters.",
269271
"consumes": [
270272
"application/json"
271273
],
@@ -293,7 +295,7 @@ const docTemplate = `{
293295
},
294296
{
295297
"type": "string",
296-
"description": "Event signature",
298+
"description": "Event signature (e.g., 'Transfer(address,address,uint256)')",
297299
"name": "signature",
298300
"in": "path",
299301
"required": true
@@ -330,6 +332,7 @@ const docTemplate = `{
330332
},
331333
{
332334
"type": "integer",
335+
"default": 5,
333336
"description": "Number of items per page",
334337
"name": "limit",
335338
"in": "query"
@@ -359,7 +362,7 @@ const docTemplate = `{
359362
"data": {
360363
"type": "array",
361364
"items": {
362-
"$ref": "#/definitions/handlers.LogModel"
365+
"$ref": "#/definitions/handlers.DecodedLogModel"
363366
}
364367
}
365368
}
@@ -446,6 +449,7 @@ const docTemplate = `{
446449
},
447450
{
448451
"type": "integer",
452+
"default": 5,
449453
"description": "Number of items per page",
450454
"name": "limit",
451455
"in": "query"
@@ -569,6 +573,7 @@ const docTemplate = `{
569573
},
570574
{
571575
"type": "integer",
576+
"default": 5,
572577
"description": "Number of items per page",
573578
"name": "limit",
574579
"in": "query"
@@ -634,7 +639,7 @@ const docTemplate = `{
634639
"BasicAuth": []
635640
}
636641
],
637-
"description": "Retrieve transactions for a specific contract and signature (Not implemented yet)",
642+
"description": "Retrieve transactions for a specific contract and signature. When a valid function signature is provided, the response includes decoded transaction data with function inputs.",
638643
"consumes": [
639644
"application/json"
640645
],
@@ -662,7 +667,7 @@ const docTemplate = `{
662667
},
663668
{
664669
"type": "string",
665-
"description": "Function signature",
670+
"description": "Function signature (e.g., 'transfer(address,uint256)')",
666671
"name": "signature",
667672
"in": "path",
668673
"required": true
@@ -699,6 +704,7 @@ const docTemplate = `{
699704
},
700705
{
701706
"type": "integer",
707+
"default": 5,
702708
"description": "Number of items per page",
703709
"name": "limit",
704710
"in": "query"
@@ -728,7 +734,7 @@ const docTemplate = `{
728734
"data": {
729735
"type": "array",
730736
"items": {
731-
"$ref": "#/definitions/handlers.TransactionModel"
737+
"$ref": "#/definitions/handlers.DecodedTransactionModel"
732738
}
733739
}
734740
}
@@ -817,9 +823,10 @@ const docTemplate = `{
817823
"properties": {
818824
"aggregations": {
819825
"description": "@Description Aggregation results",
820-
"type": "object",
821-
"additionalProperties": {
822-
"type": "string"
826+
"type": "array",
827+
"items": {
828+
"type": "object",
829+
"additionalProperties": true
823830
}
824831
},
825832
"data": {
@@ -835,6 +842,169 @@ const docTemplate = `{
835842
}
836843
}
837844
},
845+
"handlers.DecodedLogDataModel": {
846+
"type": "object",
847+
"properties": {
848+
"inputs": {
849+
"type": "object",
850+
"additionalProperties": true
851+
},
852+
"name": {
853+
"type": "string"
854+
},
855+
"signature": {
856+
"type": "string"
857+
}
858+
}
859+
},
860+
"handlers.DecodedLogModel": {
861+
"type": "object",
862+
"properties": {
863+
"address": {
864+
"type": "string"
865+
},
866+
"block_hash": {
867+
"type": "string"
868+
},
869+
"block_number": {
870+
"type": "string"
871+
},
872+
"block_timestamp": {
873+
"type": "integer"
874+
},
875+
"chain_id": {
876+
"type": "string"
877+
},
878+
"data": {
879+
"type": "string"
880+
},
881+
"decoded": {
882+
"$ref": "#/definitions/handlers.DecodedLogDataModel"
883+
},
884+
"log_index": {
885+
"type": "integer"
886+
},
887+
"topics": {
888+
"type": "array",
889+
"items": {
890+
"type": "string"
891+
}
892+
},
893+
"transaction_hash": {
894+
"type": "string"
895+
},
896+
"transaction_index": {
897+
"type": "integer"
898+
}
899+
}
900+
},
901+
"handlers.DecodedTransactionDataModel": {
902+
"type": "object",
903+
"properties": {
904+
"inputs": {
905+
"type": "object",
906+
"additionalProperties": true
907+
},
908+
"name": {
909+
"type": "string"
910+
},
911+
"signature": {
912+
"type": "string"
913+
}
914+
}
915+
},
916+
"handlers.DecodedTransactionModel": {
917+
"type": "object",
918+
"properties": {
919+
"access_list_json": {
920+
"type": "string"
921+
},
922+
"blob_gas_price": {
923+
"type": "string"
924+
},
925+
"blob_gas_used": {
926+
"type": "integer"
927+
},
928+
"block_hash": {
929+
"type": "string"
930+
},
931+
"block_number": {
932+
"type": "string"
933+
},
934+
"block_timestamp": {
935+
"type": "integer"
936+
},
937+
"chain_id": {
938+
"type": "string"
939+
},
940+
"contract_address": {
941+
"type": "string"
942+
},
943+
"cumulative_gas_used": {
944+
"type": "integer"
945+
},
946+
"data": {
947+
"type": "string"
948+
},
949+
"decoded": {
950+
"$ref": "#/definitions/handlers.DecodedTransactionDataModel"
951+
},
952+
"effective_gas_price": {
953+
"type": "string"
954+
},
955+
"from_address": {
956+
"type": "string"
957+
},
958+
"gas": {
959+
"type": "integer"
960+
},
961+
"gas_price": {
962+
"type": "string"
963+
},
964+
"gas_used": {
965+
"type": "integer"
966+
},
967+
"hash": {
968+
"type": "string"
969+
},
970+
"logs_bloom": {
971+
"type": "string"
972+
},
973+
"max_fee_per_gas": {
974+
"type": "string"
975+
},
976+
"max_priority_fee_per_gas": {
977+
"type": "string"
978+
},
979+
"nonce": {
980+
"type": "integer"
981+
},
982+
"r": {
983+
"type": "string"
984+
},
985+
"s": {
986+
"type": "string"
987+
},
988+
"status": {
989+
"type": "integer"
990+
},
991+
"to_address": {
992+
"type": "string"
993+
},
994+
"transaction_index": {
995+
"type": "integer"
996+
},
997+
"transaction_type": {
998+
"type": "integer"
999+
},
1000+
"v": {
1001+
"type": "string"
1002+
},
1003+
"value": {
1004+
"type": "string"
1005+
}
1006+
}
1007+
},
8381008
"handlers.LogModel": {
8391009
"type": "object",
8401010
"properties": {
@@ -879,6 +1049,12 @@ const docTemplate = `{
8791049
"access_list_json": {
8801050
"type": "string"
8811051
},
1052+
"blob_gas_price": {
1053+
"type": "string"
1054+
},
1055+
"blob_gas_used": {
1056+
"type": "integer"
1057+
},
8821058
"block_hash": {
8831059
"type": "string"
8841060
},
@@ -891,9 +1067,18 @@ const docTemplate = `{
8911067
"chain_id": {
8921068
"type": "string"
8931069
},
1070+
"contract_address": {
1071+
"type": "string"
1072+
},
1073+
"cumulative_gas_used": {
1074+
"type": "integer"
1075+
},
8941076
"data": {
8951077
"type": "string"
8961078
},
1079+
"effective_gas_price": {
1080+
"type": "string"
1081+
},
8971082
"from_address": {
8981083
"type": "string"
8991084
},
@@ -903,9 +1088,15 @@ const docTemplate = `{
9031088
"gas_price": {
9041089
"type": "string"
9051090
},
1091+
"gas_used": {
1092+
"type": "integer"
1093+
},
9061094
"hash": {
9071095
"type": "string"
9081096
},
1097+
"logs_bloom": {
1098+
"type": "string"
1099+
},
9091100
"max_fee_per_gas": {
9101101
"type": "string"
9111102
},
@@ -921,6 +1112,9 @@ const docTemplate = `{
9211112
"s": {
9221113
"type": "string"
9231114
},
1115+
"status": {
1116+
"type": "integer"
1117+
},
9241118
"to_address": {
9251119
"type": "string"
9261120
},

0 commit comments

Comments
 (0)