Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ cache:
- "node_modules"
before_script:
- npm run build
script:
script:
- npm run test:cov
- npm run coveralls-report
- npm install --global typedoc
- typedoc --out ts-docs src
- touch ./ts-docs/.nojekyll
deploy:
provider: pages
skip_cleanup: true
local_dir: ts-docs
github_token: $GITHUB_TOKEN
on:
branch: master

- provider: pages
skip_cleanup: true
local_dir: ts-docs
github_token: $GITHUB_TOKEN
on:
branch: master
- provider: script
skip_cleanup: true
script: /bin/sh travis/uploadArchives.sh
on:
branch: master
node_js: "8"
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "symbol-sdk",
"version": "0.17.3",
"version": "0.17.4",
"description": "Reactive symbol sdk for typescript and javascript",
"scripts": {
"pretest": "npm run build",
Expand All @@ -11,7 +11,8 @@
"build": "rm -rf dist/ && tsc && npm run e2econfigcopy",
"test:cov": "nyc --reporter=lcov --reporter=text-summary npm t",
"test:coveralls": "npm run test:cov | coveralls",
"coveralls-report": "cat ./coverage/lcov.info | coveralls"
"coveralls-report": "cat ./coverage/lcov.info | coveralls",
"version": "echo $npm_package_version"
},
"contributors": [
{
Expand Down
116 changes: 42 additions & 74 deletions src/infrastructure/AccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import { from as observableFrom, Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-node-client';
import { Observable } from 'rxjs';
import { AccountIds, AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-node-client';
import { AccountInfo } from '../model/account/AccountInfo';
import { ActivityBucket } from '../model/account/ActivityBucket';
import { Address } from '../model/account/Address';
Expand Down Expand Up @@ -58,25 +57,18 @@ export class AccountHttp extends Http implements AccountRepository {
* @returns Observable<AccountInfo>
*/
public getAccountInfo(address: Address): Observable<AccountInfo> {
return observableFrom(this.accountRoutesApi.getAccountInfo(address.plain())).pipe(
map(({body}) => this.toAccountInfo(body)),
catchError((error) => throwError(this.errorHandling(error))),
);
return this.call(this.accountRoutesApi.getAccountInfo(address.plain()), (body) => this.toAccountInfo(body));
}

/**
* Gets AccountsInfo for different accounts.
* @param addresses List of Address
* @returns Observable<AccountInfo[]>
*/
public getAccountsInfo(addresses: Address[]): Observable<AccountInfo[]> {
const accountIdsBody = {
addresses: addresses.map((address) => address.plain()),
};
return observableFrom(
this.accountRoutesApi.getAccountsInfo(accountIdsBody)).pipe(
map(({body}) => body.map(this.toAccountInfo)),
catchError((error) => throwError(this.errorHandling(error))),
);
const accountIds = new AccountIds();
accountIds.addresses = addresses.map((address) => address.plain());
return this.call(this.accountRoutesApi.getAccountsInfo(accountIds), (body) => body.map(this.toAccountInfo));
}

/**
Expand Down Expand Up @@ -122,17 +114,13 @@ export class AccountHttp extends Http implements AccountRepository {
public getAccountTransactions(address: Address,
queryParams?: QueryParams,
transactionFilter?: TransactionFilter): Observable<Transaction[]> {
return observableFrom(
this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type)).pipe(
map(({body}) => body.map((transactionDTO) => {
return CreateTransactionFromDTO(transactionDTO);
})),
catchError((error) => throwError(this.errorHandling(error))),
);

return this.call(this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type),
(body) => body.map((transactionDTO) => CreateTransactionFromDTO(transactionDTO)));
}

/**
Expand All @@ -145,18 +133,13 @@ export class AccountHttp extends Http implements AccountRepository {
*/
public getAccountIncomingTransactions(address: Address,
queryParams?: QueryParams,
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
return observableFrom(
this.accountRoutesApi.getAccountIncomingTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering),
this.transactionFilter(transactionFilter).type).pipe(
map(({body}) => body.map((transactionDTO) => {
return CreateTransactionFromDTO(transactionDTO);
})),
catchError((error) => throwError(this.errorHandling(error))),
);
transactionFilter?: TransactionFilter): Observable<Transaction[]> {
return this.call(this.accountRoutesApi.getAccountIncomingTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type),
(body) => body.map((transactionDTO) => CreateTransactionFromDTO(transactionDTO)));
}

/**
Expand All @@ -169,18 +152,13 @@ export class AccountHttp extends Http implements AccountRepository {
*/
public getAccountOutgoingTransactions(address: Address,
queryParams?: QueryParams,
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
return observableFrom(
this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering),
this.transactionFilter(transactionFilter).type).pipe(
map(({body}) => body.map((transactionDTO) => {
return CreateTransactionFromDTO(transactionDTO);
})),
catchError((error) => throwError(this.errorHandling(error))),
);
transactionFilter?: TransactionFilter): Observable<Transaction[]> {
return this.call(this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type),
(body) => body.map((transactionDTO) => CreateTransactionFromDTO(transactionDTO)));
}

/**
Expand All @@ -194,18 +172,13 @@ export class AccountHttp extends Http implements AccountRepository {
*/
public getAccountUnconfirmedTransactions(address: Address,
queryParams?: QueryParams,
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
return observableFrom(
this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering),
this.transactionFilter(transactionFilter).type).pipe(
map(({body}) => body.map((transactionDTO) => {
return CreateTransactionFromDTO(transactionDTO);
})),
catchError((error) => throwError(this.errorHandling(error))),
);
transactionFilter?: TransactionFilter): Observable<Transaction[]> {
return this.call(this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type),
(body) => body.map((transactionDTO) => CreateTransactionFromDTO(transactionDTO)));
}

/**
Expand All @@ -218,17 +191,12 @@ export class AccountHttp extends Http implements AccountRepository {
*/
public getAccountPartialTransactions(address: Address,
queryParams?: QueryParams,
transactionFilter?: TransactionFilter): Observable <AggregateTransaction[]> {
return observableFrom(
this.accountRoutesApi.getAccountPartialTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering),
this.transactionFilter(transactionFilter).type).pipe(
map(({body}) => body.map((transactionDTO) => {
return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction;
})),
catchError((error) => throwError(this.errorHandling(error))),
);
transactionFilter?: TransactionFilter): Observable<AggregateTransaction[]> {
return this.call(this.accountRoutesApi.getAccountPartialTransactions(address.plain(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).ordering,
this.transactionFilter(transactionFilter).type),
(body) => body.map((transactionDTO) => CreateTransactionFromDTO(transactionDTO) as AggregateTransaction));
}
}
3 changes: 3 additions & 0 deletions src/infrastructure/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export abstract class Http {
if (error.code && error.address && error.code === 'ECONNREFUSED') {
return new Error(`Cannot reach node: ${error.address}:${error.port}`);
}
if (error instanceof Error) {
return error;
}
return new Error(error);
}
Comment on lines +82 to 86
Copy link
Contributor Author

@fboucquez fboucquez Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment about his change: If we just wrap the exception into a new one Error, the original stack trace is lost. We want the stack trace when something in our code fails, like an NPE when mapping the DTO.


Expand Down
Loading