fix: 统一追溯码并修正天河链存证跳转
This commit is contained in:
@@ -60,7 +60,6 @@ export class AttestationService {
|
||||
|
||||
const summary = {
|
||||
shortCode: code.shortCode,
|
||||
code: code.code,
|
||||
title: code.artwork.title,
|
||||
artist: code.artwork.artist,
|
||||
archiveNo: code.artwork.archiveNo,
|
||||
|
||||
@@ -22,7 +22,7 @@ function mockHttpsRequestOnce(responseJson: unknown, statusCode = 200) {
|
||||
|
||||
// 放在 jest.mock 之后导入,确保 provider 拿到被 mock 的 https
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { TianheProvider } = require('./tianhe.provider') as typeof import('./tianhe.provider');
|
||||
const { TianheProvider, buildTianheExplorerTxUrl } = require('./tianhe.provider') as typeof import('./tianhe.provider');
|
||||
|
||||
describe('TianheProvider', () => {
|
||||
const provider = new TianheProvider({
|
||||
@@ -37,6 +37,16 @@ describe('TianheProvider', () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('按天河环境生成 DApp 浏览器交易详情地址', () => {
|
||||
const txHash = '0xabc/123';
|
||||
expect(buildTianheExplorerTxUrl('https://test.api.tichain.tianhecloud.com', txHash)).toBe(
|
||||
'https://test.explorer.tianhecloud.com/#/tiChain/transDetail?hash=0xabc%2F123',
|
||||
);
|
||||
expect(
|
||||
buildTianheExplorerTxUrl('https://custom-api.example.com', txHash, 'production'),
|
||||
).toBe('https://explorer.tianhecloud.com/#/tiChain/transDetail?hash=0xabc%2F123');
|
||||
});
|
||||
|
||||
it('按天河链 upload 文档映射交易哈希、存证链接和文件哈希', async () => {
|
||||
const response = {
|
||||
code: 0,
|
||||
|
||||
@@ -71,6 +71,15 @@ function redactSecrets(obj: Record<string, unknown>): Record<string, unknown> {
|
||||
return masked;
|
||||
}
|
||||
|
||||
export function buildTianheExplorerTxUrl(baseUrl: string, txHash: string, environment?: string): string {
|
||||
const testEnvironment =
|
||||
environment === 'test' || (environment !== 'production' && baseUrl.toLowerCase().includes('test.'));
|
||||
const explorerBase = testEnvironment
|
||||
? 'https://test.explorer.tianhecloud.com'
|
||||
: 'https://explorer.tianhecloud.com';
|
||||
return `${explorerBase}/#/tiChain/transDetail?hash=${encodeURIComponent(txHash)}`;
|
||||
}
|
||||
|
||||
export class TianheProvider implements AttestationProvider {
|
||||
readonly name = 'tianhe';
|
||||
private readonly logger = new Logger('TianheAPI');
|
||||
@@ -89,16 +98,9 @@ export class TianheProvider implements AttestationProvider {
|
||||
return required(this.opts.baseUrl, 'Base URL').replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
// 天河区块浏览器域名:测试 test.explorer.tianhecloud.com / 生产 explorer.tianhecloud.com(由 API base 是否含 test. 判定)
|
||||
private explorerBase(): string {
|
||||
return this.baseUrl().includes('test.')
|
||||
? 'https://test.explorer.tianhecloud.com'
|
||||
: 'https://explorer.tianhecloud.com';
|
||||
}
|
||||
|
||||
// 交易详情页:客户凭 mint 交易哈希可查看状态/区块高度/追溯码(productId)/存证链接(feature),比裸 UDFS JSON 规范
|
||||
// DApp 浏览器交易详情页使用 mint 交易哈希,不使用 API 地址或本地 dataHash。
|
||||
explorerTxUrl(txHash: string): string {
|
||||
return `${this.explorerBase()}/#/tiChain/transDetail?hash=${encodeURIComponent(txHash)}`;
|
||||
return buildTianheExplorerTxUrl(this.baseUrl(), txHash);
|
||||
}
|
||||
|
||||
private credentials() {
|
||||
|
||||
Reference in New Issue
Block a user