From 50d7bbad51fb240f370ad86d6accfbc72d75f6f1 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Thu, 23 Dec 2021 23:09:58 +0300 Subject: [PATCH 1/3] refactor(node)!: don't wrap internal endpoints if internalUrl missed --- src/node.js | 2 +- src/utils/swagger.js | 7 ++++--- test/integration/node.js | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/node.js b/src/node.js index c58f1bc23b..5912968468 100644 --- a/src/node.js +++ b/src/node.js @@ -59,7 +59,7 @@ const Node = AsyncInit.compose({ async init ({ url, internalUrl, ignoreVersion }) { if (!url) throw new MissingParamError('"url" required') this.url = url.replace(/\/$/, '') - this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url + this.internalUrl = internalUrl?.replace(/\/$/, '') const client = await genSwaggerClient(`${this.url}/api?oas3`, { internalUrl: this.internalUrl, responseInterceptor: response => { diff --git a/src/utils/swagger.js b/src/utils/swagger.js index 844b308d95..fd229fc2a0 100644 --- a/src/utils/swagger.js +++ b/src/utils/swagger.js @@ -78,8 +78,9 @@ export default async ( }) })) - const combinedApi = [ - ...Object.values(external.apis), + const combinedApi = Object.assign( + {}, + ...external.apis.external ? [external.apis.external] : Object.values(external.apis), mapObject(internal?.apis.internal || {}, ([key, handler]) => [key, (...args) => { if (!warnedAboutInternalApiUsage) { console.warn( @@ -91,7 +92,7 @@ export default async ( } return handler(...args) }]) - ].reduce((acc, n) => ({ ...acc, ...n })) + ) const opSpecs = Object.values(spec.paths) .map(paths => Object.values(paths)) diff --git a/test/integration/node.js b/test/integration/node.js index 8d49aaafe8..86d646d475 100644 --- a/test/integration/node.js +++ b/test/integration/node.js @@ -34,11 +34,16 @@ describe('Node client', function () { expect(node.revision).to.be.a('string') }) - it('loads operations', () => { + it('wraps endpoints', () => { ['postTransaction', 'getCurrentKeyBlock'] .map(method => expect(node.api[method]).to.be.a('function')) }) + it('don\'t wraps internal endpoints if internalUrl is not provided', async () => { + const node = await Node({ url, ignoreVersion }) + expect(node.api.getPendingTransactions).to.be.an('undefined') + }) + it('gets key blocks by height for the first 3 blocks', async () => { expect(node.api.getKeyBlockByHeight).to.be.a('function') const blocks = await Promise.all([1, 2, 3].map(i => node.api.getKeyBlockByHeight(i))) From efa224bfae3c069b8762fa60612dab7b973fd0ca Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Fri, 24 Dec 2021 09:46:44 +0300 Subject: [PATCH 2/3] refactor(pool): remove unnecessary error omitting --- src/chain/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chain/node.js b/src/chain/node.js index 3387f928f3..362ce63eb6 100644 --- a/src/chain/node.js +++ b/src/chain/node.js @@ -161,8 +161,8 @@ async function poll ( ) { const max = await this.height() + blocks do { - const tx = await this.tx(th).catch(_ => null) - if (tx && (tx.blockHeight !== -1 || (allowUnsynced && tx.height))) { + const tx = await this.tx(th) + if (tx.blockHeight !== -1 || (allowUnsynced && tx.height)) { return tx } await pause(interval) From 690db5bd2919958edcadca79fd75b5ad96b77c62 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Fri, 24 Dec 2021 09:57:54 +0300 Subject: [PATCH 3/3] feat(poll): use getCheckTxInPool if available --- src/chain/node.js | 3 ++- src/utils/errors.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/chain/node.js b/src/chain/node.js index 362ce63eb6..fd522e98fc 100644 --- a/src/chain/node.js +++ b/src/chain/node.js @@ -167,7 +167,8 @@ async function poll ( } await pause(interval) } while (await this.height() < max) - throw new TxTimedOutError(blocks, th) + const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status + throw new TxTimedOutError(blocks, th, status) } async function getTxInfo (hash) { diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 7af230cc8c..435e59d520 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -161,8 +161,12 @@ export class RequestTimedOutError extends AeError { } export class TxTimedOutError extends AeError { - constructor (blocks: number, th: string) { - super(`Giving up after ${blocks} blocks mined, transaction hash: ${th}`) + constructor (blocks: number, th: string, status?: string) { + super([ + `Giving up after ${blocks} blocks mined`, + `transaction hash: ${th}`, + ...status ? [`status: ${status}`] : [] + ].join(', ')) this.name = 'TxTimedOutError' } }