@@ -30,7 +30,6 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction
3030import { AggregateTransactionCosignature } from '../../model/transaction/AggregateTransactionCosignature' ;
3131import { AggregateTransactionInfo } from '../../model/transaction/AggregateTransactionInfo' ;
3232import { Deadline } from '../../model/transaction/Deadline' ;
33- import { LinkAction } from '../../model/transaction/LinkAction' ;
3433import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction' ;
3534import { ModifyAccountPropertyAddressTransaction } from '../../model/transaction/ModifyAccountPropertyAddressTransaction' ;
3635import { ModifyAccountPropertyEntityTypeTransaction } from '../../model/transaction/ModifyAccountPropertyEntityTypeTransaction' ;
@@ -88,23 +87,24 @@ export const CreateTransactionFromDTO = (transactionDTO): Transaction => {
8887 extractNetworkType ( transactionDTO . transaction . version ) ) ) ;
8988 } ) : [ ] ,
9089 transactionDTO . transaction . signature ,
91- PublicAccount . createFromPublicKey ( transactionDTO . transaction . signer , extractNetworkType ( transactionDTO . transaction . version ) ) ,
92- new TransactionInfo (
90+ transactionDTO . transaction . signer ? PublicAccount . createFromPublicKey ( transactionDTO . transaction . signer ,
91+ extractNetworkType ( transactionDTO . transaction . version ) ) : undefined ,
92+ transactionDTO . meta ? new TransactionInfo (
9393 new UInt64 ( transactionDTO . meta . height ) ,
9494 transactionDTO . meta . index ,
9595 transactionDTO . meta . id ,
9696 transactionDTO . meta . hash ,
9797 transactionDTO . meta . merkleComponentHash ,
98- ) ,
98+ ) : undefined ,
9999 ) ;
100100 } else {
101- const transactionInfo = new TransactionInfo (
101+ const transactionInfo = transactionDTO . meta ? new TransactionInfo (
102102 new UInt64 ( transactionDTO . meta . height ) ,
103103 transactionDTO . meta . index ,
104104 transactionDTO . meta . id ,
105105 transactionDTO . meta . hash ,
106106 transactionDTO . meta . merkleComponentHash ,
107- ) ;
107+ ) : undefined ;
108108 return CreateStandaloneTransactionFromDTO ( transactionDTO . transaction , transactionInfo ) ;
109109 }
110110} ;
@@ -118,17 +118,27 @@ export const CreateTransactionFromDTO = (transactionDTO): Transaction => {
118118 */
119119const CreateStandaloneTransactionFromDTO = ( transactionDTO , transactionInfo ) : Transaction => {
120120 if ( transactionDTO . type === TransactionType . TRANSFER ) {
121+ /**
122+ * Check if message is encoded (from DTO) or is raw (from JSON)
123+ */
124+ let message = EmptyMessage ;
125+ if ( transactionDTO . message !== undefined && convert . isHexString ( transactionDTO . message . payload ) ) {
126+ message = PlainMessage . createFromDTO ( transactionDTO . message . payload ) ;
127+ } else {
128+ message = PlainMessage . create ( transactionDTO . message . payload ) ;
129+ }
130+
121131 return new TransferTransaction (
122132 extractNetworkType ( transactionDTO . version ) ,
123133 extractTransactionVersion ( transactionDTO . version ) ,
124134 Deadline . createFromDTO ( transactionDTO . deadline ) ,
125135 new UInt64 ( transactionDTO . fee || [ 0 , 0 ] ) ,
126136 extractRecipient ( transactionDTO . recipient ) ,
127137 extractMosaics ( transactionDTO . mosaics ) ,
128- transactionDTO . message !== undefined ?
129- PlainMessage . createFromDTO ( transactionDTO . message . payload ) : EmptyMessage ,
138+ message ,
130139 transactionDTO . signature ,
131- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
140+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
141+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
132142 transactionInfo ,
133143 ) ;
134144 } else if ( transactionDTO . type === TransactionType . REGISTER_NAMESPACE ) {
@@ -143,7 +153,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
143153 transactionDTO . namespaceType === 0 ? new UInt64 ( transactionDTO . duration ) : undefined ,
144154 transactionDTO . namespaceType === 1 ? new NamespaceId ( transactionDTO . parentId ) : undefined ,
145155 transactionDTO . signature ,
146- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
156+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
157+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
147158 transactionInfo ,
148159 ) ;
149160 } else if ( transactionDTO . type === TransactionType . MOSAIC_DEFINITION ) {
@@ -160,7 +171,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
160171 new UInt64 ( transactionDTO . properties . length === 3 ? transactionDTO . properties [ 2 ] . value : [ 0 , 0 ] ) ,
161172 ) ,
162173 transactionDTO . signature ,
163- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
174+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
175+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
164176 transactionInfo ,
165177 ) ;
166178 } else if ( transactionDTO . type === TransactionType . MOSAIC_SUPPLY_CHANGE ) {
@@ -173,7 +185,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
173185 transactionDTO . direction ,
174186 new UInt64 ( transactionDTO . delta ) ,
175187 transactionDTO . signature ,
176- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
188+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
189+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
177190 transactionInfo ,
178191 ) ;
179192 } else if ( transactionDTO . type === TransactionType . MODIFY_MULTISIG_ACCOUNT ) {
@@ -189,7 +202,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
189202 PublicAccount . createFromPublicKey ( modificationDTO . cosignatoryPublicKey , extractNetworkType ( transactionDTO . version ) ) ,
190203 ) ) : [ ] ,
191204 transactionDTO . signature ,
192- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
205+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
206+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
193207 transactionInfo ,
194208 ) ;
195209 } else if ( transactionDTO . type === TransactionType . LOCK ) {
@@ -203,10 +217,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
203217 new UInt64 ( transactionDTO . duration ) ,
204218 new SignedTransaction ( '' , transactionDTO . hash , '' , TransactionType . AGGREGATE_BONDED , networkType ) ,
205219 transactionDTO . signature ,
206- PublicAccount . createFromPublicKey ( transactionDTO . signer , networkType ) ,
220+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer , networkType ) : undefined ,
207221 transactionInfo ,
208222 ) ;
209223 } else if ( transactionDTO . type === TransactionType . SECRET_LOCK ) {
224+ const recipient = transactionDTO . recipient ;
210225 return new SecretLockTransaction (
211226 extractNetworkType ( transactionDTO . version ) ,
212227 extractTransactionVersion ( transactionDTO . version ) ,
@@ -216,9 +231,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
216231 new UInt64 ( transactionDTO . duration ) ,
217232 transactionDTO . hashAlgorithm ,
218233 transactionDTO . secret ,
219- Address . createFromEncoded ( transactionDTO . recipient ) ,
234+ typeof recipient === 'object' && recipient . hasOwnProperty ( 'address' ) ?
235+ Address . createFromRawAddress ( recipient . address ) : Address . createFromEncoded ( recipient ) ,
220236 transactionDTO . signature ,
221- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
237+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
238+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
222239 transactionInfo ,
223240 ) ;
224241 } else if ( transactionDTO . type === TransactionType . SECRET_PROOF ) {
@@ -231,7 +248,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
231248 transactionDTO . secret ,
232249 transactionDTO . proof ,
233250 transactionDTO . signature ,
234- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
251+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
252+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
235253 transactionInfo ,
236254 ) ;
237255 } else if ( transactionDTO . type === TransactionType . MOSAIC_ALIAS ) {
@@ -244,7 +262,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
244262 new NamespaceId ( transactionDTO . namespaceId ) ,
245263 new MosaicId ( transactionDTO . mosaicId ) ,
246264 transactionDTO . signature ,
247- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
265+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
266+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
248267 transactionInfo ,
249268 ) ;
250269 } else if ( transactionDTO . type === TransactionType . ADDRESS_ALIAS ) {
@@ -257,7 +276,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
257276 new NamespaceId ( transactionDTO . namespaceId ) ,
258277 extractRecipient ( transactionDTO . address ) as Address ,
259278 transactionDTO . signature ,
260- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
279+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
280+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
261281 transactionInfo ,
262282 ) ;
263283 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_ADDRESS ) {
@@ -272,7 +292,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
272292 modificationDTO . value ,
273293 ) ) : [ ] ,
274294 transactionDTO . signature ,
275- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
295+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
296+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
276297 transactionInfo ,
277298 ) ;
278299 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE ) {
@@ -287,7 +308,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
287308 modificationDTO . value ,
288309 ) ) : [ ] ,
289310 transactionDTO . signature ,
290- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
311+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
312+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
291313 transactionInfo ,
292314 ) ;
293315 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_MOSAIC ) {
@@ -302,7 +324,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
302324 modificationDTO . value ,
303325 ) ) : [ ] ,
304326 transactionDTO . signature ,
305- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
327+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
328+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
306329 transactionInfo ,
307330 ) ;
308331 } else if ( transactionDTO . type === TransactionType . LINK_ACCOUNT ) {
@@ -314,11 +337,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
314337 transactionDTO . remoteAccountKey ,
315338 transactionDTO . linkAction ,
316339 transactionDTO . signature ,
317- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
340+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
341+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
318342 transactionInfo ,
319343 ) ;
320344 }
321-
322345 throw new Error ( 'Unimplemented transaction with type ' + transactionDTO . type ) ;
323346} ;
324347
@@ -349,20 +372,29 @@ const extractTransactionVersion = (version: number): number => {
349372 * @param recipient {string} Encoded hexadecimal recipient notation
350373 * @return {Address | NamespaceId }
351374 */
352- const extractRecipient = ( recipient : string ) : Address | NamespaceId => {
353- // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
354- // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
355- const bit0 = convert . hexToUint8 ( recipient . substr ( 1 , 2 ) ) [ 0 ] ;
375+ const extractRecipient = ( recipient : any ) : Address | NamespaceId => {
376+ if ( typeof recipient === 'string' ) {
377+ // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
378+ // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
379+ const bit0 = convert . hexToUint8 ( recipient . substr ( 1 , 2 ) ) [ 0 ] ;
356380
357- if ( ( bit0 & 16 ) === 16 ) {
358- // namespaceId encoded hexadecimal notation provided
359- // only 8 bytes are relevant to resolve the NamespaceId
360- const relevantPart = recipient . substr ( 2 , 16 ) ;
361- return NamespaceId . createFromEncoded ( relevantPart ) ;
362- }
381+ if ( ( bit0 & 16 ) === 16 ) {
382+ // namespaceId encoded hexadecimal notation provided
383+ // only 8 bytes are relevant to resolve the NamespaceId
384+ const relevantPart = recipient . substr ( 2 , 16 ) ;
385+ return NamespaceId . createFromEncoded ( relevantPart ) ;
386+ }
363387
364- // read address from encoded hexadecimal notation
365- return Address . createFromEncoded ( recipient ) ;
388+ // read address from encoded hexadecimal notation
389+ return Address . createFromEncoded ( recipient ) ;
390+ } else if ( typeof recipient === 'object' ) { // Is JSON object
391+ if ( recipient . hasOwnProperty ( 'address' ) ) {
392+ return Address . createFromRawAddress ( recipient . address ) ;
393+ }
394+
395+ return new NamespaceId ( recipient . id ) ;
396+ }
397+ throw new Error ( `Recipient: ${ recipient } type is not recognised` ) ;
366398} ;
367399
368400/**
0 commit comments