Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit bdade740 authored by Éloïs's avatar Éloïs
Browse files

[fix] typage treatment of all "server:any"

parent ebc7edc5
import {Server} from "../../server"
const constants = require('../lib/constants');
const wizard = require('../lib/wizard');
......@@ -8,7 +10,7 @@ module.exports = {
name: 'check-config',
desc: 'Checks the node\'s configuration',
onConfiguredExecute: async (server:any) => {
onConfiguredExecute: async (server:Server) => {
await server.checkConfig()
const logger = require('../lib/logger').NewLogger('wizard')
logger.warn('Configuration seems correct.');
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
import {CommonConstants} from "../lib/common-libs/constants"
module.exports = {
......@@ -20,7 +21,7 @@ module.exports = {
name: 'config',
desc: 'Register configuration in database',
// The command does nothing particular, it just stops the process right after configuration phase is over
onConfiguredExecute: (server:any, conf:ConfDTO) => Promise.resolve(conf)
onConfiguredExecute: (server:Server, conf:ConfDTO) => Promise.resolve(conf)
}]
}
}
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
"use strict";
......@@ -16,7 +17,7 @@ module.exports = {
],
service: {
process: (server:any) => ServerService(server)
process: (server:Server) => ServerService(server)
},
config: {
......@@ -34,7 +35,7 @@ module.exports = {
name: 'start',
desc: 'Starts Duniter as a daemon (background task).',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
await server.checkConfig()
const daemon = server.getDaemon('direct_start', 'start')
await startDaemon(daemon)
......@@ -44,7 +45,7 @@ module.exports = {
name: 'stop',
desc: 'Stops Duniter daemon if it is running.',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const daemon = server.getDaemon()
await stopDaemon(daemon)
}
......@@ -53,7 +54,7 @@ module.exports = {
name: 'restart',
desc: 'Stops Duniter daemon and restart it.',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
await server.checkConfig()
const daemon = server.getDaemon('direct_start', 'restart')
await stopDaemon(daemon)
......@@ -64,7 +65,7 @@ module.exports = {
name: 'status',
desc: 'Get Duniter daemon status.',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
await server.checkConfig()
const pid = server.getDaemon().status()
if (pid) {
......@@ -80,7 +81,7 @@ module.exports = {
name: 'logs',
desc: 'Follow duniter logs.',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
printTailAndWatchFile(directory.INSTANCE_HOMELOG_FILE, constants.NB_INITIAL_LINES_TO_SHOW)
// Never ending command
return new Promise(res => null)
......@@ -89,7 +90,7 @@ module.exports = {
name: 'direct_start',
desc: 'Start Duniter node with direct output, non-daemonized.',
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any, startServices:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any, startServices:any) => {
const logger = server.logger;
logger.info(">> Server starting...");
......@@ -110,7 +111,7 @@ module.exports = {
}
};
function ServerService(server:any) {
function ServerService(server:Server) {
server.startService = () => Promise.resolve();
server.stopService = () => Promise.resolve();
return server;
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
import {BlockDTO} from "../lib/dto/BlockDTO"
const _ = require('underscore');
......@@ -10,7 +11,7 @@ module.exports = {
name: 'export-bc [upto]',
desc: 'Exports the whole blockchain as JSON array, up to [upto] block number (excluded).',
logs: false,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const upto = params[0];
const logger = server.logger;
try {
......
import {randomKey} from "../../lib/common-libs/crypto/keyring"
import {ConfDTO, KeypairConfDTO} from "../../lib/dto/ConfDTO"
import {Server} from "../../../server"
import {Scrypt} from "./lib/scrypt"
const inquirer = require('inquirer');
......@@ -38,14 +39,14 @@ export const KeypairDependency = {
name: 'pub',
desc: 'Shows the node public key',
logs: false,
onConfiguredExecute: (server:any, conf:ConfDTO) => {
onConfiguredExecute: (server:Server, conf:ConfDTO) => {
console.log(conf.pair.pub)
}
}, {
name: 'sec',
desc: 'Shows the node secret key',
logs: false,
onConfiguredExecute: (server:any, conf:ConfDTO) => {
onConfiguredExecute: (server:Server, conf:ConfDTO) => {
console.log(conf.pair.sec)
}
}],
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
const async = require('async');
const constants = require('../lib/constants');
......@@ -7,7 +8,7 @@ const constants = require('../lib/constants');
module.exports = {
duniter: {
service: {
neutral: (server:any, conf:ConfDTO) => {
neutral: (server:Server, conf:ConfDTO) => {
for (const ep of conf.endpoints || []) {
server.addEndpointsDefinitions(async () => ep)
}
......@@ -28,7 +29,7 @@ class PeerSignalEmitter {
task(callback);
}, 1)
constructor(private server:any, private conf:ConfDTO) {
constructor(private server:Server, private conf:ConfDTO) {
}
async startService() {
......
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
"use strict";
......@@ -19,7 +20,7 @@ module.exports = {
name: 'plug [what]',
desc: 'Plugs in a duniter module to this Duniter codebase, making it available for the node.',
logs: false,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const what = params[0];
try {
console.log('Trying to install module "%s"...', what)
......@@ -36,7 +37,7 @@ module.exports = {
name: 'unplug [what]',
desc: 'Plugs in a duniter module to this Duniter codebase, making it available for the node.',
logs: false,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const what = params[0];
try {
console.log('Trying to remove module "%s"...', what)
......
......@@ -34,7 +34,7 @@ export const ProverDependency = {
},
service: {
output: (server:any) => {
output: (server:Server) => {
const generator = new BlockGenerator(server);
server.generatorGetJoinData = generator.getSinglePreJoinData.bind(generator)
server.generatorComputeNewCerts = generator.computeNewCerts.bind(generator)
......@@ -44,20 +44,20 @@ export const ProverDependency = {
},
methods: {
hookServer: (server:any) => {
hookServer: (server:Server) => {
const generator = new BlockGenerator(server);
server.generatorGetJoinData = generator.getSinglePreJoinData.bind(generator)
server.generatorComputeNewCerts = generator.computeNewCerts.bind(generator)
server.generatorNewCertsToLinks = generator.newCertsToLinks.bind(generator)
},
prover: (server:any, conf:ConfDTO, logger:any) => new Prover(server),
blockGenerator: (server:any, prover:any) => new BlockGeneratorWhichProves(server, prover),
generateTheNextBlock: async (server:any, manualValues:any) => {
prover: (server:Server, conf:ConfDTO, logger:any) => new Prover(server),
blockGenerator: (server:Server, prover:any) => new BlockGeneratorWhichProves(server, prover),
generateTheNextBlock: async (server:Server, manualValues:any) => {
const prover = new BlockProver(server);
const generator = new BlockGeneratorWhichProves(server, prover);
return generator.nextBlock(manualValues);
},
generateAndProveTheNext: async (server:any, block:any, trial:any, manualValues:any) => {
generateAndProveTheNext: async (server:Server, block:any, trial:any, manualValues:any) => {
const prover = new BlockProver(server);
const generator = new BlockGeneratorWhichProves(server, prover);
let res = await generator.makeNextBlock(block, trial, manualValues);
......@@ -79,7 +79,7 @@ export const ProverDependency = {
cli: [{
name: 'gen-next [difficulty]',
desc: 'Tries to generate the next block of the blockchain.',
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const difficulty = params[0]
const generator = new BlockGeneratorWhichProves(server, null);
return generateAndSend(program, difficulty, server, () => () => generator.nextBlock())
......@@ -88,7 +88,7 @@ export const ProverDependency = {
name: 'gen-root [difficulty]',
desc: 'Tries to generate the next block of the blockchain.',
preventIfRunning: true,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const difficulty = params[0]
const generator = new BlockGeneratorWhichProves(server, null);
let toDelete, catched = true;
......@@ -110,7 +110,7 @@ export const ProverDependency = {
name: 'gen-root-choose [difficulty]',
desc: 'Tries to generate root block, with choice of root members.',
preventIfRunning: true,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const difficulty = params[0]
if (!difficulty) {
throw 'Difficulty is required.';
......@@ -122,7 +122,7 @@ export const ProverDependency = {
}
}
function generateAndSend(program:any, difficulty:string, server:any, getGenerationMethod:any) {
function generateAndSend(program:any, difficulty:string, server:Server, getGenerationMethod:any) {
const logger = server.logger;
return new Promise((resolve, reject) => {
if (!program.submitLocal) {
......
"use strict";
import {ConfDTO} from "../../../lib/dto/ConfDTO"
import {Server} from "../../../../server"
import {BlockchainContext} from "../../../lib/computation/BlockchainContext"
import {TransactionDTO} from "../../../lib/dto/TransactionDTO"
import {GLOBAL_RULES_HELPERS} from "../../../lib/rules/global_rules"
......@@ -30,7 +31,7 @@ export class BlockGenerator {
selfPubkey:string
logger:any
constructor(private server:any) {
constructor(private server:Server) {
this.conf = server.conf;
this.dal = server.dal;
this.mainContext = server.BlockchainService.getContext();
......@@ -641,7 +642,7 @@ export class BlockGenerator {
export class BlockGeneratorWhichProves extends BlockGenerator {
constructor(server:any, private prover:any) {
constructor(server:Server, private prover:any) {
super(server)
}
......
import {Constants} from "./constants"
import {ConfDTO, Keypair} from "../../../lib/dto/ConfDTO"
import {Server} from "../../../../server"
import {PowEngine} from "./engine"
import {DBBlock} from "../../../lib/db/DBBlock"
import {CommonConstants} from "../../../lib/common-libs/constants"
......@@ -19,7 +20,7 @@ export class WorkerFarm {
private stopPromise:any = null
private checkPoWandNotify:any = null
constructor(private server:any, private logger:any) {
constructor(private server:Server, private logger:any) {
this.theEngine = new PowEngine(server.conf, server.logger)
......@@ -99,7 +100,7 @@ export class BlockProver {
waitResolve:any
workerFarmPromise:any
constructor(private server:any) {
constructor(private server:Server) {
this.conf = server.conf
this.pair = this.conf.pair
this.logger = server.logger
......
......@@ -5,6 +5,8 @@ import {DBBlock} from "../../../lib/db/DBBlock"
import {dos2unix} from "../../../lib/common-libs/dos2unix"
import {parsers} from "../../../lib/common-libs/parsers/index"
import {Server} from "../../../../server"
const querablep = require('querablep');
interface Querable<T> extends Promise<T> {
......@@ -29,7 +31,7 @@ export class PermanentProver {
private resolveContinuePromise:any = null
private continuePromise:any = null
constructor(private server:any) {
constructor(private server:Server) {
this.logger = server.logger;
this.conf = server.conf;
this.prover = new BlockProver(server)
......
......@@ -2,12 +2,13 @@
import {PermanentProver} from "./permanentProver"
import * as stream from "stream"
import {OtherConstants} from "../../../lib/other_constants"
import {Server} from "../../../../server"
export class Prover extends stream.Transform {
permaProver:PermanentProver
constructor(server:any) {
constructor(server:Server) {
super({ objectMode: true })
this.permaProver = new PermanentProver(server)
}
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
module.exports = {
duniter: {
......@@ -7,7 +8,7 @@ module.exports = {
name: 'reapply-to [number]',
desc: 'Reapply reverted blocks until block #[number] is reached. EXPERIMENTAL',
preventIfRunning: true,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const number = params[0];
const logger = server.logger;
try {
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
const constants = require('../lib/constants');
const wizard = require('../lib/wizard');
......@@ -13,7 +14,7 @@ module.exports = {
desc: 'Reset configuration, data, peers, transactions or everything in the database',
preventIfRunning: true,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const type = params[0];
if (type === 'peers') {
// Needs the DAL plugged
......
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
module.exports = {
duniter: {
cli: [{
......@@ -6,7 +8,7 @@ module.exports = {
desc: 'Revert (undo + remove) the top [count] blocks from the blockchain. EXPERIMENTAL',
preventIfRunning: true,
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const count = params[0];
const logger = server.logger;
try {
......@@ -22,7 +24,7 @@ module.exports = {
},{
name: 'revert-to [number]',
desc: 'Revert (undo + remove) top blockchain blocks until block #[number] is reached. EXPERIMENTAL',
onDatabaseExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onDatabaseExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const number = params[0];
const logger = server.logger;
try {
......
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
import * as stream from "stream"
import {Multicaster} from "../lib/streams/multicaster"
import {RouterStream} from "../lib/streams/router"
......@@ -9,10 +10,10 @@ const constants = require('../lib/constants');
module.exports = {
duniter: {
service: {
output: (server:any, conf:ConfDTO, logger:any) => new Router(server)
output: (server:Server, conf:ConfDTO, logger:any) => new Router(server)
},
methods: {
routeToNetwork: (server:any) => {
routeToNetwork: (server:Server) => {
const theRouter = new Router(server);
theRouter.startService();
server.pipe(theRouter);
......@@ -30,7 +31,7 @@ class Router extends stream.Transform {
theRouter:any
theMulticaster:Multicaster = new Multicaster()
constructor(private server:any) {
constructor(private server:Server) {
super({ objectMode: true })
}
......
import {ConfDTO} from "../lib/dto/ConfDTO"
import {Server} from "../../server"
import {Wizard} from "../lib/wizard"
const _ = require('underscore')
......@@ -18,7 +19,7 @@ module.exports = {
name: 'wizard [key|network|network-reconfigure|currency|pow|parameters]',
desc: 'Launch the configuration wizard.',
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any, wizardTasks:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any, wizardTasks:any) => {
const step = params[0];
const tasks = step ? [wizardTasks[step]] : _.values(wizardTasks);
for (const task of tasks) {
......
......@@ -5,6 +5,7 @@ import * as stream from "stream"
import {WS2PCluster} from "./lib/WS2PCluster"
import {WS2PUpnp} from "./lib/ws2p-upnp"
import {CommonConstants} from "../../lib/common-libs/constants"
const constants = require("../../lib/constants");
const nuuid = require('node-uuid')
......@@ -113,7 +114,7 @@ export const WS2PDependency = {
desc: 'WS2P operations for configuration and diagnosis tasks.',
logs: false,
onConfiguredExecute: async (server:any, conf:ConfDTO, program:any, params:any) => {
onConfiguredExecute: async (server:Server, conf:ConfDTO, program:any, params:any) => {
const subcmd = params[0];
if (subcmd === 'list-nodes') {
// Needs the DAL plugged
......
"use strict";
import {Server} from "../../server"
import {GlobalFifoPromise} from "./GlobalFifoPromise"
import {BlockchainContext} from "../lib/computation/BlockchainContext"
import {ConfDTO} from "../lib/dto/ConfDTO"
......@@ -30,7 +31,7 @@ export class BlockchainService extends FIFOService {
switcherDao:SwitcherDao<BlockDTO>
invalidForks:string[] = []
constructor(private server:any, fifoPromiseHandler:GlobalFifoPromise) {
constructor(private server:Server, fifoPromiseHandler:GlobalFifoPromise) {
super(fifoPromiseHandler)
this.mainContext = new BlockchainContext()
this.switcherDao = new (class ForkDao implements SwitcherDao<BlockDTO> {
......
......@@ -23,6 +23,7 @@ import {TransactionDTO} from "./app/lib/dto/TransactionDTO"
import {PeerDTO} from "./app/lib/dto/PeerDTO"
import {OtherConstants} from "./app/lib/other_constants"
import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster"
import {DBBlock} from "./app/lib/db/DBBlock"
export interface HookableServer {
generatorGetJoinData: (...args:any[]) => Promise<any>
......@@ -49,6 +50,8 @@ export class Server extends stream.Duplex implements HookableServer {
private paramsP:Promise<any>|null
private endpointsDefinitions:(()=>Promise<string>)[] = []
private wrongEndpointsFilters:((endpoints:string[])=>Promise<string[]>)[] = []
startService:()=>Promise<void>
stopService:()=>Promise<void>
ws2pCluster:WS2PCluster|undefined
conf:ConfDTO
dal:FileDAL
......@@ -352,7 +355,7 @@ export class Server extends stream.Duplex implements HookableServer {
}
}
async resetAll(done:any) {
async resetAll(done:any = null) {
await this.resetDataHook()
await this.resetConfigHook()
const files = ['stats', 'cores', 'current', directory.DUNITER_DB_NAME, directory.DUNITER_DB_NAME + '.db', directory.DUNITER_DB_NAME + '.log', directory.WOTB_FILE, 'export.zip', 'import.zip', 'conf'];
......@@ -367,20 +370,20 @@ export class Server extends stream.Duplex implements HookableServer {
await this.resetFiles(files, dirs, done);
}
async resetConf(done:any) {
async resetConf(done:any = null) {
await this.resetConfigHook()
const files = ['conf'];
const dirs:string[] = [];
return this.resetFiles(files, dirs, done);
}
resetStats(done:any) {
resetStats(done:any = null) {
const files = ['stats'];
const dirs = ['ud_history'];
return this.resetFiles(files, dirs, done);
}
resetPeers(done:any) {
resetPeers() {
return this.dal.resetPeers()
}
......@@ -613,21 +616,21 @@ export class Server extends stream.Duplex implements HookableServer {
/**
* Default WoT incoming data for new block. To be overriden by a module.
*/
generatorGetJoinData(): Promise<any> {
generatorGetJoinData(current:DBBlock, idtyHash:string , char:string): Promise<any> {
return Promise.resolve({})
}
/**
* Default WoT incoming certifications for new block, filtering wrong certs. To be overriden by a module.
*/
generatorComputeNewCerts(): Promise<any> {
generatorComputeNewCerts(...args:any[]): Promise<any> {
return Promise.resolve({})
}
/**
* Default WoT transforming method for certs => links. To be overriden by a module.
*/
generatorNewCertsToLinks(): Promise<any> {
generatorNewCertsToLinks(...args:any[]): Promise<any> {
return Promise.resolve({})
}
......
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