feat: 按交易详情版式展示站内存证
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { readMintView } from './public-mint-view';
|
||||
|
||||
describe('readMintView', () => {
|
||||
it('uses the frozen mint fields and ignores the rest of the raw response', () => {
|
||||
const view = readMintView({
|
||||
product: { productId: '154109005352', author: '黄志伟', feature: 'https://art.qclh.xyz/uploads/a.png' },
|
||||
confirmation: { appKey: 'secret' },
|
||||
}, '154109005352', '后来改名', '0xae3ecbac36b5874b0372686e5b88894c22be4296');
|
||||
expect(view).toEqual({
|
||||
author: '黄志伟',
|
||||
productId: '154109005352',
|
||||
feature: 'https://art.qclh.xyz/uploads/a.png',
|
||||
mintTo: '0xae3ecbac36b5874b0372686e5b88894c22be4296',
|
||||
});
|
||||
expect(JSON.stringify(view)).not.toContain('secret');
|
||||
});
|
||||
|
||||
it('falls back to the artwork artist and short code when the snapshot is missing', () => {
|
||||
expect(readMintView(null, '734648008702', '黄志伟', 'not-an-address')).toEqual({
|
||||
author: '黄志伟',
|
||||
productId: '734648008702',
|
||||
feature: null,
|
||||
mintTo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
export interface PublicMintView {
|
||||
author: string | null;
|
||||
productId: string;
|
||||
feature: string | null;
|
||||
mintTo: string | null;
|
||||
}
|
||||
|
||||
function text(row: Record<string, unknown>, key: string): string | null {
|
||||
const value = row[key];
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
||||
}
|
||||
|
||||
/** 只取出发行时保存的产品字段,不把原始响应里的其他内容交给浏览器。 */
|
||||
export function readMintView(raw: unknown, shortCode: string, artist: string | null, wallet: string | null): PublicMintView {
|
||||
const product = raw && typeof raw === 'object' ? (raw as { product?: unknown }).product : null;
|
||||
const row = product && typeof product === 'object' ? product as Record<string, unknown> : {};
|
||||
return {
|
||||
author: text(row, 'author') || artist?.trim() || null,
|
||||
productId: text(row, 'productId') || shortCode,
|
||||
feature: text(row, 'feature'),
|
||||
mintTo: wallet && /^0x[0-9a-fA-F]{40}$/.test(wallet) ? wallet : null,
|
||||
};
|
||||
}
|
||||
@@ -96,7 +96,8 @@ function createHarness(options: {
|
||||
set: jest.fn().mockResolvedValue('OK'),
|
||||
};
|
||||
const storage = { getUrl: jest.fn((key: string) => `/uploads/${key}`) };
|
||||
const service = new PublicTraceService(prisma as any, storage as any, redis as any);
|
||||
const settings = { get: jest.fn().mockResolvedValue(null) };
|
||||
const service = new PublicTraceService(prisma as any, storage as any, redis as any, settings as any);
|
||||
return { service, prisma };
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,10 @@ import {
|
||||
} from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module';
|
||||
import { parseUserAgent } from '../common/utils/ua.util';
|
||||
import { readMintView } from './public-mint-view';
|
||||
|
||||
type TraceCodeWithRel = Prisma.TraceCodeGetPayload<{ include: { batch: true; artwork: true } }>;
|
||||
type ArtworkWithRel = Prisma.ArtworkGetPayload<{
|
||||
@@ -44,6 +46,7 @@ export class PublicTraceService {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly storage: StorageService,
|
||||
@Inject(REDIS_CLIENT) private readonly redis: Redis,
|
||||
private readonly settings: SettingsService,
|
||||
) {}
|
||||
|
||||
private mapMedia(
|
||||
@@ -265,6 +268,7 @@ export class PublicTraceService {
|
||||
const updated = await this.prisma.traceCode.findUniqueOrThrow({ where: { id } });
|
||||
|
||||
const proof = await this.prisma.blockchainProof.findUnique({ where: { traceCodeId: id } });
|
||||
const mintTo = await this.mintRecipient(proof);
|
||||
|
||||
const result = firstActivate ? QueryResult.FIRST_ACTIVATE : QueryResult.REPEAT;
|
||||
await this.writeLog(id, artwork.id, shortCode, result, ctx, { ...code, ...updated });
|
||||
@@ -276,7 +280,7 @@ export class PublicTraceService {
|
||||
queryCount: updated.queryCount,
|
||||
firstActivatedAt: updated.firstActivatedAt,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
...this.buildArtworkPayload(artwork, code, proof, mintTo),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -321,6 +325,7 @@ export class PublicTraceService {
|
||||
}
|
||||
|
||||
const proof = await this.prisma.blockchainProof.findUnique({ where: { traceCodeId: id } });
|
||||
const mintTo = await this.mintRecipient(proof);
|
||||
|
||||
const now = new Date();
|
||||
const firstQuery = state === 'inactive';
|
||||
@@ -335,7 +340,7 @@ export class PublicTraceService {
|
||||
queryCount: code.queryCount > 0 ? code.queryCount : 2,
|
||||
firstActivatedAt: code.firstActivatedAt ?? now,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
...this.buildArtworkPayload(artwork, code, proof, mintTo),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -343,6 +348,7 @@ export class PublicTraceService {
|
||||
private buildArtworkPayload(
|
||||
artwork: ArtworkWithRel,
|
||||
code: {
|
||||
shortCode: string;
|
||||
outbound?: {
|
||||
outTime: Date;
|
||||
remark: string | null;
|
||||
@@ -357,11 +363,15 @@ export class PublicTraceService {
|
||||
chainName: string | null;
|
||||
onchainAt: Date | null;
|
||||
contractAddress: string | null;
|
||||
tokenId: bigint | null;
|
||||
rawResponse: unknown;
|
||||
status: string;
|
||||
failureReason: string | null;
|
||||
submittedAt: Date | null;
|
||||
} | null,
|
||||
mintTo: string | null,
|
||||
) {
|
||||
const mint = proof ? readMintView(proof.rawResponse, code.shortCode, artwork.artist, mintTo) : null;
|
||||
return {
|
||||
artwork: {
|
||||
title: artwork.title,
|
||||
@@ -407,6 +417,11 @@ export class PublicTraceService {
|
||||
chainName: proof.chainName,
|
||||
onchainAt: proof.onchainAt,
|
||||
contractAddress: proof.contractAddress,
|
||||
tokenId: proof.tokenId === null || proof.tokenId === undefined ? null : proof.tokenId.toString(),
|
||||
author: mint?.author ?? null,
|
||||
productId: mint?.productId ?? code.shortCode,
|
||||
feature: mint?.feature ?? null,
|
||||
mintTo: mint?.mintTo ?? null,
|
||||
submittedAt: proof.submittedAt,
|
||||
failureReason: this.publicFailureReason(proof.status, proof.failureReason),
|
||||
}
|
||||
@@ -414,6 +429,12 @@ export class PublicTraceService {
|
||||
};
|
||||
}
|
||||
|
||||
private async mintRecipient(proof: { chainName: string | null } | null): Promise<string | null> {
|
||||
if (proof?.chainName !== '天河链') return null;
|
||||
const value = await this.settings.get('tianheWalletAddress');
|
||||
return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value) ? value : null;
|
||||
}
|
||||
|
||||
private publicFailureReason(status: string, reason: string | null): string | null {
|
||||
if (status === ProofStatus.UNKNOWN) return '链上结果暂时无法确认,请稍后重试或联系平台管理员';
|
||||
if (status === ProofStatus.FAILED) return reason ? '上链处理失败,请联系平台管理员' : '上链处理失败';
|
||||
|
||||
Reference in New Issue
Block a user