Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test_images_up": "docker-compose -f ./__tests__/integration/scripts/docker-compose.yml up -d",
"test_images_down": "docker-compose -f ./__tests__/integration/scripts/docker-compose.yml down",
"test_images_integration": "jest --config ./jest_integration.config.js --runInBand --forceExit",
"test_images_migrate": "DB_NAME=hathor DB_PORT=3380 DB_PASS=hathor DB_USER=hathor yarn run sequelize-cli --migrations-path ../../db/migrations --config ./__tests__/integration/scripts/sequelize-db-config.js db:migrate",
"test_images_migrate": "NODE_ENV=test DB_NAME=hathor DB_PORT=3380 DB_PASS=hathor DB_USER=hathor yarn run sequelize-cli --migrations-path ../../db/migrations --config ./__tests__/integration/scripts/sequelize-db-config.js db:migrate",
Comment thread
andreabadesso marked this conversation as resolved.
"test_images_wait_for_db": "yarn dlx ts-node ./__tests__/integration/scripts/wait-for-db-up.ts",
"test_images_wait_for_ws": "yarn dlx ts-node ./__tests__/integration/scripts/wait-for-ws-up.ts",
"test_images_setup_database": "yarn dlx ts-node ./__tests__/integration/scripts/setup-database.ts",
Expand Down
29 changes: 13 additions & 16 deletions packages/daemon/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,16 @@ export const voidTransaction = async (
addressBalanceMap: StringMap<TokenBalanceMap>,
): Promise<void> => {
const addressEntries = Object.keys(addressBalanceMap).map((address) => [address, 0]);
await mysql.query(
`INSERT INTO \`address\`(\`address\`, \`transactions\`)
VALUES ?
ON DUPLICATE KEY UPDATE transactions = transactions - 1`,
[addressEntries],
);

const entries = [];
if (addressEntries.length > 0) {
await mysql.query(
`INSERT INTO \`address\`(\`address\`, \`transactions\`)
VALUES ?
ON DUPLICATE KEY UPDATE transactions = transactions - 1`,
[addressEntries],
);
}

for (const [address, tokenMap] of Object.entries(addressBalanceMap)) {
for (const [token, tokenBalance] of tokenMap.iterator()) {
// update address_balance table or update balance and transactions if there's an entry already
Expand Down Expand Up @@ -438,25 +440,20 @@ export const voidTransaction = async (
// for locked authorities, it doesn't make sense to perform the same operation. The authority needs to be
// unlocked before it can be spent. In case we're just adding new locked authorities, this will be taken
// care by the first sql query.

// update address_tx_history with one entry for each pair (address, token)
entries.push(txId);
Comment thread
andreabadesso marked this conversation as resolved.
}
}

await mysql.query(
`DELETE FROM \`address_tx_history\`
WHERE \`tx_id\`
IN (?)`,
[entries],
WHERE \`tx_id\` = ?`,
[txId],
);

await mysql.query(
`UPDATE \`transaction\`
SET \`voided\` = TRUE
WHERE \`tx_id\`
IN (?)`,
[entries],
WHERE \`tx_id\` = ?`,
[txId],
);
};

Expand Down