|
| 1 | +// tslint:disable: jsdoc-format |
| 2 | +/** |
| 3 | +*** Copyright (c) 2016-present, |
| 4 | +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. |
| 5 | +*** |
| 6 | +*** This file is part of Catapult. |
| 7 | +*** |
| 8 | +*** Catapult is free software: you can redistribute it and/or modify |
| 9 | +*** it under the terms of the GNU Lesser General Public License as published by |
| 10 | +*** the Free Software Foundation, either version 3 of the License, or |
| 11 | +*** (at your option) any later version. |
| 12 | +*** |
| 13 | +*** Catapult is distributed in the hope that it will be useful, |
| 14 | +*** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +*** GNU Lesser General Public License for more details. |
| 17 | +*** |
| 18 | +*** You should have received a copy of the GNU Lesser General Public License |
| 19 | +*** along with Catapult. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +**/ |
| 21 | + |
| 22 | +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; |
| 23 | +import { AmountDto } from './AmountDto'; |
| 24 | +import { EntityTypeDto } from './EntityTypeDto'; |
| 25 | +import { GeneratorUtils } from './GeneratorUtils'; |
| 26 | +import { KeyDto } from './KeyDto'; |
| 27 | +import { SignatureDto } from './SignatureDto'; |
| 28 | +import { TimestampDto } from './TimestampDto'; |
| 29 | +import { TransactionBuilder } from './TransactionBuilder'; |
| 30 | + |
| 31 | +/** Binary layout for an aggregate complete transaction. */ |
| 32 | +export class AggregateCompleteTransactionBuilder extends TransactionBuilder { |
| 33 | + /** Aggregate transaction body. */ |
| 34 | + aggregateTransactionBody: AggregateTransactionBodyBuilder; |
| 35 | + |
| 36 | + /** |
| 37 | + * Constructor. |
| 38 | + * |
| 39 | + * @param signature Entity signature. |
| 40 | + * @param signer Entity signer's public key. |
| 41 | + * @param version Entity version. |
| 42 | + * @param type Entity type. |
| 43 | + * @param fee Transaction fee. |
| 44 | + * @param deadline Transaction deadline. |
| 45 | + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). |
| 46 | + * @param cosignatures Cosignatures data (fills remaining body space after transactions). |
| 47 | + */ |
| 48 | + // tslint:disable-next-line: max-line-length |
| 49 | + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { |
| 50 | + super(signature, signer, version, type, fee, deadline); |
| 51 | + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Creates an instance of AggregateCompleteTransactionBuilder from binary payload. |
| 56 | + * |
| 57 | + * @param payload Byte payload to use to serialize the object. |
| 58 | + * @return Instance of AggregateCompleteTransactionBuilder. |
| 59 | + */ |
| 60 | + public static loadFromBinary(payload: Uint8Array): AggregateCompleteTransactionBuilder { |
| 61 | + const byteArray = Array.from(payload); |
| 62 | + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); |
| 63 | + byteArray.splice(0, superObject.getSize()); |
| 64 | + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); |
| 65 | + byteArray.splice(0, aggregateTransactionBody.getSize()); |
| 66 | + // tslint:disable-next-line: max-line-length |
| 67 | + return new AggregateCompleteTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). |
| 72 | + * |
| 73 | + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). |
| 74 | + */ |
| 75 | + public getTransactions(): Uint8Array { |
| 76 | + return this.aggregateTransactionBody.getTransactions(); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Gets cosignatures data (fills remaining body space after transactions). |
| 81 | + * |
| 82 | + * @return Cosignatures data (fills remaining body space after transactions). |
| 83 | + */ |
| 84 | + public getCosignatures(): Uint8Array { |
| 85 | + return this.aggregateTransactionBody.getCosignatures(); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Gets the size of the object. |
| 90 | + * |
| 91 | + * @return Size in bytes. |
| 92 | + */ |
| 93 | + public getSize(): number { |
| 94 | + let size: number = super.getSize(); |
| 95 | + size += this.aggregateTransactionBody.getSize(); |
| 96 | + return size; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Serializes an object to bytes. |
| 101 | + * |
| 102 | + * @return Serialized bytes. |
| 103 | + */ |
| 104 | + public serialize(): Uint8Array { |
| 105 | + let newArray = Uint8Array.from([]); |
| 106 | + const superBytes = super.serialize(); |
| 107 | + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); |
| 108 | + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); |
| 109 | + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); |
| 110 | + return newArray; |
| 111 | + } |
| 112 | +} |
0 commit comments