From 8af3ad1071c550568c7f23e236e0a013bbf54206 Mon Sep 17 00:00:00 2001 From: fernando Date: Mon, 30 Nov 2020 22:13:09 -0300 Subject: [PATCH 1/5] Lazy node health check when loading the page Fixed mosaic id resolution (invalid instance of) --- server/app.ts | 47 ++++++++++++++------------------------- server/handlers/claims.ts | 11 +++++---- server/handlers/faucet.ts | 15 +++++++------ 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/server/app.ts b/server/app.ts index 31d4ccb..5703286 100644 --- a/server/app.ts +++ b/server/app.ts @@ -3,55 +3,42 @@ import { timeout } from 'rxjs/operators'; import { IConfig, Config } from './config'; export interface IApp { - networkType: NetworkType; - isNodeHealth: boolean; - networkGenerationHash: string; - faucetAccount: Account; + networkType: Promise; + isNodeHealth: Promise; + networkGenerationHash: Promise; + faucetAccount: Promise; config: IConfig; repositoryFactory: RepositoryFactory; } export default class App implements IApp { - constructor( - private readonly _repositoryFactory: RepositoryFactory, - private readonly _config: IConfig, - private readonly _networkType: NetworkType, - private readonly _networkGenerationHash: string, - private readonly _isNodeHealth: boolean, - ) {} + constructor(private readonly _repositoryFactory: RepositoryFactory, private readonly _config: IConfig) {} public static async init(): Promise { const repositoryFactory = new RepositoryFactoryHttp(Config.DEFAULT_NODE); - const isNodeHealth: boolean = await App.isNodeHealth(repositoryFactory); - - if (!isNodeHealth) { - return new App(repositoryFactory, Config, NetworkType.TEST_NET, '', isNodeHealth); - } - - const [networkType, networkGenerationHash] = await Promise.all([ - repositoryFactory.getNetworkType().toPromise(), - repositoryFactory.getGenerationHash().toPromise(), - ]); - return new App(repositoryFactory, Config, networkType, networkGenerationHash, isNodeHealth); + return new App(repositoryFactory, Config); } - get networkType(): NetworkType { - return this._networkType; + get networkType(): Promise { + // network type is lazily cached in repo factory. + return this._repositoryFactory.getNetworkType().toPromise(); } - get isNodeHealth(): boolean { - return this._isNodeHealth; + get isNodeHealth(): Promise { + // perform a health check when is requested. + return App.isNodeHealth(this._repositoryFactory); } - get networkGenerationHash(): string { - return this._networkGenerationHash; + get networkGenerationHash(): Promise { + // generation hash is lazily cached in repo factory. + return this._repositoryFactory.getGenerationHash().toPromise(); } get config(): IConfig { return this._config; } - get faucetAccount(): Account { - return Account.createFromPrivateKey(this._config.FAUCET_PRIVATE_KEY as string, this._networkType as NetworkType); + get faucetAccount(): Promise { + return this.networkType.then((networkType) => Account.createFromPrivateKey(this._config.FAUCET_PRIVATE_KEY, networkType)); } get repositoryFactory(): RepositoryFactory { diff --git a/server/handlers/claims.ts b/server/handlers/claims.ts index c9418ea..0f917f8 100644 --- a/server/handlers/claims.ts +++ b/server/handlers/claims.ts @@ -18,8 +18,10 @@ export const claimsHandler = (appConfig: IApp) => { return async (req: any, res: any, next: any) => { const { recipient, amount, selectedMosaics } = req.body; - const { repositoryFactory, config, faucetAccount } = appConfig; - + const { repositoryFactory, config } = appConfig; + const faucetAccount = await appConfig.faucetAccount; + const networkType = await appConfig.networkType; + const generationHash = await appConfig.networkGenerationHash; console.debug({ recipient, amount, selectedMosaics }); if (typeof recipient !== 'string' || recipient.length !== 39) throw new Error(`recipient address invalid.`); @@ -30,10 +32,7 @@ export const claimsHandler = (appConfig: IApp) => { const mosaicIds = selectedMosaics.map((mosaic) => new MosaicId(mosaic)); const recipientAddress: Address = Address.createFromRawAddress(recipient); - const networkType = await repositoryFactory.getNetworkType().toPromise(); - const generationHash = await repositoryFactory.getGenerationHash().toPromise(); - const feeMultiplier = await (await repositoryFactory.createNetworkRepository().getTransactionFees().toPromise()) - .highestFeeMultiplier; + const feeMultiplier = (await repositoryFactory.createNetworkRepository().getTransactionFees().toPromise()).highestFeeMultiplier; forkJoin( repositoryFactory.createNamespaceRepository().getMosaicsNames(mosaicIds), diff --git a/server/handlers/faucet.ts b/server/handlers/faucet.ts index 9ca236e..f717348 100644 --- a/server/handlers/faucet.ts +++ b/server/handlers/faucet.ts @@ -1,5 +1,5 @@ import { ServerMiddleware } from '@nuxt/types'; -import { MosaicId, Mosaic, NamespaceId } from 'symbol-sdk'; +import { MosaicId, Mosaic, NamespaceId, UnresolvedMosaicId } from 'symbol-sdk'; import Url from 'url-parse'; import { IApp } from '../app'; import helper from '../helper'; @@ -12,13 +12,13 @@ interface Ibalance { export const faucetHandler = (appConfig: IApp): ServerMiddleware => { return async (_req: any, res: any, next: any) => { - const { repositoryFactory, config, faucetAccount, isNodeHealth } = appConfig; - + const { repositoryFactory, config } = appConfig; + const isNodeHealth = await appConfig.isNodeHealth; if (!isNodeHealth) { res.error = Error(`API node is offline.`); return next(); } - + const faucetAccount = await appConfig.faucetAccount; try { const defaultNode = new Url(config.DEFAULT_NODE_CLIENT); @@ -43,9 +43,10 @@ export const faucetHandler = (appConfig: IApp): ServerMiddleware => { // Gets resolved mosaic from account. const resolvedMosaics = await Promise.all( accountInfo.mosaics.map(async (mosaic) => { - let mosaicId: MosaicId = mosaic.id; - if (mosaic instanceof NamespaceId) { - mosaicId = (await repositoryFactory.createNamespaceRepository().getLinkedMosaicId(mosaic).toPromise()) || mosaic.id; + let mosaicId: UnresolvedMosaicId = mosaic.id; + if (mosaicId instanceof NamespaceId) { + mosaicId = + (await repositoryFactory.createNamespaceRepository().getLinkedMosaicId(mosaicId).toPromise()) || mosaic.id; } return new Mosaic(mosaicId, mosaic.amount); From 2cbb7ac74e68fd97fd361d765a10edfb81013a02 Mon Sep 17 00:00:00 2001 From: fernando Date: Mon, 30 Nov 2020 22:20:05 -0300 Subject: [PATCH 2/5] Improved validation order --- server/handlers/claims.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handlers/claims.ts b/server/handlers/claims.ts index 0f917f8..34cd874 100644 --- a/server/handlers/claims.ts +++ b/server/handlers/claims.ts @@ -18,14 +18,14 @@ export const claimsHandler = (appConfig: IApp) => { return async (req: any, res: any, next: any) => { const { recipient, amount, selectedMosaics } = req.body; + if (typeof recipient !== 'string' || recipient.length !== 39) throw new Error(`recipient address invalid.`); + const { repositoryFactory, config } = appConfig; const faucetAccount = await appConfig.faucetAccount; const networkType = await appConfig.networkType; const generationHash = await appConfig.networkGenerationHash; console.debug({ recipient, amount, selectedMosaics }); - if (typeof recipient !== 'string' || recipient.length !== 39) throw new Error(`recipient address invalid.`); - if (typeof amount !== 'number') throw new Error(`amount format invalid.`); if (!Array.isArray(selectedMosaics)) throw new Error(`mosaics is not array.`); From cc06f46629bf7839ebc7c86408c7ccb8e14e5ab5 Mon Sep 17 00:00:00 2001 From: Anthony Law Yong Chuan Date: Wed, 9 Dec 2020 04:37:08 +0800 Subject: [PATCH 3/5] update to alpha sdk 0.22 --- package-lock.json | 154 ++++++++++++++++++++++++++++++++++++---------- package.json | 4 +- 2 files changed, 124 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index db7fbc1..4f6c939 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1840,6 +1840,11 @@ } } }, + "@js-joda/core": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@js-joda/core/-/core-3.2.0.tgz", + "integrity": "sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==" + }, "@nodelib/fs.scandir": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", @@ -6289,9 +6294,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.22", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.22.tgz", - "integrity": "sha512-Wip3kJFnXrsMRF+4yJSE/F+aEqrTYLPPXdNuVftHNl9oFaKwQ9si8oI2ruSu53QIR+/ohOlY4QYtOagRpHnrFg==" + "version": "0.0.24-alpha-202011261917", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.24-alpha-202011261917.tgz", + "integrity": "sha512-lyWdQFP7/ekc/mU5vVgPfHvHAIXufaH5t3jo6XVQq+2s8bn2rWlN2zGgO55Xyo1QRBwYmBQa5o4itk5NwP5KHw==" }, "center-align": { "version": "0.1.3", @@ -16176,9 +16181,9 @@ "integrity": "sha1-grjbrnXieneFOItz+ddyXQ9vMyY=" }, "merkletreejs": { - "version": "0.1.11", - "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.1.11.tgz", - "integrity": "sha512-nJN3VIHeIAyB/PjO5Dj/Y0SEK7CGCCLD2IbV4el2kUIwlOtX3GOr5MwVO4EU+0AXvoDnJ0nmaLe5O86uIjWz/Q==", + "version": "0.2.11", + "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.2.11.tgz", + "integrity": "sha512-oQ8HV2N6ZkOk0114nC1IiqqaE1YMVeHjzcaCcnhUaMIH0f0GdUbZqzHCJmJGefj8iMPjQagOPniPyl8pktK1ng==", "requires": { "buffer-reverse": "^1.0.1", "crypto-js": "^3.1.9-1", @@ -16193,9 +16198,9 @@ "integrity": "sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==" }, "is-buffer": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", - "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" } } }, @@ -19640,9 +19645,10 @@ } }, "rxjs": { - "version": "6.5.5", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.5.tgz", - "integrity": "sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==", + "version": "6.6.3", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.3.tgz", + "integrity": "sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==", + "dev": true, "requires": { "tslib": "^1.9.0" } @@ -20916,6 +20922,18 @@ "winston": "^3.3.3" }, "dependencies": { + "catbuffer-typescript": { + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.22.tgz", + "integrity": "sha512-Wip3kJFnXrsMRF+4yJSE/F+aEqrTYLPPXdNuVftHNl9oFaKwQ9si8oI2ruSu53QIR+/ohOlY4QYtOagRpHnrFg==", + "dev": true + }, + "is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", + "dev": true + }, "js-yaml": { "version": "3.14.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", @@ -20926,6 +20944,71 @@ "esprima": "^4.0.0" } }, + "merkletreejs": { + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/merkletreejs/-/merkletreejs-0.1.11.tgz", + "integrity": "sha512-nJN3VIHeIAyB/PjO5Dj/Y0SEK7CGCCLD2IbV4el2kUIwlOtX3GOr5MwVO4EU+0AXvoDnJ0nmaLe5O86uIjWz/Q==", + "dev": true, + "requires": { + "buffer-reverse": "^1.0.1", + "crypto-js": "^3.1.9-1", + "is-buffer": "^2.0.3", + "merkle-lib": "^2.0.10", + "treeify": "^1.1.0" + }, + "dependencies": { + "crypto-js": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.3.0.tgz", + "integrity": "sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==", + "dev": true + } + } + }, + "symbol-openapi-typescript-fetch-client": { + "version": "0.10.0-3", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.10.0-3.tgz", + "integrity": "sha512-cdRz7Nc/m2i7CC8wHtj//z5RxOKEKhS4l+fFQvh7YUlYcUPaHbgcq4RMXSZPmMJ4PnzocnqWpVKjMj5cTYgrPA==", + "dev": true + }, + "symbol-sdk": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/symbol-sdk/-/symbol-sdk-0.21.0.tgz", + "integrity": "sha512-YFJ1PcVlFSivZe8RUOOGJJvXN2uleNTZB8ma6VONdz+obyI8QMAzdt4c6niyGTr76Md6dRQVJ/uaq+MpbJtDQg==", + "dev": true, + "requires": { + "bluebird": "^3.7.2", + "catbuffer-typescript": "0.0.22", + "crypto-js": "^4.0.0", + "diff": "^4.0.2", + "futoin-hkdf": "^1.3.1", + "js-joda": "^1.6.2", + "js-sha256": "^0.9.0", + "js-sha3": "^0.8.0", + "js-sha512": "^0.8.0", + "long": "^4.0.0", + "merkletreejs": "^0.1.7", + "minimist": "^1.2.5", + "node-fetch": "^2.6.0", + "request": "^2.88.0", + "request-promise-native": "^1.0.5", + "ripemd160": "^2.0.2", + "rxjs": "^6.5.3", + "rxjs-compat": "^6.5.3", + "symbol-openapi-typescript-fetch-client": "0.10.0-3", + "tweetnacl": "^1.0.3", + "utf8": "^3.0.0", + "ws": "^7.2.3" + }, + "dependencies": { + "utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", + "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==", + "dev": true + } + } + }, "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", @@ -20941,37 +21024,44 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.10.0-3", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.10.0-3.tgz", - "integrity": "sha512-cdRz7Nc/m2i7CC8wHtj//z5RxOKEKhS4l+fFQvh7YUlYcUPaHbgcq4RMXSZPmMJ4PnzocnqWpVKjMj5cTYgrPA==" + "version": "0.10.1-SNAPSHOT.202012011711", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.10.1-SNAPSHOT.202012011711.tgz", + "integrity": "sha512-siNjO76byI75+PuOsDKkCFMvDcsbmFwuX0qAxYGN/qJdevOAgEoEo80uozaP69JGVUkOw8Xdqt+GXmoeQTrjlA==" }, "symbol-sdk": { - "version": "0.21.0", - "resolved": "https://registry.npmjs.org/symbol-sdk/-/symbol-sdk-0.21.0.tgz", - "integrity": "sha512-YFJ1PcVlFSivZe8RUOOGJJvXN2uleNTZB8ma6VONdz+obyI8QMAzdt4c6niyGTr76Md6dRQVJ/uaq+MpbJtDQg==", + "version": "0.22.0-alpha-202012081346", + "resolved": "https://registry.npmjs.org/symbol-sdk/-/symbol-sdk-0.22.0-alpha-202012081346.tgz", + "integrity": "sha512-eEfsOUdsBpL2oz+fDFM+FxilymBx0gRnThRmdCQanFDzJbP2/GuC+HNFgzDqt/Du4wwmZjelx0RbNNKJrKrc/A==", "requires": { + "@js-joda/core": "^3.2.0", "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.22", + "catbuffer-typescript": "0.0.24-alpha-202011261917", "crypto-js": "^4.0.0", "diff": "^4.0.2", - "futoin-hkdf": "^1.3.1", - "js-joda": "^1.6.2", + "futoin-hkdf": "^1.3.2", "js-sha256": "^0.9.0", "js-sha3": "^0.8.0", "js-sha512": "^0.8.0", "long": "^4.0.0", - "merkletreejs": "^0.1.7", + "merkletreejs": "^0.2.9", "minimist": "^1.2.5", "node-fetch": "^2.6.0", - "request": "^2.88.0", - "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", - "rxjs": "^6.5.3", - "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.10.0-3", + "rxjs": "^6.6.3", + "rxjs-compat": "^6.6.3", + "symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202012011711", "tweetnacl": "^1.0.3", - "utf8": "^3.0.0", - "ws": "^7.2.3" + "ws": "^7.3.1" + }, + "dependencies": { + "rxjs": { + "version": "6.6.3", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.3.tgz", + "integrity": "sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==", + "requires": { + "tslib": "^1.9.0" + } + } } }, "symbol-tree": { @@ -23300,9 +23390,9 @@ } }, "ws": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz", - "integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==" + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.1.tgz", + "integrity": "sha512-pTsP8UAfhy3sk1lSk/O/s4tjD0CRwvMnzvwr4OKGX7ZvqZtUyx4KIJB5JWbkykPoc55tixMGgTNoh3k4FkNGFQ==" }, "xdg-basedir": { "version": "4.0.0", diff --git a/package.json b/package.json index 3fa0027..13b981e 100644 --- a/package.json +++ b/package.json @@ -52,13 +52,13 @@ "pug-loader": "^2.4.0", "pug-plain-loader": "^1.0.0", "querystring": "^0.2.0", - "rxjs": "^6.5.5", "stylus": "^0.54.7", "stylus-loader": "^3.0.2", - "symbol-sdk": "^0.21.0", + "symbol-sdk": "^0.22.0-alpha-202012081346", "tls": "0.0.1", "tsconfig-paths": "^3.9.0", "utf-8-validate": "^5.0.2", + "utf8": "^3.0.0", "vue-material-design-icons": "^4.4.0", "vue-property-decorator": "^8.4.0" }, From 444d06179fa4506901179e08282d2394137b19c1 Mon Sep 17 00:00:00 2001 From: Anthony Law Yong Chuan Date: Wed, 9 Dec 2020 06:58:58 +0800 Subject: [PATCH 4/5] update to sdk 0.22 --- package-lock.json | 33 +++++++++++---------------------- package.json | 2 +- server/app.ts | 12 +++++++++++- server/handlers/claims.ts | 3 ++- server/handlers/faucet.ts | 26 ++++++++++++++------------ 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4f6c939..ec9f87d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6294,9 +6294,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.24-alpha-202011261917", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.24-alpha-202011261917.tgz", - "integrity": "sha512-lyWdQFP7/ekc/mU5vVgPfHvHAIXufaH5t3jo6XVQq+2s8bn2rWlN2zGgO55Xyo1QRBwYmBQa5o4itk5NwP5KHw==" + "version": "0.0.24", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.24.tgz", + "integrity": "sha512-kHXDDXfZlTCk7QKh9j1zddtpChxSLd+vmWGqHQ0mO0+ekyJUT1h77tjviccQY1HONT0+ddQ2o3AhvdU77coytw==" }, "center-align": { "version": "0.1.3", @@ -19648,7 +19648,6 @@ "version": "6.6.3", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.3.tgz", "integrity": "sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==", - "dev": true, "requires": { "tslib": "^1.9.0" } @@ -21024,18 +21023,18 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.10.1-SNAPSHOT.202012011711", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.10.1-SNAPSHOT.202012011711.tgz", - "integrity": "sha512-siNjO76byI75+PuOsDKkCFMvDcsbmFwuX0qAxYGN/qJdevOAgEoEo80uozaP69JGVUkOw8Xdqt+GXmoeQTrjlA==" + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.10.4.tgz", + "integrity": "sha512-WME5yuvfYTT7BxvKOyKu6iAWPPXCBmuARTpwBfh5jW+3SkmZ5KVVgl2H54ORmJILFGBm1ozzvMlyuGa+fsd7hw==" }, "symbol-sdk": { - "version": "0.22.0-alpha-202012081346", - "resolved": "https://registry.npmjs.org/symbol-sdk/-/symbol-sdk-0.22.0-alpha-202012081346.tgz", - "integrity": "sha512-eEfsOUdsBpL2oz+fDFM+FxilymBx0gRnThRmdCQanFDzJbP2/GuC+HNFgzDqt/Du4wwmZjelx0RbNNKJrKrc/A==", + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/symbol-sdk/-/symbol-sdk-0.22.0.tgz", + "integrity": "sha512-cWIqHLKArv5RjInENgOdnyCBV06Eb41BWB0lQ05yeYdbxvz5eW/mFbSTxAxw6ai72f5I1yAIbKaxEzLKzTbMbQ==", "requires": { "@js-joda/core": "^3.2.0", "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.24-alpha-202011261917", + "catbuffer-typescript": "0.0.24", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.2", @@ -21049,19 +21048,9 @@ "ripemd160": "^2.0.2", "rxjs": "^6.6.3", "rxjs-compat": "^6.6.3", - "symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202012011711", + "symbol-openapi-typescript-fetch-client": "0.10.4", "tweetnacl": "^1.0.3", "ws": "^7.3.1" - }, - "dependencies": { - "rxjs": { - "version": "6.6.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.3.tgz", - "integrity": "sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==", - "requires": { - "tslib": "^1.9.0" - } - } } }, "symbol-tree": { diff --git a/package.json b/package.json index 13b981e..252e3ea 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "querystring": "^0.2.0", "stylus": "^0.54.7", "stylus-loader": "^3.0.2", - "symbol-sdk": "^0.22.0-alpha-202012081346", + "symbol-sdk": "^0.22.0", "tls": "0.0.1", "tsconfig-paths": "^3.9.0", "utf-8-validate": "^5.0.2", diff --git a/server/app.ts b/server/app.ts index 5703286..80ca713 100644 --- a/server/app.ts +++ b/server/app.ts @@ -1,4 +1,4 @@ -import { Account, RepositoryFactoryHttp, RepositoryFactory, NetworkType } from 'symbol-sdk'; +import { Account, RepositoryFactoryHttp, RepositoryFactory, NetworkType, CurrencyService } from 'symbol-sdk'; import { timeout } from 'rxjs/operators'; import { IConfig, Config } from './config'; @@ -6,9 +6,11 @@ export interface IApp { networkType: Promise; isNodeHealth: Promise; networkGenerationHash: Promise; + epochAdjustment: Promise; faucetAccount: Promise; config: IConfig; repositoryFactory: RepositoryFactory; + currencyService: CurrencyService; } export default class App implements IApp { @@ -33,6 +35,10 @@ export default class App implements IApp { return this._repositoryFactory.getGenerationHash().toPromise(); } + get epochAdjustment(): Promise { + return this._repositoryFactory.getEpochAdjustment().toPromise(); + } + get config(): IConfig { return this._config; } @@ -45,6 +51,10 @@ export default class App implements IApp { return this._repositoryFactory; } + get currencyService(): CurrencyService { + return new CurrencyService(this._repositoryFactory); + } + static isNodeHealth(repositoryFactory: RepositoryFactory): Promise { return new Promise((resolve) => { repositoryFactory diff --git a/server/handlers/claims.ts b/server/handlers/claims.ts index 34cd874..53ee934 100644 --- a/server/handlers/claims.ts +++ b/server/handlers/claims.ts @@ -24,6 +24,7 @@ export const claimsHandler = (appConfig: IApp) => { const faucetAccount = await appConfig.faucetAccount; const networkType = await appConfig.networkType; const generationHash = await appConfig.networkGenerationHash; + const epochAdjustment = await appConfig.epochAdjustment; console.debug({ recipient, amount, selectedMosaics }); if (typeof amount !== 'number') throw new Error(`amount format invalid.`); @@ -150,7 +151,7 @@ export const claimsHandler = (appConfig: IApp) => { }); const transaction = TransferTransaction.create( - Deadline.create(), + Deadline.create(epochAdjustment), recipientAddress, requestedMosicList, EmptyMessage, diff --git a/server/handlers/faucet.ts b/server/handlers/faucet.ts index f717348..f499933 100644 --- a/server/handlers/faucet.ts +++ b/server/handlers/faucet.ts @@ -1,5 +1,5 @@ import { ServerMiddleware } from '@nuxt/types'; -import { MosaicId, Mosaic, NamespaceId, UnresolvedMosaicId } from 'symbol-sdk'; +import { MosaicId, NamespaceId, UnresolvedMosaicId } from 'symbol-sdk'; import Url from 'url-parse'; import { IApp } from '../app'; import helper from '../helper'; @@ -23,8 +23,8 @@ export const faucetHandler = (appConfig: IApp): ServerMiddleware => { const defaultNode = new Url(config.DEFAULT_NODE_CLIENT); // Gets native mosaic info and faucet account info. - const [nativeMosaicInfo, accountInfo] = await Promise.all([ - repositoryFactory.createMosaicRepository().getMosaic(new MosaicId(config.NATIVE_CURRENCY_ID)).toPromise(), + const [getCurrencies, accountInfo] = await Promise.all([ + repositoryFactory.getCurrencies().toPromise(), repositoryFactory.createAccountRepository().getAccountInfo(faucetAccount.address).toPromise(), ]); @@ -33,7 +33,7 @@ export const faucetHandler = (appConfig: IApp): ServerMiddleware => { address: faucetAccount.address.pretty(), hostname: defaultNode.hostname, defaultNode: defaultNode.origin, - nativeCurrencyMaxOut: config.NATIVE_CURRENCY_OUT_MAX / Math.pow(10, nativeMosaicInfo.divisibility), + nativeCurrencyMaxOut: config.NATIVE_CURRENCY_OUT_MAX / Math.pow(10, getCurrencies.currency.divisibility), nativeCurrencyName: config.NATIVE_CURRENCY_NAME, nativeCurrencyId: config.NATIVE_CURRENCY_ID, blackListMosaicIds: config.BLACKLIST_MOSAICIDS, @@ -41,28 +41,30 @@ export const faucetHandler = (appConfig: IApp): ServerMiddleware => { }; // Gets resolved mosaic from account. - const resolvedMosaics = await Promise.all( + const mosaics = await Promise.all( accountInfo.mosaics.map(async (mosaic) => { - let mosaicId: UnresolvedMosaicId = mosaic.id; + let mosaicId: UnresolvedMosaicId | MosaicId = mosaic.id; if (mosaicId instanceof NamespaceId) { mosaicId = (await repositoryFactory.createNamespaceRepository().getLinkedMosaicId(mosaicId).toPromise()) || mosaic.id; } - return new Mosaic(mosaicId, mosaic.amount); + return { + id: new MosaicId(mosaicId.toHex()), + amount: mosaic.amount, + }; }), ); - const resolvedMosaicIds = resolvedMosaics.map((mosaic) => mosaic.id); + const mosaicIds = mosaics.map((mosaic) => mosaic.id); // Gets mosaics info and mosaice namespace const [mosaicInfos, mosaicNames] = await Promise.all([ - repositoryFactory.createMosaicRepository().getMosaics(resolvedMosaicIds).toPromise(), - repositoryFactory.createNamespaceRepository().getMosaicsNames(resolvedMosaicIds).toPromise(), + repositoryFactory.createMosaicRepository().getMosaics(mosaicIds).toPromise(), + repositoryFactory.createNamespaceRepository().getMosaicsNames(mosaicIds).toPromise(), ]); - // Build balance object. - const balance: Ibalance[] = resolvedMosaics.map((mosaic) => { + const balance: Ibalance[] = mosaics.map((mosaic) => { let mosaicInfo: any = mosaicInfos.find((info) => info.id.equals(mosaic.id)); return { From 6746a1aaa2e25610fe9b18b53bbd14ddcfda9e7d Mon Sep 17 00:00:00 2001 From: Anthony Law Yong Chuan Date: Wed, 9 Dec 2020 07:14:18 +0800 Subject: [PATCH 5/5] updated change log --- CHANGELOG.md | 16 ++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1c326..691e518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [0.4.1] - 9-Dec-2020 + +### Milestone: [catapult-server@v0.10.0.4](https://github.com/nemtech/catapult-server/releases/tag/v0.10.0.4) + +Package | Version | Link +---|---|--- +REST Core| v2.2.0 | [catapult-rest](https://github.com/nemtech/catapult-rest/releases/tag/v2.2.0) +SDK Core| v0.22.0 | [symbol-sdk](https://www.npmjs.com/package/symbol-sdk) + +### Added +- Added compatibility for 0.10.0.4 server. + +### Fixed +- Lazy node health check when loading the page + ## [0.4.0] - 24-Nov-2020 ### Milestone: [catapult-server@v0.10.0.3](https://github.com/nemtech/catapult-server/releases/tag/v0.10.0.3) diff --git a/package-lock.json b/package-lock.json index ec9f87d..830430e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "symbol-faucet", - "version": "0.4.0", + "version": "0.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 252e3ea..25e6ff7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "symbol-faucet", - "version": "0.4.0", + "version": "0.4.1", "description": "Symbol faucet web application", "author": "Yoshiyuki Ieyama", "homepage": "https://github.com/44uk/symbol-faucet",