feat: 实现存储抽象、任务队列与区块链/归属地 Mock 适配

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 15:53:39 +08:00
co-authored by Cursor
parent 9368574cf7
commit 6e5c767a53
17 changed files with 425 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import { createHash, randomBytes } from 'crypto';
import { AttestPayload, AttestResult, AttestationProvider } from './blockchain.types';
// 模拟区块链存证:返回结构与真实链一致的拟真数据,便于联调与前端展示。
// 真实接入(天河链)确认后,仅需切换 BLOCKCHAIN_DRIVER=tianhe 即可替换。
export class MockProvider implements AttestationProvider {
readonly name = 'mock-chain';
async attest(payload: AttestPayload): Promise<AttestResult> {
// 模拟网络与出块耗时
await new Promise((r) => setTimeout(r, 200));
const txHash = '0x' + randomBytes(32).toString('hex');
const blockHash =
'0x' + createHash('sha256').update(txHash).digest('hex');
const blockHeight = 8_000_000 + Math.floor(Math.random() * 2_000_000);
const onchainAt = new Date();
return {
dataHash: payload.dataHash,
txHash,
blockHash,
blockHeight,
chainName: 'MockChain',
explorerUrl: `https://mock-explorer.local/tx/${txHash}`,
onchainAt,
raw: {
provider: this.name,
code: 0,
message: 'success',
data: { txHash, blockHash, blockHeight, dataHash: payload.dataHash },
},
};
}
}