Skip to content

Commit 508e24f

Browse files
committed
Added #192 Updated AccountPropertyTransaction Names
1 parent 881bfdf commit 508e24f

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 { Builder } from '../../infrastructure/builders/AccountPropertiesEntityTypeTransaction';
18+
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
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 { AccountRestrictionModification } from './AccountRestrictionModification';
24+
import { Deadline } from './Deadline';
25+
import { Transaction } from './Transaction';
26+
import { TransactionInfo } from './TransactionInfo';
27+
import { TransactionType } from './TransactionType';
28+
import { TransactionVersion } from './TransactionVersion';
29+
30+
export class AccountEntityTypeRestrictionModificationTransaction extends Transaction {
31+
32+
/**
33+
* Create a modify account property entity type transaction object
34+
* @param deadline - The deadline to include the transaction.
35+
* @param propertyType - The account property type.
36+
* @param modifications - The array of modifications.
37+
* @param networkType - The network type.
38+
* @param maxFee - (Optional) Max fee defined by the sender
39+
* @returns {AccountEntityTypeRestrictionModificationTransaction}
40+
*/
41+
public static create(deadline: Deadline,
42+
propertyType: PropertyType,
43+
modifications: Array<AccountRestrictionModification<TransactionType>>,
44+
networkType: NetworkType,
45+
maxFee: UInt64 = new UInt64([0, 0])): AccountEntityTypeRestrictionModificationTransaction {
46+
return new AccountEntityTypeRestrictionModificationTransaction(networkType,
47+
TransactionVersion.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE,
48+
deadline,
49+
maxFee,
50+
propertyType,
51+
modifications);
52+
}
53+
54+
/**
55+
* @param networkType
56+
* @param version
57+
* @param deadline
58+
* @param maxFee
59+
* @param minApprovalDelta
60+
* @param minRemovalDelta
61+
* @param modifications
62+
* @param signature
63+
* @param signer
64+
* @param transactionInfo
65+
*/
66+
constructor(networkType: NetworkType,
67+
version: number,
68+
deadline: Deadline,
69+
maxFee: UInt64,
70+
public readonly propertyType: PropertyType,
71+
public readonly modifications: Array<AccountRestrictionModification<TransactionType>>,
72+
signature?: string,
73+
signer?: PublicAccount,
74+
transactionInfo?: TransactionInfo) {
75+
super(TransactionType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
76+
}
77+
78+
/**
79+
* @override Transaction.size()
80+
* @description get the byte size of a AccountEntityTypeRestrictionModificationTransaction
81+
* @returns {number}
82+
* @memberof AccountEntityTypeRestrictionModificationTransaction
83+
*/
84+
public get size(): number {
85+
const byteSize = super.size;
86+
87+
// set static byte size fields
88+
const bytePropertyType = 1;
89+
const byteModificationCount = 1;
90+
91+
// each modification contains :
92+
// - 1 byte for modificationType
93+
// - 2 bytes for the modification value (transaction type)
94+
const byteModifications = 3 * this.modifications.length;
95+
96+
return byteSize + bytePropertyType + byteModificationCount + byteModifications;
97+
}
98+
99+
/**
100+
* @internal
101+
* @returns {VerifiableTransaction}
102+
*/
103+
protected buildTransaction(): VerifiableTransaction {
104+
return new Builder()
105+
.addDeadline(this.deadline.toDTO())
106+
.addFee(this.maxFee.toDTO())
107+
.addVersion(this.versionToDTO())
108+
.addPropertyType(this.propertyType)
109+
.addModifications(this.modifications.map((modification) => modification.toDTO()))
110+
.build();
111+
}
112+
113+
}

0 commit comments

Comments
 (0)