diff --git a/tools/walletextension/storage/database/mariadb/mariadb.go b/tools/walletextension/storage/database/mariadb/mariadb.go index 4af4290693..23030f168f 100644 --- a/tools/walletextension/storage/database/mariadb/mariadb.go +++ b/tools/walletextension/storage/database/mariadb/mariadb.go @@ -153,16 +153,20 @@ func (m *MariaDB) StoreTransaction(rawTx string, userID []byte) error { } defer stmt.Close() - // Calculate tx hash + // Validate rawTx length and get the txHash + txHash := "" if len(rawTx) < 3 { fmt.Println("Invalid rawTx: ", rawTx) - return nil - } - rawTxBytes, err := hex.DecodeString(rawTx[2:]) - if err != nil { - fmt.Println("Error decoding rawTx: ", rawTx) + } else { + // Decode the hex string to bytes, excluding the '0x' prefix + rawTxBytes, err := hex.DecodeString(rawTx[2:]) + if err != nil { + fmt.Println("Error decoding rawTx: ", err) + } else { + // Compute Keccak-256 hash + txHash = crypto.Keccak256Hash(rawTxBytes).Hex() + } } - txHash := crypto.Keccak256Hash(rawTxBytes) _, err = stmt.Exec(userID, txHash, rawTx) if err != nil { diff --git a/tools/walletextension/storage/database/sqlite/sqlite.go b/tools/walletextension/storage/database/sqlite/sqlite.go index 68e504072f..e1ee97d3fb 100644 --- a/tools/walletextension/storage/database/sqlite/sqlite.go +++ b/tools/walletextension/storage/database/sqlite/sqlite.go @@ -211,16 +211,19 @@ func (s *Database) StoreTransaction(rawTx string, userID []byte) error { } defer stmt.Close() - // Calculate tx hash + txHash := "" if len(rawTx) < 3 { fmt.Println("Invalid rawTx: ", rawTx) - return nil - } - rawTxBytes, err := hex.DecodeString(rawTx[2:]) - if err != nil { - fmt.Println("Error decoding rawTx: ", rawTx) + } else { + // Decode the hex string to bytes, excluding the '0x' prefix + rawTxBytes, err := hex.DecodeString(rawTx[2:]) + if err != nil { + fmt.Println("Error decoding rawTx: ", err) + } else { + // Compute Keccak-256 hash + txHash = crypto.Keccak256Hash(rawTxBytes).Hex() + } } - txHash := crypto.Keccak256Hash(rawTxBytes) _, err = stmt.Exec(userID, txHash, rawTx) if err != nil {