Skip to content

Commit a570696

Browse files
authored
Merge branch 'master' into task/g295_namespace_id_in_metadata_mosaic_restriction_transaction
2 parents 9000c02 + 8348b1b commit a570696

File tree

15 files changed

+280
-20
lines changed

15 files changed

+280
-20
lines changed

src/infrastructure/receipt/CreateReceiptFromDTO.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,21 @@ const createResolutionStatement = (statementDTO, resolutionType): ResolutionStat
9393
switch (resolutionType) {
9494
case ResolutionType.Address:
9595
return new ResolutionStatement(
96+
ResolutionType.Address,
9697
UInt64.fromNumericString(statementDTO.height),
9798
Address.createFromEncoded(statementDTO.unresolved),
9899
statementDTO.resolutionEntries.map((entry) => {
99-
return new ResolutionEntry(new AddressAlias(Address.createFromEncoded(entry.resolved)),
100+
return new ResolutionEntry(Address.createFromEncoded(entry.resolved),
100101
new ReceiptSource(entry.source.primaryId, entry.source.secondaryId));
101102
}),
102103
);
103104
case ResolutionType.Mosaic:
104105
return new ResolutionStatement(
106+
ResolutionType.Mosaic,
105107
UInt64.fromNumericString(statementDTO.height),
106108
new MosaicId(statementDTO.unresolved),
107109
statementDTO.resolutionEntries.map((entry) => {
108-
return new ResolutionEntry(new MosaicAlias(new MosaicId(entry.resolved)),
110+
return new ResolutionEntry(new MosaicId(entry.resolved),
109111
new ReceiptSource(entry.source.primaryId, entry.source.secondaryId));
110112
}),
111113
);
@@ -200,6 +202,7 @@ const extractArtifactId = (receiptType: ReceiptType, id: string): MosaicId | Nam
200202
case ReceiptType.Mosaic_Expired:
201203
return new MosaicId(id);
202204
case ReceiptType.Namespace_Expired:
205+
case ReceiptType.Namespace_Deleted:
203206
return NamespaceId.createFromEncoded(id);
204207
default:
205208
throw new Error('Receipt type is not supported.');

src/model/namespace/AddressAlias.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { RawAddress } from '../../core/format/RawAddress';
1617
import {Address} from '../account/Address';
1718
import {Alias} from './Alias';
1819
import { AliasType } from './AliasType';
@@ -46,4 +47,12 @@ export class AddressAlias extends Alias {
4647
}
4748
return false;
4849
}
50+
51+
/**
52+
* Generate alias buffer
53+
* @return {Uint8Array}
54+
*/
55+
public serialize(): Uint8Array {
56+
return RawAddress.stringToAddress(this.address.plain());
57+
}
4958
}

src/model/namespace/Alias.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export abstract class Alias {
5353
* @internal
5454
* Compares alias for equality.
5555
* @param alias - MosaicAlias
56+
* @return {boolean}
5657
*/
5758
protected abstract equals(alias: any): boolean;
5859
}

src/model/namespace/EmptyAlias.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ export class EmptyAlias extends Alias {
4545
public equals(alias: any): boolean {
4646
return alias instanceof EmptyAlias || alias.type === 0;
4747
}
48+
49+
/**
50+
* Generate alias buffer
51+
* @return {Uint8Array}
52+
*/
53+
public serialize(): Uint8Array {
54+
return new Uint8Array(0);
55+
}
4856
}

src/model/receipt/ArtifactExpiryReceipt.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Convert } from '../../core/format/Convert';
18+
import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils';
1719
import { MosaicId } from '../mosaic/MosaicId';
1820
import { NamespaceId } from '../namespace/NamespaceId';
21+
import { UInt64 } from '../UInt64';
1922
import { Receipt } from './Receipt';
2023
import { ReceiptType } from './ReceiptType';
2124
import { ReceiptVersion } from './ReceiptVersion';
@@ -38,4 +41,17 @@ export class ArtifactExpiryReceipt extends Receipt {
3841
size?: number) {
3942
super(version, type, size);
4043
}
44+
45+
/**
46+
* @internal
47+
* Generate buffer
48+
* @return {Uint8Array}
49+
*/
50+
public serialize(): Uint8Array {
51+
const buffer = new Uint8Array(12);
52+
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.ARTIFACT_EXPIRY, 2));
53+
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
54+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.artifactId.toHex()).toDTO()), 4);
55+
return buffer;
56+
}
4157
}

src/model/receipt/BalanceChangeReceipt.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Convert } from '../../core/format/Convert';
18+
import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils';
1719
import { PublicAccount } from '../account/PublicAccount';
1820
import { MosaicId } from '../mosaic/MosaicId';
1921
import { UInt64 } from '../UInt64';
@@ -53,4 +55,19 @@ export class BalanceChangeReceipt extends Receipt {
5355
size?: number) {
5456
super(version, type, size);
5557
}
58+
59+
/**
60+
* @internal
61+
* Generate buffer
62+
* @return {Uint8Array}
63+
*/
64+
public serialize(): Uint8Array {
65+
const buffer = new Uint8Array(52);
66+
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.BALANCE_CHANGE, 2));
67+
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
68+
buffer.set(Convert.hexToUint8(this.targetPublicAccount.publicKey), 4);
69+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 36);
70+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 44);
71+
return buffer;
72+
}
5673
}

src/model/receipt/BalanceTransferReceipt.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Convert } from '../../core/format/Convert';
18+
import { RawAddress } from '../../core/format/RawAddress';
19+
import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils';
1720
import { Address } from '../account/Address';
1821
import { PublicAccount } from '../account/PublicAccount';
1922
import { MosaicId } from '../mosaic/MosaicId';
@@ -60,4 +63,39 @@ export class BalanceTransferReceipt extends Receipt {
6063
size?: number) {
6164
super(version, type, size);
6265
}
66+
67+
/**
68+
* @internal
69+
* Generate buffer
70+
* @return {Uint8Array}
71+
*/
72+
public serialize(): Uint8Array {
73+
const recipient = this.getRecipientBytes();
74+
const buffer = new Uint8Array(52 + recipient.length);
75+
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.BALANCE_TRANSFER, 2));
76+
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
77+
buffer.set(Convert.hexToUint8(this.sender.publicKey), 4);
78+
buffer.set(recipient, 36);
79+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 36 + recipient.length);
80+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 44 + recipient.length);
81+
return buffer;
82+
}
83+
84+
/**
85+
* @internal
86+
* Generate buffer for recipientAddress
87+
* @return {Uint8Array}
88+
*/
89+
private getRecipientBytes(): Uint8Array {
90+
const recipientString =
91+
this.recipientAddress instanceof NamespaceId ? (this.recipientAddress as NamespaceId).toHex()
92+
: (this.recipientAddress as Address).plain();
93+
if (/^[0-9a-fA-F]{16}$/.test(recipientString)) {
94+
// received hexadecimal notation of namespaceId (alias)
95+
return RawAddress.aliasToRecipient(Convert.hexToUint8(recipientString));
96+
} else {
97+
// received recipient address
98+
return RawAddress.stringToAddress(recipientString);
99+
}
100+
}
63101
}

src/model/receipt/InflationReceipt.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Convert } from '../../core/format/Convert';
18+
import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils';
1719
import { MosaicId } from '../mosaic/MosaicId';
1820
import { UInt64 } from '../UInt64';
1921
import { Receipt } from './Receipt';
@@ -47,4 +49,18 @@ export class InflationReceipt extends Receipt {
4749
size?: number) {
4850
super(version, type, size);
4951
}
52+
53+
/**
54+
* @internal
55+
* Generate buffer
56+
* @return {Uint8Array}
57+
*/
58+
public serialize(): Uint8Array {
59+
const buffer = new Uint8Array(20);
60+
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.INFLATION_RECEIPT, 2));
61+
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
62+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 4);
63+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 12);
64+
return buffer;
65+
}
5066
}

src/model/receipt/Receipt.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ export abstract class Receipt {
4242
*/
4343
public readonly size?: number) {
4444
}
45+
46+
/**
47+
* @internal
48+
* Generate buffer
49+
* @return {Uint8Array}
50+
*/
51+
abstract serialize(): Uint8Array;
4552
}

src/model/receipt/ReceiptSource.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Convert } from '../../core/format/Convert';
2+
import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils';
3+
14
/*
25
* Copyright 2019 NEM
36
*
@@ -34,4 +37,14 @@ export class ReceiptSource {
3437
*/
3538
public readonly secondaryId: number) {
3639
}
40+
41+
/**
42+
* @internal
43+
* Generate buffer
44+
* @return {Uint8Array}
45+
*/
46+
public serialize(): Uint8Array {
47+
return GeneratorUtils.concatTypedArrays(
48+
GeneratorUtils.uintToBuffer(this.primaryId, 4), GeneratorUtils.uintToBuffer(this.secondaryId, 4));
49+
}
3750
}

0 commit comments

Comments
 (0)