From 5ea2e21bcd21b27c0ff72e0037af6571cae4d3d1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 21 Nov 2024 15:42:36 +0200 Subject: [PATCH 1/3] Update event decoding logic. --- blockchain/common/decoding.go | 50 +++++++++-------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/blockchain/common/decoding.go b/blockchain/common/decoding.go index a4008f0..98102c2 100644 --- a/blockchain/common/decoding.go +++ b/blockchain/common/decoding.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "log" - "math/big" "os" "strings" @@ -200,13 +199,14 @@ func DecodeTransactionInputDataToInterface(contractABI *abi.ABI, data []byte) (m func DecodeLogArgsToLabelData(contractABI *abi.ABI, topics []string, data string) (map[string]interface{}, error) { - topic0 := topics[0] + var topicHashes []common.Hash - // Convert the topic0 string to common.Hash - topic0Hash := common.HexToHash(topic0) + for _, topic := range topics { + topicHashes = append(topicHashes, common.HexToHash(topic)) + } event, err := contractABI.EventByID( - topic0Hash, + topicHashes[0], ) if err != nil { log.Fatal(err) @@ -224,41 +224,17 @@ func DecodeLogArgsToLabelData(contractABI *abi.ABI, topics []string, data string labelData["name"] = event.Name labelData["args"] = make(map[string]interface{}) - i := 1 - // Extract indexed parameters from topics + indexed := make([]abi.Argument, 0) for _, input := range event.Inputs { - var arg interface{} if input.Indexed { - // Note: topic[0] is the event signature, so indexed params start from topic[1] - switch input.Type.T { - case abi.AddressTy: - arg = common.HexToAddress(topics[i]).Hex() - case abi.BytesTy: - arg = common.HexToHash(topics[i]).Hex() - case abi.FixedBytesTy: - if input.Type.Size == 32 { - arg = common.HexToHash(topics[i]).Hex() - } else { - arg = common.BytesToHash(common.Hex2Bytes(topics[i][2:])).Hex() // for other fixed sizes - } - case abi.UintTy: - arg = new(big.Int).SetBytes(common.Hex2Bytes(topics[i][2:])) - case abi.BoolTy: - arg = new(big.Int).SetBytes(common.Hex2Bytes(topics[i][2:])).Cmp(big.NewInt(0)) != 0 - case abi.StringTy: - argBytes, err := hex.DecodeString(strings.TrimPrefix(topics[i], "0x")) - if err != nil { - return nil, fmt.Errorf("failed to decode hex string to normal string: %v", err) - } - arg = string(argBytes) - default: - log.Fatalf("Unsupported indexed type: %s", input.Type.String()) - } - i++ - } else { - arg = "NON-INDEXED" // Placeholder for non-indexed arguments, which will be unpacked later + indexed = append(indexed, input) } - labelData["args"].(map[string]interface{})[input.Name] = arg + } + + // parse topics into map + err = abi.ParseTopicsIntoMap(labelData["args"].(map[string]interface{}), indexed, topicHashes[1:]) + if err != nil { + return nil, err } // Unpack the data bytes into the args map From fd2de08711252f01e57e6d0ec9816497b486e96a Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 21 Nov 2024 16:11:42 +0200 Subject: [PATCH 2/3] Update batch reading. --- indexer/db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indexer/db.go b/indexer/db.go index 474065d..daa43ba 100644 --- a/indexer/db.go +++ b/indexer/db.go @@ -630,7 +630,7 @@ func (p *PostgreSQLpgx) ReadUpdates(blockchain string, fromBlock uint64, custome ) SELECT latest_block_number, - (SELECT array_agg(path) FROM path) as paths, + (SELECT array_agg(DISTINCT path) FROM path) as paths, (SELECT json_agg(json_build_object(customer_id, abis)) FROM reformatted_jobs) as jobs FROM latest_block_of_path @@ -1469,7 +1469,7 @@ func (p *PostgreSQLpgx) RetrievePathsAndBlockBounds(blockchain string, blockNumb order by block_number asc limit 1 ) - select ARRAY_AGG(path) as paths, (SELECT first_block_number FROM earliest_block_of_path) as min_block_number, (SELECT latest_block_number FROM latest_block_of_path) as max_block_number from path + select ARRAY_AGG( DISTINCT path) as paths, (SELECT first_block_number FROM earliest_block_of_path) as min_block_number, (SELECT latest_block_number FROM latest_block_of_path) as max_block_number from path `, BlocksTableName(blockchain), BlocksTableName(blockchain), BlocksTableName(blockchain)) err = conn.QueryRow(context.Background(), query, blockNumber, blockNumber-uint64(minBlocksToSync)).Scan(&paths, &minBlockNumber, &maxBlockNumber) From 90e8ee06f3e5f01945f3fc9fa66fdc2feb7b5fc4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 21 Nov 2024 16:13:23 +0200 Subject: [PATCH 3/3] Bump version. --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 3111c63..ac013a2 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -var SeerVersion string = "0.3.12" +var SeerVersion string = "0.3.13"