Skip to content

Commit d877351

Browse files
committed
feat: view human-readable database size and v2 route reporting
Change the action route for `getDatabaseSize()` to v2 route and adds `getDatabaseSizePretty()` method to the Action class, enabling clients to retrieve database size in a user-friendly format (e.g., "22 GB", "1.5 TB") instead of raw byte counts. This complements the existing `getDatabaseSize()` method by providing a more accessible view of database storage metrics for end users and dashboards. resolves: trufnetwork/truf-network#1219
1 parent 5f8462d commit d877351

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/contracts-api/action.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ export class Action {
937937
* Returns the size of database
938938
*/
939939
public async getDatabaseSize(): Promise<BigInt> {
940-
const result = await this.call<{ database_size: BigInt }[]>("get_database_size", {})
940+
const result = await this.call<{ database_size: BigInt }[]>("get_database_size_v2", {})
941941
return result
942942
.map((rows) => {
943943
const raw = rows[0].database_size;
@@ -946,6 +946,16 @@ export class Action {
946946
}).throw();
947947
}
948948

949+
/**
950+
* Returns the size of database in human-readable format (e.g., "22 GB", "1.5 TB")
951+
*/
952+
public async getDatabaseSizePretty(): Promise<string> {
953+
const result = await this.call<{ database_size_pretty: string }[]>("get_database_size_v2_pretty", {})
954+
return result
955+
.map((rows) => rows[0].database_size_pretty)
956+
.throw();
957+
}
958+
949959
/**
950960
* Gets the wallet balance on any supported blockchain network
951961
* @param chain The chain identifier (e.g., "sepolia", "mainnet", "polygon", etc.)

tests/integration/databaseSize.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,17 @@ describe.sequential("Get Database Size", { timeout: 360000 }, () => {
2222
expect(databaseSize).toBeGreaterThan(0n)
2323
}
2424
)
25+
26+
testWithDefaultWallet(
27+
"should get database size in human-readable format",
28+
async ({ defaultClient }) => {
29+
const actions = defaultClient.loadAction()
30+
const databaseSizePretty = await actions.getDatabaseSizePretty()
31+
32+
expect(databaseSizePretty).toBeTruthy()
33+
expect(typeof databaseSizePretty).toBe("string")
34+
// Should contain a number followed by a unit (e.g., "22 GB", "1.5 MB")
35+
expect(databaseSizePretty).toMatch(/\d+.*\s*(bytes|kB|MB|GB|TB)/i)
36+
}
37+
)
2538
});

0 commit comments

Comments
 (0)