Skip to content

Commit

Permalink
fix: handling empty arrays on IN conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Aug 6, 2024
1 parent 7c8c45d commit 6bf6e1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 20 additions & 6 deletions packages/daemon/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ export const updateAddressTablesWithTx = async (
timestamp: number,
addressBalanceMap: StringMap<TokenBalanceMap>,
): Promise<void> => {
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
*
Expand All @@ -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)) {
Expand Down Expand Up @@ -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<StringMap<Wallet>> => {
if (addresses.length === 0) {
return {};
}

const addressWalletMap: StringMap<Wallet> = {};
const [results] = await mysql.query(
`SELECT DISTINCT a.\`address\`,
Expand Down Expand Up @@ -1036,6 +1046,10 @@ export const incrementTokensTxCount = async (
mysql: MysqlConnection,
tokenList: string[],
): Promise<void> => {
if (tokenList.length === 0) {
return;
}

await mysql.query(`
UPDATE \`token\`
SET \`transactions\` = \`transactions\` + 1
Expand Down
4 changes: 3 additions & 1 deletion packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bf6e1f

Please sign in to comment.