Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9863862
JAV-52 [github #276] Fixed mosaicAmountView observable issue
rg911 Oct 4, 2019
b8bbd1b
JAV-54 [Github #277] Improved AccountRestriction payload
rg911 Oct 4, 2019
78dd1eb
JAV-57 [Github #285] Fixed error handling issue
rg911 Oct 5, 2019
b7d116a
JAV-27 [Github #246] Fixed Alias issue
rg911 Oct 5, 2019
fb09d73
Added @interal for abstract mathod
rg911 Oct 5, 2019
7e6a770
JAV-58 [Github #286] Fixed MosaicId significant byte not detected
rg911 Oct 6, 2019
cb426f3
Implement KeyGenerator
contractormario Oct 7, 2019
c061e4b
Merge branch 'master' into task/g278_key_generator
contractormario Oct 7, 2019
e39cf99
Fix copyright, jsdoc and return value type. Remove regex
contractormario Oct 7, 2019
275a7ab
JAV-59 [Github #287] Fixed network http only allow MIJIN_TEST issue
rg911 Oct 7, 2019
b61506a
Changed metadataTransactionService key from string to UInt64
rg911 Oct 7, 2019
11934dc
Rename, relax validation, convert to arraybuf instead of hex
contractormario Oct 7, 2019
7615a42
Merge pull request #288 from contractormario/task/g278_key_generator
rg911 Oct 7, 2019
cb000ff
JAV-52 [github #276] Fixed mosaicAmountView observable issue
rg911 Oct 4, 2019
7271217
JAV-54 [Github #277] Improved AccountRestriction payload
rg911 Oct 4, 2019
df11c9f
JAV-57 [Github #285] Fixed error handling issue
rg911 Oct 5, 2019
266f064
JAV-27 [Github #246] Fixed Alias issue
rg911 Oct 5, 2019
7f3bbd0
Added @interal for abstract mathod
rg911 Oct 5, 2019
7acd163
JAV-58 [Github #286] Fixed MosaicId significant byte not detected
rg911 Oct 6, 2019
709680c
JAV-59 [Github #287] Fixed network http only allow MIJIN_TEST issue
rg911 Oct 7, 2019
e5e216f
Changed metadataTransactionService key from string to UInt64
rg911 Oct 7, 2019
62a384b
Merge branch 'small_fixes_prior_rc' of github.com:rg911/nem2-sdk-type…
rg911 Oct 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e/infrastructure/RestrictionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {deepEqual} from 'assert';
import {assert} from 'chai';
import {assert, expect} from 'chai';
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure';
import { RestrictionHttp } from '../../src/infrastructure/RestrictionHttp';
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('RestrictionHttp', () => {
it('should call getAccountRestrictions successfully', (done) => {
setTimeout(() => {
restrictionHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
deepEqual(accountRestrictions.accountRestrictions.address, accountAddress);
expect(accountRestrictions.length).to.be.greaterThan(0);
done();
});
}, 1000);
Expand All @@ -320,7 +320,7 @@ describe('RestrictionHttp', () => {
it('should call getAccountRestrictionsFromAccounts successfully', (done) => {
setTimeout(() => {
restrictionHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress);
deepEqual(accountRestrictions[0]!.address, accountAddress);
done();
});
}, 1000);
Expand Down
8 changes: 4 additions & 4 deletions e2e/service/MetadataTransactionService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('MetadataTransactionService', () => {
NetworkType.MIJIN_TEST,
MetadataType.Account,
targetAccount.publicAccount,
key.toHex(),
key,
newValue,
targetAccount.publicAccount,
).subscribe((transaction: AccountMetadataTransaction) => {
Expand All @@ -225,7 +225,7 @@ describe('MetadataTransactionService', () => {
NetworkType.MIJIN_TEST,
MetadataType.Mosaic,
targetAccount.publicAccount,
key.toHex(),
key,
newValue + 'delta',
targetAccount.publicAccount,
mosaicId,
Expand All @@ -247,7 +247,7 @@ describe('MetadataTransactionService', () => {
NetworkType.MIJIN_TEST,
MetadataType.Namespace,
targetAccount.publicAccount,
key.toHex(),
key,
newValue + 'delta',
targetAccount.publicAccount,
namespaceId,
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('MetadataTransactionService', () => {
NetworkType.MIJIN_TEST,
MetadataType.Mosaic,
targetAccount.publicAccount,
key.toHex(),
key,
newValue + 'delta',
targetAccount.publicAccount,
mosaicId,
Expand Down
31 changes: 24 additions & 7 deletions e2e/service/MosaicService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { map, mergeMap, toArray } from 'rxjs/operators';
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { AccountHttp } from '../../src/infrastructure/AccountHttp';
import { MosaicHttp } from '../../src/infrastructure/MosaicHttp';
import { Address } from '../../src/model/account/Address';
Expand All @@ -22,15 +37,17 @@ describe('MosaicService', () => {
done();
});
});
it('should return the mosaic list skipping the expired mosaics', () => {
it('should return the mosaic list skipping the expired mosaics', (done) => {
const mosaicService = new MosaicService(accountHttp, mosaicHttp);

const address = accountAddress;

return mosaicService.mosaicsAmountViewFromAddress(address).pipe(
mergeMap((_) => _),
map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName())),
toArray(),
).toPromise();
return mosaicService.mosaicsAmountViewFromAddress(address).subscribe((amountViews) => {
const views = amountViews.map((v) => {
return {mosaicId: v.fullName(), amount: v.relativeAmount()};
});
console.log(views);
done();
});
});
});
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/chai": "^4.0.4",
"@types/crypto-js": "^3.1.43",
"@types/lodash": "^4.14.85",
"@types/long": "^4.0.0",
"@types/mocha": "^2.2.44",
"@types/request": "^2.47.0",
"@types/request-promise-native": "^1.0.14",
Expand All @@ -55,7 +56,6 @@
"typescript-require": "^0.2.9-1"
},
"dependencies": {
"@types/long": "^4.0.0",
"bluebird": "^3.5.5",
"crypto-js": "^3.1.9-1",
"js-joda": "^1.6.2",
Expand Down
34 changes: 34 additions & 0 deletions src/core/format/KeyGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { UInt64 } from '../../model/UInt64';
import { sha3_256 } from 'js-sha3';

export class KeyGenerator {
/**
* Generate UInt64 from a string
* @param {string} input Input string
* @returns {UInt64} Deterministic uint64 value for the given string
*/
public static generateUInt64Key(input: string): UInt64 {
if (input.length === 0) {
throw Error(`Input must not be empty`);
}
const buf = sha3_256.arrayBuffer(input);
const result = new Uint32Array(buf);
return new UInt64([result[0], (result[1] | 0x80000000) >>> 0]);
}
}
1 change: 1 addition & 0 deletions src/core/format/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export * from './RawAddress';
export * from './RawArray';
export * from './Convert';
export * from './IdGenerator';
export * from './KeyGenerator';
export * from './RawUInt64';
18 changes: 9 additions & 9 deletions src/infrastructure/AccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class AccountHttp extends Http implements AccountRepository {

});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -166,7 +166,7 @@ export class AccountHttp extends Http implements AccountRepository {
);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}
/**
Expand All @@ -190,7 +190,7 @@ export class AccountHttp extends Http implements AccountRepository {
.map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)),
);
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
)));
}

Expand Down Expand Up @@ -223,7 +223,7 @@ export class AccountHttp extends Http implements AccountRepository {
});
return new MultisigAccountGraphInfo(multisigAccounts);
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
)));
}

Expand All @@ -245,7 +245,7 @@ export class AccountHttp extends Http implements AccountRepository {
return CreateTransactionFromDTO(transactionDTO);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -268,7 +268,7 @@ export class AccountHttp extends Http implements AccountRepository {
return CreateTransactionFromDTO(transactionDTO);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -291,7 +291,7 @@ export class AccountHttp extends Http implements AccountRepository {
return CreateTransactionFromDTO(transactionDTO);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -315,7 +315,7 @@ export class AccountHttp extends Http implements AccountRepository {
return CreateTransactionFromDTO(transactionDTO);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -338,7 +338,7 @@ export class AccountHttp extends Http implements AccountRepository {
return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction;
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}
}
5 changes: 3 additions & 2 deletions src/infrastructure/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export abstract class Http {
}

errorHandling(error: any): Error {
if (error.response && error.response.statusCode && error.response.body) {
if (error.response && error.response.statusCode && error.body) {
const formattedError = {
statusCode: error.response.statusCode,
errorDetails: error.response.body,
errorDetails: error.response,
body: error.body,
};
return new Error(JSON.stringify(formattedError));
}
Expand Down
18 changes: 9 additions & 9 deletions src/infrastructure/MetadataHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -91,7 +91,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -109,7 +109,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
const metadataDTO = response.body;
return this.buildMetadata(metadataDTO);
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -131,7 +131,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -150,7 +150,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -168,7 +168,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
const metadataDTO = response.body;
return this.buildMetadata(metadataDTO);
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -190,7 +190,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -209,7 +209,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
return this.buildMetadata(metadataEntry);
});
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand All @@ -227,7 +227,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
const metadataDTO = response.body;
return this.buildMetadata(metadataDTO);
}),
catchError((error) => throwError(error)),
catchError((error) => throwError(this.errorHandling(error))),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/infrastructure/NamespaceHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ export class NamespaceHttp extends Http implements NamespaceRepository {
*/
private extractAlias(namespace: any): Alias {
if (namespace.alias && namespace.alias.type === AliasType.Mosaic) {
return new MosaicAlias(namespace.alias.type, namespace.alias.mosaicId);
return new MosaicAlias(namespace.alias.mosaicId);
} else if (namespace.alias && namespace.alias.type === AliasType.Address) {
return new AddressAlias(namespace.alias.type, namespace.alias.address);
return new AddressAlias(namespace.alias.address);
}

return new EmptyAlias();
Expand Down
Loading