|
| 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 { AccountLinkTransaction as AccountLinkTransactionLibrary, VerifiableTransaction } from 'nem2-library'; |
| 18 | +import { PublicAccount } from '../account/PublicAccount'; |
| 19 | +import { NetworkType } from '../blockchain/NetworkType'; |
| 20 | +import { UInt64 } from '../UInt64'; |
| 21 | +import { Deadline } from './Deadline'; |
| 22 | +import { LinkAction } from './LinkAction'; |
| 23 | +import { Transaction } from './Transaction'; |
| 24 | +import { TransactionInfo } from './TransactionInfo'; |
| 25 | +import { TransactionType } from './TransactionType'; |
| 26 | +import { TransactionVersion } from './TransactionVersion'; |
| 27 | + |
| 28 | +/** |
| 29 | + * Announce an AccountLinkTransaction to delegate the account importance to a proxy account. |
| 30 | + * By doing so, you can enable delegated harvesting |
| 31 | + */ |
| 32 | +export class AccountLinkTransaction extends Transaction { |
| 33 | + /** |
| 34 | + * Create a link account transaction object |
| 35 | + * @param deadline - The deadline to include the transaction. |
| 36 | + * @param remoteAccountKey - The public key of the remote account. |
| 37 | + * @param linkAction - The account link action. |
| 38 | + * @returns {AccountLinkTransaction} |
| 39 | + */ |
| 40 | + public static create(deadline: Deadline, |
| 41 | + remoteAccountKey: string, |
| 42 | + linkAction: LinkAction, |
| 43 | + networkType: NetworkType): AccountLinkTransaction { |
| 44 | + return new AccountLinkTransaction(networkType, |
| 45 | + TransactionVersion.LINK_ACCOUNT, |
| 46 | + deadline, |
| 47 | + new UInt64([0, 0]), |
| 48 | + remoteAccountKey, |
| 49 | + linkAction); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @param networkType |
| 54 | + * @param version |
| 55 | + * @param deadline |
| 56 | + * @param fee |
| 57 | + * @param remoteAccountKey |
| 58 | + * @param linkAction |
| 59 | + * @param signature |
| 60 | + * @param signer |
| 61 | + * @param transactionInfo |
| 62 | + */ |
| 63 | + constructor(networkType: NetworkType, |
| 64 | + version: number, |
| 65 | + deadline: Deadline, |
| 66 | + fee: UInt64, |
| 67 | + /** |
| 68 | + * The public key of the remote account. |
| 69 | + */ |
| 70 | + public readonly remoteAccountKey: string, |
| 71 | + /** |
| 72 | + * The account link action. |
| 73 | + */ |
| 74 | + public readonly linkAction: LinkAction, |
| 75 | + signature?: string, |
| 76 | + signer?: PublicAccount, |
| 77 | + transactionInfo?: TransactionInfo) { |
| 78 | + super(TransactionType.LINK_ACCOUNT, networkType, version, deadline, fee, signature, signer, transactionInfo); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @internal |
| 83 | + * @returns {VerifiableTransaction} |
| 84 | + */ |
| 85 | + protected buildTransaction(): VerifiableTransaction { |
| 86 | + return new AccountLinkTransactionLibrary.Builder() |
| 87 | + .addDeadline(this.deadline.toDTO()) |
| 88 | + .addFee(this.fee.toDTO()) |
| 89 | + .addVersion(this.versionToDTO()) |
| 90 | + .addRemoteAccountKey(this.remoteAccountKey) |
| 91 | + .addLinkAction(this.linkAction) |
| 92 | + .build(); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments