keychat-save 1.2.0 → 1.2.1
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/index.mjs +25 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -44,6 +44,20 @@ function decrypt (encrypted, privKey) {
|
|
|
44
44
|
return Utils.toUTF8(EncryptedMessage.decrypt(encrypted, privKey))
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// ── local index ──────────────────────────────────────────────────
|
|
48
|
+
// Newest-first markdown table: `| date | label | txid | cost |`.
|
|
49
|
+
// Returns the first txid-shaped cell; null if none.
|
|
50
|
+
function readNewestTxidFromIndex (path) {
|
|
51
|
+
const text = readFileSync(path, 'utf8')
|
|
52
|
+
for (const line of text.split('\n')) {
|
|
53
|
+
if (!line.startsWith('|')) continue
|
|
54
|
+
const cells = line.split('|').map(c => c.trim())
|
|
55
|
+
const txid = cells.find(c => /^[0-9a-f]{64}$/i.test(c))
|
|
56
|
+
if (txid) return txid.toLowerCase()
|
|
57
|
+
}
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
47
61
|
// ── bridge API ───────────────────────────────────────────────────
|
|
48
62
|
async function getUnspent (address) {
|
|
49
63
|
const res = await fetch(`${BRIDGE}/api/address/${address}/unspent`)
|
|
@@ -339,9 +353,19 @@ if (cmd === 'init') {
|
|
|
339
353
|
const txidIdx = args.indexOf('--txid')
|
|
340
354
|
if (txidIdx >= 0 && args[txidIdx + 1]) {
|
|
341
355
|
await cmdLoadByTxid(args[txidIdx + 1])
|
|
356
|
+
} else if (args.includes('--last')) {
|
|
357
|
+
// Fast path: read newest txid from local saves-index.md.
|
|
358
|
+
// The slow UTXO-scan path stalls when the address holds many UTXOs
|
|
359
|
+
// (e.g. packaged Compute pieces from the splitter).
|
|
360
|
+
const lastTxid = existsSync(INDEX_PATH) ? readNewestTxidFromIndex(INDEX_PATH) : null
|
|
361
|
+
if (lastTxid) {
|
|
362
|
+
await cmdLoadByTxid(lastTxid)
|
|
363
|
+
} else {
|
|
364
|
+
console.error('No local saves index found — falling back to UTXO scan.')
|
|
365
|
+
await cmdLoad({ last: true })
|
|
366
|
+
}
|
|
342
367
|
} else {
|
|
343
368
|
const opts = {}
|
|
344
|
-
if (args.includes('--last')) opts.last = true
|
|
345
369
|
if (args.includes('--search')) opts.search = args[args.indexOf('--search') + 1]
|
|
346
370
|
await cmdLoad(opts)
|
|
347
371
|
}
|