@@ -118,24 +118,14 @@ 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-
131121 return new TransferTransaction (
132122 extractNetworkType ( transactionDTO . version ) ,
133123 extractTransactionVersion ( transactionDTO . version ) ,
134124 Deadline . createFromDTO ( transactionDTO . deadline ) ,
135125 new UInt64 ( transactionDTO . fee || [ 0 , 0 ] ) ,
136126 extractRecipient ( transactionDTO . recipient ) ,
137127 extractMosaics ( transactionDTO . mosaics ) ,
138- message ,
128+ extractMessage ( transactionDTO . message . payload ) ,
139129 transactionDTO . signature ,
140130 transactionDTO . signer ? PublicAccount . createFromPublicKey ( transactionDTO . signer ,
141131 extractNetworkType ( transactionDTO . version ) ) : undefined ,
@@ -390,9 +380,9 @@ const extractRecipient = (recipient: any): Address | NamespaceId => {
390380 } else if ( typeof recipient === 'object' ) { // Is JSON object
391381 if ( recipient . hasOwnProperty ( 'address' ) ) {
392382 return Address . createFromRawAddress ( recipient . address ) ;
383+ } else if ( recipient . hasOwnProperty ( 'id' ) ) {
384+ return new NamespaceId ( recipient . id ) ;
393385 }
394-
395- return new NamespaceId ( recipient . id ) ;
396386 }
397387 throw new Error ( `Recipient: ${ recipient } type is not recognised` ) ;
398388} ;
@@ -428,3 +418,20 @@ const extractMosaics = (mosaics: any): Mosaic[] => {
428418 return new Mosaic ( new MosaicId ( mosaicDTO . id ) , new UInt64 ( mosaicDTO . amount ) ) ;
429419 } ) ;
430420} ;
421+
422+ /**
423+ * Extract message from either JSON payload (unencoded) or DTO (encoded)
424+ *
425+ * @param message - message payload
426+ * @return {PlainMessage }
427+ */
428+ const extractMessage = ( message : any ) : PlainMessage => {
429+ let plainMessage = EmptyMessage ;
430+ if ( message !== undefined && convert . isHexString ( message ) ) {
431+ plainMessage = PlainMessage . createFromDTO ( message ) ;
432+ } else {
433+ plainMessage = PlainMessage . create ( message ) ;
434+ }
435+
436+ return plainMessage ;
437+ } ;
0 commit comments