@@ -24,26 +24,28 @@ var (
2424// LogModel represents a simplified Log structure for Swagger documentation
2525type LogModel struct {
2626 ChainId string `json:"chain_id"`
27- BlockNumber string `json:"block_number"`
27+ BlockNumber uint64 `json:"block_number"`
2828 BlockHash string `json:"block_hash"`
2929 BlockTimestamp uint64 `json:"block_timestamp"`
3030 TransactionHash string `json:"transaction_hash"`
3131 TransactionIndex uint64 `json:"transaction_index"`
3232 LogIndex uint64 `json:"log_index"`
3333 Address string `json:"address"`
3434 Data string `json:"data"`
35- Topics []string `json:"topics"`
35+ Topics []string `json:"topics" swaggertype:"array,string" `
3636}
3737
3838type DecodedLogDataModel struct {
39- Name string `json:"name"`
40- Signature string `json:"signature"`
41- Inputs map [string ]interface {} `json:"inputs"`
39+ Name string `json:"name"`
40+ Signature string `json:"signature"`
41+ IndexedParams map [string ]interface {} `json:"indexedParams" swaggertype:"object"`
42+ NonIndexedParams map [string ]interface {} `json:"nonIndexedParams" swaggertype:"object"`
4243}
4344
4445type DecodedLogModel struct {
4546 LogModel
46- Decoded DecodedLogDataModel `json:"decoded"`
47+ Decoded DecodedLogDataModel `json:"decoded"`
48+ DecodedData DecodedLogDataModel `json:"decodedData" deprecated:"true"` // Deprecated: Use Decoded field instead
4749}
4850
4951// @Summary Get all logs
@@ -202,18 +204,18 @@ func handleLogsRequest(c *gin.Context, contractAddress, signature string, eventA
202204 return
203205 }
204206 if eventABI != nil {
205- decodedLogs := []* common. DecodedLog {}
207+ decodedLogs := []DecodedLogModel {}
206208 for _ , log := range logsResult .Data {
207209 decodedLog := log .Decode (eventABI )
208- decodedLogs = append (decodedLogs , decodedLog )
210+ decodedLogs = append (decodedLogs , serializeDecodedLog ( * decodedLog ) )
209211 }
210212 queryResult .Data = decodedLogs
211213 } else {
212214 if config .Cfg .API .AbiDecodingEnabled && queryParams .Decode {
213215 decodedLogs := common .DecodeLogs (chainId .String (), logsResult .Data )
214- queryResult .Data = decodedLogs
216+ queryResult .Data = serializeDecodedLogs ( decodedLogs )
215217 } else {
216- queryResult .Data = logsResult .Data
218+ queryResult .Data = serializeLogs ( logsResult .Data )
217219 }
218220 }
219221 queryResult .Meta .TotalItems = len (logsResult .Data )
@@ -237,3 +239,59 @@ func getMainStorage() (storage.IMainStorage, error) {
237239func sendJSONResponse (c * gin.Context , response interface {}) {
238240 c .JSON (http .StatusOK , response )
239241}
242+
243+ func serializeDecodedLogs (logs []* common.DecodedLog ) []DecodedLogModel {
244+ decodedLogModels := make ([]DecodedLogModel , len (logs ))
245+ for i , log := range logs {
246+ decodedLogModels [i ] = serializeDecodedLog (* log )
247+ }
248+ return decodedLogModels
249+ }
250+
251+ func serializeDecodedLog (log common.DecodedLog ) DecodedLogModel {
252+ decodedData := DecodedLogDataModel {
253+ Name : log .Decoded .Name ,
254+ Signature : log .Decoded .Signature ,
255+ IndexedParams : log .Decoded .IndexedParams ,
256+ NonIndexedParams : log .Decoded .NonIndexedParams ,
257+ }
258+ return DecodedLogModel {
259+ LogModel : serializeLog (log .Log ),
260+ Decoded : decodedData ,
261+ DecodedData : decodedData ,
262+ }
263+ }
264+
265+ func serializeLogs (logs []common.Log ) []LogModel {
266+ logModels := make ([]LogModel , len (logs ))
267+ for i , log := range logs {
268+ logModels [i ] = serializeLog (log )
269+ }
270+ return logModels
271+ }
272+
273+ func serializeLog (log common.Log ) LogModel {
274+ return LogModel {
275+ ChainId : log .ChainId .String (),
276+ BlockNumber : log .BlockNumber .Uint64 (),
277+ BlockHash : log .BlockHash ,
278+ BlockTimestamp : log .BlockTimestamp ,
279+ TransactionHash : log .TransactionHash ,
280+ TransactionIndex : log .TransactionIndex ,
281+ LogIndex : log .LogIndex ,
282+ Address : log .Address ,
283+ Data : log .Data ,
284+ Topics : serializeTopics (log ),
285+ }
286+ }
287+
288+ func serializeTopics (log common.Log ) []string {
289+ topics := []string {log .Topic0 , log .Topic1 , log .Topic2 , log .Topic3 }
290+ resultTopics := make ([]string , 0 , len (topics ))
291+ for _ , topic := range topics {
292+ if topic != "" {
293+ resultTopics = append (resultTopics , topic )
294+ }
295+ }
296+ return resultTopics
297+ }
0 commit comments