@@ -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} ;
@@ -125,10 +125,10 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
125125 UInt64 . fromUint ( transactionDTO . maxFee || 0 ) ,
126126 extractRecipient ( transactionDTO . recipient ) ,
127127 extractMosaics ( transactionDTO . mosaics ) ,
128- transactionDTO . message !== undefined ?
129- PlainMessage . createFromDTO ( transactionDTO . message . payload ) : EmptyMessage ,
128+ extractMessage ( transactionDTO . message . payload ) ,
130129 transactionDTO . signature ,
131- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
130+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
131+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
132132 transactionInfo ,
133133 ) ;
134134 } else if ( transactionDTO . type === TransactionType . REGISTER_NAMESPACE ) {
@@ -143,7 +143,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
143143 transactionDTO . namespaceType === 0 ? new UInt64 ( transactionDTO . duration ) : undefined ,
144144 transactionDTO . namespaceType === 1 ? new NamespaceId ( transactionDTO . parentId ) : undefined ,
145145 transactionDTO . signature ,
146- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
146+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
147+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
147148 transactionInfo ,
148149 ) ;
149150 } else if ( transactionDTO . type === TransactionType . MOSAIC_DEFINITION ) {
@@ -160,7 +161,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
160161 new UInt64 ( transactionDTO . properties . length === 3 ? transactionDTO . properties [ 2 ] . value : [ 0 , 0 ] ) ,
161162 ) ,
162163 transactionDTO . signature ,
163- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
164+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
165+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
164166 transactionInfo ,
165167 ) ;
166168 } else if ( transactionDTO . type === TransactionType . MOSAIC_SUPPLY_CHANGE ) {
@@ -173,7 +175,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
173175 transactionDTO . direction ,
174176 new UInt64 ( transactionDTO . delta ) ,
175177 transactionDTO . signature ,
176- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
178+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
179+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
177180 transactionInfo ,
178181 ) ;
179182 } else if ( transactionDTO . type === TransactionType . MODIFY_MULTISIG_ACCOUNT ) {
@@ -189,7 +192,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
189192 PublicAccount . createFromPublicKey ( modificationDTO . cosignatoryPublicKey , extractNetworkType ( transactionDTO . version ) ) ,
190193 ) ) : [ ] ,
191194 transactionDTO . signature ,
192- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
195+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
196+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
193197 transactionInfo ,
194198 ) ;
195199 } else if ( transactionDTO . type === TransactionType . LOCK ) {
@@ -203,10 +207,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
203207 new UInt64 ( transactionDTO . duration ) ,
204208 new SignedTransaction ( '' , transactionDTO . hash , '' , TransactionType . AGGREGATE_BONDED , networkType ) ,
205209 transactionDTO . signature ,
206- PublicAccount . createFromPublicKey ( transactionDTO . signer , networkType ) ,
210+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer , networkType ) : undefined ,
207211 transactionInfo ,
208212 ) ;
209213 } else if ( transactionDTO . type === TransactionType . SECRET_LOCK ) {
214+ const recipient = transactionDTO . recipient ;
210215 return new SecretLockTransaction (
211216 extractNetworkType ( transactionDTO . version ) ,
212217 extractTransactionVersion ( transactionDTO . version ) ,
@@ -216,9 +221,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
216221 new UInt64 ( transactionDTO . duration ) ,
217222 transactionDTO . hashAlgorithm ,
218223 transactionDTO . secret ,
219- Address . createFromEncoded ( transactionDTO . recipient ) ,
224+ typeof recipient === 'object' && recipient . hasOwnProperty ( 'address' ) ?
225+ Address . createFromRawAddress ( recipient . address ) : Address . createFromEncoded ( recipient ) ,
220226 transactionDTO . signature ,
221- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
227+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
228+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
222229 transactionInfo ,
223230 ) ;
224231 } else if ( transactionDTO . type === TransactionType . SECRET_PROOF ) {
@@ -231,7 +238,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
231238 transactionDTO . secret ,
232239 transactionDTO . proof ,
233240 transactionDTO . signature ,
234- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
241+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
242+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
235243 transactionInfo ,
236244 ) ;
237245 } else if ( transactionDTO . type === TransactionType . MOSAIC_ALIAS ) {
@@ -244,7 +252,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
244252 new NamespaceId ( transactionDTO . namespaceId ) ,
245253 new MosaicId ( transactionDTO . mosaicId ) ,
246254 transactionDTO . signature ,
247- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
255+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
256+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
248257 transactionInfo ,
249258 ) ;
250259 } else if ( transactionDTO . type === TransactionType . ADDRESS_ALIAS ) {
@@ -257,7 +266,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
257266 new NamespaceId ( transactionDTO . namespaceId ) ,
258267 extractRecipient ( transactionDTO . address ) as Address ,
259268 transactionDTO . signature ,
260- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
269+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
270+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
261271 transactionInfo ,
262272 ) ;
263273 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_ADDRESS ) {
@@ -272,7 +282,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
272282 modificationDTO . value ,
273283 ) ) : [ ] ,
274284 transactionDTO . signature ,
275- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
285+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
286+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
276287 transactionInfo ,
277288 ) ;
278289 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE ) {
@@ -287,7 +298,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
287298 modificationDTO . value ,
288299 ) ) : [ ] ,
289300 transactionDTO . signature ,
290- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
301+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
302+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
291303 transactionInfo ,
292304 ) ;
293305 } else if ( transactionDTO . type === TransactionType . MODIFY_ACCOUNT_PROPERTY_MOSAIC ) {
@@ -302,7 +314,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
302314 modificationDTO . value ,
303315 ) ) : [ ] ,
304316 transactionDTO . signature ,
305- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
317+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
318+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
306319 transactionInfo ,
307320 ) ;
308321 } else if ( transactionDTO . type === TransactionType . LINK_ACCOUNT ) {
@@ -314,11 +327,11 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
314327 transactionDTO . remoteAccountKey ,
315328 transactionDTO . linkAction ,
316329 transactionDTO . signature ,
317- PublicAccount . createFromPublicKey ( transactionDTO . signer , extractNetworkType ( transactionDTO . version ) ) ,
330+ transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
331+ extractNetworkType ( transactionDTO . version ) ) : undefined ,
318332 transactionInfo ,
319333 ) ;
320334 }
321-
322335 throw new Error ( 'Unimplemented transaction with type ' + transactionDTO . type ) ;
323336} ;
324337
@@ -349,20 +362,28 @@ export const extractTransactionVersion = (version: number): number => {
349362 * @param recipient {string} Encoded hexadecimal recipient notation
350363 * @return {Address | NamespaceId }
351364 */
352- export 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 ] ;
365+ export const extractRecipient = ( recipient : any ) : Address | NamespaceId => {
366+ if ( typeof recipient === 'string' ) {
367+ // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
368+ // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
369+ const bit0 = convert . hexToUint8 ( recipient . substr ( 1 , 2 ) ) [ 0 ] ;
370+ if ( ( bit0 & 16 ) === 16 ) {
371+ // namespaceId encoded hexadecimal notation provided
372+ // only 8 bytes are relevant to resolve the NamespaceId
373+ const relevantPart = recipient . substr ( 2 , 16 ) ;
374+ return NamespaceId . createFromEncoded ( relevantPart ) ;
375+ }
356376
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 ) ;
377+ // read address from encoded hexadecimal notation
378+ return Address . createFromEncoded ( recipient ) ;
379+ } else if ( typeof recipient === 'object' ) { // Is JSON object
380+ if ( recipient . hasOwnProperty ( 'address' ) ) {
381+ return Address . createFromRawAddress ( recipient . address ) ;
382+ } else if ( recipient . hasOwnProperty ( 'id' ) ) {
383+ return new NamespaceId ( recipient . id ) ;
384+ }
362385 }
363-
364- // read address from encoded hexadecimal notation
365- return Address . createFromEncoded ( recipient ) ;
386+ throw new Error ( `Recipient: ${ recipient } type is not recognised` ) ;
366387} ;
367388
368389/**
@@ -397,6 +418,23 @@ export const extractMosaics = (mosaics: any): Mosaic[] => {
397418 } ) ;
398419} ;
399420
421+ /**
422+ * Extract message from either JSON payload (unencoded) or DTO (encoded)
423+ *
424+ * @param message - message payload
425+ * @return {PlainMessage }
426+ */
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 ) ;
433+ }
434+
435+ return plainMessage ;
436+ } ;
437+
400438/**
401439 * Extract beneficiary public key from DTO.
402440 *
0 commit comments