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