Skip to content

Commit 9198be6

Browse files
committed
Fixed #323
1 parent cd31511 commit 9198be6

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/model/transaction/SecretLockTransaction.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { Convert, Convert as convert, RawAddress } from '../../core/format';
17+
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
1718
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
1819
import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto';
1920
import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder';
@@ -30,6 +31,7 @@ import { PublicAccount } from '../account/PublicAccount';
3031
import { NetworkType } from '../blockchain/NetworkType';
3132
import { Mosaic } from '../mosaic/Mosaic';
3233
import { MosaicId } from '../mosaic/MosaicId';
34+
import { NamespaceId } from '../namespace/NamespaceId';
3335
import { UInt64 } from '../UInt64';
3436
import { Deadline } from './Deadline';
3537
import { HashType, HashTypeLengthValidator } from './HashType';
@@ -49,7 +51,7 @@ export class SecretLockTransaction extends Transaction {
4951
* @param duration - The funds lock duration.
5052
* @param hashType - The hash algorithm secret is generated with.
5153
* @param secret - The proof hashed.
52-
* @param recipientAddress - The recipient address of the funds.
54+
* @param recipientAddress - The unresolved recipient address of the funds.
5355
* @param networkType - The network type.
5456
* @param maxFee - (Optional) Max fee defined by the sender
5557
*
@@ -60,7 +62,7 @@ export class SecretLockTransaction extends Transaction {
6062
duration: UInt64,
6163
hashType: HashType,
6264
secret: string,
63-
recipientAddress: Address,
65+
recipientAddress: Address | NamespaceId,
6466
networkType: NetworkType,
6567
maxFee: UInt64 = new UInt64([0, 0])): SecretLockTransaction {
6668
return new SecretLockTransaction(
@@ -111,9 +113,9 @@ export class SecretLockTransaction extends Transaction {
111113
*/
112114
public readonly secret: string,
113115
/**
114-
* The recipientAddress of the funds.
116+
* The unresolved recipientAddress of the funds.
115117
*/
116-
public readonly recipientAddress: Address,
118+
public readonly recipientAddress: Address | NamespaceId,
117119
signature?: string,
118120
signer?: PublicAccount,
119121
transactionInfo?: TransactionInfo) {
@@ -139,13 +141,13 @@ export class SecretLockTransaction extends Transaction {
139141
isEmbedded ? Deadline.create() : Deadline.createFromDTO(
140142
(builder as SecretLockTransactionBuilder).getDeadline().timestamp),
141143
new Mosaic(
142-
new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId),
144+
UnresolvedMapping.toUnresolvedMosaic(new UInt64(builder.getMosaic().mosaicId.unresolvedMosaicId).toHex()),
143145
new UInt64(builder.getMosaic().amount.amount),
144146
),
145147
new UInt64(builder.getDuration().blockDuration),
146148
builder.getHashAlgorithm().valueOf(),
147149
Convert.uint8ToHex(builder.getSecret().hash256),
148-
Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)),
150+
UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)),
149151
networkType,
150152
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretLockTransactionBuilder).fee.amount),
151153
);
@@ -204,7 +206,7 @@ export class SecretLockTransaction extends Transaction {
204206
new BlockDurationDto(this.duration.toDTO()),
205207
this.hashType.valueOf(),
206208
new Hash256Dto(this.getSecretByte()),
207-
new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())),
209+
new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)),
208210
);
209211
return transactionBuilder.serialize();
210212
}
@@ -223,7 +225,7 @@ export class SecretLockTransaction extends Transaction {
223225
new BlockDurationDto(this.duration.toDTO()),
224226
this.hashType.valueOf(),
225227
new Hash256Dto(this.getSecretByte()),
226-
new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())),
228+
new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)),
227229
);
228230
return transactionBuilder.serialize();
229231
}

src/model/transaction/SecretProofTransaction.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { Convert, Convert as convert, RawAddress } from '../../core/format';
18+
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
1819
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
1920
import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder';
2021
import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto';
@@ -26,6 +27,7 @@ import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedA
2627
import { Address } from '../account/Address';
2728
import { PublicAccount } from '../account/PublicAccount';
2829
import { NetworkType } from '../blockchain/NetworkType';
30+
import { NamespaceId } from '../namespace/NamespaceId';
2931
import { UInt64 } from '../UInt64';
3032
import { Deadline } from './Deadline';
3133
import { HashType, HashTypeLengthValidator } from './HashType';
@@ -53,7 +55,7 @@ export class SecretProofTransaction extends Transaction {
5355
public static create(deadline: Deadline,
5456
hashType: HashType,
5557
secret: string,
56-
recipientAddress: Address,
58+
recipientAddress: Address | NamespaceId,
5759
proof: string,
5860
networkType: NetworkType,
5961
maxFee: UInt64 = new UInt64([0, 0])): SecretProofTransaction {
@@ -88,7 +90,7 @@ export class SecretProofTransaction extends Transaction {
8890
maxFee: UInt64,
8991
public readonly hashType: HashType,
9092
public readonly secret: string,
91-
public readonly recipientAddress: Address,
93+
public readonly recipientAddress: Address | NamespaceId,
9294
public readonly proof: string,
9395
signature?: string,
9496
signer?: PublicAccount,
@@ -116,7 +118,7 @@ export class SecretProofTransaction extends Transaction {
116118
(builder as SecretProofTransactionBuilder).getDeadline().timestamp),
117119
builder.getHashAlgorithm().valueOf(),
118120
Convert.uint8ToHex(builder.getSecret().hash256),
119-
Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)),
121+
UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getRecipientAddress().unresolvedAddress)),
120122
Convert.uint8ToHex(builder.getProof()),
121123
networkType,
122124
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretProofTransactionBuilder).fee.amount),
@@ -181,7 +183,7 @@ export class SecretProofTransaction extends Transaction {
181183
new TimestampDto(this.deadline.toDTO()),
182184
this.hashType.valueOf(),
183185
new Hash256Dto(this.getSecretByte()),
184-
new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())),
186+
new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)),
185187
this.getProofByte(),
186188
);
187189
return transactionBuilder.serialize();
@@ -198,7 +200,7 @@ export class SecretProofTransaction extends Transaction {
198200
TransactionType.SECRET_PROOF.valueOf(),
199201
this.hashType.valueOf(),
200202
new Hash256Dto(this.getSecretByte()),
201-
new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientAddress.plain())),
203+
new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress)),
202204
this.getProofByte(),
203205
);
204206
return transactionBuilder.serialize();

src/service/MetadataTransactionService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class MetadataTransactionService {
5555
* @param senderPublicAccount - sender (signer) public account
5656
* @param targetId - Target Id (MosaicId | NamespaceId)
5757
* @param maxFee - Max fee
58+
* @return {AccountMetadataTransaction | MosaicMetadataTransaction | NamespaceMetadataTransaction}
5859
*/
5960
public createMetadataTransaction(deadline: Deadline,
6061
networkType: NetworkType,
@@ -64,7 +65,8 @@ export class MetadataTransactionService {
6465
value: string,
6566
senderPublicAccount: PublicAccount,
6667
targetId?: MosaicId | NamespaceId,
67-
maxFee: UInt64 = new UInt64([0, 0])): Observable<Transaction> {
68+
maxFee: UInt64 = new UInt64([0, 0])):
69+
Observable<AccountMetadataTransaction | MosaicMetadataTransaction | NamespaceMetadataTransaction> {
6870
switch (metadataType) {
6971
case MetadataType.Account:
7072
return this.createAccountMetadataTransaction(

0 commit comments

Comments
 (0)