diff --git a/dist/API/app.js b/dist/API/app.js index ebd65df..71c8fd9 100644 --- a/dist/API/app.js +++ b/dist/API/app.js @@ -35,14 +35,15 @@ function onError(error) { if (error.syscall !== "listen") { throw error; } - // handle specific listen errors with friendly messages switch (error.code) { case "EACCES": console.error(`${hostPort} requires elevated privileges`); - break; + process.exit(1); + // eslint-disable-next-line no-fallthrough case "EADDRINUSE": console.error(`${hostPort} is already in use`); - break; + process.exit(1); + // eslint-disable-next-line no-fallthrough default: throw error; } diff --git a/dist/API/app.js.map b/dist/API/app.js.map index c833dca..30089a7 100644 --- a/dist/API/app.js.map +++ b/dist/API/app.js.map @@ -1 +1 @@ -{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/API/app.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,iBAAiB,CAAC;AAEzB,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAG1C,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AACtB,GAAG,CAAC,GAAG,CAAE,MAAM,CAAE,KAAK,CAAE,CAAE,CAAC;AAC3B,GAAG,CAAC,GAAG,CAAE,OAAO,CAAC,IAAI,EAAE,CAAE,CAAC;AAC1B,GAAG,CAAC,GAAG,CAAE,OAAO,CAAC,UAAU,CAAC,EAAE,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AAC;IACb,CAAC;IACD,QAAS,KAAK,CAAC,IAAI,EACnB,CAAC;QACD,KAAK,QAAQ;YACZ,OAAO,CAAC,KAAK,CAAE,GAAG,QAAQ,+BAA+B,CAAE,CAAC;YAC5D,OAAO,CAAC,IAAI,CAAE,CAAC,CAAE,CAAC;QACnB,0CAA0C;QAC1C,KAAK,YAAY;YAChB,OAAO,CAAC,KAAK,CAAE,GAAG,QAAQ,oBAAoB,CAAE,CAAC;YACjD,OAAO,CAAC,IAAI,CAAE,CAAC,CAAE,CAAC;QACnB,0CAA0C;QAC1C;YACC,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAG,GAAgB,EAAE,GAAoB,EAAE,GAAqB,EAAE,IAA0B;IAEhH,IAAK,GAAG,CAAC,WAAW,EACpB,CAAC;QACA,OAAO,IAAI,CAAE,GAAG,CAAE,CAAC;IACpB,CAAC;IACD,GAAG,CAAC,MAAM,CAAE,GAAG,CAAE,CAAC,IAAI,CAAE,uBAAuB,CAAE,GAAG,CAAE,CAAE,CAAC;AAC1D,CAAC"} \ No newline at end of file diff --git a/dist/API/blockchain.js b/dist/API/blockchain.js index a0fc4c3..f4bedbd 100644 --- a/dist/API/blockchain.js +++ b/dist/API/blockchain.js @@ -1,9 +1,9 @@ import Blockchain from "../library/main.js"; import Consensus from "../library/pow-consensus.js"; -const consensus = new Consensus(); import { initJsonFile } from "../library/utils.js"; import Wallet from "../library/wallet.js"; import { name, dbPath, minerKeysFile, hostUrl, nodesList } from "./config.js"; +const consensus = new Consensus(); const minerKeys = initJsonFile(minerKeysFile, Wallet.generateKeyPair()); export default new Blockchain({ dbPath, diff --git a/dist/API/blockchain.js.map b/dist/API/blockchain.js.map index 40507a0..f9d0d39 100644 --- a/dist/API/blockchain.js.map +++ b/dist/API/blockchain.js.map @@ -1 +1 @@ -{"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../src/API/blockchain.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9E,MAAM,SAAS,GAAG,YAAY,CAAE,aAAa,EAAE,MAAM,CAAC,eAAe,EAAE,CAAE,CAAC;AAC1E,eAAe,IAAI,UAAU,CAAC;IAC7B,MAAM;IACN,KAAK,EAAE;QACN,IAAI,EAAE,SAAS;QACf,OAAO;KACP;IACD,SAAS,EAAE,IAAI;IACf,cAAc,EAAE,SAAS,CAAC,SAAS;IACnC,SAAS;CACT,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"blockchain.js","sourceRoot":"","sources":["../../src/API/blockchain.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC9E,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;AAElC,MAAM,SAAS,GAAG,YAAY,CAAE,aAAa,EAAE,MAAM,CAAC,eAAe,EAAE,CAAE,CAAC;AAC1E,eAAe,IAAI,UAAU,CAAC;IAC7B,MAAM;IACN,KAAK,EAAE;QACN,IAAI,EAAE,SAAS;QACf,OAAO;KACP;IACD,SAAS,EAAE,IAAI;IACf,cAAc,EAAE,SAAS,CAAC,SAAS;IACnC,SAAS;CACT,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/API/routes/block.js b/dist/API/routes/block.js index ef185a6..da43a85 100644 --- a/dist/API/routes/block.js +++ b/dist/API/routes/block.js @@ -8,19 +8,16 @@ router.get("/", function (req, res) { const { to, index, from, firstAndLast } = req.query; if (!index && !from && !to && !list && !firstAndLast) { res.json(blockchain.chain.latestBlock); - return; } else if (index) { const blockIndex = toNum(index); res.json(blockchain.chain.get(blockIndex)); - return; } else if (from || to) { const blockFrom = toNum(from); const blockTo = toNum(to); const blocks = blockchain.getBlocks(blockFrom, blockTo); res.json(blocks); - return; } else if (list) { const blockList = list.toString().split(","); @@ -29,14 +26,12 @@ router.get("/", function (req, res) { blocks.push(blockchain.chain.get(blcokIndex)); } res.json(blocks); - return; } else if (firstAndLast) { const blocks = []; blocks.push(blockchain.chain.get(0)); blocks.push(blockchain.chain.latestBlock); res.json(blocks); - return; } }); router.post("/", function (req, res) { diff --git a/dist/API/routes/block.js.map b/dist/API/routes/block.js.map index 22fac1b..d1d7627 100644 --- a/dist/API/routes/block.js.map +++ b/dist/API/routes/block.js.map @@ -1 +1 @@ -{"version":3,"file":"block.js","sourceRoot":"","sources":["../../../src/API/routes/block.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAEhC,MAAM,CAAC,GAAG,CAAE,GAAG,EAAE,UAAW,GAAG,EAAE,GAAG;IAEnC,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IAC3B,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IACpD,IAAK,CAAC,KAAK,IAAI,CAAC,IAAI,I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AAC,CAAC;AAEH,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/src/API/app.ts b/src/API/app.ts index 32aa59f..a1326ca 100644 --- a/src/API/app.ts +++ b/src/API/app.ts @@ -46,21 +46,22 @@ function onError ( error: NodeJS.ErrnoException ) { throw error; } - // handle specific listen errors with friendly messages switch ( error.code ) { case "EACCES": console.error( `${hostPort} requires elevated privileges` ); - break; + process.exit( 1 ); + // eslint-disable-next-line no-fallthrough case "EADDRINUSE": console.error( `${hostPort} is already in use` ); - break; + process.exit( 1 ); + // eslint-disable-next-line no-fallthrough default: throw error; } } -function errorHandler ( err: CustomError, req: express.Request, res: express.Response, next: express.NextFunction ) +function errorHandler ( err: SimpleError, req: express.Request, res: express.Response, next: express.NextFunction ) { if ( res.headersSent ) { diff --git a/src/API/blockchain.ts b/src/API/blockchain.ts index 2cea657..57eabb7 100644 --- a/src/API/blockchain.ts +++ b/src/API/blockchain.ts @@ -1,9 +1,9 @@ import Blockchain from "../library/main.js"; import Consensus from "../library/pow-consensus.js"; -const consensus = new Consensus(); import { initJsonFile } from "../library/utils.js"; import Wallet from "../library/wallet.js"; import { name, dbPath, minerKeysFile, hostUrl, nodesList } from "./config.js"; +const consensus = new Consensus(); const minerKeys = initJsonFile( minerKeysFile, Wallet.generateKeyPair() ); export default new Blockchain({ diff --git a/src/API/routes/block.ts b/src/API/routes/block.ts index 85ff393..f4b9b32 100644 --- a/src/API/routes/block.ts +++ b/src/API/routes/block.ts @@ -12,13 +12,11 @@ router.get( "/", function ( req, res ) if ( !index && !from && !to && !list && !firstAndLast ) { res.json( blockchain.chain.latestBlock ); - return; } else if ( index ) { const blockIndex = toNum( index ); res.json( blockchain.chain.get( blockIndex ) ); - return; } else if ( from || to ) { @@ -26,7 +24,6 @@ router.get( "/", function ( req, res ) const blockTo = toNum( to ); const blocks = blockchain.getBlocks( blockFrom, blockTo ); res.json( blocks ); - return; } else if ( list ) { @@ -37,7 +34,6 @@ router.get( "/", function ( req, res ) blocks.push( blockchain.chain.get( blcokIndex ) ); } res.json( blocks ); - return; } else if ( firstAndLast ) { @@ -45,7 +41,6 @@ router.get( "/", function ( req, res ) blocks.push( blockchain.chain.get( 0 ) ); blocks.push( blockchain.chain.latestBlock ); res.json( blocks ); - return; } }); diff --git a/src/API/utils.ts b/src/API/utils.ts index c772e1c..87c3159 100644 --- a/src/API/utils.ts +++ b/src/API/utils.ts @@ -20,7 +20,7 @@ export function toNum ( value: unknown ): number return Number( value ); } -export function convertErrorToSimpleObj ( err: CustomError ) +export function convertErrorToSimpleObj ( err: SimpleError ) { if ( err.isAxiosError ) { diff --git a/src/global.d.ts b/src/global.d.ts index 24bde1c..8b44e6a 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -64,11 +64,6 @@ interface ErrorWithStdsOutErr extends Error status?: number; } -interface CustomError extends Error -{ - [x: string]: CustomError; -} - interface SimpleError { message?: string;