Skip to content

Commit 99abbe3

Browse files
committed
added a get method for the timestamps of the last 10 transactions
1 parent a620eb4 commit 99abbe3

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

api/src/httpd/router.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { restoreBackup } from "../system/restoreBackup";
2222

2323
import { AuthenticatedRequest, HttpResponse } from "./lib";
2424
import { getSchema, getSchemaWithoutAuth } from "./schema";
25+
import { getTimestamps } from "../system/getTimestamps";
2526

2627
const send = (res, httpResponse: HttpResponse): void => {
2728
const [code, body] = httpResponse;
@@ -227,7 +228,7 @@ export const registerRoutes = (
227228
storageServiceClient: StorageServiceClient,
228229
invalidateCache: () => void,
229230
): FastifyInstance => {
230-
server.register(async function () {
231+
server.register(async function() {
231232
const multichainClient = conn.multichainClient;
232233

233234
// ------------------------------------------------------------
@@ -280,6 +281,21 @@ export const registerRoutes = (
280281
},
281282
);
282283

284+
server.get(
285+
`${urlPrefix}/timestaps`,
286+
silentRouteSettings(getSchema(server, "version")),
287+
(request, reply) => {
288+
getTimestamps(
289+
multichainClient,
290+
)
291+
.then((response) => {
292+
send(reply, response);
293+
})
294+
.catch((err) => handleError(request, reply, err));
295+
},
296+
)
297+
298+
283299
// ------------------------------------------------------------
284300
// network
285301
// ------------------------------------------------------------

api/src/service/Client_storage_service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ export default class StorageServiceClient implements StorageServiceClientI {
7171
return result?.data as Version;
7272
}
7373

74+
public async getTimestamp(): Promise<number[]> {
75+
const result: AxiosResponse<unknown> = await this.axiosInstance.get("/timestamp");
76+
if (result.status !== 200) {
77+
return [];
78+
}
79+
return result.data as number[];
80+
}
81+
7482
public async uploadObject(file: File): Promise<Result.Type<UploadResponse>> {
7583
logger.debug(`Uploading Object "${file.fileName}"`);
7684

api/src/system/getTimestamps.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { HttpResponse } from "../httpd/lib";
2+
import { MultichainClient } from "../service/Client.h";
3+
4+
type TimestampData = number;
5+
6+
const multichainTimestampData = async (
7+
multichainClient: MultichainClient,
8+
): Promise<TimestampData[]> => {
9+
const { height } = await multichainClient.getLastBlockInfo();
10+
const blocks = await multichainClient.listBlocksByHeight(Math.max(0, height - 10));
11+
const timestamps = blocks.map((block) => block.time);
12+
return timestamps
13+
};
14+
15+
export const getTimestamps = async (
16+
multichainClient: MultichainClient,
17+
): Promise<HttpResponse> => {
18+
return [
19+
200, {
20+
apiVersion: "1.0",
21+
data: await multichainTimestampData(multichainClient),
22+
}
23+
]
24+
}

0 commit comments

Comments
 (0)