Merge pull request #2109 from mempool/nymkappa/bugfix/block-audit-code-refactor
Block audit code refactor
This commit is contained in:
		
						commit
						ed4aa4e93a
					
				@ -578,7 +578,7 @@ class Blocks {
 | 
			
		||||
 | 
			
		||||
    // Index the response if needed
 | 
			
		||||
    if (Common.blocksSummariesIndexingEnabled() === true) {
 | 
			
		||||
      await BlocksSummariesRepository.$saveSummary(block.height, summary, null);
 | 
			
		||||
      await BlocksSummariesRepository.$saveSummary({height: block.height, mined: summary});
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return summary.transactions;
 | 
			
		||||
 | 
			
		||||
@ -451,9 +451,12 @@ class WebsocketHandler {
 | 
			
		||||
            value: tx.value,
 | 
			
		||||
          };
 | 
			
		||||
        });  
 | 
			
		||||
        BlocksSummariesRepository.$saveSummary(block.height, null, {
 | 
			
		||||
          id: block.id,
 | 
			
		||||
          transactions: stripped
 | 
			
		||||
        BlocksSummariesRepository.$saveSummary({
 | 
			
		||||
          height: block.height,
 | 
			
		||||
          template: {
 | 
			
		||||
            id: block.id,
 | 
			
		||||
            transactions: stripped
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        BlocksAuditsRepository.$saveAudit({
 | 
			
		||||
 | 
			
		||||
@ -17,18 +17,18 @@ class BlocksSummariesRepository {
 | 
			
		||||
    return undefined;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async $saveSummary(height: number, mined: BlockSummary | null = null, template: BlockSummary | null = null) {
 | 
			
		||||
    const blockId = mined?.id ?? template?.id;
 | 
			
		||||
  public async $saveSummary(params: { height: number, mined?: BlockSummary, template?: BlockSummary}) {
 | 
			
		||||
    const blockId = params.mined?.id ?? params.template?.id;
 | 
			
		||||
    try {
 | 
			
		||||
      const [dbSummary]: any[] = await DB.query(`SELECT * FROM blocks_summaries WHERE id = "${blockId}"`);
 | 
			
		||||
      if (dbSummary.length === 0) { // First insertion
 | 
			
		||||
        await DB.query(`INSERT INTO blocks_summaries VALUE (?, ?, ?, ?)`, [
 | 
			
		||||
          height, blockId, JSON.stringify(mined?.transactions ?? []), JSON.stringify(template?.transactions ?? [])
 | 
			
		||||
          params.height, blockId, JSON.stringify(params.mined?.transactions ?? []), JSON.stringify(params.template?.transactions ?? [])
 | 
			
		||||
        ]);
 | 
			
		||||
      } else if (mined !== null) { // Update mined block summary
 | 
			
		||||
        await DB.query(`UPDATE blocks_summaries SET transactions = ? WHERE id = "${mined.id}"`, [JSON.stringify(mined?.transactions)]);
 | 
			
		||||
      } else if (template !== null) { // Update template block summary
 | 
			
		||||
        await DB.query(`UPDATE blocks_summaries SET template = ? WHERE id = "${template.id}"`, [JSON.stringify(template?.transactions)]);
 | 
			
		||||
      } else if (params.mined !== undefined) { // Update mined block summary
 | 
			
		||||
        await DB.query(`UPDATE blocks_summaries SET transactions = ? WHERE id = "${params.mined.id}"`, [JSON.stringify(params.mined.transactions)]);
 | 
			
		||||
      } else if (params.template !== undefined) { // Update template block summary
 | 
			
		||||
        await DB.query(`UPDATE blocks_summaries SET template = ? WHERE id = "${params.template.id}"`, [JSON.stringify(params.template?.transactions)]);
 | 
			
		||||
      }
 | 
			
		||||
    } catch (e: any) {
 | 
			
		||||
      if (e.errno === 1062) { // ER_DUP_ENTRY - This scenario is possible upon node backend restart
 | 
			
		||||
 | 
			
		||||
@ -143,9 +143,7 @@ export default class TxView implements TransactionStripped {
 | 
			
		||||
 | 
			
		||||
  getColor(): Color {
 | 
			
		||||
    // Block audit
 | 
			
		||||
    if (this.status === 'found') {
 | 
			
		||||
      // return hexToColor('1a4987');
 | 
			
		||||
    } else if (this.status === 'missing') {
 | 
			
		||||
    if (this.status === 'missing') {
 | 
			
		||||
      return hexToColor('039BE5');
 | 
			
		||||
    } else if (this.status === 'added') {
 | 
			
		||||
      return hexToColor('D81B60');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user