/** *** Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. *** Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. *** All rights reserved. *** *** This file is part of Catapult. *** *** Catapult is free software: you can redistribute it and/or modify *** it under the terms of the GNU Lesser General Public License as published by *** the Free Software Foundation, either version 3 of the License, or *** (at your option) any later version. *** *** Catapult is distributed in the hope that it will be useful, *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** GNU Lesser General Public License for more details. *** *** You should have received a copy of the GNU Lesser General Public License *** along with Catapult. If not, see . **/ import { AmountDto } from './AmountDto'; import { FinalizationEpochDto } from './FinalizationEpochDto'; import { GeneratorUtils } from './GeneratorUtils'; import { LinkActionDto } from './LinkActionDto'; import { NetworkTypeDto } from './NetworkTypeDto'; import { PublicKeyDto } from './PublicKeyDto'; import { Serializer } from './Serializer'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; import { TransactionTypeDto } from './TransactionTypeDto'; import { VotingKeyLinkTransactionBodyBuilder } from './VotingKeyLinkTransactionBodyBuilder'; import { VotingPublicKeyDto } from './VotingPublicKeyDto'; /** * Link an account with a BLS public key required for finalization voting. This transaction is required for node operators wanting to vote for [finalization](/concepts/block.html#finalization). Announce a VotingKeyLinkTransaction to associate a voting key with an account during a fixed period. An account can be linked to up to **3** different voting keys at the same time. The recommended production setting is to always have at least **2** linked keys with different ``endPoint`` values to ensure a key is registered after the first one expires. See more details in [the manual node setup guide](/guides/network/running-a-symbol-node-manually.html#manual-voting-key-renewal). **/ export class VotingKeyLinkTransactionBuilder extends TransactionBuilder implements Serializer { /** Voting key link transaction body. **/ readonly votingKeyLinkTransactionBody: VotingKeyLinkTransactionBodyBuilder; /** * Constructor. * * @param signature Entity's signature generated by the signing account.. * @param signerPublicKey Public key of the signer of the entity.. * @param version Version of this structure.. * @param network Network on which this entity was created.. * @param type Transaction type. * @param fee Transaction fee. * @param deadline Transaction deadline. * @param linkedPublicKey Linked voting public key.. * @param startEpoch Starting finalization epoch.. * @param endEpoch Ending finalization epoch.. * @param linkAction Account link action.. */ public constructor( signature: SignatureDto, signerPublicKey: PublicKeyDto, version: number, network: NetworkTypeDto, type: TransactionTypeDto, fee: AmountDto, deadline: TimestampDto, linkedPublicKey: VotingPublicKeyDto, startEpoch: FinalizationEpochDto, endEpoch: FinalizationEpochDto, linkAction: LinkActionDto, ) { super(signature, signerPublicKey, version, network, type, fee, deadline); this.votingKeyLinkTransactionBody = new VotingKeyLinkTransactionBodyBuilder(linkedPublicKey, startEpoch, endEpoch, linkAction); } /** * Load from binary array - Creates an object from payload. * * @param payload - Byte payload to use to serialize the object. */ public static loadFromBinary(payload: Uint8Array): VotingKeyLinkTransactionBuilder { const byteArray = Array.from(payload); const superObject = TransactionBuilder.loadFromBinary(payload); byteArray.splice(0, superObject.getSize()); const votingKeyLinkTransactionBody: VotingKeyLinkTransactionBodyBuilder = VotingKeyLinkTransactionBodyBuilder.loadFromBinary( Uint8Array.from(byteArray), ); byteArray.splice(0, votingKeyLinkTransactionBody.getSize()); return new VotingKeyLinkTransactionBuilder( superObject.signature, superObject.signerPublicKey, superObject.version, superObject.network, superObject.type, superObject.fee, superObject.deadline, votingKeyLinkTransactionBody.linkedPublicKey, votingKeyLinkTransactionBody.startEpoch, votingKeyLinkTransactionBody.endEpoch, votingKeyLinkTransactionBody.linkAction, ); } /** * Creates an instance of VotingKeyLinkTransactionBuilder. * * @param signature Entity's signature generated by the signing account.. * @param signerPublicKey Public key of the signer of the entity.. * @param version Version of this structure.. * @param network Network on which this entity was created.. * @param type Transaction type. * @param fee Transaction fee. * @param deadline Transaction deadline. * @param linkedPublicKey Linked voting public key.. * @param startEpoch Starting finalization epoch.. * @param endEpoch Ending finalization epoch.. * @param linkAction Account link action.. * @return Instance of VotingKeyLinkTransactionBuilder. */ public static createVotingKeyLinkTransactionBuilder( signature: SignatureDto, signerPublicKey: PublicKeyDto, version: number, network: NetworkTypeDto, type: TransactionTypeDto, fee: AmountDto, deadline: TimestampDto, linkedPublicKey: VotingPublicKeyDto, startEpoch: FinalizationEpochDto, endEpoch: FinalizationEpochDto, linkAction: LinkActionDto, ): VotingKeyLinkTransactionBuilder { return new VotingKeyLinkTransactionBuilder( signature, signerPublicKey, version, network, type, fee, deadline, linkedPublicKey, startEpoch, endEpoch, linkAction, ); } /** * Gets Linked voting public key.. * * @return Linked voting public key.. */ public getLinkedPublicKey(): VotingPublicKeyDto { return this.votingKeyLinkTransactionBody.getLinkedPublicKey(); } /** * Gets Starting finalization epoch.. * * @return Starting finalization epoch.. */ public getStartEpoch(): FinalizationEpochDto { return this.votingKeyLinkTransactionBody.getStartEpoch(); } /** * Gets Ending finalization epoch.. * * @return Ending finalization epoch.. */ public getEndEpoch(): FinalizationEpochDto { return this.votingKeyLinkTransactionBody.getEndEpoch(); } /** * Gets Account link action.. * * @return Account link action.. */ public getLinkAction(): LinkActionDto { return this.votingKeyLinkTransactionBody.getLinkAction(); } /** * Gets the size of the object. * * @return Size in bytes. */ public getSize(): number { let size = super.getSize(); size += this.votingKeyLinkTransactionBody.getSize(); // votingKeyLinkTransactionBody return size; } /** * Gets the body builder of the object. * * @return Body builder. */ public getBody(): VotingKeyLinkTransactionBodyBuilder { return this.votingKeyLinkTransactionBody; } /** * Serializes an object to bytes. * * @return Serialized bytes. */ public serialize(): Uint8Array { let newArray = Uint8Array.from([]); const superBytes = super.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); const votingKeyLinkTransactionBodyBytes = this.votingKeyLinkTransactionBody.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, votingKeyLinkTransactionBodyBytes); return newArray; } }