diff --git a/backend/README.md b/backend/README.md index 1441319b9..e65205d67 100644 --- a/backend/README.md +++ b/backend/README.md @@ -17,6 +17,6 @@ sudo npm install -g ts-node nodemon > Note: You can find your npm global binary folder using `npm -g bin`, where nodemon will be installed. ``` -nodemon src/index.ts --ignore cache/ +nodemon src/index.ts --ignore cache/ --ignore pools.json ``` diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index eda348ad8..aac74584b 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -41,7 +41,7 @@ class Blocks { * @param onlyCoinbase - Set to true if you only need the coinbase transaction * @returns Promise */ - private async $getTransactionsExtended(blockHash: string, blockHeight: number, onlyCoinbase: boolean) : Promise { + private async $getTransactionsExtended(blockHash: string, blockHeight: number, onlyCoinbase: boolean): Promise { const transactions: TransactionExtended[] = []; const txIds: string[] = await bitcoinApi.$getTxIdsForBlock(blockHash); @@ -94,7 +94,7 @@ class Blocks { * @param transactions * @returns BlockExtended */ - private getBlockExtended(block: IEsploraApi.Block, transactions: TransactionExtended[]) : BlockExtended { + private getBlockExtended(block: IEsploraApi.Block, transactions: TransactionExtended[]): BlockExtended { const blockExtended: BlockExtended = Object.assign({}, block); blockExtended.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0); blockExtended.coinbaseTx = transactionUtils.stripCoinbaseTransaction(transactions[0]); @@ -113,7 +113,7 @@ class Blocks { * @param txMinerInfo * @returns */ - private async $findBlockMiner(txMinerInfo: TransactionMinerInfo | undefined) : Promise { + private async $findBlockMiner(txMinerInfo: TransactionMinerInfo | undefined): Promise { if (txMinerInfo === undefined) { return await poolsRepository.$getUnknownPool(); } @@ -124,15 +124,15 @@ class Blocks { const pools: PoolTag[] = await poolsRepository.$getPools(); for (let i = 0; i < pools.length; ++i) { if (address !== undefined) { - let addresses: string[] = JSON.parse(pools[i].addresses); + const addresses: string[] = JSON.parse(pools[i].addresses); if (addresses.indexOf(address) !== -1) { return pools[i]; } } - let regexes: string[] = JSON.parse(pools[i].regexes); + const regexes: string[] = JSON.parse(pools[i].regexes); for (let y = 0; y < regexes.length; ++y) { - let match = asciiScriptSig.match(regexes[y]); + const match = asciiScriptSig.match(regexes[y]); if (match !== null) { return pools[i]; } diff --git a/backend/src/api/database-migration.ts b/backend/src/api/database-migration.ts index c08b36ce1..50aa3a7f6 100644 --- a/backend/src/api/database-migration.ts +++ b/backend/src/api/database-migration.ts @@ -87,6 +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, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks')); } connection.release(); diff --git a/backend/src/repositories/BlocksRepository.ts b/backend/src/repositories/BlocksRepository.ts index 9ae41f536..8d36d8410 100644 --- a/backend/src/repositories/BlocksRepository.ts +++ b/backend/src/repositories/BlocksRepository.ts @@ -38,7 +38,7 @@ class BlocksRepository { await connection.query(query, params); } catch (e) { - logger.err('$updateBlocksDatabase() error' + (e instanceof Error ? e.message : e)); + logger.err('$saveBlockInDatabase() error' + (e instanceof Error ? e.message : e)); } connection.release(); diff --git a/backend/src/repositories/PoolsRepository.ts b/backend/src/repositories/PoolsRepository.ts index b2a61dc19..060418bf8 100644 --- a/backend/src/repositories/PoolsRepository.ts +++ b/backend/src/repositories/PoolsRepository.ts @@ -1,5 +1,5 @@ -import { DB } from "../database"; -import { PoolInfo, PoolTag } from "../mempool.interfaces" +import { DB } from '../database'; +import { PoolInfo, PoolTag } from '../mempool.interfaces'; class PoolsRepository { /** @@ -7,7 +7,7 @@ class PoolsRepository { */ public async $getPools(): Promise { const connection = await DB.pool.getConnection(); - const [rows] = await connection.query("SELECT * FROM pools;"); + const [rows] = await connection.query('SELECT * FROM pools;'); connection.release(); return rows; } @@ -17,7 +17,7 @@ class PoolsRepository { */ public async $getUnknownPool(): Promise { const connection = await DB.pool.getConnection(); - const [rows] = await connection.query("SELECT * FROM pools where name = 'Unknown'"); + const [rows] = await connection.query('SELECT * FROM pools where name = "Unknown"'); connection.release(); return rows[0]; } @@ -25,7 +25,7 @@ class PoolsRepository { /** * Get basic pool info and block count */ - public async $getPoolsInfo(interval: string = "100 YEARS"): Promise { + public async $getPoolsInfo(interval: string = '100 YEARS'): Promise { const connection = await DB.pool.getConnection(); const [rows] = await connection.query(` SELECT COUNT(height) as blockCount, pool_id as poolId, pools.name as name, pools.link as link @@ -40,4 +40,4 @@ class PoolsRepository { } } -export default new PoolsRepository(); \ No newline at end of file +export default new PoolsRepository();