Skip to content

Commit 0d4e609

Browse files
Steven LiuSteven Liu
authored andcommitted
added property modification transactions
1 parent c26ed38 commit 0d4e609

16 files changed

+754
-9
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) => {

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);

src/model/account/AccountProperties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { AccountProperty } from './AccountProperty';
17+
import { Address } from './Address';
1718
/**
1819
* Account properties structure describes property information for an account.
1920
*/
@@ -28,7 +29,7 @@ export class AccountProperties {
2829
/**
2930
* Account Address
3031
*/
31-
public readonly address: string,
32+
public readonly address: Address,
3233
/**
3334
* Properties.
3435
*/

src/model/model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export * from './account/Address';
2424
export * from './account/MultisigAccountGraphInfo';
2525
export * from './account/MultisigAccountInfo';
2626
export * from './account/PublicAccount';
27+
export * from './account/AccountProperties';
28+
export * from './account/AccountPropertiesInfo';
29+
export * from './account/AccountProperty';
30+
export * from './account/PropertyModificationType';
31+
export * from './account/PropertyType';
2732

2833
// Blockchain
2934
export * from './blockchain/BlockchainScore';
@@ -56,6 +61,11 @@ export * from './namespace/NamespaceType';
5661
export * from './namespace/AliasActionType';
5762

5863
// Transaction
64+
export * from './transaction/AccountPropertyTransaction';
65+
export * from './transaction/ModifyAccountPropertyAddressTransaction';
66+
export * from './transaction/ModifyAccountPropertyEntityTypeTransaction';
67+
export * from './transaction/ModifyAccountPropertyMosaicTransaction';
68+
export * from './transaction/AccountPropertyModification';
5969
export * from './transaction/AddressAliasTransaction';
6070
export * from './transaction/AggregateTransaction';
6171
export * from './transaction/AggregateTransactionCosignature';

src/model/transaction/AccountPropertyModification.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { PropertyModificationType } from '../account/PropertyModificationType';
1818

19-
export class AccountPropertyModification {
19+
export class AccountPropertyModification<T> {
2020

2121
/**
2222
* Constructor
@@ -31,19 +31,17 @@ export class AccountPropertyModification {
3131
/**
3232
* Cosignatory public account.
3333
*/
34-
public readonly value: any) {
34+
public readonly value: T) {
3535

3636
}
3737

3838
/**
3939
* @internal
4040
*/
4141
toDTO() {
42-
// TODO: Check type matches value format
43-
4442
return {
4543
value: this.value,
46-
type: this.modificationType,
44+
modificationType: this.modificationType,
4745
};
4846
}
4947
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 { NetworkType } from '../blockchain/NetworkType';
18+
import { AccountPropertyModification,
19+
Address,
20+
ModifyAccountPropertyAddressTransaction,
21+
ModifyAccountPropertyEntityTypeTransaction,
22+
ModifyAccountPropertyMosaicTransaction,
23+
PropertyModificationType, PropertyType } from '../model';
24+
import { MosaicId } from '../mosaic/MosaicId';
25+
import { Deadline } from './Deadline';
26+
import { TransactionTypeEnum } from './TransactionTypeEnum';
27+
28+
export class AccountPropertyTransaction {
29+
/**
30+
* Create an address modification transaction object
31+
* @param deadline - The deadline to include the transaction.
32+
* @param propertyType - Type of account property transaction
33+
* @param modification - array of address modifications
34+
* @param networkType - The network type.
35+
* @returns {ModifyAccountPropertyAddressTransaction}
36+
*/
37+
public static createAddressProertyModificationTransaction(deadline: Deadline,
38+
propertyType: PropertyType,
39+
modifications: Array<AccountPropertyModification<string>>,
40+
networkType: NetworkType): ModifyAccountPropertyAddressTransaction {
41+
if (![PropertyType.AllowAddress, PropertyType.BlockAddress].includes(propertyType)) {
42+
throw new Error ('Property type is not allowed.');
43+
}
44+
return ModifyAccountPropertyAddressTransaction.create(deadline, propertyType, modifications, networkType);
45+
}
46+
47+
/**
48+
* Create an mosaic modification transaction object
49+
* @param deadline - The deadline to include the transaction.
50+
* @param propertyType - Type of account property transaction
51+
* @param modification - array of mosaic modifications
52+
* @param networkType - The network type.
53+
* @returns {ModifyAccountPropertyMosaicTransaction}
54+
*/
55+
public static createMosaicProertyModificationTransaction(deadline: Deadline,
56+
propertyType: PropertyType,
57+
modifications: Array<AccountPropertyModification<number[]>>,
58+
networkType: NetworkType): ModifyAccountPropertyMosaicTransaction {
59+
if (![PropertyType.AllowMosaic, PropertyType.BlockMosaic].includes(propertyType)) {
60+
throw new Error ('Property type is not allowed.');
61+
}
62+
return ModifyAccountPropertyMosaicTransaction.create(deadline, propertyType, modifications, networkType);
63+
}
64+
65+
/**
66+
* Create an entity type modification transaction object
67+
* @param deadline - The deadline to include the transaction.
68+
* @param propertyType - Type of account property transaction
69+
* @param modification - array of entity type modifications
70+
* @param networkType - The network type.
71+
* @returns {ModifyAccountPropertyEntityTypeTransaction}
72+
*/
73+
public static createEntityTypeProertyModificationransaction(deadline: Deadline,
74+
propertyType: PropertyType,
75+
modifications: Array<AccountPropertyModification<number>>,
76+
networkType: NetworkType): ModifyAccountPropertyEntityTypeTransaction {
77+
if (![PropertyType.AllowTransaction, PropertyType.BlockTransaction].includes(propertyType)) {
78+
throw new Error ('Property type is not allowed.');
79+
}
80+
return ModifyAccountPropertyEntityTypeTransaction.create(deadline, propertyType, modifications, networkType);
81+
}
82+
83+
/**
84+
* Create an entity type modification transaction object
85+
* @param modificationType - modification type. 0: Add, 1: Remove
86+
* @param address - modification value (Address)
87+
* @returns {AccountPropertyModification}
88+
*/
89+
public static createAddressFilter(modificationType: PropertyModificationType,
90+
address: Address): AccountPropertyModification<string> {
91+
return new AccountPropertyModification<string>(modificationType, address.plain());
92+
}
93+
94+
/**
95+
* Create an entity type modification transaction object
96+
* @param modificationType - modification type. 0: Add, 1: Remove
97+
* @param mosaicId - modification value (Mosaic)
98+
* @returns {AccountPropertyModification}
99+
*/
100+
public static createMosaicFilter(modificationType: PropertyModificationType,
101+
mosaicId: MosaicId): AccountPropertyModification<number[]> {
102+
return new AccountPropertyModification<number[]>(modificationType, mosaicId.id.toDTO());
103+
}
104+
105+
/**
106+
* Create an entity type modification transaction object
107+
* @param modificationType - modification type. 0: Add, 1: Remove
108+
* @param entityType - modification value (Transaction Type)
109+
* @returns {AccountPropertyModification}
110+
*/
111+
public static createEntityTypeFilter(modificationType: PropertyModificationType,
112+
entityType: number): AccountPropertyModification<number> {
113+
if (!(entityType in TransactionTypeEnum)) {
114+
throw new Error('Not a transaction type');
115+
}
116+
return new AccountPropertyModification<number>(modificationType, entityType);
117+
}
118+
}

src/model/transaction/ModifyAccountPropertyAddressTransaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { TransactionType } from './TransactionType';
2828
export class ModifyAccountPropertyAddressTransaction extends Transaction {
2929

3030
/**
31-
* Create a modify multisig account transaction object
31+
* Create a modify account property address transaction object
3232
* @param deadline - The deadline to include the transaction.
3333
* @param propertyType - The account property type.
3434
* @param modifications - The array of modifications.
@@ -37,7 +37,7 @@ export class ModifyAccountPropertyAddressTransaction extends Transaction {
3737
*/
3838
public static create(deadline: Deadline,
3939
propertyType: PropertyType,
40-
modifications: AccountPropertyModification[],
40+
modifications: Array<AccountPropertyModification<string>>,
4141
networkType: NetworkType): ModifyAccountPropertyAddressTransaction {
4242
return new ModifyAccountPropertyAddressTransaction(networkType,
4343
3,
@@ -64,7 +64,7 @@ export class ModifyAccountPropertyAddressTransaction extends Transaction {
6464
deadline: Deadline,
6565
fee: UInt64,
6666
public readonly propertyType: PropertyType,
67-
public readonly modifications: AccountPropertyModification[],
67+
public readonly modifications: Array<AccountPropertyModification<string>>,
6868
signature?: string,
6969
signer?: PublicAccount,
7070
transactionInfo?: TransactionInfo) {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 { AccountPropertiesEntityTypeTransaction as AccountPropertiesEntityTypeTransactionLibrary,
18+
VerifiableTransaction } from 'nem2-library';
19+
import { PropertyType } from '../account/PropertyType';
20+
import { PublicAccount } from '../account/PublicAccount';
21+
import { NetworkType } from '../blockchain/NetworkType';
22+
import { UInt64 } from '../UInt64';
23+
import { AccountPropertyModification } from './AccountPropertyModification';
24+
import { Deadline } from './Deadline';
25+
import { Transaction } from './Transaction';
26+
import { TransactionInfo } from './TransactionInfo';
27+
import { TransactionType } from './TransactionType';
28+
29+
export class ModifyAccountPropertyEntityTypeTransaction extends Transaction {
30+
31+
/**
32+
* Create a modify account property entity type transaction object
33+
* @param deadline - The deadline to include the transaction.
34+
* @param propertyType - The account property type.
35+
* @param modifications - The array of modifications.
36+
* @param networkType - The network type.
37+
* @returns {ModifyAccountPropertyEntityTypeTransaction}
38+
*/
39+
public static create(deadline: Deadline,
40+
propertyType: PropertyType,
41+
modifications: Array<AccountPropertyModification<number>>,
42+
networkType: NetworkType): ModifyAccountPropertyEntityTypeTransaction {
43+
return new ModifyAccountPropertyEntityTypeTransaction(networkType,
44+
3,
45+
deadline,
46+
new UInt64([0, 0]),
47+
propertyType,
48+
modifications);
49+
}
50+
51+
/**
52+
* @param networkType
53+
* @param version
54+
* @param deadline
55+
* @param fee
56+
* @param minApprovalDelta
57+
* @param minRemovalDelta
58+
* @param modifications
59+
* @param signature
60+
* @param signer
61+
* @param transactionInfo
62+
*/
63+
constructor(networkType: NetworkType,
64+
version: number,
65+
deadline: Deadline,
66+
fee: UInt64,
67+
public readonly propertyType: PropertyType,
68+
public readonly modifications: Array<AccountPropertyModification<number>>,
69+
signature?: string,
70+
signer?: PublicAccount,
71+
transactionInfo?: TransactionInfo) {
72+
super(TransactionType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE, networkType, version, deadline, fee, signature, signer, transactionInfo);
73+
}
74+
75+
/**
76+
* @internal
77+
* @returns {VerifiableTransaction}
78+
*/
79+
protected buildTransaction(): VerifiableTransaction {
80+
return new AccountPropertiesEntityTypeTransactionLibrary.Builder()
81+
.addDeadline(this.deadline.toDTO())
82+
.addFee(this.fee.toDTO())
83+
.addVersion(this.versionToDTO())
84+
.addPropertyType(this.propertyType)
85+
.addModifications(this.modifications.map((modification) => modification.toDTO()))
86+
.build();
87+
}
88+
89+
}

0 commit comments

Comments
 (0)