Commit a124c54b authored by Benoit Lavenier's avatar Benoit Lavenier

[enh] Add blockchain query

[enh] Add log when GVA starts
parent 05852c79
Pipeline #6186 failed with stages
/node_modules
/.idea
......@@ -5,6 +5,7 @@
"license": "MIT",
"scripts": {
"install": "tsc",
"start": "node index.js direct_start --gva-host localhost",
"test": "mocha tests/"
},
"dependencies": {
......@@ -23,11 +24,12 @@
"@types/request-promise": "^4.1.42",
"@types/should": "^13.0.0",
"assert": "^1.4.1",
"duniter": "^1.7.6",
"duniter": "^1.7.19",
"mocha": "^5.2.0",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"should": "^13.2.3",
"ts-node": "^7.0.1"
"ts-node": "^7.0.1",
"yarn": "^1.17.3"
}
}
......@@ -4,10 +4,15 @@ import {Server} from "duniter/server";
import {makeExecutableSchema} from "graphql-tools";
import {FullIindexEntry, FullMindexEntry} from "duniter/app/lib/indexer";
import {hashf} from "duniter/app/lib/common";
const pkg = require('../package.json')
const logger_1 = require("duniter/app/lib/logger");
export function plugModule(server: Server, logger?: any) {
logger = logger || logger_1.NewLogger();
export function plugModule(server: Server) {
const schemaFile = path.join(__dirname, 'schema.graphqls');
const typeDefs = fs.readFileSync(schemaFile, 'utf8');
return makeExecutableSchema({
typeDefs,
resolvers: {
......@@ -17,6 +22,21 @@ export function plugModule(server: Server) {
currency: () => server.conf.currency,
nodeSummary: () => {
logger && logger.debug("GVA: Processing query: nodeSummary")
const software = 'duniter';
const version = pkg.devDependencies[software].replace('^', '');
return {
duniter: {
software,
version,
forkWindowSize: server.conf.forksize
}
};
},
blockchainParameters: () => server.dal.getParameters(),
block: async (_, { number }: { number?: number }) => {
if (number !== undefined) {
return server.dal.getBlock(number)
......@@ -33,9 +53,12 @@ export function plugModule(server: Server) {
},
pendingIdentities: async (_, { search }: { search: string }) => {
if (!search) {
logger && logger.debug("GVA: returning pending identities")
return server.dal.idtyDAL.getPendingIdentities()
}
logger && logger.debug("GVA: searching on identities {" + search + "}")
return server.dal.idtyDAL.searchThoseMatching(search)
},
......@@ -148,4 +171,4 @@ export function plugModule(server: Server) {
}
}
})
}
\ No newline at end of file
}
......@@ -3,12 +3,18 @@ import * as express from "express";
import graphqlHTTP = require("express-graphql");
import {Server} from "duniter/server";
import * as http from "http";
const logger_1 = require("duniter/app/lib/logger");
export function gvaHttpListen(server: Server, port: number, host = 'localhost'): http.Server {
const app = express()
const logger = logger_1.NewLogger('gva');
app.use('/graphql', graphqlHTTP({
schema: plugModule(server),
schema: plugModule(server, logger),
graphiql: true,
}))
return app.listen(port, host, () => console.log(`Now browse to ${host}:${port}/graphql`))
return app.listen(port, host, () => {
logger && logger.info(`GVA server listening on http${port==443 ? 's' : ''}://${host}:${port}/graphql`);
})
}
......@@ -176,6 +176,49 @@ type Block {
written_on: String!
}
type BlockchainParameters {
currency: String!
c: Int!
dt: Int!
ud0: Int!
sigPeriod: Int!
sigReplay: Int!
sigStock: Int!
sigWindow: Int!
sigValidity: Int!
sigQty: Int!
idtyWindow: Int!
msWindow: Int!
msPeriod: Int!
xpercent: Int!
msValidity: Int!
stepMax: Int!
medianTimeBlocks: Int!
avgGenTime: Int!
dtDiffEval: Int!
percentRot: Int!
udTime0: Int!
udReevalTime0: Int!
dtReeval: Int!
}
type NodeSummaryDuniter {
version: String!
software: String!
forkWindowSize: Int!
}
type NodeSummary {
duniter: NodeSummaryDuniter
}
input Paging {
pageNumber: Int! = 0
pageSize: Int! = 50
fromBlock: Int! = 0
toBlock: Int
}
type Mutation {
submitIdentity(raw: String!): PendingIdentity!
submitCertification(raw: String!): PendingIdentity!
......@@ -185,6 +228,8 @@ type Mutation {
type Query {
hello: String
nodeSummary: NodeSummary!
blockchainParameters: BlockchainParameters!
currency: String!
block(number: Int): Block
member(uid: String, pub: String): Identity
......
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