Skip to content

Commit 3526679

Browse files
authored
Merge pull request #423 from NEMStudios/task/g402_resolution_statement
Applied catbuffer on resolutionStatement
2 parents c07875d + 78beb86 commit 3526679

File tree

6 files changed

+35
-39
lines changed

6 files changed

+35
-39
lines changed

e2e/service/MosaicService.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ describe('MosaicService', () => {
4444
const views = amountViews.map((v) => {
4545
return {mosaicId: v.fullName(), amount: v.relativeAmount()};
4646
});
47-
console.log(views);
4847
done();
4948
});
5049
});

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@
5858
},
5959
"dependencies": {
6060
"bluebird": "^3.5.5",
61-
"catbuffer": "0.0.7",
61+
"catbuffer": "0.0.11",
6262
"crypto-js": "^3.1.9-1",
6363
"futoin-hkdf": "^1.3.1",
6464
"js-joda": "^1.6.2",
6565
"js-sha256": "^0.9.0",
6666
"js-sha3": "^0.8.0",
6767
"long": "^4.0.0",
6868
"merkletreejs": "^0.1.7",
69-
"nem2-sdk-openapi-typescript-node-client": "0.7.20-beta.6",
69+
"nem2-sdk-openapi-typescript-node-client": "0.7.20-alpha.7",
7070
"request": "^2.88.0",
7171
"request-promise-native": "^1.0.5",
7272
"ripemd160": "^2.0.2",

src/model/receipt/ResolutionStatement.ts

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

17-
import { GeneratorUtils } from 'catbuffer';
17+
import { AddressDto,
18+
AddressResolutionEntryBuilder,
19+
AddressResolutionStatementBuilder,
20+
MosaicIdDto, MosaicResolutionEntryBuilder,
21+
MosaicResolutionStatementBuilder,
22+
ReceiptSourceBuilder,
23+
UnresolvedAddressDto,
24+
UnresolvedMosaicIdDto } from 'catbuffer';
1825
import { sha3_256 } from 'js-sha3';
26+
import { RawAddress } from '../../core/format/RawAddress';
1927
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
2028
import { Address } from '../account/Address';
2129
import { NetworkType } from '../blockchain/NetworkType';
@@ -68,19 +76,23 @@ export class ResolutionStatement {
6876
public generateHash(networkType: NetworkType): string {
6977
const type = this.resolutionType === ResolutionType.Address ? ReceiptType.Address_Alias_Resolution
7078
: ReceiptType.Mosaic_Alias_Resolution;
71-
const unresolvedBytes = this.getUnresolvedBytes(this.resolutionType, networkType);
79+
const builder = this.resolutionType === ResolutionType.Address ? new AddressResolutionStatementBuilder(
80+
ReceiptVersion.RESOLUTION_STATEMENT, type.valueOf(),
81+
new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.unresolved as Address | NamespaceId, networkType)),
82+
this.resolutionEntries.map((entry) => new AddressResolutionEntryBuilder(
83+
new ReceiptSourceBuilder(entry.source.primaryId, entry.source.secondaryId),
84+
new AddressDto(RawAddress.stringToAddress((entry.resolved as Address).plain())),
85+
)),
86+
) : new MosaicResolutionStatementBuilder(ReceiptVersion.RESOLUTION_STATEMENT,
87+
type.valueOf(),
88+
new UnresolvedMosaicIdDto(UInt64.fromHex((this.unresolved as MosaicId | NamespaceId).toHex()).toDTO()),
89+
this.resolutionEntries.map((entry) => new MosaicResolutionEntryBuilder(
90+
new ReceiptSourceBuilder(entry.source.primaryId, entry.source.secondaryId),
91+
new MosaicIdDto((entry.resolved as MosaicId).toDTO()),
92+
)),
93+
);
7294
const hasher = sha3_256.create();
73-
hasher.update(GeneratorUtils.uintToBuffer(ReceiptVersion.RESOLUTION_STATEMENT, 2));
74-
hasher.update(GeneratorUtils.uintToBuffer(type, 2));
75-
hasher.update(unresolvedBytes);
76-
77-
let entryBytes = Uint8Array.from([]);
78-
this.resolutionEntries.forEach((entry) => {
79-
const bytes = entry.serialize();
80-
entryBytes = GeneratorUtils.concatTypedArrays(entryBytes, bytes);
81-
});
82-
83-
hasher.update(entryBytes);
95+
hasher.update(builder.serialize());
8496
return hasher.hex().toUpperCase();
8597
}
8698

@@ -195,18 +207,4 @@ export class ResolutionStatement {
195207
return Math.max(...this.resolutionEntries
196208
.map((entry) => primaryId >= entry.source.primaryId ? entry.source.primaryId : 0));
197209
}
198-
199-
/**
200-
* @internal
201-
* Generate buffer for unresulved
202-
* @param {resolutionType} The resolution Type
203-
* @param {networkType} the network type serialized in the output.
204-
* @return {Uint8Array}
205-
*/
206-
private getUnresolvedBytes(resolutionType: ResolutionType, networkType: NetworkType): Uint8Array {
207-
if (resolutionType === ResolutionType.Address) {
208-
return UnresolvedMapping.toUnresolvedAddressBytes(this.unresolved as Address | NamespaceId, networkType);
209-
}
210-
return GeneratorUtils.uint64ToBuffer(UInt64.fromHex((this.unresolved as MosaicId | NamespaceId).toHex()).toDTO());
211-
}
212210
}

test/model/receipt/Receipt.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@ describe('Receipt', () => {
347347
const statement = CreateStatementFromDTO(statementDTO, netWorkType);
348348
const receipt = statement.mosaicResolutionStatements[0];
349349
const hash = receipt.generateHash(NetworkType.MAIN_NET);
350-
expect(hash).to.be.equal('99381CE398D3AAE110FC97E984D7D35A710A5C525A4F959EC8916B382DE78A63');
350+
expect(hash).to.be.equal('DE29FB6356530E5D1FBEE0A84202520C155D882C46EA74456752D6C75F0707B3');
351351
});
352352

353353
it('should generate hash for AddressResolutionStatement', () => {
354354
const statement = CreateStatementFromDTO(statementDTO, netWorkType);
355355
const receipt = statement.addressResolutionStatements[0];
356356
const hash = receipt.generateHash(NetworkType.MAIN_NET);
357-
expect(hash).to.be.equal('952225717E26295B97F9A35E719CA1319114CCF23C927BCBD14E7A7AA4BAC617');
357+
expect(hash).to.be.equal('EFE3D51BF14E861E6E219D1ADB5715D132D6AB7481B29726104933E517F7FBCC');
358358
});
359359

360360
it('should generate hash for TransactionStatement', () => {

test/model/transaction/Deadline.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('Deadline', () => {
5353

5454
it('make sure epochAdjustment is correct', () => {
5555
const epochAdjustment = new Date(Deadline.timestampNemesisBlock * 1000);
56-
console.log(epochAdjustment.toUTCString());
5756

5857
expect(epochAdjustment.getUTCFullYear()).to.be.equal(2019);
5958
expect(epochAdjustment.getUTCMonth() + 1).to.be.equal(11);

0 commit comments

Comments
 (0)