Skip to content

Commit c0dd776

Browse files
author
Grégory Saive
authored
Merge branch 'master' into master
2 parents cafb4a8 + 3d8a889 commit c0dd776

21 files changed

+287
-143
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.
33

44
The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## [0.11.5] - 18-Apr-2019
7+
8+
- Fixed #125, maxFee DTO value errors with in-aggregate MosaicSupplyChange and HashLock transactions
9+
10+
## [0.11.4] - 17-Apr-2019
11+
12+
- Fixed #117, Typo in AddressAliasTransaction and MosaicAliasTransaction comments
13+
- Fixed several typos in documentation
14+
- Fixed CreateTransactionFromDTO to allow `message` to be undefined
15+
- Added transaction/EncryptedMessage
16+
- Added QueryParams.order order parameter
17+
618
## [0.11.3] - 10-Apr-2019
719

820
- Added `Transaction.maxFee` optional property in `create()` methods. (fixes #53)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ with the NEM2 (a.k.a Catapult)
1212

1313
Due to a network upgrade with [catapult-server@cow](https://github.com/nemtech/catapult-server/releases/tag/v0.3.0.2) version, **transactions from Alpaca&Bison are not compatible anymore**.
1414

15-
The upgrade to this SDK's [version v0.11](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.11) is mandatory for **cow compatibility**.
15+
The upgrade to this SDK's [version v0.11.5](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.11.5) is mandatory for **cow compatibility**.
1616

1717
Other versions like [version v0.10.1-beta](https://github.com/nemtech/nem2-sdk-typescript-javascript/releases/tag/v0.10.1-beta) can be used for **bison** network version.
1818

@@ -55,6 +55,8 @@ Please, use the following available resources to get help:
5555

5656
Important versions listed below. Refer to the [Changelog](CHANGELOG.md) for a full history of the project.
5757

58+
- [0.11.5](CHANGELOG.md#0115-18-Apr-2019) - **Cow compatible** - 18.04.2019
59+
- [0.11.4](CHANGELOG.md#0114-17-Apr-2019) - **Cow compatible** - 17.04.2019
5860
- [0.11.3](CHANGELOG.md#0113-10-Apr-2019) - **Cow compatible** - 10.04.2019
5961
- [0.11.2](CHANGELOG.md#0112-1-Apr-2019) - **Cow compatible** - 01.04.2019
6062
- [0.11](CHANGELOG.md#011-14-Mar-2019) - **Cow compatible** - 14.03.2019

e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,53 @@ describe('CreateTransactionFromDTO', () => {
7171
ValidateTransaction.validateStandaloneTx(transferTransaction, transferTransactionDTO);
7272
});
7373

74+
it('standalone without message', () => {
75+
const transferTransactionDTO = {
76+
meta: {
77+
hash: '18C036C20B32348D63684E09A13128A2C18F6A75650D3A5FB43853D716E5E219',
78+
height: [
79+
1,
80+
0,
81+
],
82+
id: '59FDA0733F17CF0001772CA7',
83+
index: 19,
84+
merkleComponentHash: '18C036C20B32348D63684E09A13128A2C18F6A75650D3A5FB43853D716E5E219',
85+
},
86+
transaction: {
87+
deadline: [
88+
10000,
89+
0,
90+
],
91+
fee: [
92+
0,
93+
0,
94+
],
95+
mosaics: [
96+
{
97+
amount: [
98+
3863990592,
99+
95248,
100+
],
101+
id: [
102+
3646934825,
103+
3576016193,
104+
],
105+
},
106+
],
107+
recipient: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142',
108+
signature: '553E696EB4A54E43A11D180EBA57E4B89D0048C9DD2604A9E0608120018B9E0' +
109+
'2F6EE63025FEEBCED3293B622AF8581334D0BDAB7541A9E7411E7EE4EF0BC5D0E',
110+
signer: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF',
111+
type: 16724,
112+
version: 36867,
113+
},
114+
};
115+
116+
const transferTransaction = CreateTransactionFromDTO(transferTransactionDTO);
117+
118+
ValidateTransaction.validateStandaloneTx(transferTransaction, transferTransactionDTO);
119+
});
120+
74121
it('aggregate', () => {
75122
const aggregateTransferTransactionDTO = {
76123
meta: {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nem2-sdk",
3-
"version": "0.11.3",
3+
"version": "0.11.5",
44
"description": "Reactive Nem2 sdk for typescript and javascript",
55
"scripts": {
66
"pretest": "npm run build",

src/infrastructure/QueryParams.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* @since 0.11.3
19+
*/
20+
export enum Order {
21+
ASC = 'id',
22+
DESC = '-id',
23+
}
24+
25+
1726
/**
1827
* The query params structure describes pagination params for requests.
1928
*
@@ -34,7 +43,14 @@ export class QueryParams {
3443
/**
3544
* Id after which we want objects to be returned
3645
*/
37-
public readonly id?: string) {
46+
public readonly id?: string,
47+
/**
48+
* Order of transactions.
49+
* DESC. Newer to older.
50+
* ASC. Older to newer.
51+
*/
52+
public readonly order: Order = Order.DESC,
53+
) {
3854
this.pageSize = (pageSize >= 10 && pageSize <= 100) ? pageSize : 10;
3955
this.id = id;
4056
}

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction
3030
import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature';
3131
import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo';
3232
import {Deadline} from '../../model/transaction/Deadline';
33+
import { EncryptedMessage } from '../../model/transaction/EncryptedMessage';
3334
import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction';
35+
import { MessageType } from '../../model/transaction/MessageType';
3436
import {ModifyAccountPropertyAddressTransaction} from '../../model/transaction/ModifyAccountPropertyAddressTransaction';
3537
import {ModifyAccountPropertyEntityTypeTransaction} from '../../model/transaction/ModifyAccountPropertyEntityTypeTransaction';
3638
import {ModifyAccountPropertyMosaicTransaction} from '../../model/transaction/ModifyAccountPropertyMosaicTransaction';
@@ -117,15 +119,16 @@ export const CreateTransactionFromDTO = (transactionDTO): Transaction => {
117119
* @constructor
118120
*/
119121
const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Transaction => {
122+
120123
if (transactionDTO.type === TransactionType.TRANSFER) {
121124
return new TransferTransaction(
122125
extractNetworkType(transactionDTO.version),
123126
extractTransactionVersion(transactionDTO.version),
124127
Deadline.createFromDTO(transactionDTO.deadline),
125-
UInt64.fromUint(transactionDTO.maxFee || 0),
128+
new UInt64(transactionDTO.maxFee || [0, 0]),
126129
extractRecipient(transactionDTO.recipient),
127130
extractMosaics(transactionDTO.mosaics),
128-
extractMessage(transactionDTO.message.payload),
131+
extractMessage(transactionDTO.message !== undefined ? transactionDTO.message : undefined),
129132
transactionDTO.signature,
130133
transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer,
131134
extractNetworkType(transactionDTO.version)) : undefined,
@@ -136,7 +139,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
136139
extractNetworkType(transactionDTO.version),
137140
extractTransactionVersion(transactionDTO.version),
138141
Deadline.createFromDTO(transactionDTO.deadline),
139-
UInt64.fromUint(transactionDTO.maxFee || 0),
142+
new UInt64(transactionDTO.maxFee || [0, 0]),
140143
transactionDTO.namespaceType,
141144
transactionDTO.name,
142145
new NamespaceId(transactionDTO.namespaceId),
@@ -152,13 +155,14 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
152155
extractNetworkType(transactionDTO.version),
153156
extractTransactionVersion(transactionDTO.version),
154157
Deadline.createFromDTO(transactionDTO.deadline),
155-
UInt64.fromUint(transactionDTO.maxFee || 0),
158+
new UInt64(transactionDTO.maxFee || [0, 0]),
156159
transactionDTO.nonce,
157160
new MosaicId(transactionDTO.mosaicId),
158161
new MosaicProperties(
159162
new UInt64(transactionDTO.properties[0].value),
160163
(new UInt64(transactionDTO.properties[1].value)).compact(),
161-
new UInt64(transactionDTO.properties.length === 3 ? transactionDTO.properties[2].value : undefined),
164+
transactionDTO.properties.length === 3 && transactionDTO.properties[2].value ?
165+
new UInt64(transactionDTO.properties[2].value) : undefined,
162166
),
163167
transactionDTO.signature,
164168
transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer,
@@ -170,7 +174,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
170174
extractNetworkType(transactionDTO.version),
171175
extractTransactionVersion(transactionDTO.version),
172176
Deadline.createFromDTO(transactionDTO.deadline),
173-
UInt64.fromUint(transactionDTO.maxFee || 0),
177+
new UInt64(transactionDTO.maxFee || [0, 0]),
174178
new MosaicId(transactionDTO.mosaicId),
175179
transactionDTO.direction,
176180
new UInt64(transactionDTO.delta),
@@ -184,7 +188,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
184188
extractNetworkType(transactionDTO.version),
185189
extractTransactionVersion(transactionDTO.version),
186190
Deadline.createFromDTO(transactionDTO.deadline),
187-
UInt64.fromUint(transactionDTO.maxFee || 0),
191+
new UInt64(transactionDTO.maxFee || [0, 0]),
188192
transactionDTO.minApprovalDelta,
189193
transactionDTO.minRemovalDelta,
190194
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new MultisigCosignatoryModification(
@@ -202,7 +206,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
202206
networkType,
203207
extractTransactionVersion(transactionDTO.version),
204208
Deadline.createFromDTO(transactionDTO.deadline),
205-
UInt64.fromUint(transactionDTO.maxFee || 0),
209+
new UInt64(transactionDTO.maxFee || [0, 0]),
206210
new Mosaic(new MosaicId(transactionDTO.mosaicId), new UInt64(transactionDTO.amount)),
207211
new UInt64(transactionDTO.duration),
208212
new SignedTransaction('', transactionDTO.hash, '', TransactionType.AGGREGATE_BONDED, networkType),
@@ -216,7 +220,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
216220
extractNetworkType(transactionDTO.version),
217221
extractTransactionVersion(transactionDTO.version),
218222
Deadline.createFromDTO(transactionDTO.deadline),
219-
UInt64.fromUint(transactionDTO.maxFee || 0),
223+
new UInt64(transactionDTO.maxFee || [0, 0]),
220224
new Mosaic(new MosaicId(transactionDTO.mosaicId), new UInt64(transactionDTO.amount)),
221225
new UInt64(transactionDTO.duration),
222226
transactionDTO.hashAlgorithm,
@@ -233,7 +237,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
233237
extractNetworkType(transactionDTO.version),
234238
extractTransactionVersion(transactionDTO.version),
235239
Deadline.createFromDTO(transactionDTO.deadline),
236-
UInt64.fromUint(transactionDTO.maxFee || 0),
240+
new UInt64(transactionDTO.maxFee || [0, 0]),
237241
transactionDTO.hashAlgorithm,
238242
transactionDTO.secret,
239243
transactionDTO.proof,
@@ -247,7 +251,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
247251
extractNetworkType(transactionDTO.version),
248252
extractTransactionVersion(transactionDTO.version),
249253
Deadline.createFromDTO(transactionDTO.deadline),
250-
UInt64.fromUint(transactionDTO.maxFee || 0),
254+
new UInt64(transactionDTO.maxFee || [0, 0]),
251255
transactionDTO.aliasAction,
252256
new NamespaceId(transactionDTO.namespaceId),
253257
new MosaicId(transactionDTO.mosaicId),
@@ -261,7 +265,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
261265
extractNetworkType(transactionDTO.version),
262266
extractTransactionVersion(transactionDTO.version),
263267
Deadline.createFromDTO(transactionDTO.deadline),
264-
UInt64.fromUint(transactionDTO.maxFee || 0),
268+
new UInt64(transactionDTO.maxFee || [0, 0]),
265269
transactionDTO.aliasAction,
266270
new NamespaceId(transactionDTO.namespaceId),
267271
extractRecipient(transactionDTO.address) as Address,
@@ -275,7 +279,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
275279
extractNetworkType(transactionDTO.version),
276280
extractTransactionVersion(transactionDTO.version),
277281
Deadline.createFromDTO(transactionDTO.deadline),
278-
UInt64.fromUint(transactionDTO.maxFee || 0),
282+
new UInt64(transactionDTO.maxFee || [0, 0]),
279283
transactionDTO.propertyType,
280284
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
281285
modificationDTO.modificationType,
@@ -291,7 +295,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
291295
extractNetworkType(transactionDTO.version),
292296
extractTransactionVersion(transactionDTO.version),
293297
Deadline.createFromDTO(transactionDTO.deadline),
294-
UInt64.fromUint(transactionDTO.maxFee || 0),
298+
new UInt64(transactionDTO.maxFee || [0, 0]),
295299
transactionDTO.propertyType,
296300
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
297301
modificationDTO.modificationType,
@@ -307,7 +311,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
307311
extractNetworkType(transactionDTO.version),
308312
extractTransactionVersion(transactionDTO.version),
309313
Deadline.createFromDTO(transactionDTO.deadline),
310-
UInt64.fromUint(transactionDTO.maxFee || 0),
314+
new UInt64(transactionDTO.maxFee || [0, 0]),
311315
transactionDTO.propertyType,
312316
transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new AccountPropertyModification(
313317
modificationDTO.modificationType,
@@ -323,7 +327,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
323327
extractNetworkType(transactionDTO.version),
324328
extractTransactionVersion(transactionDTO.version),
325329
Deadline.createFromDTO(transactionDTO.deadline),
326-
UInt64.fromUint(transactionDTO.maxFee || 0),
330+
new UInt64(transactionDTO.maxFee || [0, 0]),
327331
transactionDTO.remoteAccountKey,
328332
transactionDTO.linkAction,
329333
transactionDTO.signature,
@@ -424,15 +428,15 @@ export const extractMosaics = (mosaics: any): Mosaic[] => {
424428
* @param message - message payload
425429
* @return {PlainMessage}
426430
*/
427-
const extractMessage = (message: any): PlainMessage => {
428-
let plainMessage = EmptyMessage;
429-
if (message !== undefined && convert.isHexString(message)) {
430-
plainMessage = PlainMessage.createFromPayload(message);
431-
} else {
432-
plainMessage = PlainMessage.create(message);
431+
const extractMessage = (message: any): PlainMessage | EncryptedMessage => {
432+
let msgObj = EmptyMessage;
433+
if (message.type === MessageType.PlainMessage) {
434+
msgObj = convert.isHexString(message) ? PlainMessage.createFromPayload(message.payload) :
435+
PlainMessage.create(message.payload);
436+
} else if (message.type === MessageType.EncryptedMessage) {
437+
msgObj = EncryptedMessage.createFromPayload(message.payload);
433438
}
434-
435-
return plainMessage;
439+
return msgObj;
436440
};
437441

438442
/**
@@ -452,7 +456,7 @@ const extractMessage = (message: any): PlainMessage => {
452456
*/
453457
export const extractBeneficiary = (
454458
blockDTO: any,
455-
networkType: NetworkType
459+
networkType: NetworkType,
456460
): PublicAccount | undefined => {
457461

458462
let dtoPublicAccount: PublicAccount | undefined;

src/infrastructure/transaction/CreateTransactionFromPayload.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTra
3131
import { AggregateTransaction } from '../../model/transaction/AggregateTransaction';
3232
import { AggregateTransactionCosignature } from '../../model/transaction/AggregateTransactionCosignature';
3333
import { Deadline } from '../../model/transaction/Deadline';
34+
import { EncryptedMessage } from '../../model/transaction/EncryptedMessage';
3435
import { HashType } from '../../model/transaction/HashType';
3536
import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction';
3637
import { Message } from '../../model/transaction/Message';
38+
import { MessageType } from '../../model/transaction/MessageType';
3739
import { ModifyAccountPropertyAddressTransaction } from '../../model/transaction/ModifyAccountPropertyAddressTransaction';
3840
import { ModifyAccountPropertyEntityTypeTransaction } from '../../model/transaction/ModifyAccountPropertyEntityTypeTransaction';
3941
import { ModifyAccountPropertyMosaicTransaction } from '../../model/transaction/ModifyAccountPropertyMosaicTransaction';
@@ -267,7 +269,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N
267269
const transferMessageSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(50, 54)).reverse()), 16);
268270

269271
const transferMessageAndMosaicSubString = transactionData.substring(56);
270-
const transferMessageType = transferMessageAndMosaicSubString.substring(0, 2);
272+
const transferMessageType = parseInt(convert.uint8ToHex(convert.hexToUint8(
273+
transferMessageAndMosaicSubString.substring(0, 2)).reverse()), 16);
271274
const transferMessage = transferMessageAndMosaicSubString.substring(2, (transferMessageSize - 1) * 2 + 2);
272275
const transferMosaic = transferMessageAndMosaicSubString.substring(transferMessageSize * 2);
273276
const transferMosaicArray = transferMosaic.match(/.{1,32}/g);
@@ -279,7 +282,7 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N
279282
new MosaicId(UInt64.fromHex(reverse(mosaic.substring(0, 16))).toDTO()),
280283
UInt64.fromHex(reverse(mosaic.substring(16))),
281284
)) : [],
282-
PlainMessage.createFromPayload(transferMessage),
285+
extractMessage(transferMessageType, transferMessage),
283286
networkType,
284287
);
285288
case TransactionType.SECRET_LOCK:
@@ -480,3 +483,20 @@ const decodeHex = (hex: string): string => {
480483
return str;
481484
}
482485
};
486+
487+
488+
/**
489+
* @internal
490+
* @param messageType - Message Type
491+
* @param payload - Message Payload
492+
* @returns {Message}
493+
*/
494+
const extractMessage = (messageType: MessageType, payload: string): Message => {
495+
if (messageType === MessageType.PlainMessage) {
496+
return PlainMessage.createFromPayload(payload);
497+
} else if (messageType === MessageType.EncryptedMessage) {
498+
return EncryptedMessage.createFromPayload(payload);
499+
} else {
500+
throw new Error('Invalid message type');
501+
}
502+
};

src/model/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export * from './transaction/AliasTransaction';
7575
export * from './transaction/CosignatureSignedTransaction';
7676
export * from './transaction/CosignatureTransaction';
7777
export * from './transaction/Deadline';
78+
export * from './transaction/EncryptedMessage';
7879
export * from './transaction/HashLockTransaction';
7980
export * from './transaction/HashType';
8081
export * from './transaction/InnerTransaction';

0 commit comments

Comments
 (0)