From 9aa2d4c3c035174855343764883a4f8d7d747576 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 12 Feb 2020 09:30:24 +0000 Subject: [PATCH] Fxied #443 - Applied openAPI 0.8.3 - Added NetworkFees --- e2e/infrastructure/NetworkHttp.spec.ts | 10 ++++++++ package-lock.json | 6 ++--- package.json | 2 +- src/infrastructure/NetworkHttp.ts | 15 +++++++++++ src/infrastructure/NetworkRepository.ts | 8 ++++++ src/model/blockchain/NetworkFees.ts | 33 +++++++++++++++++++++++++ src/model/blockchain/NetworkName.ts | 2 +- src/model/blockchain/NetworkSetting.ts | 0 8 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/model/blockchain/NetworkFees.ts delete mode 100644 src/model/blockchain/NetworkSetting.ts diff --git a/e2e/infrastructure/NetworkHttp.spec.ts b/e2e/infrastructure/NetworkHttp.spec.ts index e450a4cf9c..c0859b2feb 100644 --- a/e2e/infrastructure/NetworkHttp.spec.ts +++ b/e2e/infrastructure/NetworkHttp.spec.ts @@ -44,4 +44,14 @@ describe('NetworkHttp', () => { expect(networkName.description.toLowerCase()).to.be.not.null; }); }); + + describe('getNetworkFees', () => { + it('should return network fees', async () => { + const fees = await networkRepository.getNetworkFees().toPromise(); + expect(fees.averageFeeMultiplier).to.be.not.null; + expect(fees.highestFeeMultiplier).to.be.not.null; + expect(fees.lowestFeeMultiplier).to.be.not.null; + expect(fees.medianFeeMultiplier).to.be.not.null; + }); + }); }); diff --git a/package-lock.json b/package-lock.json index cc75b3fdcf..ee8b2830f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3820,9 +3820,9 @@ } }, "nem2-sdk-openapi-typescript-node-client": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.2.tgz", - "integrity": "sha512-0ftmqqeJhfyFhVQBbnXhU9Ep9D8TTWv7KQIhGubSNnGmsPlddRRf17XBhYDAYuHdPV9L9P9L49NJDc9xh8s8Lw==", + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.3.tgz", + "integrity": "sha512-e0B4FCi/uOjag84wpWTMAvR/J//JAmtP0agKg8fEBTiuD4gbGDKLLhfNtMCuMWdCw1nFX5aVVJrx3MakP/ad8w==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 9ac5c50d64..2be04b25e7 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "js-sha3": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", - "nem2-sdk-openapi-typescript-node-client": "0.8.2", + "nem2-sdk-openapi-typescript-node-client": "0.8.3", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index 878820c3fb..027b74e4a6 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -17,6 +17,7 @@ import { NetworkRoutesApi } from 'nem2-sdk-openapi-typescript-node-client'; import { from as observableFrom, Observable, throwError } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; +import { NetworkFees } from '../model/blockchain/NetworkFees'; import { NetworkName } from '../model/blockchain/NetworkName'; import { NetworkType } from '../model/blockchain/NetworkType'; import { NodeInfo } from '../model/node/NodeInfo'; @@ -71,4 +72,18 @@ export class NetworkHttp extends Http implements NetworkRepository { catchError((error) => throwError(this.errorHandling(error))), ); } + + /** + * Returns information about the average, median, highest and lower fee multiplier over the last + * \"numBlocksTransactionFeeStats\". The setting \"numBlocksTransactionFeeStats\" is adjustable + * via a configuration file (rest/resources/rest.json) per REST instance. + * @summary Get transaction fees information + */ + public getNetworkFees(): Observable { + return observableFrom(this.networkRouteApi.getNetworkFees()).pipe( + map((({body}) => + new NetworkFees(body.averageFeeMultiplier, body.medianFeeMultiplier, body.highestFeeMultiplier, body.lowestFeeMultiplier))), + catchError((error) => throwError(this.errorHandling(error))), + ); + } } diff --git a/src/infrastructure/NetworkRepository.ts b/src/infrastructure/NetworkRepository.ts index 0dccbfca82..0c4f661f16 100644 --- a/src/infrastructure/NetworkRepository.ts +++ b/src/infrastructure/NetworkRepository.ts @@ -15,6 +15,7 @@ */ import {Observable} from 'rxjs'; +import { NetworkFees } from '../model/blockchain/NetworkFees'; import { NetworkName } from '../model/blockchain/NetworkName'; import {NetworkType} from '../model/blockchain/NetworkType'; @@ -37,4 +38,11 @@ export interface NetworkRepository { * @return current network type name and description */ getNetworkName(): Observable; + + /** + * Returns information about the average, median, highest and lower fee multiplier over the last "numBlocksTransactionFeeStats". + * @return the NetworkFees + */ + getNetworkFees(): Observable ; + } diff --git a/src/model/blockchain/NetworkFees.ts b/src/model/blockchain/NetworkFees.ts new file mode 100644 index 0000000000..fb39b430fd --- /dev/null +++ b/src/model/blockchain/NetworkFees.ts @@ -0,0 +1,33 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Network Fees + */ +export class NetworkFees { + + /** + * @param averageFeeMultiplier - Average fee multiplier over the last \"numBlocksTransactionFeeStats\". + * @param medianFeeMultiplier - Median fee multiplier over the last \"numBlocksTransactionFeeStats\". + * @param highestFeeMultiplier - Fee multiplier applied to transactions contained in block. + * @param lowestFeeMultiplier - Fee multiplier applied to transactions contained in block. + */ + constructor(public readonly averageFeeMultiplier: number, + public readonly medianFeeMultiplier: number, + public readonly highestFeeMultiplier: number, + public readonly lowestFeeMultiplier: number) { + } +} diff --git a/src/model/blockchain/NetworkName.ts b/src/model/blockchain/NetworkName.ts index d68059ac5e..93ad34a06f 100644 --- a/src/model/blockchain/NetworkName.ts +++ b/src/model/blockchain/NetworkName.ts @@ -15,7 +15,7 @@ */ /** - * The block merkle proof info + * Network Name */ export class NetworkName { diff --git a/src/model/blockchain/NetworkSetting.ts b/src/model/blockchain/NetworkSetting.ts deleted file mode 100644 index e69de29bb2..0000000000