feat: 天河链去掉元数据上链存证改为仅发行NFT(feature用作品主图)
This commit is contained in:
@@ -4,6 +4,7 @@ import { Queue } from 'bullmq';
|
||||
import { ErrorCode, ProofStatus, QUEUE_NAMES } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { BlockchainService } from './blockchain.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -11,9 +12,18 @@ export class AttestationService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly blockchain: BlockchainService,
|
||||
private readonly storage: StorageService,
|
||||
@InjectQueue(QUEUE_NAMES.ONCHAIN) private readonly queue: Queue,
|
||||
) {}
|
||||
|
||||
// 取作品主图的公开 URL 作为发行 feature(天河文档:feature=作品对应媒体文件地址;媒体本体存我方 OSS)
|
||||
private firstImageUrl(images: unknown): string | undefined {
|
||||
const list = Array.isArray(images) ? images : [];
|
||||
const first = list[0] as { key?: string } | string | undefined;
|
||||
const key = typeof first === 'string' ? first : first?.key;
|
||||
return key ? this.storage.getUrl(key) : undefined;
|
||||
}
|
||||
|
||||
async trigger(traceCodeId: bigint) {
|
||||
const code = await this.prisma.traceCode.findUnique({
|
||||
where: { id: traceCodeId },
|
||||
@@ -66,8 +76,13 @@ export class AttestationService {
|
||||
status: ProofStatus.PENDING,
|
||||
rawResponse: {
|
||||
requestMeta: summary,
|
||||
// 发行 NFT 用的产品信息(天河链:productId=追溯码、name=作品名、author=艺术家)
|
||||
product: { productId: code.shortCode, name: code.artwork.title, author: code.artwork.artist ?? undefined },
|
||||
// 发行 NFT 用的产品信息(天河链:productId=追溯码、name=作品名、author=艺术家、feature=作品主图 OSS 地址)
|
||||
product: {
|
||||
productId: code.shortCode,
|
||||
name: code.artwork.title,
|
||||
author: code.artwork.artist ?? undefined,
|
||||
feature: this.firstImageUrl(code.artwork.images),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -47,12 +47,13 @@ export class BlockchainService {
|
||||
return provider.attest(payload);
|
||||
}
|
||||
|
||||
// 天河链「存证 + 发行」双层:① upload 存证 JSON(拿存证哈希/digest/存证链接)
|
||||
// ② publish 铸 1 个 NFT(productId=追溯码、feature=存证链接)→ mint 交易可经接口 9 确认拿区块信息。
|
||||
// 天河链「仅发行」:直接 publish 铸 1 个 NFT(productId=追溯码、feature=作品主图 OSS 地址)→ mint 交易经接口 9 确认拿区块信息。
|
||||
// 甲方确认:不做数字商品元数据上链存储(upload),作品详情/媒体存我方 OSS;链上凭据即 NFT(tokenId + mint 交易)。
|
||||
// 合约地址与已发行最大 tokenId 存系统设置(上链队列串行,无并发争用)。
|
||||
private async attestWithTianhe(provider: TianheProvider, payload: AttestPayload): Promise<AttestResult> {
|
||||
const attest = await provider.attest(payload);
|
||||
if (!payload.product) return attest; // 无产品信息时退化为纯存证(防御,正常流程总是携带)
|
||||
if (!payload.product) {
|
||||
throw new Error('天河链发行失败:缺少产品信息(productId/name)');
|
||||
}
|
||||
|
||||
const settings = await this.settings.getAllRaw();
|
||||
const contractAddress = (settings.tianheContractAddress || '').trim() || undefined;
|
||||
@@ -61,7 +62,7 @@ export class BlockchainService {
|
||||
productId: payload.product.productId,
|
||||
name: payload.product.name,
|
||||
author: payload.product.author,
|
||||
feature: attest.explorerUrl ?? undefined,
|
||||
feature: payload.product.feature ?? undefined,
|
||||
contractAddress,
|
||||
// 官方要求:指定 contractAddress 时 baseTokenId 须为「已发行 tokenId 的最大值」
|
||||
baseTokenId: contractAddress ? maxTokenId : undefined,
|
||||
@@ -75,23 +76,21 @@ export class BlockchainService {
|
||||
|
||||
return {
|
||||
dataHash: payload.dataHash,
|
||||
// 主凭据切换为 mint 交易(可确认、有区块信息、tokenId 资产语义);存证交易哈希保留在 raw.attestTxHash
|
||||
// 凭据为 mint 交易(可确认、有区块信息、tokenId 资产语义)
|
||||
txHash: pub.txHash,
|
||||
blockHash: null,
|
||||
blockHeight: null,
|
||||
chainName: '天河链',
|
||||
// 「查看存证」跳天河区块浏览器交易详情页(规范展示);UDFS 裸 JSON 存证链接保留在 raw.proofUrl / feature 字段
|
||||
// 「查看存证」跳天河区块浏览器交易详情页(规范展示 mint 交易:追溯码 productId、作品主图 feature、tokenId)
|
||||
explorerUrl: provider.explorerTxUrl(pub.txHash),
|
||||
tokenId: pub.tokenId >= 0 ? pub.tokenId : null,
|
||||
contractAddress: pub.contractAddress,
|
||||
onchainAt: new Date(),
|
||||
raw: {
|
||||
...attest.raw,
|
||||
attestTxHash: attest.txHash,
|
||||
attestUrl: attest.explorerUrl,
|
||||
product: payload.product,
|
||||
publishResponse: pub.raw,
|
||||
transactionStatus: 'submitted',
|
||||
transactionStatusNote: '存证已生效(upload);NFT 铸造交易已提交,等待接口 9 确认区块信息。',
|
||||
transactionStatusNote: 'NFT 铸造交易已提交,等待接口 9 确认区块信息。',
|
||||
},
|
||||
confirmationRequired: true,
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export interface AttestPayload {
|
||||
dataHash: string;
|
||||
meta?: Record<string, unknown>;
|
||||
// 发行 NFT 用的产品信息(天河链 publish:productId=追溯码、name=专题名≤42、author≤120)
|
||||
product?: { productId: string; name: string; author?: string };
|
||||
// 发行 NFT 用的产品信息(天河链 publish:productId=追溯码、name=专题名≤42、author≤120、feature=作品主图地址≤500)
|
||||
product?: { productId: string; name: string; author?: string; feature?: string };
|
||||
}
|
||||
|
||||
export interface AttestResult {
|
||||
|
||||
@@ -24,11 +24,15 @@ function requestMeta(raw: unknown): Record<string, unknown> | undefined {
|
||||
return meta && typeof meta === 'object' ? (meta as Record<string, unknown>) : undefined;
|
||||
}
|
||||
|
||||
function productInfo(raw: unknown): { productId: string; name: string; author?: string } | undefined {
|
||||
function productInfo(
|
||||
raw: unknown,
|
||||
): { productId: string; name: string; author?: string; feature?: string } | undefined {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
const product = (raw as Record<string, unknown>).product as { productId?: string; name?: string; author?: string } | undefined;
|
||||
const product = (raw as Record<string, unknown>).product as
|
||||
| { productId?: string; name?: string; author?: string; feature?: string }
|
||||
| undefined;
|
||||
return product?.productId && product?.name
|
||||
? { productId: product.productId, name: product.name, author: product.author }
|
||||
? { productId: product.productId, name: product.name, author: product.author, feature: product.feature }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user