@lawrenceliang-btc/atel-sdk 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/atel.mjs +71 -6
- package/package.json +1 -1
package/bin/atel.mjs
CHANGED
|
@@ -5772,7 +5772,9 @@ async function cmdTradeTask(capability, description) {
|
|
|
5772
5772
|
while (Date.now() - startTime < timeout) {
|
|
5773
5773
|
await new Promise(r => setTimeout(r, 3000));
|
|
5774
5774
|
try {
|
|
5775
|
-
const
|
|
5775
|
+
const pollResp = await fetch(`${PLATFORM_URL}/trade/v1/order/${orderId}`, { signal: AbortSignal.timeout(10000) });
|
|
5776
|
+
if (!pollResp.ok) throw new Error(`HTTP ${pollResp.status}`);
|
|
5777
|
+
const info = await pollResp.json();
|
|
5776
5778
|
if (info.status !== lastStatus) {
|
|
5777
5779
|
console.error(`[trade-task] Status: ${lastStatus} → ${info.status}`);
|
|
5778
5780
|
lastStatus = info.status;
|
|
@@ -6359,8 +6361,8 @@ async function cmdMilestoneFeedback(orderId) {
|
|
|
6359
6361
|
|
|
6360
6362
|
async function cmdMilestoneSubmit(orderId, indexStr) {
|
|
6361
6363
|
if (!orderId || indexStr === undefined) {
|
|
6362
|
-
console.error('Usage: atel milestone-submit <orderId> <index> --result "结果描述"');
|
|
6363
|
-
console.error(' atel milestone-submit <orderId> <index> --result ./file.pdf [--hash 0x...]');
|
|
6364
|
+
console.error('Usage: atel milestone-submit <orderId> <index> --result "结果描述" [--file <path>]');
|
|
6365
|
+
console.error(' atel milestone-submit <orderId> <index> --result ./file.pdf [--hash 0x...] [--file <path>]');
|
|
6364
6366
|
process.exit(1);
|
|
6365
6367
|
}
|
|
6366
6368
|
const resultIdx = rawArgs.findIndex(a => a === '--result');
|
|
@@ -6394,11 +6396,35 @@ async function cmdMilestoneSubmit(orderId, indexStr) {
|
|
|
6394
6396
|
resultHash = ethers.keccak256(ethers.toUtf8Bytes(result));
|
|
6395
6397
|
}
|
|
6396
6398
|
|
|
6397
|
-
|
|
6399
|
+
// --file support: upload attachment before submitting
|
|
6400
|
+
let resultText = result;
|
|
6401
|
+
const filePath = rawArgs.find((a, i) => rawArgs[i - 1] === '--file');
|
|
6402
|
+
if (filePath) {
|
|
6403
|
+
const { execFileSync } = await import('child_process');
|
|
6404
|
+
const path = await import('path');
|
|
6405
|
+
try {
|
|
6406
|
+
const id = requireIdentity();
|
|
6407
|
+
const uploadResult = execFileSync('curl', ['-s', '-X', 'POST',
|
|
6408
|
+
`${PLATFORM_URL}/attachment/v1/upload`,
|
|
6409
|
+
'-F', `file=@${filePath}`,
|
|
6410
|
+
'-F', 'kind=file',
|
|
6411
|
+
'-F', `uploadedBy=${id.did}`
|
|
6412
|
+
], { encoding: 'utf8' });
|
|
6413
|
+
const uploadData = JSON.parse(uploadResult);
|
|
6414
|
+
if (uploadData.attachmentId) {
|
|
6415
|
+
resultText += `\n[Attachment: ${uploadData.attachmentId} (${path.basename(filePath)})]`;
|
|
6416
|
+
console.error(`File uploaded: ${uploadData.attachmentId}`);
|
|
6417
|
+
}
|
|
6418
|
+
} catch (e) {
|
|
6419
|
+
console.error(`File upload failed: ${e.message}`);
|
|
6420
|
+
}
|
|
6421
|
+
}
|
|
6422
|
+
|
|
6423
|
+
console.log(`Submitting M${indexStr}: "${resultText.slice(0, 60)}${resultText.length > 60 ? '...' : ''}"`);
|
|
6398
6424
|
console.log(`Hash: ${resultHash}`);
|
|
6399
6425
|
|
|
6400
6426
|
const data = await signedFetch('POST', `/trade/v1/order/${orderId}/milestone/${indexStr}/submit`, {
|
|
6401
|
-
resultSummary:
|
|
6427
|
+
resultSummary: resultText,
|
|
6402
6428
|
resultHash,
|
|
6403
6429
|
});
|
|
6404
6430
|
console.log(JSON.stringify(data, null, 2));
|
|
@@ -6489,10 +6515,34 @@ async function cmdDispute(orderId, reason, description) {
|
|
|
6489
6515
|
}
|
|
6490
6516
|
|
|
6491
6517
|
async function cmdEvidence(disputeId, evidenceJson) {
|
|
6492
|
-
if (!disputeId || !evidenceJson) { console.error('Usage: atel evidence <disputeId> <json>'); process.exit(1); }
|
|
6518
|
+
if (!disputeId || !evidenceJson) { console.error('Usage: atel evidence <disputeId> <json> [--file <path>]'); process.exit(1); }
|
|
6493
6519
|
let evidence;
|
|
6494
6520
|
try { evidence = JSON.parse(evidenceJson); } catch { console.error('Invalid JSON'); process.exit(1); }
|
|
6495
6521
|
|
|
6522
|
+
// --file support: upload attachment and attach to evidence
|
|
6523
|
+
const filePath = rawArgs.find((a, i) => rawArgs[i - 1] === '--file');
|
|
6524
|
+
if (filePath) {
|
|
6525
|
+
const { execFileSync } = await import('child_process');
|
|
6526
|
+
const path = await import('path');
|
|
6527
|
+
try {
|
|
6528
|
+
const id = requireIdentity();
|
|
6529
|
+
const uploadResult = execFileSync('curl', ['-s', '-X', 'POST',
|
|
6530
|
+
`${PLATFORM_URL}/attachment/v1/upload`,
|
|
6531
|
+
'-F', `file=@${filePath}`,
|
|
6532
|
+
'-F', 'kind=file',
|
|
6533
|
+
'-F', `uploadedBy=${id.did}`
|
|
6534
|
+
], { encoding: 'utf8' });
|
|
6535
|
+
const uploadData = JSON.parse(uploadResult);
|
|
6536
|
+
if (uploadData.attachmentId) {
|
|
6537
|
+
evidence.attachmentId = uploadData.attachmentId;
|
|
6538
|
+
evidence.attachmentName = path.basename(filePath);
|
|
6539
|
+
console.error(`File uploaded: ${uploadData.attachmentId}`);
|
|
6540
|
+
}
|
|
6541
|
+
} catch (e) {
|
|
6542
|
+
console.error(`File upload failed: ${e.message}`);
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
|
|
6496
6546
|
// Submit to Platform API
|
|
6497
6547
|
const data = await signedFetch('POST', `/dispute/v1/${disputeId}/evidence`, { evidence });
|
|
6498
6548
|
|
|
@@ -6548,6 +6598,21 @@ async function cmdCertStatus(did) {
|
|
|
6548
6598
|
const text = await res.text(); console.error("DEBUG Response:", text); const data = JSON.parse(text);
|
|
6549
6599
|
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
6550
6600
|
console.log(JSON.stringify(data, null, 2));
|
|
6601
|
+
|
|
6602
|
+
// Fetch and display certification requirements
|
|
6603
|
+
try {
|
|
6604
|
+
const reqResp = await fetch(`${PLATFORM_URL}/cert/v1/requirements`, { signal: AbortSignal.timeout(5000) });
|
|
6605
|
+
if (reqResp.ok) {
|
|
6606
|
+
const reqs = await reqResp.json();
|
|
6607
|
+
console.log('\nCertification Requirements:');
|
|
6608
|
+
if (reqs.certified) {
|
|
6609
|
+
console.log(` Certified: trust_score >= ${reqs.certified.minTrustScore}, cost: $${reqs.certified.cost}`);
|
|
6610
|
+
}
|
|
6611
|
+
if (reqs.enterprise) {
|
|
6612
|
+
console.log(` Enterprise: trust_score >= ${reqs.enterprise.minTrustScore}, cost: $${reqs.enterprise.cost}`);
|
|
6613
|
+
}
|
|
6614
|
+
}
|
|
6615
|
+
} catch {}
|
|
6551
6616
|
}
|
|
6552
6617
|
|
|
6553
6618
|
async function cmdCertRenew(level) {
|