Skip to content

Commit 52141de

Browse files
committed
added linked acount transactions
1 parent f5a39e9 commit 52141de

File tree

4 files changed

+130
-0
lines changed

4 files changed

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

src/model/transaction/TransactionType.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ export class TransactionType {
107107
* @type {number}
108108
*/
109109
public static readonly MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE = 0x4350;
110+
111+
/**
112+
* Link account transaction type
113+
* @type {number}
114+
*/
115+
public static readonly LINK_ACCOUNT = 0x414C;
110116
}

src/model/transaction/TransactionVersion.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,10 @@ export class TransactionVersion {
115115
* @type {number}
116116
*/
117117
public static readonly MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE = 1;
118+
119+
/**
120+
* Link account transaction version
121+
* @type {number}
122+
*/
123+
public static readonly LINK_ACCOUNT = 2;
118124
}

0 commit comments

Comments
 (0)