From 6bf6e1fd46266678ac2b46bf793c352553cae5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Tue, 6 Aug 2024 10:45:34 -0300 Subject: [PATCH] fix: handling empty arrays on IN conditions --- packages/daemon/src/db/index.ts | 26 ++++++++++++++++++++------ packages/daemon/src/services/index.ts | 4 +++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/daemon/src/db/index.ts b/packages/daemon/src/db/index.ts index 68e7c143..4ef65fe4 100644 --- a/packages/daemon/src/db/index.ts +++ b/packages/daemon/src/db/index.ts @@ -497,6 +497,10 @@ export const updateAddressTablesWithTx = async ( timestamp: number, addressBalanceMap: StringMap, ): Promise => { + if (Object.keys(addressBalanceMap).length === 0) { + // No need to do anything here, the transaction most likely has no inputs and outputs + return; + } /* * update address table * @@ -506,12 +510,14 @@ export const updateAddressTablesWithTx = async ( * If address is already present, just increment the transactions counter. */ const addressEntries = Object.keys(addressBalanceMap).map((address) => [address, 1]); - await mysql.query( - `INSERT INTO \`address\`(\`address\`, \`transactions\`) - VALUES ? - ON DUPLICATE KEY UPDATE transactions = transactions + 1`, - [addressEntries], - ); + if (addressEntries.length > 0) { + await mysql.query( + `INSERT INTO \`address\`(\`address\`, \`transactions\`) + VALUES ? + ON DUPLICATE KEY UPDATE transactions = transactions + 1`, + [addressEntries], + ); + } const entries = []; for (const [address, tokenMap] of Object.entries(addressBalanceMap)) { @@ -769,6 +775,10 @@ export const updateAddressLockedBalance = async ( * @returns A map of address and corresponding wallet information */ export const getAddressWalletInfo = async (mysql: MysqlConnection, addresses: string[]): Promise> => { + if (addresses.length === 0) { + return {}; + } + const addressWalletMap: StringMap = {}; const [results] = await mysql.query( `SELECT DISTINCT a.\`address\`, @@ -1036,6 +1046,10 @@ export const incrementTokensTxCount = async ( mysql: MysqlConnection, tokenList: string[], ): Promise => { + if (tokenList.length === 0) { + return; + } + await mysql.query(` UPDATE \`token\` SET \`transactions\` = \`transactions\` + 1 diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index 1b69d354..18199b0e 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -226,7 +226,9 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => { const blockRewardOutput = outputs[0]; // add miner to the miners table - await addMiner(mysql, blockRewardOutput.decoded.address, hash); + if (blockRewardOutput.decoded) { + await addMiner(mysql, blockRewardOutput.decoded.address, hash); + } // here we check if we have any utxos on our database that is locked but // has its timelock < now