|
| 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 | +} |
0 commit comments