Drop legacy blocks table during migration - Fix linter issues
				
					
				
			This commit is contained in:
		
							parent
							
								
									b8410f00d9
								
							
						
					
					
						commit
						aa457e316b
					
				@ -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
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@ class Blocks {
 | 
			
		||||
   * @param onlyCoinbase - Set to true if you only need the coinbase transaction
 | 
			
		||||
   * @returns Promise<TransactionExtended[]>
 | 
			
		||||
   */
 | 
			
		||||
  private async $getTransactionsExtended(blockHash: string, blockHeight: number, onlyCoinbase: boolean) : Promise<TransactionExtended[]> {
 | 
			
		||||
  private async $getTransactionsExtended(blockHash: string, blockHeight: number, onlyCoinbase: boolean): Promise<TransactionExtended[]> {
 | 
			
		||||
    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<PoolTag> {
 | 
			
		||||
  private async $findBlockMiner(txMinerInfo: TransactionMinerInfo | undefined): Promise<PoolTag> {
 | 
			
		||||
    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];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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<PoolTag[]> {
 | 
			
		||||
    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 <PoolTag[]>rows;
 | 
			
		||||
  }
 | 
			
		||||
@ -17,7 +17,7 @@ class PoolsRepository {
 | 
			
		||||
   */
 | 
			
		||||
  public async $getUnknownPool(): Promise<PoolTag> {
 | 
			
		||||
    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 <PoolTag>rows[0];
 | 
			
		||||
  }
 | 
			
		||||
@ -25,7 +25,7 @@ class PoolsRepository {
 | 
			
		||||
  /**
 | 
			
		||||
   * Get basic pool info and block count
 | 
			
		||||
   */
 | 
			
		||||
  public async $getPoolsInfo(interval: string = "100 YEARS"): Promise<PoolInfo[]> {
 | 
			
		||||
  public async $getPoolsInfo(interval: string = '100 YEARS'): Promise<PoolInfo[]> {
 | 
			
		||||
    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();
 | 
			
		||||
export default new PoolsRepository();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user