1515 */
1616
1717import { sha3_256 } from 'js-sha3' ;
18- import { Convert } from '../../core/format/Convert' ;
19- import { RawAddress } from '../../core/format/RawAddress' ;
2018import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils' ;
2119import { Address } from '../account/Address' ;
2220import { MosaicId } from '../mosaic/MosaicId' ;
@@ -26,6 +24,8 @@ import { ReceiptType } from './ReceiptType';
2624import { ReceiptVersion } from './ReceiptVersion' ;
2725import { ResolutionEntry } from './ResolutionEntry' ;
2826import { ResolutionType } from './ResolutionType' ;
27+ import { NetworkType } from "../blockchain/NetworkType" ;
28+ import { UnresolvedMapping } from "../../core/utils/UnresolvedMapping" ;
2929
3030/**
3131 * When a transaction includes an alias, a so called resolution statement reflects the resolved value for that block:
@@ -62,12 +62,13 @@ export class ResolutionStatement {
6262
6363 /**
6464 * Generate receipt hash
65+ * @param {networkType } the network type serialized in the output.
6566 * @return {string } receipt hash in hex
6667 */
67- public generateHash ( ) : string {
68+ public generateHash ( networkType : NetworkType ) : string {
6869 const type = this . resolutionType === ResolutionType . Address ? ReceiptType . Address_Alias_Resolution
69- : ReceiptType . Mosaic_Alias_Resolution ;
70- const unresolvedBytes = this . getUnresolvedBytes ( this . resolutionType ) ;
70+ : ReceiptType . Mosaic_Alias_Resolution ;
71+ const unresolvedBytes = this . getUnresolvedBytes ( this . resolutionType , networkType ) ;
7172 const hasher = sha3_256 . create ( ) ;
7273 hasher . update ( GeneratorUtils . uintToBuffer ( ReceiptVersion . RESOLUTION_STATEMENT , 2 ) ) ;
7374 hasher . update ( GeneratorUtils . uintToBuffer ( type , 2 ) ) ;
@@ -86,23 +87,14 @@ export class ResolutionStatement {
8687 /**
8788 * @internal
8889 * Generate buffer for unresulved
89- * @param - The resolution Type
90+ * @param {resolutionType } The resolution Type
91+ * @param {networkType } the network type serialized in the output.
9092 * @return {Uint8Array }
9193 */
92- private getUnresolvedBytes ( resolutionType : ResolutionType ) : Uint8Array {
94+ private getUnresolvedBytes ( resolutionType : ResolutionType , networkType : NetworkType ) : Uint8Array {
9395 if ( resolutionType === ResolutionType . Address ) {
94- const recipientString =
95- this . unresolved instanceof NamespaceId ? ( this . unresolved as NamespaceId ) . toHex ( )
96- : ( this . unresolved as Address ) . plain ( ) ;
97- if ( / ^ [ 0 - 9 a - f A - F ] { 16 } $ / . test ( recipientString ) ) {
98- // received hexadecimal notation of namespaceId (alias)
99- return RawAddress . aliasToRecipient ( Convert . hexToUint8 ( recipientString ) ) ;
100- } else {
101- // received recipient address
102- return RawAddress . stringToAddress ( recipientString ) ;
103- }
96+ return UnresolvedMapping . toUnresolvedAddressBytes ( this . unresolved as Address | NamespaceId , networkType ) ;
10497 }
105-
10698 return GeneratorUtils . uint64ToBuffer ( UInt64 . fromHex ( ( this . unresolved as MosaicId | NamespaceId ) . toHex ( ) ) . toDTO ( ) ) ;
10799 }
108100}
0 commit comments