Skip to content

Commit 3707d3e

Browse files
author
Greg S
committed
github PR#63: Added TransactionVersion class containing constants for current network transaction format versions
1 parent 77b655c commit 3707d3e

10 files changed

+107
-10
lines changed

src/model/transaction/AggregateTransaction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { SignedTransaction } from './SignedTransaction';
2626
import { Transaction } from './Transaction';
2727
import { TransactionInfo } from './TransactionInfo';
2828
import { TransactionType } from './TransactionType';
29+
import { TransactionVersion } from './TransactionVersion';
2930

3031
/**
3132
* Aggregate innerTransactions contain multiple innerTransactions that can be initiated by different accounts.
@@ -77,7 +78,7 @@ export class AggregateTransaction extends Transaction {
7778
cosignatures: AggregateTransactionCosignature[]): AggregateTransaction {
7879
return new AggregateTransaction(networkType,
7980
TransactionType.AGGREGATE_COMPLETE,
80-
2,
81+
TransactionVersion.AGGREGATE_COMPLETE,
8182
deadline,
8283
new UInt64([0, 0]),
8384
innerTransactions,
@@ -99,7 +100,7 @@ export class AggregateTransaction extends Transaction {
99100
cosignatures: AggregateTransactionCosignature[] = []): AggregateTransaction {
100101
return new AggregateTransaction(networkType,
101102
TransactionType.AGGREGATE_BONDED,
102-
2,
103+
TransactionVersion.AGGREGATE_BONDED,
103104
deadline,
104105
new UInt64([0, 0]),
105106
innerTransactions,

src/model/transaction/LockFundsTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { SignedTransaction } from './SignedTransaction';
2424
import { Transaction } from './Transaction';
2525
import { TransactionInfo } from './TransactionInfo';
2626
import { TransactionType } from './TransactionType';
27+
import { TransactionVersion } from './TransactionVersion';
2728

2829
/**
2930
* Lock funds transaction is used before sending an Aggregate bonded transaction, as a deposit to announce the transaction.
@@ -53,7 +54,7 @@ export class LockFundsTransaction extends Transaction {
5354
networkType: NetworkType): LockFundsTransaction {
5455
return new LockFundsTransaction(
5556
networkType,
56-
1,
57+
TransactionVersion.LOCK,
5758
deadline,
5859
UInt64.fromUint(0),
5960
mosaic,

src/model/transaction/ModifyMultisigAccountTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { MultisigCosignatoryModification } from './MultisigCosignatoryModificati
2323
import { Transaction } from './Transaction';
2424
import { TransactionInfo } from './TransactionInfo';
2525
import { TransactionType } from './TransactionType';
26+
import { TransactionVersion } from './TransactionVersion';
2627

2728
/**
2829
* Modify multisig account transactions are part of the NEM's multisig account system.
@@ -47,7 +48,7 @@ export class ModifyMultisigAccountTransaction extends Transaction {
4748
modifications: MultisigCosignatoryModification[],
4849
networkType: NetworkType): ModifyMultisigAccountTransaction {
4950
return new ModifyMultisigAccountTransaction(networkType,
50-
3,
51+
TransactionVersion.MODIFY_MULTISIG_ACCOUNT,
5152
deadline,
5253
new UInt64([0, 0]),
5354
minApprovalDelta,

src/model/transaction/MosaicDefinitionTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Deadline } from './Deadline';
2525
import { Transaction } from './Transaction';
2626
import { TransactionInfo } from './TransactionInfo';
2727
import { TransactionType } from './TransactionType';
28+
import { TransactionVersion } from './TransactionVersion';
2829

2930
/**
3031
* Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network.
@@ -47,7 +48,7 @@ export class MosaicDefinitionTransaction extends Transaction {
4748
mosaicProperties: MosaicProperties,
4849
networkType: NetworkType): MosaicDefinitionTransaction {
4950
return new MosaicDefinitionTransaction(networkType,
50-
3,
51+
TransactionVersion.MOSAIC_DEFINITION,
5152
deadline,
5253
new UInt64([0, 0]),
5354
mosaicNonce,

src/model/transaction/MosaicSupplyChangeTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Deadline } from './Deadline';
2424
import { Transaction } from './Transaction';
2525
import { TransactionInfo } from './TransactionInfo';
2626
import { TransactionType } from './TransactionType';
27+
import { TransactionVersion } from './TransactionVersion';
2728

2829
/**
2930
* In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply,
@@ -46,7 +47,7 @@ export class MosaicSupplyChangeTransaction extends Transaction {
4647
delta: UInt64,
4748
networkType: NetworkType): MosaicSupplyChangeTransaction {
4849
return new MosaicSupplyChangeTransaction(networkType,
49-
2,
50+
TransactionVersion.MOSAIC_SUPPLY_CHANGE,
5051
deadline,
5152
new UInt64([0, 0]),
5253
mosaicId,

src/model/transaction/RegisterNamespaceTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Deadline } from './Deadline';
2424
import { Transaction } from './Transaction';
2525
import { TransactionInfo } from './TransactionInfo';
2626
import { TransactionType } from './TransactionType';
27+
import { TransactionVersion } from './TransactionVersion';
2728

2829
/**
2930
* Accounts can rent a namespace for an amount of blocks and after a this renew the contract.
@@ -44,7 +45,7 @@ export class RegisterNamespaceTransaction extends Transaction {
4445
duration: UInt64,
4546
networkType: NetworkType): RegisterNamespaceTransaction {
4647
return new RegisterNamespaceTransaction(networkType,
47-
2,
48+
TransactionVersion.REGISTER_NAMESPACE,
4849
deadline,
4950
new UInt64([0, 0]),
5051
NamespaceType.RootNamespace,

src/model/transaction/SecretLockTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { HashType, HashTypeLengthValidator } from './HashType';
2424
import { Transaction } from './Transaction';
2525
import { TransactionInfo } from './TransactionInfo';
2626
import { TransactionType } from './TransactionType';
27+
import { TransactionVersion } from './TransactionVersion';
2728

2829
export class SecretLockTransaction extends Transaction {
2930

@@ -49,7 +50,7 @@ export class SecretLockTransaction extends Transaction {
4950
networkType: NetworkType): SecretLockTransaction {
5051
return new SecretLockTransaction(
5152
networkType,
52-
1,
53+
TransactionVersion.SECRET_LOCK,
5354
deadline,
5455
UInt64.fromUint(0),
5556
mosaic,

src/model/transaction/SecretProofTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { HashType, HashTypeLengthValidator } from './HashType';
2222
import { Transaction } from './Transaction';
2323
import { TransactionInfo } from './TransactionInfo';
2424
import { TransactionType } from './TransactionType';
25+
import { TransactionVersion } from './TransactionVersion';
2526

2627
export class SecretProofTransaction extends Transaction {
2728

@@ -43,7 +44,7 @@ export class SecretProofTransaction extends Transaction {
4344
networkType: NetworkType): SecretProofTransaction {
4445
return new SecretProofTransaction(
4546
networkType,
46-
1,
47+
TransactionVersion.SECRET_PROOF,
4748
deadline,
4849
UInt64.fromUint(0),
4950
hashType,
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
* Static class containing transaction version constants.
19+
*
20+
* Transaction format versions are defined in catapult-server in
21+
* each transaction's plugin source code.
22+
*
23+
* In [catapult-server](https://github.com/nemtech/catapult-server), the `DEFINE_TRANSACTION_CONSTANTS` macro
24+
* is used to define the `TYPE` and `VERSION` of the transaction format.
25+
*
26+
* @see https://github.com/nemtech/catapult-server/blob/master/plugins/txes/transfer/src/model/TransferTransaction.h#L37
27+
*/
28+
export class TransactionVersion {
29+
30+
/**
31+
* Transfer Transaction transaction version.
32+
* @type {number}
33+
*/
34+
public static readonly TRANSFER = 3;
35+
36+
/**
37+
* Register namespace transaction version.
38+
* @type {number}
39+
*/
40+
public static readonly REGISTER_NAMESPACE = 2;
41+
42+
/**
43+
* Mosaic definition transaction version.
44+
* @type {number}
45+
*/
46+
public static readonly MOSAIC_DEFINITION = 3;
47+
48+
/**
49+
* Mosaic supply change transaction.
50+
* @type {number}
51+
*/
52+
public static readonly MOSAIC_SUPPLY_CHANGE = 2;
53+
54+
/**
55+
* Modify multisig account transaction version.
56+
* @type {number}
57+
*/
58+
public static readonly MODIFY_MULTISIG_ACCOUNT = 3;
59+
60+
/**
61+
* Aggregate complete transaction version.
62+
* @type {number}
63+
*/
64+
public static readonly AGGREGATE_COMPLETE = 2;
65+
66+
/**
67+
* Aggregate bonded transaction version
68+
*/
69+
public static readonly AGGREGATE_BONDED = 2;
70+
71+
/**
72+
* Lock transaction version
73+
* @type {number}
74+
*/
75+
public static readonly LOCK = 1;
76+
77+
/**
78+
* Secret Lock transaction version
79+
* @type {number}
80+
*/
81+
public static readonly SECRET_LOCK = 1;
82+
83+
/**
84+
* Secret Proof transaction version
85+
* @type {number}
86+
*/
87+
public static readonly SECRET_PROOF = 1;
88+
}

src/model/transaction/TransferTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Message } from './Message';
2525
import { Transaction } from './Transaction';
2626
import { TransactionInfo } from './TransactionInfo';
2727
import { TransactionType } from './TransactionType';
28+
import { TransactionVersion } from './TransactionVersion';
2829

2930
/**
3031
* Transfer transactions contain data about transfers of mosaics and message to another account.
@@ -45,7 +46,7 @@ export class TransferTransaction extends Transaction {
4546
message: Message,
4647
networkType: NetworkType): TransferTransaction {
4748
return new TransferTransaction(networkType,
48-
3,
49+
TransactionVersion.TRANSFER,
4950
deadline,
5051
new UInt64([0, 0]),
5152
recipient,

0 commit comments

Comments
 (0)