diff --git a/packages/api-sync/source/restore.ts b/packages/api-sync/source/restore.ts index 1419c6095..889e20186 100644 --- a/packages/api-sync/source/restore.ts +++ b/packages/api-sync/source/restore.ts @@ -244,25 +244,22 @@ export class Restore { context.addressToPublicKey[address] = senderPublicKey; } - // TODO adjust according to api refactor PR transactions.push({ amount: data.value.toFixed(), - asset: {}, blockHeight: block.header.height.toFixed(), blockId: block.header.id, - fee: data.gasPrice.toFixed(), + data: data.data, + gasLimit: data.gasLimit, + gasPrice: data.gasPrice, id: data.id as unknown as string, nonce: data.nonce.toFixed(), - recipientId: data.recipientAddress, + recipientAddress: data.recipientAddress, + senderAddress: data.senderAddress, senderPublicKey: data.senderPublicKey, sequence: data.sequence as unknown as number, signature: data.signature, - signatures: undefined, + signatures: undefined, //data.signatures, timestamp: block.header.timestamp.toFixed(), - type: 0, - typeGroup: 0, - vendorField: undefined, - version: 0, }); } @@ -439,28 +436,16 @@ export class Restore { for (const handler of transactionHandlers) { const constructor = handler.getConstructor(); - const type: number | undefined = constructor.type; const key: string | undefined = constructor.key; - Utils.assert.defined(type); Utils.assert.defined(key); - types.push({ key, schema: constructor.getSchema().properties, type, typeGroup: 0, version: 0 }); + types.push({ key, schema: constructor.getSchema().properties }); } - types.sort((a, b) => { - if (a.type !== b.type) { - return a.type - b.type; - } - - if (a.typeGroup !== b.typeGroup) { - return a.typeGroup - b.typeGroup; - } - - return a.version - b.version; - }); + types.sort((a, b) => a.key.localeCompare(b.key, undefined, { sensitivity: "base" })); - await context.transactionTypeRepository.upsert(types, ["type", "typeGroup", "version"]); + await context.transactionTypeRepository.upsert(types, ["key"]); } async #ingestConfiguration(context: RestoreContext): Promise { diff --git a/packages/api-sync/source/service.ts b/packages/api-sync/source/service.ts index 077540337..4cf45f674 100644 --- a/packages/api-sync/source/service.ts +++ b/packages/api-sync/source/service.ts @@ -55,18 +55,12 @@ export class Sync implements Contracts.ApiSync.Service { @inject(ApiDatabaseIdentifiers.TransactionRepositoryFactory) private readonly transactionRepositoryFactory!: ApiDatabaseContracts.TransactionRepositoryFactory; - @inject(ApiDatabaseIdentifiers.TransactionTypeRepositoryFactory) - private readonly transactionTypeRepositoryFactory!: ApiDatabaseContracts.TransactionTypeRepositoryFactory; - @inject(ApiDatabaseIdentifiers.ValidatorRoundRepositoryFactory) private readonly validatorRoundRepositoryFactory!: ApiDatabaseContracts.ValidatorRoundRepositoryFactory; @inject(ApiDatabaseIdentifiers.WalletRepositoryFactory) private readonly walletRepositoryFactory!: ApiDatabaseContracts.WalletRepositoryFactory; - @inject(Identifiers.State.Store) - private readonly stateStore!: Contracts.State.Store; - @inject(Identifiers.State.State) private readonly state!: Contracts.State.State; @@ -76,9 +70,6 @@ export class Sync implements Contracts.ApiSync.Service { @inject(Identifiers.Proposer.Selector) private readonly proposerSelector!: Contracts.Proposer.Selector; - @inject(Identifiers.Transaction.Handler.Registry) - private readonly transactionHandlerRegistry!: Contracts.Transactions.TransactionHandlerRegistry; - @inject(Identifiers.Services.Log.Service) private readonly logger!: Contracts.Kernel.Logger; @@ -96,6 +87,7 @@ export class Sync implements Contracts.ApiSync.Service { public async prepareBootstrap(): Promise { await this.migrations.run(); await this.#resetDatabaseIfNecessary(); + this.#queue = await this.createQueue(); } public async bootstrap(): Promise { @@ -103,15 +95,10 @@ export class Sync implements Contracts.ApiSync.Service { const [blocks] = await this.dataSource.query("select count(1) from blocks"); if (blocks.count === "0") { await this.#bootstrapRestore(); - } else { - await this.#bootstrapConfiguration(); - await this.#bootstrapState(); - await this.#bootstrapTransactionTypes(); } await this.listeners.bootstrap(); - this.#queue = await this.createQueue(); await this.#queue.start(); } @@ -328,54 +315,6 @@ export class Sync implements Contracts.ApiSync.Service { await this.app.resolve(Restore).restore(); } - async #bootstrapConfiguration(): Promise { - await this.configurationRepositoryFactory() - .createQueryBuilder() - .insert() - .values({ - activeMilestones: this.configuration.getMilestone(0) as Record, - cryptoConfiguration: (this.configuration.all() ?? {}) as Record, - id: 1, - version: this.app.version(), - }) - .orUpdate(["crypto_configuration", "version"], ["id"]) - .execute(); - } - - async #bootstrapState(): Promise { - const genesisCommit = this.stateStore.getGenesisCommit(); - await this.stateRepositoryFactory() - .createQueryBuilder() - .insert() - .orIgnore() - .values({ - height: "0", - id: 1, - supply: genesisCommit.block.data.totalAmount.toFixed(), - }) - .execute(); - } - - async #bootstrapTransactionTypes(): Promise { - const transactionHandlers = await this.transactionHandlerRegistry.getActivatedHandlers(); - - const types: Models.TransactionType[] = []; - - for (const handler of transactionHandlers) { - const constructor = handler.getConstructor(); - - const key: string | undefined = constructor.key; - - Utils.assert.defined(key); - - types.push({ key, schema: constructor.getSchema().properties }); - } - - types.sort((a, b) => a.key.localeCompare(b.key, undefined, { sensitivity: "base" })); - - await this.transactionTypeRepositoryFactory().upsert(types, ["key"]); - } - async #queueDeferredSync(deferredSync: DeferredSync): Promise { void this.#queue.push({ handle: async () => {