Skip to content

Commit

Permalink
cleanup merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Oct 30, 2024
1 parent 31a8ffa commit 606faff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 86 deletions.
33 changes: 9 additions & 24 deletions packages/api-sync/source/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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<number>(type);
Utils.assert.defined<string>(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<void> {
Expand Down
63 changes: 1 addition & 62 deletions packages/api-sync/source/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -96,22 +87,18 @@ export class Sync implements Contracts.ApiSync.Service {
public async prepareBootstrap(): Promise<void> {
await this.migrations.run();
await this.#resetDatabaseIfNecessary();
this.#queue = await this.createQueue();
}

public async bootstrap(): Promise<void> {
// if our database is empty, we sync all blocks from scratch
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();
}

Expand Down Expand Up @@ -328,54 +315,6 @@ export class Sync implements Contracts.ApiSync.Service {
await this.app.resolve(Restore).restore();
}

async #bootstrapConfiguration(): Promise<void> {
await this.configurationRepositoryFactory()
.createQueryBuilder()
.insert()
.values({
activeMilestones: this.configuration.getMilestone(0) as Record<string, any>,
cryptoConfiguration: (this.configuration.all() ?? {}) as Record<string, any>,
id: 1,
version: this.app.version(),
})
.orUpdate(["crypto_configuration", "version"], ["id"])
.execute();
}

async #bootstrapState(): Promise<void> {
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<void> {
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<string>(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> {
void this.#queue.push({
handle: async () => {
Expand Down

0 comments on commit 606faff

Please sign in to comment.