Create difficulty chart component

This commit is contained in:
nymkappa
2022-02-16 21:20:28 +09:00
parent e2e3546934
commit 7270b1ccac
11 changed files with 192 additions and 16 deletions

View File

@@ -223,6 +223,30 @@ class BlocksRepository {
return rows[0];
}
/**
* Return blocks difficulty
*/
public async $getBlocksDifficulty(interval: string | null): Promise<object[]> {
interval = Common.getSqlInterval(interval);
const connection = await DB.pool.getConnection();
let query = `SELECT MIN(blockTimestamp) as timestamp, difficulty
FROM blocks`;
if (interval) {
query += ` WHERE blockTimestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
}
query += ` GROUP BY difficulty
ORDER BY blockTimestamp DESC`;
const [rows]: any[] = await connection.query(query);
connection.release();
return rows;
}
}
export default new BlocksRepository();