From 5b32ab6dde8e678c8bdb27cefa4a5c6882383992 Mon Sep 17 00:00:00 2001 From: nymkappa Date: Fri, 21 Jan 2022 00:08:51 +0900 Subject: [PATCH] DROP -> DROP IF EXISTS --- backend/src/api/blocks.ts | 9 ++++++++- backend/src/api/database-migration.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index aac74584b..28877a6d7 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -146,6 +146,10 @@ class Blocks { * Index all blocks metadata for the mining dashboard */ public async $generateBlockDatabase() { + if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) { + return; + } + let currentBlockHeight = await bitcoinClient.getBlockCount(); const indexedBlockCount = await blocksRepository.$blockCount(); @@ -231,7 +235,10 @@ class Blocks { const blockExtended: BlockExtended = this.getBlockExtended(block, transactions); const miner = await this.$findBlockMiner(blockExtended.coinbaseTx); 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) { this.previousDifficultyRetarget = (block.difficulty - this.currentDifficulty) / this.currentDifficulty * 100; diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index 50aa3a7f6..baa518598 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -87,7 +87,7 @@ class DatabaseMigration { await this.$executeQuery(connection, this.getCreatePoolsTableQuery(), await this.$checkIfTableExists('pools')); } 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')); } connection.release();