Skip to content

Commit 2808eb8

Browse files
committed
Added transaction filter param in accontHttp
1 parent 8419038 commit 2808eb8

File tree

9 files changed

+109
-58
lines changed

9 files changed

+109
-58
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
import { expect } from 'chai';
1818
import { AccountRepository } from '../../src/infrastructure/AccountRepository';
19+
import { TransactionFilter } from '../../src/infrastructure/infrastructure';
1920
import { MultisigRepository } from '../../src/infrastructure/MultisigRepository';
2021
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
22+
import { QueryParams } from '../../src/infrastructure/QueryParams';
2123
import { Account } from '../../src/model/account/Account';
2224
import { Address } from '../../src/model/account/Address';
2325
import { PublicAccount } from '../../src/model/account/PublicAccount';
@@ -35,7 +37,6 @@ import { TransactionType } from '../../src/model/transaction/TransactionType';
3537
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
3638
import { UInt64 } from '../../src/model/UInt64';
3739
import { IntegrationTestHelper } from './IntegrationTestHelper';
38-
import { QueryParams } from '../../src/infrastructure/QueryParams';
3940

4041
describe('AccountHttp', () => {
4142
const helper = new IntegrationTestHelper();
@@ -227,7 +228,7 @@ describe('AccountHttp', () => {
227228
describe('transactions', () => {
228229
it('should call transactions successfully by type', async () => {
229230
const transactions = await accountRepository.getAccountTransactions(
230-
publicAccount.address, new QueryParams().setType([TransactionType.TRANSFER])).toPromise();
231+
publicAccount.address, new QueryParams(), new TransactionFilter().setType([TransactionType.TRANSFER])).toPromise();
231232
expect(transactions.length).to.be.greaterThan(0);
232233
transactions.forEach((t) => {
233234
expect(t.type).to.be.eq(TransactionType.TRANSFER);

src/infrastructure/AccountHttp.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AccountRepository } from './AccountRepository';
2929
import { Http } from './Http';
3030
import { QueryParams } from './QueryParams';
3131
import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO';
32+
import { TransactionFilter } from './TransactionFilter';
3233

3334
/**
3435
* Account http repository.
@@ -115,15 +116,18 @@ export class AccountHttp extends Http implements AccountRepository {
115116
* Gets an array of confirmed transactions for which an account is signer or receiver.
116117
* @param address - * Address can be created rawAddress or publicKey
117118
* @param queryParams - (Optional) Query params
119+
* @param transactionFilter - (Optional) Transaction filter
118120
* @returns Observable<Transaction[]>
119121
*/
120-
public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable<Transaction[]> {
122+
public getAccountTransactions(address: Address,
123+
queryParams?: QueryParams,
124+
transactionFilter?: TransactionFilter): Observable<Transaction[]> {
121125
return observableFrom(
122126
this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(),
123127
this.queryParams(queryParams).pageSize,
124128
this.queryParams(queryParams).id,
125129
this.queryParams(queryParams).ordering,
126-
this.queryParams(queryParams).type)).pipe(
130+
this.transactionFilter(transactionFilter).type)).pipe(
127131
map(({body}) => body.map((transactionDTO) => {
128132
return CreateTransactionFromDTO(transactionDTO);
129133
})),
@@ -136,15 +140,18 @@ export class AccountHttp extends Http implements AccountRepository {
136140
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
137141
* @param address - * Address can be created rawAddress or publicKey
138142
* @param queryParams - (Optional) Query params
143+
* @param transactionFilter - (Optional) Transaction filter
139144
* @returns Observable<Transaction[]>
140145
*/
141-
public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable <Transaction[]> {
146+
public getAccountIncomingTransactions(address: Address,
147+
queryParams?: QueryParams,
148+
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
142149
return observableFrom(
143150
this.accountRoutesApi.getAccountIncomingTransactions(address.plain(),
144151
this.queryParams(queryParams).pageSize,
145152
this.queryParams(queryParams).id,
146153
this.queryParams(queryParams).ordering),
147-
this.queryParams(queryParams).type).pipe(
154+
this.transactionFilter(transactionFilter).type).pipe(
148155
map(({body}) => body.map((transactionDTO) => {
149156
return CreateTransactionFromDTO(transactionDTO);
150157
})),
@@ -157,15 +164,18 @@ export class AccountHttp extends Http implements AccountRepository {
157164
* A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction.
158165
* @param address - * Address can be created rawAddress or publicKey
159166
* @param queryParams - (Optional) Query params
167+
* @param transactionFilter - (Optional) Transaction filter
160168
* @returns Observable<Transaction[]>
161169
*/
162-
public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable <Transaction[]> {
170+
public getAccountOutgoingTransactions(address: Address,
171+
queryParams?: QueryParams,
172+
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
163173
return observableFrom(
164174
this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(),
165175
this.queryParams(queryParams).pageSize,
166176
this.queryParams(queryParams).id,
167177
this.queryParams(queryParams).ordering),
168-
this.queryParams(queryParams).type).pipe(
178+
this.transactionFilter(transactionFilter).type).pipe(
169179
map(({body}) => body.map((transactionDTO) => {
170180
return CreateTransactionFromDTO(transactionDTO);
171181
})),
@@ -179,15 +189,18 @@ export class AccountHttp extends Http implements AccountRepository {
179189
* Unconfirmed transactions are not guaranteed to be included in any block.
180190
* @param address - * Address can be created rawAddress or publicKey
181191
* @param queryParams - (Optional) Query params
192+
* @param transactionFilter - (Optional) Transaction filter
182193
* @returns Observable<Transaction[]>
183194
*/
184-
public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable <Transaction[]> {
195+
public getAccountUnconfirmedTransactions(address: Address,
196+
queryParams?: QueryParams,
197+
transactionFilter?: TransactionFilter): Observable <Transaction[]> {
185198
return observableFrom(
186199
this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(),
187200
this.queryParams(queryParams).pageSize,
188201
this.queryParams(queryParams).id,
189202
this.queryParams(queryParams).ordering),
190-
this.queryParams(queryParams).type).pipe(
203+
this.transactionFilter(transactionFilter).type).pipe(
191204
map(({body}) => body.map((transactionDTO) => {
192205
return CreateTransactionFromDTO(transactionDTO);
193206
})),
@@ -200,15 +213,18 @@ export class AccountHttp extends Http implements AccountRepository {
200213
* A transaction is said to be aggregate bonded with respect to an account if there are missing signatures.
201214
* @param address - * Address can be created rawAddress or publicKey
202215
* @param queryParams - (Optional) Query params
216+
* @param transactionFilter - (Optional) Transaction filter
203217
* @returns Observable<AggregateTransaction[]>
204218
*/
205-
public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable <AggregateTransaction[]> {
219+
public getAccountPartialTransactions(address: Address,
220+
queryParams?: QueryParams,
221+
transactionFilter?: TransactionFilter): Observable <AggregateTransaction[]> {
206222
return observableFrom(
207223
this.accountRoutesApi.getAccountPartialTransactions(address.plain(),
208224
this.queryParams(queryParams).pageSize,
209225
this.queryParams(queryParams).id,
210226
this.queryParams(queryParams).ordering),
211-
this.queryParams(queryParams).type).pipe(
227+
this.transactionFilter(transactionFilter).type).pipe(
212228
map(({body}) => body.map((transactionDTO) => {
213229
return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction;
214230
})),

src/infrastructure/AccountRepository.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {Address} from '../model/account/Address';
2020
import {AggregateTransaction} from '../model/transaction/AggregateTransaction';
2121
import {Transaction} from '../model/transaction/Transaction';
2222
import { QueryParams } from './QueryParams';
23+
import { TransactionFilter } from './TransactionFilter';
2324

2425
/**
2526
* Account interface repository.
@@ -46,44 +47,53 @@ export interface AccountRepository {
4647
* Gets an array of confirmed transactions for which an account is signer or receiver.
4748
* @param address - * Address can be created rawAddress or publicKey
4849
* @param queryParams - (Optional) Query params
50+
* @param transactionFilter - (Optional) Transaction fitler
4951
* @returns Observable<Transaction[]>
5052
*/
51-
getAccountTransactions(address: Address, queryParams?: QueryParams): Observable<Transaction[]>;
53+
getAccountTransactions(address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable<Transaction[]>;
5254

5355
/**
5456
* Gets an array of transactions for which an account is the recipient of a transaction.
5557
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
5658
* @param address - * Address can be created rawAddress or publicKey
5759
* @param queryParams - (Optional) Query params
60+
* @param transactionFilter - (Optional) Transaction fitler
5861
* @returns Observable<Transaction[]>
5962
*/
60-
getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable<Transaction[]>;
63+
getAccountIncomingTransactions(
64+
address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable<Transaction[]>;
6165

6266
/**
6367
* Gets an array of transactions for which an account is the sender a transaction.
6468
* A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction.
6569
* @param address - * Address can be created rawAddress or publicKey
6670
* @param queryParams - (Optional) Query params
71+
* @param transactionFilter - (Optional) Transaction fitler
6772
* @returns Observable<Transaction[]>
6873
*/
69-
getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable<Transaction[]>;
74+
getAccountOutgoingTransactions(
75+
address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable<Transaction[]>;
7076

7177
/**
7278
* Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block.
7379
* Unconfirmed transactions are those transactions that have not yet been included in a block.
7480
* Unconfirmed transactions are not guaranteed to be included in any block.
7581
* @param address - * Address can be created rawAddress or publicKey
7682
* @param queryParams - (Optional) Query params
83+
* @param transactionFilter - (Optional) Transaction fitler
7784
* @returns Observable<Transaction[]>
7885
*/
79-
getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable<Transaction[]>;
86+
getAccountUnconfirmedTransactions(
87+
address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable<Transaction[]>;
8088

8189
/**
8290
* Gets an array of transactions for which an account is the sender or has sign the transaction.
8391
* A transaction is said to be aggregate bonded with respect to an account if there are missing signatures.
8492
* @param address - * Address can be created rawAddress or publicKey
8593
* @param queryParams - (Optional) Query params
94+
* @param transactionFilter - (Optional) Transaction fitler
8695
* @returns Observable<AggregateTransaction[]>
8796
*/
88-
getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable<AggregateTransaction[]>;
97+
getAccountPartialTransactions(
98+
address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable<AggregateTransaction[]>;
8999
}

src/infrastructure/Http.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr
2020
import { catchError, map, shareReplay } from 'rxjs/operators';
2121
import { NetworkType } from '../model/blockchain/NetworkType';
2222
import { QueryParams } from './QueryParams';
23+
import { TransactionFilter } from './TransactionFilter';
2324

2425
/**
2526
* Http extended by all http services
@@ -56,12 +57,9 @@ export abstract class Http {
5657
};
5758
}
5859

59-
transactionSearchCriteria(queryParams?: QueryParams): any {
60+
transactionFilter(filter?: TransactionFilter): any {
6061
return {
61-
pageSize: queryParams ? queryParams.pageSize : undefined,
62-
id: queryParams ? queryParams.id : undefined,
63-
ordering: queryParams ? queryParams.order : undefined,
64-
type: queryParams ? queryParams.convertCSV(queryParams.type) : undefined,
62+
type: filter ? filter.convertCSV(filter.type) : undefined,
6563
};
6664
}
6765

src/infrastructure/QueryParams.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { TransactionType } from '../model/transaction/TransactionType';
2-
31
/*
42
* Copyright 2018 NEM
53
*
@@ -16,6 +14,8 @@ import { TransactionType } from '../model/transaction/TransactionType';
1614
* limitations under the License.
1715
*/
1816

17+
import { TransactionType } from '../model/transaction/TransactionType';
18+
1919
/**
2020
* @since 0.11.3
2121
*/
@@ -45,10 +45,6 @@ export class QueryParams {
4545
*/
4646
public order: Order = Order.DESC;
4747

48-
/**
49-
* Transaction type list
50-
*/
51-
public type?: TransactionType[];
5248
/**
5349
* Constructor
5450
*/
@@ -69,21 +65,4 @@ export class QueryParams {
6965
this.order = order;
7066
return this;
7167
}
72-
73-
public setType(type?: TransactionType[]): QueryParams {
74-
this.type = type;
75-
return this;
76-
}
77-
78-
/**
79-
* Return comma seperated list
80-
* @param type Transaction type list
81-
*/
82-
public convertCSV(type?: TransactionType[]): string | undefined {
83-
if (!type || type.length === 0) {
84-
return undefined;
85-
} else {
86-
return type.map((t) => t.valueOf().toString()).join(',');
87-
}
88-
}
8968
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2020 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+
import { TransactionType } from '../model/transaction/TransactionType';
18+
import { QueryParams } from './QueryParams';
19+
20+
/**
21+
* The Transaction filter class
22+
*/
23+
export class TransactionFilter {
24+
/**
25+
* Transaction type list
26+
*/
27+
public type?: TransactionType[];
28+
/**
29+
* Constructor
30+
*/
31+
constructor() {
32+
}
33+
34+
public setType(type?: TransactionType[]): TransactionFilter {
35+
this.type = type;
36+
return this;
37+
}
38+
39+
/**
40+
* Return comma seperated list
41+
* @param type Transaction type list
42+
*/
43+
public convertCSV(type?: TransactionType[]): string | undefined {
44+
if (!type || type.length === 0) {
45+
return undefined;
46+
} else {
47+
return type.map((t) => t.valueOf().toString()).join(',');
48+
}
49+
}
50+
}

src/infrastructure/infrastructure.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ export * from './RepositoryFactory';
4747
export * from './RestrictionAccountRepository';
4848
export * from './RestrictionMosaicRepository';
4949
export * from './TransactionRepository';
50+
export * from './TransactionFilter';

test/infrastructure/QueryParams.spec.ts renamed to test/infrastructure/TransactionFilter.spec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@
1515
*/
1616

1717
import { expect } from 'chai';
18-
import { Order, QueryParams } from '../../src/infrastructure/QueryParams';
18+
import { TransactionFilter } from '../../src/infrastructure/TransactionFilter';
1919
import { TransactionType } from '../../src/model/transaction/TransactionType';
2020

21-
describe('QueryParams', () => {
21+
describe('TransactionFilter', () => {
2222
it('should return correct query param', () => {
23-
const param = new QueryParams().setId('0')
24-
.setOrder(Order.ASC)
25-
.setPageSize(10)
23+
const param = new TransactionFilter()
2624
.setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]);
2725

28-
expect(param.id).to.be.equal('0');
29-
expect(param.order.valueOf()).to.be.equal(Order.ASC.valueOf());
30-
expect(param.pageSize).to.be.equal(10);
3126
expect(param.convertCSV(param.type)).to.be.equal('16724,16716');
3227
});
3328
});

test/service/BlockService.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType';
2828
import { UInt64 } from '../../src/model/UInt64';
2929
import { BlockService } from '../../src/service/BlockService';
3030
import { TestingAccount } from '../conf/conf.spec';
31+
import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client';
3132

3233
describe('BlockService', () => {
3334

@@ -100,11 +101,11 @@ describe('BlockService', () => {
100101
function mockMerklePath(): MerkleProofInfo {
101102
return new MerkleProofInfo(
102103
[
103-
new MerklePathItem(1, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'),
104-
new MerklePathItem(2, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'),
105-
new MerklePathItem(1, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'),
106-
new MerklePathItem(2, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'),
107-
new MerklePathItem(2, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'),
104+
new MerklePathItem(PositionEnum.Left, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'),
105+
new MerklePathItem(PositionEnum.Right, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'),
106+
new MerklePathItem(PositionEnum.Left, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'),
107+
new MerklePathItem(PositionEnum.Right, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'),
108+
new MerklePathItem(PositionEnum.Right, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'),
108109
],
109110
);
110111
}

0 commit comments

Comments
 (0)