Skip to content

Commit b2f7731

Browse files
author
Greg S
committed
#55: Added MosaicAliasTransaction transaction type
1 parent bdcf5d2 commit b2f7731

File tree

7 files changed

+225
-0
lines changed

7 files changed

+225
-0
lines changed

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransac
2727
import {Deadline} from '../../model/transaction/Deadline';
2828
import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction';
2929
import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction';
30+
import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction';
3031
import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction';
3132
import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction';
3233
import {MultisigCosignatoryModification} from '../../model/transaction/MultisigCosignatoryModification';
@@ -226,6 +227,19 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
226227
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
227228
transactionInfo,
228229
);
230+
} else if (transactionDTO.type === TransactionType.MOSAIC_ALIAS) {
231+
return new MosaicAliasTransaction(
232+
extractNetworkType(transactionDTO.version),
233+
extractTransactionVersion(transactionDTO.version),
234+
Deadline.createFromDTO(transactionDTO.deadline),
235+
new UInt64(transactionDTO.fee),
236+
transactionDTO.actionType,
237+
transactionDTO.namespaceId,
238+
transactionDTO.mosaicId,
239+
transactionDTO.signature,
240+
PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)),
241+
transactionInfo,
242+
);
229243
}
230244

231245
throw new Error('Unimplemented transaction with type ' + transactionDTO.type);

src/model/model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export * from './namespace/NamespaceId';
4747
export * from './namespace/NamespaceInfo';
4848
export * from './namespace/NamespaceName';
4949
export * from './namespace/NamespaceType';
50+
export * from './namespace/AliasActionType';
5051

5152
// Transaction
5253
export * from './transaction/AggregateTransaction';
@@ -60,6 +61,7 @@ export * from './transaction/InnerTransaction';
6061
export * from './transaction/LockFundsTransaction';
6162
export * from './transaction/Message';
6263
export * from './transaction/ModifyMultisigAccountTransaction';
64+
export * from './transaction/MosaicAliasTransaction';
6365
export * from './transaction/MosaicDefinitionTransaction';
6466
export * from './transaction/MosaicSupplyChangeTransaction';
6567
export * from './transaction/MultisigCosignatoryModification';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
/**
18+
* The alias action type. Supported actions are:
19+
* 0: Link an alias.
20+
* 1: Unlink an alias.
21+
*/
22+
export enum AliasActionType {
23+
Link = 0,
24+
Unlink = 1,
25+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 { MosaicSupplyChangeTransaction as MosaicSupplyChangeTransactionLibrary, VerifiableTransaction } from 'nem2-library';
18+
import { Address } from '../account/Address';
19+
import { PublicAccount } from '../account/PublicAccount';
20+
import { NetworkType } from '../blockchain/NetworkType';
21+
import { MosaicId } from '../mosaic/MosaicId';
22+
import { AliasActionType } from '../namespace/AliasActionType';
23+
import { NamespaceId } from '../namespace/NamespaceId';
24+
import { UInt64 } from '../UInt64';
25+
import { Deadline } from './Deadline';
26+
import { MosaicAliasTransaction } from './MosaicAliasTransaction';
27+
import { Transaction } from './Transaction';
28+
import { TransactionInfo } from './TransactionInfo';
29+
import { TransactionType } from './TransactionType';
30+
import { TransactionVersion } from './TransactionVersion';
31+
32+
export abstract class AliasTransaction extends Transaction {
33+
34+
/**
35+
* Create a mosaic supply change transaction object
36+
* @param deadline - The deadline to include the transaction.
37+
* @param aliasAction - The namespace id.
38+
* @param namespaceId - The namespace id.
39+
* @param mosaicId - The mosaic id.
40+
* @param networkType - The network type.
41+
* @returns {MosaicAliasTransaction}
42+
*/
43+
public static createForMosaic(deadline: Deadline,
44+
aliasAction: AliasActionType,
45+
namespaceId: NamespaceId,
46+
mosaicId: MosaicId,
47+
networkType: NetworkType): AliasTransaction {
48+
return MosaicAliasTransaction.create(deadline, aliasAction, namespaceId, mosaicId, networkType);
49+
}
50+
51+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 { MosaicAliasTransaction as MosaicAliasTransactionLibrary, VerifiableTransaction } from 'nem2-library';
18+
import { PublicAccount } from '../account/PublicAccount';
19+
import { NetworkType } from '../blockchain/NetworkType';
20+
import { MosaicId } from '../mosaic/MosaicId';
21+
import { AliasActionType } from '../namespace/AliasActionType';
22+
import { NamespaceId } from '../namespace/NamespaceId';
23+
import { UInt64 } from '../UInt64';
24+
import { Deadline } from './Deadline';
25+
import { Transaction } from './Transaction';
26+
import { TransactionInfo } from './TransactionInfo';
27+
import { TransactionType } from './TransactionType';
28+
import { TransactionVersion } from './TransactionVersion';
29+
30+
/**
31+
* In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply,
32+
* i.e. increase or decrease the supply.
33+
*/
34+
export class MosaicAliasTransaction extends Transaction {
35+
36+
/**
37+
* Create a mosaic supply change transaction object
38+
* @param deadline - The deadline to include the transaction.
39+
* @param actionType - The namespace id.
40+
* @param namespaceId - The namespace id.
41+
* @param mosaicId - The mosaic id.
42+
* @param networkType - The network type.
43+
* @returns {MosaicAliasTransaction}
44+
*/
45+
public static create(deadline: Deadline,
46+
actionType: AliasActionType,
47+
namespaceId: NamespaceId,
48+
mosaicId: MosaicId,
49+
networkType: NetworkType): MosaicAliasTransaction {
50+
return new MosaicAliasTransaction(networkType,
51+
TransactionVersion.MOSAIC_ALIAS,
52+
deadline,
53+
new UInt64([0, 0]),
54+
actionType,
55+
namespaceId,
56+
mosaicId,
57+
);
58+
}
59+
60+
/**
61+
* @param networkType
62+
* @param version
63+
* @param deadline
64+
* @param fee
65+
* @param actionType
66+
* @param namespaceId
67+
* @param mosaicId
68+
* @param signature
69+
* @param signer
70+
* @param transactionInfo
71+
*/
72+
constructor(networkType: NetworkType,
73+
version: number,
74+
deadline: Deadline,
75+
fee: UInt64,
76+
/**
77+
* The alias action type.
78+
*/
79+
public readonly actionType: AliasActionType,
80+
/**
81+
* The namespace id that will be an alias.
82+
*/
83+
public readonly namespaceId: NamespaceId,
84+
/**
85+
* The mosaic id.
86+
*/
87+
public readonly mosaicId: MosaicId,
88+
signature?: string,
89+
signer?: PublicAccount,
90+
transactionInfo?: TransactionInfo) {
91+
super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, fee, signature, signer, transactionInfo);
92+
}
93+
94+
/**
95+
* @internal
96+
* @returns {VerifiableTransaction}
97+
*/
98+
protected buildTransaction(): VerifiableTransaction {
99+
return new MosaicAliasTransactionLibrary.Builder()
100+
.addDeadline(this.deadline.toDTO())
101+
.addFee(this.fee.toDTO())
102+
.addVersion(this.versionToDTO())
103+
.addActionType(this.actionType)
104+
.addNamespaceId(this.namespaceId.id.toDTO())
105+
.addMosaicId(this.mosaicId.id.toDTO())
106+
.build();
107+
}
108+
109+
}

src/model/transaction/TransactionType.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ export class TransactionType {
3131
*/
3232
public static readonly REGISTER_NAMESPACE = 0x414E;
3333

34+
/**
35+
* Address alias transaction type
36+
* @type {number}
37+
*/
38+
public static readonly ADDRESS_ALIAS = 0x424E;
39+
40+
/**
41+
* Mosaic alias transaction type
42+
* @type {number}
43+
*/
44+
public static readonly MOSAIC_ALIAS = 0x434E;
45+
3446
/**
3547
* Mosaic definition transaction type.
3648
* @type {number}

src/model/transaction/TransactionVersion.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,16 @@ export class TransactionVersion {
8585
* @type {number}
8686
*/
8787
public static readonly SECRET_PROOF = 1;
88+
89+
/**
90+
* Address Alias transaction version
91+
* @type {number}
92+
*/
93+
public static readonly ADDRESS_ALIAS = 1;
94+
95+
/**
96+
* Mosaic Alias transaction version
97+
* @type {number}
98+
*/
99+
public static readonly MOSAIC_ALIAS = 1;
88100
}

0 commit comments

Comments
 (0)