feat: 实现出库导入、区块链存证、查询日志、看板与系统设置
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Job } from 'bullmq';
|
||||
import { ProofStatus, QUEUE_NAMES } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { BlockchainService } from './blockchain.service';
|
||||
|
||||
interface OnchainJobData {
|
||||
proofId: number;
|
||||
}
|
||||
|
||||
@Processor(QUEUE_NAMES.ONCHAIN)
|
||||
export class OnchainProcessor extends WorkerHost {
|
||||
private readonly logger = new Logger(OnchainProcessor.name);
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly blockchain: BlockchainService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async process(job: Job<OnchainJobData>): Promise<void> {
|
||||
const { proofId } = job.data;
|
||||
const proof = await this.prisma.blockchainProof.findUnique({ where: { id: proofId } });
|
||||
if (!proof) return;
|
||||
try {
|
||||
const result = await this.blockchain.attest({ dataHash: proof.dataHash });
|
||||
await this.prisma.blockchainProof.update({
|
||||
where: { id: proofId },
|
||||
data: {
|
||||
status: ProofStatus.ONCHAIN,
|
||||
txHash: result.txHash,
|
||||
blockHash: result.blockHash,
|
||||
blockHeight: BigInt(result.blockHeight),
|
||||
chainName: result.chainName,
|
||||
explorerUrl: result.explorerUrl,
|
||||
onchainAt: result.onchainAt,
|
||||
rawResponse: result.raw as object,
|
||||
},
|
||||
});
|
||||
this.logger.log(`存证 ${proofId} 上链成功`);
|
||||
} catch (e) {
|
||||
await this.prisma.blockchainProof.update({
|
||||
where: { id: proofId },
|
||||
data: { status: ProofStatus.FAILED },
|
||||
});
|
||||
this.logger.error(`存证 ${proofId} 上链失败: ${(e as Error).message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user