DROP -> DROP IF EXISTS

This commit is contained in:
nymkappa 2022-01-21 00:08:51 +09:00
parent f982f6b4b6
commit 5b32ab6dde
No known key found for this signature in database
GPG key ID: E155910B16E8BD04
2 changed files with 9 additions and 2 deletions

View file

@ -146,6 +146,10 @@ class Blocks {
* Index all blocks metadata for the mining dashboard * Index all blocks metadata for the mining dashboard
*/ */
public async $generateBlockDatabase() { public async $generateBlockDatabase() {
if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) {
return;
}
let currentBlockHeight = await bitcoinClient.getBlockCount(); let currentBlockHeight = await bitcoinClient.getBlockCount();
const indexedBlockCount = await blocksRepository.$blockCount(); const indexedBlockCount = await blocksRepository.$blockCount();
@ -231,7 +235,10 @@ class Blocks {
const blockExtended: BlockExtended = this.getBlockExtended(block, transactions); const blockExtended: BlockExtended = this.getBlockExtended(block, transactions);
const miner = await this.$findBlockMiner(blockExtended.coinbaseTx); const miner = await this.$findBlockMiner(blockExtended.coinbaseTx);
const coinbase: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(transactions[0].txid, true); const coinbase: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(transactions[0].txid, true);
await blocksRepository.$saveBlockInDatabase(blockExtended, blockHash, coinbase.hex, miner);
if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === true) {
await blocksRepository.$saveBlockInDatabase(blockExtended, blockHash, coinbase.hex, miner);
}
if (block.height % 2016 === 0) { if (block.height % 2016 === 0) {
this.previousDifficultyRetarget = (block.difficulty - this.currentDifficulty) / this.currentDifficulty * 100; this.previousDifficultyRetarget = (block.difficulty - this.currentDifficulty) / this.currentDifficulty * 100;

View file

@ -87,7 +87,7 @@ class DatabaseMigration {
await this.$executeQuery(connection, this.getCreatePoolsTableQuery(), await this.$checkIfTableExists('pools')); await this.$executeQuery(connection, this.getCreatePoolsTableQuery(), await this.$checkIfTableExists('pools'));
} }
if (databaseSchemaVersion < 4) { if (databaseSchemaVersion < 4) {
await this.$executeQuery(connection, 'DROP table blocks;'); await this.$executeQuery(connection, 'DROP table IF EXISTS blocks;');
await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks')); await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks'));
} }
connection.release(); connection.release();