Skip to content

Commit 7a0d720

Browse files
committed
Merge branch 'task/g449_block_service' of github.com:NEMStudios/nem2-sdk-typescript-javascript into task/g449_block_service
2 parents ec38331 + 3c9619c commit 7a0d720

File tree

12 files changed

+76
-54
lines changed

12 files changed

+76
-54
lines changed

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('BlockHttp', () => {
9595
expect(blockInfo.height.higher).to.be.equal(0);
9696
expect(blockInfo.timestamp.lower).to.be.equal(0);
9797
expect(blockInfo.timestamp.higher).to.be.equal(0);
98-
98+
expect(blockInfo.beneficiaryPublicKey).not.to.be.undefined;
9999
});
100100
});
101101

e2e/infrastructure/NetworkHttp.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ describe('NetworkHttp', () => {
4444
expect(networkName.description.toLowerCase()).to.be.not.null;
4545
});
4646
});
47+
48+
describe('getNetworkFees', () => {
49+
it('should return network fees', async () => {
50+
const fees = await networkRepository.getNetworkFees().toPromise();
51+
expect(fees.averageFeeMultiplier).to.be.not.null;
52+
expect(fees.highestFeeMultiplier).to.be.not.null;
53+
expect(fees.lowestFeeMultiplier).to.be.not.null;
54+
expect(fees.medianFeeMultiplier).to.be.not.null;
55+
});
56+
});
4757
});

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"js-sha3": "^0.8.0",
6767
"long": "^4.0.0",
6868
"merkletreejs": "^0.1.7",
69-
"nem2-sdk-openapi-typescript-node-client": "0.8.2",
69+
"nem2-sdk-openapi-typescript-node-client": "0.8.3",
7070
"request": "^2.88.0",
7171
"request-promise-native": "^1.0.5",
7272
"ripemd160": "^2.0.2",

src/infrastructure/BlockHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { UInt64 } from '../model/UInt64';
2626
import { BlockRepository } from './BlockRepository';
2727
import { Http } from './Http';
2828
import { QueryParams } from './QueryParams';
29-
import { CreateTransactionFromDTO, extractBeneficiary } from './transaction/CreateTransactionFromDTO';
29+
import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO';
3030

3131
/**
3232
* Blockchain http repository.
@@ -122,7 +122,7 @@ export class BlockHttp extends Http implements BlockRepository {
122122
dto.block.transactionsHash,
123123
dto.block.receiptsHash,
124124
dto.block.stateHash,
125-
extractBeneficiary(dto, networkType),
125+
dto.block.beneficiaryPublicKey ? PublicAccount.createFromPublicKey(dto.block.beneficiaryPublicKey, networkType) : undefined,
126126
);
127127
}
128128

src/infrastructure/Listener.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ import { TransactionStatusError } from '../model/transaction/TransactionStatusEr
3232
import { TransferTransaction } from '../model/transaction/TransferTransaction';
3333
import { UInt64 } from '../model/UInt64';
3434
import { IListener } from './IListener';
35-
import {
36-
CreateTransactionFromDTO,
37-
extractBeneficiary,
38-
} from './transaction/CreateTransactionFromDTO';
35+
import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO';
3936

4037
enum ListenerChannelName {
4138
block = 'block',
@@ -157,7 +154,7 @@ export class Listener implements IListener {
157154
message.block.blockTransactionsHash,
158155
message.block.blockReceiptsHash,
159156
message.block.stateHash,
160-
extractBeneficiary(message, message.block.network), // passing `message` as `blockDTO`
157+
message.block.beneficiaryPublicKey,
161158
),
162159
});
163160
} else if (message.code) {

src/infrastructure/NetworkHttp.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { NetworkRoutesApi } from 'nem2-sdk-openapi-typescript-node-client';
1818
import { from as observableFrom, Observable, throwError } from 'rxjs';
1919
import { catchError, map } from 'rxjs/operators';
20+
import { NetworkFees } from '../model/blockchain/NetworkFees';
2021
import { NetworkName } from '../model/blockchain/NetworkName';
2122
import { NetworkType } from '../model/blockchain/NetworkType';
2223
import { NodeInfo } from '../model/node/NodeInfo';
@@ -71,4 +72,18 @@ export class NetworkHttp extends Http implements NetworkRepository {
7172
catchError((error) => throwError(this.errorHandling(error))),
7273
);
7374
}
75+
76+
/**
77+
* Returns information about the average, median, highest and lower fee multiplier over the last
78+
* \"numBlocksTransactionFeeStats\". The setting \"numBlocksTransactionFeeStats\" is adjustable
79+
* via a configuration file (rest/resources/rest.json) per REST instance.
80+
* @summary Get transaction fees information
81+
*/
82+
public getNetworkFees(): Observable<NetworkFees> {
83+
return observableFrom(this.networkRouteApi.getNetworkFees()).pipe(
84+
map((({body}) =>
85+
new NetworkFees(body.averageFeeMultiplier, body.medianFeeMultiplier, body.highestFeeMultiplier, body.lowestFeeMultiplier))),
86+
catchError((error) => throwError(this.errorHandling(error))),
87+
);
88+
}
7489
}

src/infrastructure/NetworkRepository.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {Observable} from 'rxjs';
18+
import { NetworkFees } from '../model/blockchain/NetworkFees';
1819
import { NetworkName } from '../model/blockchain/NetworkName';
1920
import {NetworkType} from '../model/blockchain/NetworkType';
2021

@@ -37,4 +38,11 @@ export interface NetworkRepository {
3738
* @return current network type name and description
3839
*/
3940
getNetworkName(): Observable<NetworkName>;
41+
42+
/**
43+
* Returns information about the average, median, highest and lower fee multiplier over the last "numBlocksTransactionFeeStats".
44+
* @return the NetworkFees
45+
*/
46+
getNetworkFees(): Observable<NetworkFees> ;
47+
4048
}

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -481,44 +481,3 @@ const extractMessage = (message: any): PlainMessage | EncryptedMessage => {
481481
}
482482
return msgObj;
483483
};
484-
485-
/**
486-
* Extract beneficiary public key from DTO.
487-
*
488-
* @todo Upgrade of catapult-rest WITH catapult-service-bootstrap versioning.
489-
*
490-
* With `cow` upgrade (nemtech/catapult-server@0.3.0.2), `catapult-rest` block DTO
491-
* was updated and latest catapult-service-bootstrap uses the wrong block DTO.
492-
* This will be fixed with next catapult-server upgrade to `dragon`.
493-
*
494-
* :warning It is currently not possible to read the block's beneficiary public key
495-
* except when working with a local instance of `catapult-rest`.
496-
*
497-
* @param beneficiary {string | undefined} The beneficiary public key if set
498-
* @return {Mosaic[]}
499-
*/
500-
export const extractBeneficiary = (
501-
blockDTO: any,
502-
networkType: NetworkType,
503-
): PublicAccount | undefined => {
504-
505-
let dtoPublicAccount: PublicAccount | undefined;
506-
let dtoFieldValue: string | undefined;
507-
if (blockDTO.beneficiaryPublicKey) {
508-
dtoFieldValue = blockDTO.beneficiaryPublicKey;
509-
} else if (blockDTO.beneficiary) {
510-
dtoFieldValue = blockDTO.beneficiary;
511-
}
512-
513-
if (! dtoFieldValue) {
514-
return undefined;
515-
}
516-
517-
try {
518-
// @FIX with latest catapult-service-bootstrap version, catapult-rest still returns
519-
// a `string` formatted copy of the public *when it is set at all*.
520-
dtoPublicAccount = PublicAccount.createFromPublicKey(dtoFieldValue, networkType);
521-
} catch (e) { dtoPublicAccount =  undefined; }
522-
523-
return dtoPublicAccount;
524-
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Network Fees
19+
*/
20+
export class NetworkFees {
21+
22+
/**
23+
* @param averageFeeMultiplier - Average fee multiplier over the last \"numBlocksTransactionFeeStats\".
24+
* @param medianFeeMultiplier - Median fee multiplier over the last \"numBlocksTransactionFeeStats\".
25+
* @param highestFeeMultiplier - Fee multiplier applied to transactions contained in block.
26+
* @param lowestFeeMultiplier - Fee multiplier applied to transactions contained in block.
27+
*/
28+
constructor(public readonly averageFeeMultiplier: number,
29+
public readonly medianFeeMultiplier: number,
30+
public readonly highestFeeMultiplier: number,
31+
public readonly lowestFeeMultiplier: number) {
32+
}
33+
}

0 commit comments

Comments
 (0)