Commit d9d236c3 authored by Benoit Lavenier's avatar Benoit Lavenier

[enh] Add commonTime in block query

parent 2043d71e
Pipeline #7367 failed with stages
......@@ -25,7 +25,7 @@ export type IFieldContext = {
export function plugModule(server: Server, logger?: any) {
logger = logger || logger_1.NewLogger();
const schemaFile = path.join(__dirname, 'schema.graphqls');
const schemaFile = path.join(__dirname, 'schema.graphql');
const typeDefs = fs.readFileSync(schemaFile, 'utf8');
return makeExecutableSchema({
......@@ -55,11 +55,18 @@ export function plugModule(server: Server, logger?: any) {
blockchainParameters: () => server.dal.getParameters(),
block: async (_, { number }: { number?: number }) => {
if (number !== undefined) {
return server.dal.getBlock(number)
}
const b = await server.dal.getCurrentBlockOrNull()
return b
const block = (number !== undefined) ?
await server.dal.getBlock(number) :
await server.dal.getCurrentBlockOrNull();
if (!block) return null;
return {
...block,
// TODO make sure this is the final RFC name
commonTime: async () => {
const parameters = await server.dal.getParameters();
return parameters && (block.medianTime + (parameters.avgGenTime * parameters.medianTimeBlocks / 2)) || null;
}
} || null;
},
member: async (_, { uid, pub }: { uid: string, pub: string }) => {
......
export declare interface BlockRef {
export declare class Block {
number: number;
// Block hash
hash: string;
......@@ -9,6 +9,10 @@ export declare interface BlockRef {
// Block median time
medianTime: number;
// = median time + (avgGenTime * medianTime / 2)
userTime: number;
// commonTime = medianTime + (avgGenTime * medianTimeBlocks / 2)
// TODO check the RFC final name
commonTime: number;
// TODO: check if define in the RFC
issuerName: string;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment