Skip to content

Commit 7b2041e

Browse files
author
Grégory Saive
authored
Merge pull request #73 from rg911/task/g50-account-properties
## Added - Added transaction type AccountPropertyAddressTransaction - Added transaction type AccountPropertyMosaicTransaction - Added transaction type AccountPropertyEntityTypeTransaction. - Added AccountHttp.getAccountProperties()
2 parents 44e88e6 + babb10d commit 7b2041e

22 files changed

+1078
-26
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ describe('AccountHttp', () => {
6262
});
6363
});
6464

65+
describe('getAccountProperty', () => {
66+
it('should call getAccountProperty successfully', (done) => {
67+
accountHttp.getAccountProperty(publicAccount).subscribe((accountProperty) => {
68+
expect(accountProperty.accountProperties[0]!.address).to.be.equal(accountAddress);
69+
done();
70+
});
71+
});
72+
});
73+
74+
describe('getAccountProperties', () => {
75+
it('should call getAccountProperties successfully', (done) => {
76+
accountHttp.getAccountProperties([accountAddress]).subscribe((accountProperties) => {
77+
expect(accountProperties[0]!.accountProperties[0]!.address).to.be.equal(accountAddress);
78+
done();
79+
});
80+
});
81+
});
6582
describe('getMultisigAccountGraphInfo', () => {
6683
it('should call getMultisigAccountGraphInfo successfully', (done) => {
6784
accountHttp.getMultisigAccountGraphInfo(multisigPublicAccount.address).subscribe((multisigAccountGraphInfo) => {

package-lock.json

Lines changed: 12 additions & 12 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
@@ -53,7 +53,7 @@
5353
"@types/crypto-js": "^3.1.43",
5454
"crypto-js": "^3.1.9-1",
5555
"js-joda": "^1.6.2",
56-
"nem2-library": "^0.9.8",
56+
"nem2-library": "^0.9.11",
5757
"request": "^2.83.0",
5858
"request-promise-native": "^1.0.5",
5959
"rxjs": "^6.2.1",

src/infrastructure/AccountHttp.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {AccountRoutesApi} from 'nem2-library';
1818
import {from as observableFrom, Observable} from 'rxjs';
1919
import {map, mergeMap} from 'rxjs/operators';
2020
import {AccountInfo} from '../model/account/AccountInfo';
21+
import { AccountPropertiesInfo } from '../model/account/AccountPropertiesInfo';
22+
import { AccountProperty } from '../model/account/AccountProperty';
2123
import {Address} from '../model/account/Address';
2224
import {MultisigAccountGraphInfo} from '../model/account/MultisigAccountGraphInfo';
2325
import {MultisigAccountInfo} from '../model/account/MultisigAccountInfo';
@@ -79,6 +81,38 @@ export class AccountHttp extends Http implements AccountRepository {
7981
}));
8082
}
8183

84+
/**
85+
* Gets Account property.
86+
* @param publicAccount public account
87+
* @returns Observable<AccountProperty>
88+
*/
89+
public getAccountProperty(publicAccount: PublicAccount): Observable<AccountPropertiesInfo> {
90+
return observableFrom(this.accountRoutesApi.getAccountProperties(publicAccount.publicKey)).pipe(map((accountProperties) => {
91+
return new AccountPropertiesInfo(
92+
accountProperties.meta,
93+
accountProperties.accountProperties,
94+
);
95+
}));
96+
}
97+
98+
/**
99+
* Gets Account properties.
100+
* @param address list of addresses
101+
* @returns Observable<AccountProperty[]>
102+
*/
103+
public getAccountProperties(addresses: Address[]): Observable<AccountPropertiesInfo[]> {
104+
const accountIds = addresses.map((address) => address.plain());
105+
return observableFrom(
106+
this.accountRoutesApi.getAccountPropertiesFromAccounts(accountIds)).pipe(map((accountProperties) => {
107+
return accountProperties.map((property) => {
108+
return new AccountPropertiesInfo(
109+
property.meta,
110+
property.accountProperties,
111+
);
112+
});
113+
}));
114+
}
115+
82116
/**
83117
* Gets AccountsInfo for different accounts.
84118
* @param addresses List of Address
@@ -160,8 +194,7 @@ export class AccountHttp extends Http implements AccountRepository {
160194
* @param queryParams - (Optional) Query params
161195
* @returns Observable<Transaction[]>
162196
*/
163-
public transactions(publicAccount: PublicAccount,
164-
queryParams?: QueryParams): Observable<Transaction[]> {
197+
public transactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable<Transaction[]> {
165198
return observableFrom(
166199
this.accountRoutesApi.transactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
167200
map((transactionsDTO) => {
@@ -178,8 +211,7 @@ export class AccountHttp extends Http implements AccountRepository {
178211
* @param queryParams - (Optional) Query params
179212
* @returns Observable<Transaction[]>
180213
*/
181-
public incomingTransactions(publicAccount: PublicAccount,
182-
queryParams?: QueryParams): Observable<Transaction[]> {
214+
public incomingTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable <Transaction[]> {
183215
return observableFrom(
184216
this.accountRoutesApi.incomingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
185217
map((transactionsDTO) => {
@@ -196,8 +228,7 @@ export class AccountHttp extends Http implements AccountRepository {
196228
* @param queryParams - (Optional) Query params
197229
* @returns Observable<Transaction[]>
198230
*/
199-
public outgoingTransactions(publicAccount: PublicAccount,
200-
queryParams?: QueryParams): Observable<Transaction[]> {
231+
public outgoingTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable <Transaction[]> {
201232
return observableFrom(
202233
this.accountRoutesApi.outgoingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
203234
map((transactionsDTO) => {
@@ -215,8 +246,7 @@ export class AccountHttp extends Http implements AccountRepository {
215246
* @param queryParams - (Optional) Query params
216247
* @returns Observable<Transaction[]>
217248
*/
218-
public unconfirmedTransactions(publicAccount: PublicAccount,
219-
queryParams?: QueryParams): Observable<Transaction[]> {
249+
public unconfirmedTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable <Transaction[]> {
220250
return observableFrom(
221251
this.accountRoutesApi.unconfirmedTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
222252
map((transactionsDTO) => {
@@ -233,9 +263,7 @@ export class AccountHttp extends Http implements AccountRepository {
233263
* @param queryParams - (Optional) Query params
234264
* @returns Observable<AggregateTransaction[]>
235265
*/
236-
public aggregateBondedTransactions(publicAccount: PublicAccount,
237-
queryParams?: QueryParams): Observable<AggregateTransaction[]> {
238-
266+
public aggregateBondedTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable <AggregateTransaction[]> {
239267
return observableFrom(
240268
this.accountRoutesApi.partialTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
241269
map((transactionsDTO) => {

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import {Address} from '../../model/account/Address';
1818
import {PublicAccount} from '../../model/account/PublicAccount';
1919
import {NetworkType} from '../../model/blockchain/NetworkType';
20+
import { AccountPropertyModification,
21+
ModifyAccountPropertyAddressTransaction,
22+
ModifyAccountPropertyEntityTypeTransaction,
23+
ModifyAccountPropertyMosaicTransaction } from '../../model/model';
2024
import {Mosaic} from '../../model/mosaic/Mosaic';
2125
import {MosaicId} from '../../model/mosaic/MosaicId';
2226
import {MosaicProperties} from '../../model/mosaic/MosaicProperties';
@@ -254,6 +258,51 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
254258
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
255259
transactionInfo,
256260
);
261+
} else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_PROPERTY_ADDRESS) {
262+
return new ModifyAccountPropertyAddressTransaction(
263+
extractNetworkType(transactionDTO.version),
264+
extractTransactionVersion(transactionDTO.version),
265+
Deadline.createFromDTO(transactionDTO.deadline),
266+
new UInt64(transactionDTO.fee),
267+
transactionDTO.propertyType,
268+
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
269+
modificationDTO.modificationType,
270+
modificationDTO.value,
271+
)) : [],
272+
transactionDTO.signature,
273+
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
274+
transactionInfo,
275+
);
276+
} else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE) {
277+
return new ModifyAccountPropertyEntityTypeTransaction(
278+
extractNetworkType(transactionDTO.version),
279+
extractTransactionVersion(transactionDTO.version),
280+
Deadline.createFromDTO(transactionDTO.deadline),
281+
new UInt64(transactionDTO.fee),
282+
transactionDTO.propertyType,
283+
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
284+
modificationDTO.modificationType,
285+
modificationDTO.value,
286+
)) : [],
287+
transactionDTO.signature,
288+
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
289+
transactionInfo,
290+
);
291+
} else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_PROPERTY_MOSAIC) {
292+
return new ModifyAccountPropertyMosaicTransaction(
293+
extractNetworkType(transactionDTO.version),
294+
extractTransactionVersion(transactionDTO.version),
295+
Deadline.createFromDTO(transactionDTO.deadline),
296+
new UInt64(transactionDTO.fee),
297+
transactionDTO.propertyType,
298+
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
299+
modificationDTO.modificationType,
300+
modificationDTO.value,
301+
)) : [],
302+
transactionDTO.signature,
303+
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
304+
transactionInfo,
305+
);
257306
}
258307

259308
throw new Error('Unimplemented transaction with type ' + transactionDTO.type);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
import { AccountProperty } from './AccountProperty';
17+
import { Address } from './Address';
18+
/**
19+
* Account properties structure describes property information for an account.
20+
*/
21+
export class AccountProperties {
22+
23+
/**
24+
* Constructor
25+
* @param address
26+
* @param properties
27+
*/
28+
constructor(
29+
/**
30+
* Account Address
31+
*/
32+
public readonly address: Address,
33+
/**
34+
* Properties.
35+
*/
36+
public readonly properties: AccountProperty[]) {
37+
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
import { AccountProperties } from './AccountProperties';
17+
/**
18+
* Account properties structure describes property information for an account.
19+
*/
20+
export class AccountPropertiesInfo {
21+
22+
/**
23+
* Constructor
24+
* @param meta
25+
* @param accountProperties
26+
*/
27+
constructor(
28+
/**
29+
* meta
30+
*/
31+
public readonly meta: any,
32+
/**
33+
* Properties.
34+
*/
35+
public readonly accountProperties: AccountProperties[]) {
36+
37+
}
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
import { PropertyType } from './PropertyType';
18+
/**
19+
* Account property structure describes property information.
20+
*/
21+
export class AccountProperty {
22+
23+
/**
24+
* Constructor
25+
* @param propertyType
26+
* @param values
27+
*/
28+
constructor(
29+
/**
30+
* Account property type
31+
*/
32+
public readonly propertyType: PropertyType,
33+
/**
34+
* Property values.
35+
*/
36+
public readonly values: object[]) {
37+
38+
}
39+
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
* Account property modification type
19+
*/
20+
export enum PropertyModificationType {
21+
Add = 0x00,
22+
Remove = 0x01,
23+
}

0 commit comments

Comments
 (0)