Skip to content

Commit 93b6b40

Browse files
committed
Added AccountLInkTransaction
1 parent 2b82033 commit 93b6b40

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/infrastructure/transaction/CreateTransactionFromPayload.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import {decode} from 'utf8';
1919
import { Address } from '../../model/account/Address';
2020
import { PublicAccount } from '../../model/account/PublicAccount';
2121
import { NetworkType } from '../../model/blockchain/NetworkType';
22-
import { NamespaceType } from '../../model/model';
2322
import { Mosaic } from '../../model/mosaic/Mosaic';
2423
import { MosaicId } from '../../model/mosaic/MosaicId';
2524
import { MosaicNonce } from '../../model/mosaic/MosaicNonce';
2625
import { MosaicProperties } from '../../model/mosaic/MosaicProperties';
2726
import { NamespaceId } from '../../model/namespace/NamespaceId';
27+
import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction';
2828
import { AccountPropertyModification } from '../../model/transaction/AccountPropertyModification';
2929
import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction';
3030
import { AggregateTransaction } from '../../model/transaction/AggregateTransaction';
@@ -143,6 +143,17 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N
143143
);
144144
}
145145
throw new Error ('Account property transaction type not recognised.');
146+
case TransactionType.LINK_ACCOUNT:
147+
// read bytes
148+
const remoteAccountKey = transactionData.substring(0, 64);
149+
const linkAction = transactionData.substring(64, 66);
150+
151+
return AccountLinkTransaction.create(
152+
Deadline.createFromDTO(deadline),
153+
remoteAccountKey,
154+
parseInt(convert.uint8ToHex(convert.hexToUint8(linkAction).reverse()), 16),
155+
networkType,
156+
);
146157
case TransactionType.ADDRESS_ALIAS:
147158
// read bytes
148159
const addressAliasAction = transactionData.substring(0, 2);
@@ -364,7 +375,7 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N
364375
networkType,
365376
deadline,
366377
);
367-
return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType))
378+
return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType));
368379
}),
369380
networkType,
370381
bondedConsignatureArray ? bondedConsignatureArray.map((cosignature) => new AggregateTransactionCosignature(

src/infrastructure/transaction/SerializeTransactionToJSON.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction';
1718
import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction';
1819
import { AggregateTransaction } from '../../model/transaction/AggregateTransaction';
1920
import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction';
@@ -39,6 +40,11 @@ import { TransferTransaction } from '../../model/transaction/TransferTransaction
3940
*/
4041
export const SerializeTransactionToJSON = (transaction: Transaction): any => {
4142
switch (transaction.type) {
43+
case TransactionType.LINK_ACCOUNT:
44+
return {
45+
remoteAccountKey: (transaction as AccountLinkTransaction).remoteAccountKey,
46+
linkAction: (transaction as AccountLinkTransaction).linkAction,
47+
};
4248
case TransactionType.ADDRESS_ALIAS:
4349
return {
4450
actionType: (transaction as AddressAliasTransaction).actionType,
@@ -149,6 +155,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
149155
}),
150156
message: (transaction as TransferTransaction).message.toDTO(),
151157
};
158+
default:
159+
throw new Error ('Transaction type not implemented yet.');
152160
}
153161

154162
};

test/infrastructure/SerializeTransactionToJSON.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac
5454
import { UInt64 } from '../../src/model/UInt64';
5555
import { TransactionMapping } from '../../src/utility/TransactionMapping';
5656
import { TestingAccount } from '../conf/conf.spec';
57+
import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction';
58+
import { LinkAction } from '../../src/model/transaction/LinkAction';
5759

5860
describe('SerializeTransactionToJSON', () => {
5961
let account: Account;
@@ -62,6 +64,20 @@ describe('SerializeTransactionToJSON', () => {
6264
account = TestingAccount;
6365
});
6466

67+
it('should create AccountLinkTransaction', () => {
68+
const accountLinkTransaction = AccountLinkTransaction.create(
69+
Deadline.create(),
70+
account.publicKey,
71+
LinkAction.Link,
72+
NetworkType.MIJIN_TEST,
73+
);
74+
75+
const json = accountLinkTransaction.toJSON();
76+
77+
expect(json.remoteAccountKey).to.be.equal(account.publicKey);
78+
expect(json.linkAction).to.be.equal(LinkAction.Link);
79+
});
80+
6581
it('should create AccountPropertyAddressTransaction', () => {
6682
const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
6783
const addressPropertyFilter = AccountPropertyTransaction.createAddressFilter(

test/utility/TransactionMapping.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac
5454
import { UInt64 } from '../../src/model/UInt64';
5555
import { TransactionMapping } from '../../src/utility/TransactionMapping';
5656
import { TestingAccount } from '../conf/conf.spec';
57+
import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction';
58+
import { LinkAction } from '../../src/model/transaction/LinkAction';
5759

5860
describe('TransactionMapping', () => {
5961
let account: Account;
@@ -237,7 +239,7 @@ describe('TransactionMapping', () => {
237239

238240
expect(transaction.message.payload).to.be.equal('test-message');
239241
expect(transaction.mosaics.length).to.be.equal(1);
240-
expect(transaction.recipient.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
242+
expect(transaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
241243

242244
});
243245

@@ -379,4 +381,19 @@ describe('TransactionMapping', () => {
379381
expect(transaction.mosaic.amount.compact()).to.be.equal(10000000);
380382
expect(transaction.hash).to.be.equal(signedTransaction.hash);
381383
});
384+
385+
it('should create an AccountLinkTransaction object with link action', () => {
386+
const accountLinkTransaction = AccountLinkTransaction.create(
387+
Deadline.create(),
388+
account.publicKey,
389+
LinkAction.Link,
390+
NetworkType.MIJIN_TEST,
391+
);
392+
393+
const signedTransaction = accountLinkTransaction.signWith(account);
394+
const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountLinkTransaction;
395+
396+
expect(transaction.linkAction).to.be.equal(0);
397+
expect(transaction.remoteAccountKey).to.be.equal(account.publicKey);
398+
});
382399
});

0 commit comments

Comments
 (0)