@1sat/sweep-ui 0.0.93 → 0.0.94
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/dist/components/SweepApp.d.ts.map +1 -1
- package/dist/index.js +53 -29
- package/dist/lib/sweeper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/SweepApp.tsx +23 -4
- package/src/lib/sweeper.ts +24 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAgB3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAmB1C,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,cAAc,EACtB,SAAS,GACT,EAAE,aAAa,+
|
|
1
|
+
{"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAgB3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAmB1C,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,cAAc,EACtB,SAAS,GACT,EAAE,aAAa,+BAonBf"}
|
package/dist/index.js
CHANGED
|
@@ -286,12 +286,13 @@ var SWEEP_BATCH_SIZE = 25;
|
|
|
286
286
|
function getOwner(output) {
|
|
287
287
|
return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
|
|
288
288
|
}
|
|
289
|
-
function buildKeys(outputs, keyMap) {
|
|
290
|
-
|
|
291
|
-
|
|
289
|
+
function buildKeys(outputs, keyMap, inputs = outputs) {
|
|
290
|
+
const owners = new Map(outputs.map((output) => [output.outpoint, getOwner(output)]));
|
|
291
|
+
return inputs.map(({ outpoint }) => {
|
|
292
|
+
const owner = owners.get(outpoint);
|
|
292
293
|
const key = owner ? keyMap.get(owner) : undefined;
|
|
293
294
|
if (!key)
|
|
294
|
-
throw new Error(`No key for output ${
|
|
295
|
+
throw new Error(`No key for output ${outpoint} (owner: ${owner})`);
|
|
295
296
|
return key;
|
|
296
297
|
});
|
|
297
298
|
}
|
|
@@ -330,18 +331,19 @@ async function executeSweep(params) {
|
|
|
330
331
|
const inputs = await prepareSweepInputs(ctx, batch);
|
|
331
332
|
const cancelResult = await sweepOrdinals.execute(ctx, {
|
|
332
333
|
inputs,
|
|
333
|
-
keys: buildKeys(batch, keys)
|
|
334
|
+
keys: buildKeys(batch, keys, inputs)
|
|
334
335
|
});
|
|
335
|
-
if (cancelResult.error)
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
336
|
+
if (cancelResult.error)
|
|
337
|
+
throw new Error(cancelResult.error);
|
|
338
|
+
const txid = cancelResult.txid?.trim();
|
|
339
|
+
if (!txid)
|
|
340
|
+
throw new Error("Cancellation returned no transaction ID");
|
|
341
|
+
result.listingTxids.push(txid);
|
|
341
342
|
result.cancelledListings.push(...batch.map((o) => o.outpoint));
|
|
342
343
|
} catch (e) {
|
|
343
344
|
result.errors.push(`Listings batch ${b + 1}: ${e instanceof Error ? e.message : String(e)}`);
|
|
344
|
-
|
|
345
|
+
onProgress("Sweep stopped with errors");
|
|
346
|
+
return result;
|
|
345
347
|
}
|
|
346
348
|
}
|
|
347
349
|
}
|
|
@@ -351,13 +353,15 @@ async function executeSweep(params) {
|
|
|
351
353
|
const inputs = await prepareSweepInputs(ctx, funding);
|
|
352
354
|
const bsvResult = await sweepBsv.execute(ctx, {
|
|
353
355
|
inputs,
|
|
354
|
-
keys: buildKeys(funding, keys),
|
|
356
|
+
keys: buildKeys(funding, keys, inputs),
|
|
355
357
|
amount
|
|
356
358
|
});
|
|
357
359
|
if (bsvResult.error)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
360
|
+
throw new Error(bsvResult.error);
|
|
361
|
+
const txid = bsvResult.txid?.trim();
|
|
362
|
+
if (!txid)
|
|
363
|
+
throw new Error("Sweep returned no transaction ID");
|
|
364
|
+
result.bsvTxid = txid;
|
|
361
365
|
} catch (e) {
|
|
362
366
|
result.errors.push(`BSV: ${e instanceof Error ? e.message : String(e)}`);
|
|
363
367
|
}
|
|
@@ -373,14 +377,14 @@ async function executeSweep(params) {
|
|
|
373
377
|
const inputs = await prepareSweepInputs(ctx, batch);
|
|
374
378
|
const ordResult = await sweepOrdinals.execute(ctx, {
|
|
375
379
|
inputs,
|
|
376
|
-
keys: buildKeys(batch, keys)
|
|
380
|
+
keys: buildKeys(batch, keys, inputs)
|
|
377
381
|
});
|
|
378
|
-
if (ordResult.error)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
if (ordResult.error)
|
|
383
|
+
throw new Error(ordResult.error);
|
|
384
|
+
const txid = ordResult.txid?.trim();
|
|
385
|
+
if (!txid)
|
|
386
|
+
throw new Error("Sweep returned no transaction ID");
|
|
387
|
+
result.ordinalTxids.push(txid);
|
|
384
388
|
result.sweptOutpoints.push(...batch.map((o) => o.outpoint));
|
|
385
389
|
} catch (e) {
|
|
386
390
|
result.errors.push(`Ordinals batch ${b + 1}/${batches.length}: ${e instanceof Error ? e.message : String(e)}`);
|
|
@@ -2465,10 +2469,13 @@ function SweepApp({
|
|
|
2465
2469
|
amount: sweepAmount ?? undefined,
|
|
2466
2470
|
onProgress: setSweepProgress
|
|
2467
2471
|
});
|
|
2468
|
-
if (result.errors.length > 0)
|
|
2469
|
-
throw new Error(result.errors[0]);
|
|
2470
2472
|
for (const txid of result.listingTxids)
|
|
2471
2473
|
addTx("Cancel listings", txid);
|
|
2474
|
+
if (result.errors.length > 0) {
|
|
2475
|
+
if (result.cancelledListings.length > 0)
|
|
2476
|
+
await refreshAssets();
|
|
2477
|
+
throw new Error(result.errors[0]);
|
|
2478
|
+
}
|
|
2472
2479
|
return result.bsvTxid ?? result.listingTxids[0] ?? "";
|
|
2473
2480
|
});
|
|
2474
2481
|
}, [
|
|
@@ -2479,7 +2486,8 @@ function SweepApp({
|
|
|
2479
2486
|
getSelectedFunding,
|
|
2480
2487
|
runOperation,
|
|
2481
2488
|
keyMap,
|
|
2482
|
-
addTx
|
|
2489
|
+
addTx,
|
|
2490
|
+
refreshAssets
|
|
2483
2491
|
]);
|
|
2484
2492
|
const handleCancelListings = useCallback2(async () => {
|
|
2485
2493
|
const wallet = resolveWallet();
|
|
@@ -2494,11 +2502,27 @@ function SweepApp({
|
|
|
2494
2502
|
listings: assets.listings,
|
|
2495
2503
|
onProgress: setSweepProgress
|
|
2496
2504
|
});
|
|
2497
|
-
if (result.errors.length > 0)
|
|
2505
|
+
if (result.errors.length > 0) {
|
|
2506
|
+
for (const txid of result.listingTxids)
|
|
2507
|
+
addTx("Cancel listings", txid);
|
|
2508
|
+
if (result.cancelledListings.length > 0)
|
|
2509
|
+
await refreshAssets();
|
|
2498
2510
|
throw new Error(result.errors[0]);
|
|
2499
|
-
|
|
2511
|
+
}
|
|
2512
|
+
for (let i = 0;i < result.listingTxids.length - 1; i++) {
|
|
2513
|
+
addTx("Cancel listings", result.listingTxids[i]);
|
|
2514
|
+
}
|
|
2515
|
+
return result.listingTxids[result.listingTxids.length - 1] ?? "";
|
|
2500
2516
|
});
|
|
2501
|
-
}, [
|
|
2517
|
+
}, [
|
|
2518
|
+
resolveWallet,
|
|
2519
|
+
legacyKeys,
|
|
2520
|
+
assets,
|
|
2521
|
+
keyMap,
|
|
2522
|
+
runOperation,
|
|
2523
|
+
addTx,
|
|
2524
|
+
refreshAssets
|
|
2525
|
+
]);
|
|
2502
2526
|
const handleSendBsv = useCallback2(async (destination) => {
|
|
2503
2527
|
if (!legacyKeys || !assets)
|
|
2504
2528
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAG7C,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,oDAAoD;IACpD,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,2DAA2D;IAC3D,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAC3B;
|
|
1
|
+
{"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAG7C,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,oDAAoD;IACpD,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,2DAA2D;IAC3D,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAC3B;AA8BD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC7B,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC,GAAG,OAAO,CAAC,WAAW,CAAC,CAsGvB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC7C,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC7B,KAAK,EAAE,YAAY,CAAA;IACnB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC,GAAG,OAAO,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA4B7C"}
|
package/package.json
CHANGED
|
@@ -261,8 +261,11 @@ export function SweepApp({
|
|
|
261
261
|
amount: sweepAmount ?? undefined,
|
|
262
262
|
onProgress: setSweepProgress,
|
|
263
263
|
})
|
|
264
|
-
if (result.errors.length > 0) throw new Error(result.errors[0])
|
|
265
264
|
for (const txid of result.listingTxids) addTx('Cancel listings', txid)
|
|
265
|
+
if (result.errors.length > 0) {
|
|
266
|
+
if (result.cancelledListings.length > 0) await refreshAssets()
|
|
267
|
+
throw new Error(result.errors[0])
|
|
268
|
+
}
|
|
266
269
|
return result.bsvTxid ?? result.listingTxids[0] ?? ''
|
|
267
270
|
})
|
|
268
271
|
}, [
|
|
@@ -274,6 +277,7 @@ export function SweepApp({
|
|
|
274
277
|
runOperation,
|
|
275
278
|
keyMap,
|
|
276
279
|
addTx,
|
|
280
|
+
refreshAssets,
|
|
277
281
|
])
|
|
278
282
|
|
|
279
283
|
const handleCancelListings = useCallback(async () => {
|
|
@@ -289,10 +293,25 @@ export function SweepApp({
|
|
|
289
293
|
listings: assets.listings,
|
|
290
294
|
onProgress: setSweepProgress,
|
|
291
295
|
})
|
|
292
|
-
if (result.errors.length > 0)
|
|
293
|
-
|
|
296
|
+
if (result.errors.length > 0) {
|
|
297
|
+
for (const txid of result.listingTxids) addTx('Cancel listings', txid)
|
|
298
|
+
if (result.cancelledListings.length > 0) await refreshAssets()
|
|
299
|
+
throw new Error(result.errors[0])
|
|
300
|
+
}
|
|
301
|
+
for (let i = 0; i < result.listingTxids.length - 1; i++) {
|
|
302
|
+
addTx('Cancel listings', result.listingTxids[i])
|
|
303
|
+
}
|
|
304
|
+
return result.listingTxids[result.listingTxids.length - 1] ?? ''
|
|
294
305
|
})
|
|
295
|
-
}, [
|
|
306
|
+
}, [
|
|
307
|
+
resolveWallet,
|
|
308
|
+
legacyKeys,
|
|
309
|
+
assets,
|
|
310
|
+
keyMap,
|
|
311
|
+
runOperation,
|
|
312
|
+
addTx,
|
|
313
|
+
refreshAssets,
|
|
314
|
+
])
|
|
296
315
|
|
|
297
316
|
const handleSendBsv = useCallback(
|
|
298
317
|
async (destination: string) => {
|
package/src/lib/sweeper.ts
CHANGED
|
@@ -32,12 +32,15 @@ function getOwner(output: IndexedOutput): string | undefined {
|
|
|
32
32
|
function buildKeys(
|
|
33
33
|
outputs: IndexedOutput[],
|
|
34
34
|
keyMap: Map<string, PrivateKey>,
|
|
35
|
+
inputs: Pick<IndexedOutput, 'outpoint'>[] = outputs,
|
|
35
36
|
): PrivateKey[] {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const owners = new Map(
|
|
38
|
+
outputs.map((output) => [output.outpoint, getOwner(output)]),
|
|
39
|
+
)
|
|
40
|
+
return inputs.map(({ outpoint }) => {
|
|
41
|
+
const owner = owners.get(outpoint)
|
|
38
42
|
const key = owner ? keyMap.get(owner) : undefined
|
|
39
|
-
if (!key)
|
|
40
|
-
throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`)
|
|
43
|
+
if (!key) throw new Error(`No key for output ${outpoint} (owner: ${owner})`)
|
|
41
44
|
return key
|
|
42
45
|
})
|
|
43
46
|
}
|
|
@@ -95,19 +98,19 @@ export async function executeSweep(params: {
|
|
|
95
98
|
const inputs = await prepareSweepInputs(ctx, batch)
|
|
96
99
|
const cancelResult = await sweepOrdinals.execute(ctx, {
|
|
97
100
|
inputs,
|
|
98
|
-
keys: buildKeys(batch, keys),
|
|
101
|
+
keys: buildKeys(batch, keys, inputs),
|
|
99
102
|
})
|
|
100
|
-
if (cancelResult.error)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (cancelResult.txid) result.listingTxids.push(cancelResult.txid)
|
|
103
|
+
if (cancelResult.error) throw new Error(cancelResult.error)
|
|
104
|
+
const txid = cancelResult.txid?.trim()
|
|
105
|
+
if (!txid) throw new Error('Cancellation returned no transaction ID')
|
|
106
|
+
result.listingTxids.push(txid)
|
|
105
107
|
result.cancelledListings.push(...batch.map((o) => o.outpoint))
|
|
106
108
|
} catch (e) {
|
|
107
109
|
result.errors.push(
|
|
108
110
|
`Listings batch ${b + 1}: ${e instanceof Error ? e.message : String(e)}`,
|
|
109
111
|
)
|
|
110
|
-
|
|
112
|
+
onProgress('Sweep stopped with errors')
|
|
113
|
+
return result
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -118,11 +121,13 @@ export async function executeSweep(params: {
|
|
|
118
121
|
const inputs = await prepareSweepInputs(ctx, funding)
|
|
119
122
|
const bsvResult = await sweepBsv.execute(ctx, {
|
|
120
123
|
inputs,
|
|
121
|
-
keys: buildKeys(funding, keys),
|
|
124
|
+
keys: buildKeys(funding, keys, inputs),
|
|
122
125
|
amount,
|
|
123
126
|
})
|
|
124
|
-
if (bsvResult.error)
|
|
125
|
-
|
|
127
|
+
if (bsvResult.error) throw new Error(bsvResult.error)
|
|
128
|
+
const txid = bsvResult.txid?.trim()
|
|
129
|
+
if (!txid) throw new Error('Sweep returned no transaction ID')
|
|
130
|
+
result.bsvTxid = txid
|
|
126
131
|
} catch (e) {
|
|
127
132
|
result.errors.push(`BSV: ${e instanceof Error ? e.message : String(e)}`)
|
|
128
133
|
}
|
|
@@ -143,15 +148,12 @@ export async function executeSweep(params: {
|
|
|
143
148
|
const inputs = await prepareSweepInputs(ctx, batch)
|
|
144
149
|
const ordResult = await sweepOrdinals.execute(ctx, {
|
|
145
150
|
inputs,
|
|
146
|
-
keys: buildKeys(batch, keys),
|
|
151
|
+
keys: buildKeys(batch, keys, inputs),
|
|
147
152
|
})
|
|
148
|
-
if (ordResult.error)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
break
|
|
153
|
-
}
|
|
154
|
-
if (ordResult.txid) result.ordinalTxids.push(ordResult.txid)
|
|
153
|
+
if (ordResult.error) throw new Error(ordResult.error)
|
|
154
|
+
const txid = ordResult.txid?.trim()
|
|
155
|
+
if (!txid) throw new Error('Sweep returned no transaction ID')
|
|
156
|
+
result.ordinalTxids.push(txid)
|
|
155
157
|
result.sweptOutpoints.push(...batch.map((o) => o.outpoint))
|
|
156
158
|
} catch (e) {
|
|
157
159
|
result.errors.push(
|