Skip to content

Commit c26ed38

Browse files
Steven LiuSteven Liu
authored andcommitted
Added #50 Account property and modifications. Initial commit
1 parent dbda900 commit c26ed38

13 files changed

+7226
-365
lines changed

package-lock.json

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

src/infrastructure/AccountHttp.ts

Lines changed: 40 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
@@ -131,7 +165,7 @@ export class AccountHttp extends Http implements AccountRepository {
131165
* @param address - User address
132166
* @returns Observable<MultisigAccountGraphInfo>
133167
*/
134-
public getMultisigAccountGraphInfo(address: Address): Observable<MultisigAccountGraphInfo> {
168+
public getMultisigAccountGraphInfo(address: Address): Observable<MultisigAccountGraphInfo > {
135169
return this.getNetworkTypeObservable().pipe(
136170
mergeMap((networkType) => observableFrom(
137171
this.accountRoutesApi.getAccountMultisigGraph(address.plain())).pipe(map((multisigAccountGraphInfosDTO) => {
@@ -161,7 +195,7 @@ export class AccountHttp extends Http implements AccountRepository {
161195
* @returns Observable<Transaction[]>
162196
*/
163197
public transactions(publicAccount: PublicAccount,
164-
queryParams?: QueryParams): Observable<Transaction[]> {
198+
queryParams?: QueryParams): Observable<Transaction[] > {
165199
return observableFrom(
166200
this.accountRoutesApi.transactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
167201
map((transactionsDTO) => {
@@ -178,8 +212,7 @@ export class AccountHttp extends Http implements AccountRepository {
178212
* @param queryParams - (Optional) Query params
179213
* @returns Observable<Transaction[]>
180214
*/
181-
public incomingTransactions(publicAccount: PublicAccount,
182-
queryParams?: QueryParams): Observable<Transaction[]> {
215+
public incomingTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable < Transaction[] > {
183216
return observableFrom(
184217
this.accountRoutesApi.incomingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
185218
map((transactionsDTO) => {
@@ -196,8 +229,7 @@ export class AccountHttp extends Http implements AccountRepository {
196229
* @param queryParams - (Optional) Query params
197230
* @returns Observable<Transaction[]>
198231
*/
199-
public outgoingTransactions(publicAccount: PublicAccount,
200-
queryParams?: QueryParams): Observable<Transaction[]> {
232+
public outgoingTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable < Transaction[] > {
201233
return observableFrom(
202234
this.accountRoutesApi.outgoingTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
203235
map((transactionsDTO) => {
@@ -215,8 +247,7 @@ export class AccountHttp extends Http implements AccountRepository {
215247
* @param queryParams - (Optional) Query params
216248
* @returns Observable<Transaction[]>
217249
*/
218-
public unconfirmedTransactions(publicAccount: PublicAccount,
219-
queryParams?: QueryParams): Observable<Transaction[]> {
250+
public unconfirmedTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable < Transaction[] > {
220251
return observableFrom(
221252
this.accountRoutesApi.unconfirmedTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
222253
map((transactionsDTO) => {
@@ -233,9 +264,7 @@ export class AccountHttp extends Http implements AccountRepository {
233264
* @param queryParams - (Optional) Query params
234265
* @returns Observable<AggregateTransaction[]>
235266
*/
236-
public aggregateBondedTransactions(publicAccount: PublicAccount,
237-
queryParams?: QueryParams): Observable<AggregateTransaction[]> {
238-
267+
public aggregateBondedTransactions(publicAccount: PublicAccount, queryParams?: QueryParams): Observable < AggregateTransaction[] > {
239268
return observableFrom(
240269
this.accountRoutesApi.partialTransactions(publicAccount.publicKey, queryParams != null ? queryParams : {})).pipe(
241270
map((transactionsDTO) => {

src/infrastructure/TransactionHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ export class TransactionHttp extends Http implements TransactionRepository {
182182
} else {
183183
return CreateTransactionFromDTO(response);
184184
}
185-
}),catchError((err) => {
185+
}), catchError((err) => {
186186
if (err.statusCode === 405) {
187187
return observableThrowError('non sync server');
188188
}
189189
return observableThrowError(err);
190-
}),);
190+
}));
191191
}
192192
}
193193

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 { AccountProperty } from './AccountProperty';
17+
/**
18+
* Account properties structure describes property information for an account.
19+
*/
20+
export class AccountProperties {
21+
22+
/**
23+
* Constructor
24+
* @param address
25+
* @param properties
26+
*/
27+
constructor(
28+
/**
29+
* Account Address
30+
*/
31+
public readonly address: string,
32+
/**
33+
* Properties.
34+
*/
35+
public readonly properties: AccountProperty[]) {
36+
37+
}
38+
}
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+
}

src/model/account/PropertyType.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 type
19+
* 0x01 The property type is an address.
20+
* 0x02 The property type is mosaic id.
21+
* 0x03 The property type is a transaction type.
22+
* 0x04 Property type sentinel.
23+
* 0x80 + type The property is interpreted as a blocking operation.
24+
*/
25+
26+
export enum PropertyType {
27+
AllowAddress = 0x01,
28+
AllowMosaic = 0x02,
29+
AllowTransaction = 0x03,
30+
Sentinel = 0x04,
31+
BlockAddress = (0x80 + 0x01),
32+
BlockMosaic = (0x80 + 0x02),
33+
BlockTransaction = (0x80 + 0x03),
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 { PropertyModificationType } from '../account/PropertyModificationType';
18+
19+
export class AccountPropertyModification {
20+
21+
/**
22+
* Constructor
23+
* @param modificationType
24+
* @param value
25+
*/
26+
constructor(
27+
/**
28+
* Modification type.
29+
*/
30+
public readonly modificationType: PropertyModificationType,
31+
/**
32+
* Cosignatory public account.
33+
*/
34+
public readonly value: any) {
35+
36+
}
37+
38+
/**
39+
* @internal
40+
*/
41+
toDTO() {
42+
// TODO: Check type matches value format
43+
44+
return {
45+
value: this.value,
46+
type: this.modificationType,
47+
};
48+
}
49+
}

0 commit comments

Comments
 (0)