Added mining/pool/:poolId and mining/pool/:poolId/:interval APIs

This commit is contained in:
nymkappa
2022-02-08 18:28:53 +09:00
parent 039a627d1c
commit b854c071d0
5 changed files with 94 additions and 15 deletions

View File

@@ -135,6 +135,23 @@ class BlocksRepository {
return <number>rows[0].blockTimestamp;
}
/**
* Get blocks mined by a specific mining pool
*/
public async $getBlocksByPool(interval: string | null, poolId: number): Promise<object> {
const query = `
SELECT *
FROM blocks
WHERE pool_id = ${poolId}`
+ (interval != null ? ` AND blockTimestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()` : ``);
const connection = await DB.pool.getConnection();
const [rows] = await connection.query(query);
connection.release();
return rows;
}
/**
* Get one block by height
*/
@@ -156,4 +173,4 @@ class BlocksRepository {
}
}
export default new BlocksRepository();
export default new BlocksRepository();

View File

@@ -41,6 +41,23 @@ class PoolsRepository {
return <PoolInfo[]>rows;
}
/**
* Get mining pool statistics for one pool
*/
public async $getPool(poolId: number) : Promise<object> {
const query = `
SELECT *
FROM pools
WHERE pools.id = ${poolId}
`;
const connection = await DB.pool.getConnection();
const [rows] = await connection.query(query);
connection.release();
return rows[0];
}
}
export default new PoolsRepository();