Skip to content

Commit

Permalink
Merge pull request #3358 from hashgraph/fix/3311
Browse files Browse the repository at this point in the history
Fix/3311
  • Loading branch information
Artem Buslaev authored Mar 28, 2024
2 parents 7217b03 + 2cc3a68 commit 7f6ea43
Show file tree
Hide file tree
Showing 57 changed files with 2,950 additions and 818 deletions.
Binary file not shown.
360 changes: 354 additions & 6 deletions common/src/database-modules/database-server.ts

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions common/src/entity/dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,90 @@ export class DryRun extends BaseEntity {
@Property({ nullable: true, type: 'unknown' })
verificationMethods?: any;

/**
* Vp message identifier
*/
@Property({ nullable: true })
vpMessageId?: string;

/**
* Secondary vp identifiers
*/
@Property({ nullable: true })
secondaryVpIds?: string[]

/**
* Start serial
*/
@Property({ nullable: true })
startSerial?: number

/**
* Start transaction
*/
@Property({ nullable: true })
startTransaction?: string

/**
* Is mint needed
*/
@Property({ default: true })
isMintNeeded: boolean = true;

/**
* Is transfer needed
*/
@Property({ default: false })
isTransferNeeded: boolean = false;

/**
* Was transfer needed
*/
@Property({ default: false })
wasTransferNeeded: boolean = false;

/**
* Memo
*/
@Property({ nullable: true })
memo?: string;

/**
* Metadata
*/
@Property({ nullable: true })
metadata?: string;

/**
* Mint request identifier
*/
@Property({ nullable: true })
mintRequestId?: string;

/**
* Mint status
*/
@Property({ nullable: true, type: 'unknown'})
mintStatus?: any;

/**
* Transfer status
*/
@Property({ nullable: true, type: 'unknown'})
transferStatus?: any;

/**
* Error
*/
@Property({ nullable: true })
error?: string;

/**
* Mint date
*/
@Property({ nullable: true })
processDate?: Date;

/**
* Default document values
*/
Expand Down
2 changes: 2 additions & 0 deletions common/src/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export * from './wiper-request';
export * from './record';
export * from './policy-category';
export * from './policy-property';
export * from './mint-request';
export * from './mint-transaction';
92 changes: 92 additions & 0 deletions common/src/entity/mint-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Entity, Property } from '@mikro-orm/core';
import { BaseEntity } from '../models';

/**
* Mint request
*/
@Entity()
export class MintRequest extends BaseEntity {
/**
* Amount
*/
@Property()
amount: number;

/**
* Token identifier
*/
@Property()
tokenId: string;

/**
* Target account
*/
@Property()
target: string;

/**
* VP message identifier
*/
@Property()
vpMessageId: string;

/**
* Secondary VP identifiers
*/
@Property({ nullable: true })
secondaryVpIds?: string[]

/**
* Start serial
*/
@Property({ nullable: true })
startSerial?: number

/**
* Start transaction
*/
@Property({ nullable: true })
startTransaction?: string

/**
* Is mint needed
*/
@Property({ default: true })
isMintNeeded: boolean = true;

/**
* Is transfer needed
*/
@Property({ default: false })
isTransferNeeded: boolean = false;

/**
* Was transfer needed
*/
@Property({ default: false })
wasTransferNeeded: boolean = false;

/**
* Memo
*/
@Property()
memo: string;

/**
* Metadata
*/
@Property({ nullable: true })
metadata?: string;

/**
* Error
*/
@Property({ nullable: true })
error?: string;

/**
* Mint date
*/
@Property({ nullable: true })
processDate?: Date;
}
55 changes: 55 additions & 0 deletions common/src/entity/mint-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Entity, Enum, Index, Property } from '@mikro-orm/core';
import { BaseEntity } from '../models';
import {
MintTransactionStatus,
} from '@guardian/interfaces';

/**
* Mint transaction
*/
@Index({
properties: ['mintRequestId', 'mintStatus'],
name: 'mint_status_index',
})
@Index({
properties: ['mintRequestId', 'transferStatus'],
name: 'transfer_status_index',
})
@Entity()
export class MintTransaction extends BaseEntity {
/**
* Amount
*/
@Property()
amount: number;

/**
* Mint request identifier
*/
@Property()
mintRequestId: string;

/**
* Mint status
*/
@Enum(() => MintTransactionStatus)
mintStatus: MintTransactionStatus;

/**
* Transfer status
*/
@Enum(() => MintTransactionStatus)
transferStatus: MintTransactionStatus;

/**
* Serials
*/
@Property({ nullable: true })
serials?: number[];

/**
* Error
*/
@Property({ nullable: true })
error?: string;
}
6 changes: 6 additions & 0 deletions common/src/entity/multi-policy-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class MultiPolicyTransaction extends BaseEntity {
@Property({ nullable: true })
policyId?: string;

/**
* Vp message identifier
*/
@Property({ nullable: true })
vpMessageId?: string;

/**
* User DID
*/
Expand Down
3 changes: 2 additions & 1 deletion common/src/hedera-modules/message/message-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ export class MessageServer {
network: Environment.network,
localNodeAddress: Environment.localNodeAddress,
localNodeProtocol: Environment.localNodeProtocol,
memo: memo || MessageMemo.getMessageMemo(message)
memo: memo || MessageMemo.getMessageMemo(message),
dryRun: this.dryRun,
}
}, 10);
await this.messageEndLog(time, 'Hedera');
Expand Down
21 changes: 20 additions & 1 deletion common/src/helpers/db-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MikroORM, UseRequestContext, wrap } from '@mikro-orm/core';
import { MongoDriver, MongoEntityManager, ObjectId } from '@mikro-orm/mongodb';
import { MongoDriver, MongoEntityManager, MongoEntityRepository, ObjectId } from '@mikro-orm/mongodb';
import { BaseEntity } from '../models';
import { DataBaseNamingStrategy } from './db-naming-strategy';
import { GridFSBucket } from 'mongodb';
Expand Down Expand Up @@ -310,4 +310,23 @@ export class DataBaseHelper<T extends BaseEntity> {
? entitiesToUpdate[0]
: entitiesToUpdate;
}

/**
* Create a lot of data
* @param data Data
* @param amount Amount
*/
@UseRequestContext(() => DataBaseHelper.orm)
public async createMuchData(data: any, amount: number): Promise<void> {
const repository: MongoEntityRepository<T> = this._em.getRepository(this.entityClass);
delete data.id;
delete data._id;
while(amount > 0) {
delete data.id;
delete data._id;
await this._em.persist(repository.create(data));
amount --;
}
await this._em.flush();
}
}
17 changes: 12 additions & 5 deletions common/src/helpers/workers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Singleton } from '../decorators/singleton';
import { GenerateUUIDv4, HederaResponseCode, IActiveTask, ITask, WorkerEvents, } from '@guardian/interfaces';
import { GenerateUUIDv4, HederaResponseCode, IActiveTask, ITask, TimeoutError, WorkerEvents, } from '@guardian/interfaces';
import { Environment } from '../hedera-modules';
import { NatsService } from '../mq';

Expand Down Expand Up @@ -99,6 +99,13 @@ export class Workers extends NatsService {
*/
private readonly maxRepetitions = 25;

private _wrapError(error, isTimeoutError?: boolean): any {
if (isTimeoutError) {
return new TimeoutError(error);
}
return error;
}

/**
* Check error message for retryable
* @param error Error
Expand Down Expand Up @@ -178,7 +185,7 @@ export class Workers extends NatsService {
this.tasksCallbacks.set(taskId, {
task,
number: 0,
callback: (data, error) => {
callback: (data, error, isTimeoutError) => {
if (error) {
if (isRetryableTask && !Workers.isNotRetryableError(error)) {
if (this.tasksCallbacks.has(taskId)) {
Expand All @@ -187,15 +194,15 @@ export class Workers extends NatsService {
if (callback.number > attempts) {
this.tasksCallbacks.delete(taskId);
this.publish(WorkerEvents.TASK_COMPLETE_BROADCAST, { id: taskId, data, error });
reject(error);
reject(this._wrapError(error, isTimeoutError));
return;
}
}
task.sent = false;
this.queue.add(task);
} else {
this.publish(WorkerEvents.TASK_COMPLETE_BROADCAST, { id: taskId ,data, error });
reject(error);
reject(this._wrapError(error, isTimeoutError));
}
} else {
this.tasksCallbacks.delete(task.id);
Expand Down Expand Up @@ -292,7 +299,7 @@ export class Workers extends NatsService {
}
if (this.tasksCallbacks.has(msg.id)) {
const activeTask = this.tasksCallbacks.get(msg.id);
activeTask.callback(msg.data, msg.error);
activeTask.callback(msg.data, msg.error, msg.isTimeoutError);
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { BrandingComponent } from './views/branding/branding.component';
import { StandardRegistryCardComponent } from './components/standard-registry-card/standard-registry-card.component';
import { SuggestionsConfigurationComponent } from './views/suggestions-configuration/suggestions-configuration.component';
import { NotificationComponent } from './components/notification/notification.component';
import { TokenDialogComponent } from './components/token-dialog/token-dialog.component';
//Modules
import { MaterialModule } from './modules/common/material.module';
import { PolicyEngineModule } from './modules/policy-engine/policy-engine.module';
Expand Down Expand Up @@ -156,7 +157,8 @@ import { UseWithServiceDirective } from './directives/use-with-service.directive
AccountTypeSelectorDialogComponent,
ForgotPasswordDialogComponent,
OnlyForDemoDirective,
UseWithServiceDirective
TokenDialogComponent,
UseWithServiceDirective,
],
imports: [
BrowserModule,
Expand Down
Loading

0 comments on commit 7f6ea43

Please sign in to comment.