Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions e2e/infrastructure/AccountHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { toArray, take } from 'rxjs/operators';
import { deepEqual } from 'assert';
import { Order } from '../../src/infrastructure/infrastructure';
import { AccountOrderBy } from '../../src/infrastructure/searchCriteria/AccountOrderBy';
import { Duration } from 'js-joda';

describe('AccountHttp', () => {
const helper = new IntegrationTestHelper();
Expand All @@ -57,7 +56,7 @@ describe('AccountHttp', () => {
let generationHash: string;
let networkType: NetworkType;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/BlockHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { take } from 'rxjs/operators';
import { TransactionStatement } from '../../src/model/model';
import { ReceiptPaginationStreamer } from '../../src/infrastructure/paginationStreamer/ReceiptPaginationStreamer';
import { Order } from '../../src/infrastructure/infrastructure';
import { Duration } from 'js-joda';

describe('BlockHttp', () => {
const helper = new IntegrationTestHelper();
Expand All @@ -44,7 +43,7 @@ describe('BlockHttp', () => {
let networkType: NetworkType;
let transactionHash;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
5 changes: 2 additions & 3 deletions e2e/infrastructure/HashLockHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import { deepEqual } from 'assert';
import { Order, HashLockPaginationStreamer } from '../../src/infrastructure/infrastructure';
import { Mosaic } from '../../src/model/mosaic/Mosaic';
import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction';
import { ChronoUnit } from 'js-joda';
import { ChronoUnit } from '@js-joda/core';
import { SignedTransaction } from '../../src/model/transaction/SignedTransaction';
import { UnresolvedMosaicId } from '../../src/model/mosaic/UnresolvedMosaicId';
import { HashLockRepository } from '../../src/infrastructure/HashLockRepository';
import { Duration } from 'js-joda';

describe('HashLockHttp', () => {
const helper = new IntegrationTestHelper();
Expand All @@ -49,7 +48,7 @@ describe('HashLockHttp', () => {
let generationHash: string;
let networkType: NetworkType;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/IntegrationTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { SignedTransaction } from '../../src/model/transaction/SignedTransaction
import { Transaction } from '../../src/model/transaction/Transaction';
import { UInt64 } from '../../src/model/UInt64';
import { TransactionService } from '../../src/service/TransactionService';
import { Duration } from 'js-joda';

export class IntegrationTestHelper {
public apiUrl: string;
Expand All @@ -53,7 +52,7 @@ export class IntegrationTestHelper {
public service = new BootstrapService();
public config: StartParams;
public startEachTime = true;
public epochAdjustment: Duration;
public epochAdjustment: number;

private async startBootstrapServer(): Promise<{ accounts: string[]; apiUrl: string }> {
this.config = {
Expand Down
4 changes: 2 additions & 2 deletions e2e/infrastructure/Listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { assert, expect } from 'chai';
import { ChronoUnit, Duration } from 'js-joda';
import { ChronoUnit } from '@js-joda/core';
import { filter, mergeMap } from 'rxjs/operators';
import { TransactionRepository } from '../../src/infrastructure/TransactionRepository';
import { Account } from '../../src/model/account/Account';
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('Listener', () => {
let networkType: NetworkType;
let transactionRepository: TransactionRepository;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/MetadataHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { MetadataType } from '../../src/model/model';
import { Order, MetadataPaginationStreamer } from '../../src/infrastructure/infrastructure';
import { deepEqual } from 'assert';
import { take, toArray } from 'rxjs/operators';
import { Duration } from 'js-joda';

describe('MetadataHttp', () => {
const helper = new IntegrationTestHelper();
Expand All @@ -48,7 +47,7 @@ describe('MetadataHttp', () => {
let networkType: NetworkType;
let metadataRepository: MetadataRepository;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/MosaicHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { MosaicPaginationStreamer } from '../../src/infrastructure/paginationStr
import { toArray, take } from 'rxjs/operators';
import { deepEqual } from 'assert';
import { TransactionGroup } from '../../src/infrastructure/TransactionGroup';
import { Duration } from 'js-joda';

describe('MosaicHttp', () => {
let mosaicId: MosaicId;
Expand All @@ -45,7 +44,7 @@ describe('MosaicHttp', () => {
const helper = new IntegrationTestHelper();
let networkType: NetworkType;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/MultisigAccounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Duration } from 'js-joda';
import { Account } from '../../src/model/account/Account';
import { NetworkType } from '../../src/model/network/NetworkType';
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
Expand All @@ -30,7 +29,7 @@ describe('MultisigAccounts', () => {
let generationHash: string;
let networkType: NetworkType;

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/NamespaceHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { IntegrationTestHelper } from './IntegrationTestHelper';
import { NamespacePaginationStreamer } from '../../src/infrastructure/paginationStreamer/NamespacePaginationStreamer';
import { take, toArray } from 'rxjs/operators';
import { Order } from '../../src/infrastructure/infrastructure';
import { Duration } from 'js-joda';

describe('NamespaceHttp', () => {
let defaultNamespaceId: NamespaceId;
Expand All @@ -38,7 +37,7 @@ describe('NamespaceHttp', () => {
let generationHash: string;
const helper = new IntegrationTestHelper();

const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/RestrictionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { UInt64 } from '../../src/model/UInt64';
import { IntegrationTestHelper } from './IntegrationTestHelper';
import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag';
import { MosaicAddressRestriction } from '../../src/model/restriction/MosaicAddressRestriction';
import { Duration } from 'js-joda';

describe('RestrictionHttp', () => {
const helper = new IntegrationTestHelper();
Expand All @@ -49,7 +48,7 @@ describe('RestrictionHttp', () => {
let mosaicId: MosaicId;
let referenceMosaicId: MosaicId;
let restrictionAccountRepository: RestrictionAccountRepository;
const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { expect } from 'chai';
import { ChronoUnit } from 'js-joda';
import { ChronoUnit } from '@js-joda/core';
import { sha3_256 } from 'js-sha3';
import { Crypto } from '../../src/core/crypto';
import { Convert, Convert as convert } from '../../src/core/format';
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/UnresolvedMapping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/
import { expect } from 'chai';
import { Duration } from 'js-joda';
import { Convert } from '../../src/core/format';
import { Account } from '../../src/model/account/Account';
import { PlainMessage } from '../../src/model/message/PlainMessage';
Expand Down Expand Up @@ -49,7 +48,7 @@ describe('Unresolved Mapping', () => {
let mosaicId: MosaicId;
let namespaceIdAddress: NamespaceId;
let namespaceIdMosaic: NamespaceId;
const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand Down
3 changes: 1 addition & 2 deletions e2e/service/MetadataTransactionService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { Duration } from 'js-joda';
import { Convert } from '../../src/core/format';
import { MetadataRepository } from '../../src/infrastructure/MetadataRepository';
import { Account } from '../../src/model/account/Account';
Expand All @@ -20,7 +19,7 @@ import { MetadataTransactionService } from '../../src/service/MetadataTransactio
import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper';

describe('MetadataTransactionService', () => {
const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;
const deadline = Deadline.create(epochAdjustment);
const key = UInt64.fromUint(Math.round(Math.random() * 10));
const newValue = 'new test value';
Expand Down
3 changes: 1 addition & 2 deletions e2e/service/MosaicRestrictionTransactionService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { Duration } from 'js-joda';
import { KeyGenerator } from '../../src/core/format/KeyGenerator';
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository';
Expand All @@ -25,7 +24,7 @@ import { MosaicRestrictionTransactionService } from '../../src/service/MosaicRes
import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper';

describe('MosaicRestrictionTransactionService', () => {
const epochAdjustment = Duration.ofSeconds(1573430400);
const epochAdjustment = 1573430400;
const deadline = Deadline.create(epochAdjustment);
const key = KeyGenerator.generateUInt64Key('TestKey');
let account: Account;
Expand Down
2 changes: 1 addition & 1 deletion e2e/service/TransactionService_AggregateBonded.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { expect } from 'chai';
import { ChronoUnit } from 'js-joda';
import { ChronoUnit } from '@js-joda/core';
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
import { Account } from '../../src/model/account/Account';
import { Address } from '../../src/model/account/Address';
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@
"tweetnacl": "^1.0.3",
"ws": "^7.3.1"
},
"peerDependencies": {
"utf8": "^2.1.2",
"rxjs": "^6.5.3"
},
"nyc": {
"exclude-after-remap": false,
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/DtoMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Duration } from 'js-joda';
import { Duration } from '@js-joda/core';
import { Address } from '../../model/account/Address';
import { MosaicId } from '../../model/mosaic/MosaicId';
import { AccountRestriction } from '../../model/restriction/AccountRestriction';
Expand Down
5 changes: 2 additions & 3 deletions src/infrastructure/RepositoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { TransactionRepository } from './TransactionRepository';
import { TransactionStatusRepository } from './TransactionStatusRepository';
import { HashLockRepository } from './HashLockRepository';
import { SecretLockRepository } from './SecretLockRepository';
import { Duration } from 'js-joda';

/**
* A repository factory allows clients to create repositories to access NEM Server without knowing
Expand Down Expand Up @@ -139,7 +138,7 @@ export interface RepositoryFactory {
createListener(): IListener;

/**
* @returns nemesis block epoch
* @returns nemesis block epoch adjustment in seconds
*/
getEpochAdjustment(): Observable<Duration>;
getEpochAdjustment(): Observable<number>;
}
9 changes: 4 additions & 5 deletions src/infrastructure/RepositoryFactoryHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { HashLockRepository } from './HashLockRepository';
import { SecretLockRepository } from './SecretLockRepository';
import { SecretLockHttp } from './SecretLockHttp';
import { HashLockHttp } from './HashLockHttp';
import { Duration } from 'js-joda';
import { DtoMapping } from '../core/utils/DtoMapping';
/**
* Receipt http repository.
Expand All @@ -66,7 +65,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
private readonly websocketUrl: string;
private readonly websocketInjected?: any;
private readonly fetchApi?: any;
private readonly epochAdjustment: Observable<Duration>;
private readonly epochAdjustment: Observable<number>;

/**
* Constructor
Expand All @@ -79,12 +78,12 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
this.fetchApi = configs?.fetchApi;
this.networkType = configs?.networkType ? observableOf(configs.networkType) : networkRepo.getNetworkType().pipe(shareReplay(1));
this.epochAdjustment = configs?.epochAdjustment
? observableOf(Duration.ofSeconds(configs.epochAdjustment))
? observableOf(configs.epochAdjustment)
: networkRepo
.getNetworkProperties()
.pipe(
map((property) => {
return DtoMapping.parseServerDuration(property.network.epochAdjustment ?? '-');
return DtoMapping.parseServerDuration(property.network.epochAdjustment ?? '-').seconds();
}),
)
.pipe(shareReplay(1));
Expand Down Expand Up @@ -174,7 +173,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
return new Listener(this.websocketUrl, this.createNamespaceRepository(), this.websocketInjected);
}

getEpochAdjustment(): Observable<Duration> {
getEpochAdjustment(): Observable<number> {
return this.epochAdjustment;
}
}
26 changes: 16 additions & 10 deletions src/model/transaction/Deadline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ChronoUnit, Duration, Instant, LocalDateTime, ZoneId } from 'js-joda';
import { ChronoUnit, Duration, Instant, LocalDateTime, ZoneId } from '@js-joda/core';
import { UInt64 } from '../UInt64';

/**
Expand All @@ -29,19 +29,19 @@ export class Deadline {

/**
* Create deadline model. Default to 2 chrono hours in advance.
* @param {Duration} epochAdjustment the network's epoch adjustment (seconds). Defined in the network/properties. e.g. Duration.ofSeconds(1573430400);
* @param {number} epochAdjustment the network's epoch adjustment (seconds). Defined in the network/properties. e.g. 1573430400;
* @param {number} deadline the deadline unit value.
* @param {ChronoUnit} chronoUnit the crhono unit. e.g ChronoUnit.HOURS
* @returns {Deadline}
*/
public static create(epochAdjustment: Duration, deadline = 2, chronoUnit: ChronoUnit = ChronoUnit.HOURS): Deadline {
public static create(epochAdjustment: number, deadline = 2, chronoUnit: ChronoUnit = ChronoUnit.HOURS): Deadline {
const now = Instant.now();
const deadlineDateTime = now.plus(deadline, chronoUnit);

if (deadline <= 0) {
throw new Error('deadline should be greater than 0');
}
return new Deadline(deadlineDateTime.minusMillis(epochAdjustment.toMillis()).toEpochMilli());
return new Deadline(deadlineDateTime.minusMillis(Duration.ofSeconds(epochAdjustment).toMillis()).toEpochMilli());
}

/**
Expand Down Expand Up @@ -87,20 +87,26 @@ export class Deadline {

/**
* Returns deadline as local date time.
* @param epochAdjustment the network's epoch adjustment. Defined in the network/properties.
* @param epochAdjustment the network's epoch adjustment (seconds). Defined in the network/properties.
* @returns {LocalDateTime}
*/
public toLocalDateTime(epochAdjustment: Duration): LocalDateTime {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.adjustedValue).plusMillis(epochAdjustment.toMillis()), ZoneId.SYSTEM);
public toLocalDateTime(epochAdjustment: number): LocalDateTime {
return LocalDateTime.ofInstant(
Instant.ofEpochMilli(this.adjustedValue).plusMillis(Duration.ofSeconds(epochAdjustment).toMillis()),
ZoneId.SYSTEM,
);
}

/**
* Returns deadline as local date time.
* @param epochAdjustment the network's epoch adjustment. Defined in the network/properties.
* @param epochAdjustment the network's epoch adjustment (seconds). Defined in the network/properties.
* @param zoneId the Zone Id.
* @returns {LocalDateTime}
*/
public toLocalDateTimeGivenTimeZone(epochAdjustment: Duration, zoneId: ZoneId): LocalDateTime {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.adjustedValue).plusMillis(epochAdjustment.toMillis()), zoneId);
public toLocalDateTimeGivenTimeZone(epochAdjustment: number, zoneId: ZoneId): LocalDateTime {
return LocalDateTime.ofInstant(
Instant.ofEpochMilli(this.adjustedValue).plusMillis(Duration.ofSeconds(epochAdjustment).toMillis()),
zoneId,
);
}
}
Loading