@@ -322,7 +322,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
322322 throw new Error ( 'Unimplemented transaction with type ' + transactionDTO . type ) ;
323323} ;
324324
325- const extractNetworkType = ( version : number ) : NetworkType => {
325+ export const extractNetworkType = ( version : number ) : NetworkType => {
326326 const networkType = parseInt ( version . toString ( 16 ) . substr ( 0 , 2 ) , 16 ) ;
327327 if ( networkType === NetworkType . MAIN_NET ) {
328328 return NetworkType . MAIN_NET ;
@@ -336,7 +336,7 @@ const extractNetworkType = (version: number): NetworkType => {
336336 throw new Error ( 'Unimplemented network type' ) ;
337337} ;
338338
339- const extractTransactionVersion = ( version : number ) : number => {
339+ export const extractTransactionVersion = ( version : number ) : number => {
340340 return parseInt ( version . toString ( 16 ) . substr ( 2 , 2 ) , 16 ) ;
341341} ;
342342
@@ -349,7 +349,7 @@ const extractTransactionVersion = (version: number): number => {
349349 * @param recipient {string} Encoded hexadecimal recipient notation
350350 * @return {Address | NamespaceId }
351351 */
352- const extractRecipient = ( recipient : string ) : Address | NamespaceId => {
352+ export const extractRecipient = ( recipient : string ) : Address | NamespaceId => {
353353 // If bit 0 of byte 0 is not set (like in 0x90), then it is a regular address.
354354 // Else (e.g. 0x91) it represents a namespace id which starts at byte 1.
355355 const bit0 = convert . hexToUint8 ( recipient . substr ( 1 , 2 ) ) [ 0 ] ;
@@ -374,7 +374,7 @@ const extractRecipient = (recipient: string): Address | NamespaceId => {
374374 * @param mosaics {Array | undefined} The DTO array of mosaics (with UInt64 Id notation)
375375 * @return {Mosaic[] }
376376 */
377- const extractMosaics = ( mosaics : any ) : Mosaic [ ] => {
377+ export const extractMosaics = ( mosaics : any ) : Mosaic [ ] => {
378378
379379 if ( mosaics === undefined ) {
380380 return [ ] ;
@@ -396,3 +396,44 @@ const extractMosaics = (mosaics: any): Mosaic[] => {
396396 return new Mosaic ( new MosaicId ( mosaicDTO . id ) , new UInt64 ( mosaicDTO . amount ) ) ;
397397 } ) ;
398398} ;
399+
400+ /**
401+ * Extract beneficiary public key from DTO.
402+ *
403+ * @todo Upgrade of catapult-rest WITH catapult-service-bootstrap versioning.
404+ *
405+ * With `cow` upgrade (nemtech/catapult-server@0.3.0.2), `catapult-rest` block DTO
406+ * was updated and latest catapult-service-bootstrap uses the wrong block DTO.
407+ * This will be fixed with next catapult-server upgrade to `dragon`.
408+ *
409+ * :warning It is currently not possible to read the block's beneficiary public key
410+ * except when working with a local instance of `catapult-rest`.
411+ *
412+ * @param beneficiary {string | undefined} The beneficiary public key if set
413+ * @return {Mosaic[] }
414+ */
415+ export const extractBeneficiary = (
416+ blockDTO : any ,
417+ networkType : NetworkType
418+ ) : PublicAccount | undefined => {
419+
420+ let dtoPublicAccount : PublicAccount | undefined ;
421+ let dtoFieldValue : string | undefined ;
422+ if ( blockDTO . beneficiaryPublicKey ) {
423+ dtoFieldValue = blockDTO . beneficiaryPublicKey ;
424+ } else if ( blockDTO . beneficiary ) {
425+ dtoFieldValue = blockDTO . beneficiary ;
426+ }
427+
428+ if ( ! dtoFieldValue ) {
429+ return undefined ;
430+ }
431+
432+ try {
433+ // @FIX with latest catapult-service-bootstrap version, catapult-rest still returns
434+ // a `string` formatted copy of the public *when it is set at all*.
435+ dtoPublicAccount = PublicAccount . createFromPublicKey ( dtoFieldValue , networkType ) ;
436+ } catch ( e ) { dtoPublicAccount = undefined ; }
437+
438+ return dtoPublicAccount ;
439+ } ;
0 commit comments