@1sat/sweep-ui 0.0.5 → 0.0.7
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 +3 -2
- package/dist/components/SweepApp.d.ts.map +1 -1
- package/dist/components/asset-preview.d.ts +3 -3
- package/dist/components/asset-preview.d.ts.map +1 -1
- package/dist/components/opns-section.d.ts +2 -2
- package/dist/components/opns-section.d.ts.map +1 -1
- package/dist/index.js +45 -21
- package/dist/lib/sweeper.d.ts +2 -2
- package/dist/lib/sweeper.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/SweepApp.tsx +20 -8
- package/src/components/asset-preview.tsx +17 -7
- package/src/components/opns-section.tsx +10 -4
- package/src/lib/sweeper.ts +19 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { LegacyKeys } from "../types";
|
|
2
|
-
import type
|
|
2
|
+
import { type WalletInterface } from "@bsv/sdk";
|
|
3
3
|
export interface SweepAppProps {
|
|
4
4
|
legacyKeys?: LegacyKeys;
|
|
5
5
|
wallet?: WalletInterface | null;
|
|
6
|
+
sweepOnly?: boolean;
|
|
6
7
|
}
|
|
7
|
-
export declare function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: SweepAppProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }: SweepAppProps): import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
//# sourceMappingURL=SweepApp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SweepApp.d.ts","sourceRoot":"","sources":["../../src/components/SweepApp.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAI5D,MAAM,WAAW,aAAa;IAC7B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,QAAQ,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,EAAE,aAAa,2CA4QrG"}
|
|
@@ -6,7 +6,7 @@ export declare function FundingSection({ funding, totalBsv, sweepAmount, onSweep
|
|
|
6
6
|
sweepAmount: number | null;
|
|
7
7
|
onSweepAmountChange: (amount: number | null) => void;
|
|
8
8
|
onSweep: () => void;
|
|
9
|
-
onSend
|
|
9
|
+
onSend?: (destination: string) => void;
|
|
10
10
|
walletConnected: boolean;
|
|
11
11
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
12
12
|
export declare function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelectAll, onDeselectAll, onSweep, onSend, onBurn, walletConnected }: {
|
|
@@ -16,8 +16,8 @@ export declare function OrdinalsSection({ ordinals, selectedOrdinals, onToggle,
|
|
|
16
16
|
onSelectAll: () => void;
|
|
17
17
|
onDeselectAll: () => void;
|
|
18
18
|
onSweep: () => void;
|
|
19
|
-
onSend
|
|
20
|
-
onBurn
|
|
19
|
+
onSend?: (destination: string) => void;
|
|
20
|
+
onBurn?: () => void;
|
|
21
21
|
walletConnected: boolean;
|
|
22
22
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
23
23
|
export declare function Bsv21Section({ tokens }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-preview.d.ts","sourceRoot":"","sources":["../../src/components/asset-preview.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA8CjD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;IACzH,OAAO,EAAE,aAAa,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"asset-preview.d.ts","sourceRoot":"","sources":["../../src/components/asset-preview.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA8CjD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;IACzH,OAAO,EAAE,aAAa,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;CACpN,kDAqCA;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;IAC/I,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;CACjQ,kDAsDA;AA0BD,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,EAAE,CAAA;CAAE,kDAsBlE;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,kDAmBnE;AAED,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,kDAapE"}
|
|
@@ -6,8 +6,8 @@ export declare function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelec
|
|
|
6
6
|
onSelectAll: () => void;
|
|
7
7
|
onDeselectAll: () => void;
|
|
8
8
|
onSweep: () => void;
|
|
9
|
-
onSend
|
|
10
|
-
onBurn
|
|
9
|
+
onSend?: (destination: string) => void;
|
|
10
|
+
onBurn?: () => void;
|
|
11
11
|
walletConnected: boolean;
|
|
12
12
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
13
13
|
//# sourceMappingURL=opns-section.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opns-section.d.ts","sourceRoot":"","sources":["../../src/components/opns-section.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;IACxI,SAAS,EAAE,eAAe,EAAE,CAAC;IAAC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"opns-section.d.ts","sourceRoot":"","sources":["../../src/components/opns-section.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;IACxI,SAAS,EAAE,eAAe,EAAE,CAAC;IAAC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,IAAI,CAAC;IAAC,aAAa,EAAE,MAAM,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAC;CAC9P,kDAyGA"}
|
package/dist/index.js
CHANGED
|
@@ -1144,7 +1144,7 @@ function FundingSection({ funding, totalBsv, sweepAmount, onSweepAmountChange, o
|
|
|
1144
1144
|
/* @__PURE__ */ jsxs3("div", {
|
|
1145
1145
|
className: "mt-3 space-y-2",
|
|
1146
1146
|
children: [
|
|
1147
|
-
/* @__PURE__ */ jsx8(Input, {
|
|
1147
|
+
onSend && /* @__PURE__ */ jsx8(Input, {
|
|
1148
1148
|
type: "text",
|
|
1149
1149
|
placeholder: "Destination address...",
|
|
1150
1150
|
value: address,
|
|
@@ -1154,7 +1154,7 @@ function FundingSection({ funding, totalBsv, sweepAmount, onSweepAmountChange, o
|
|
|
1154
1154
|
/* @__PURE__ */ jsxs3("div", {
|
|
1155
1155
|
className: "flex gap-2",
|
|
1156
1156
|
children: [
|
|
1157
|
-
/* @__PURE__ */ jsxs3(Button, {
|
|
1157
|
+
onSend && /* @__PURE__ */ jsxs3(Button, {
|
|
1158
1158
|
variant: "outline",
|
|
1159
1159
|
size: "sm",
|
|
1160
1160
|
className: "flex-1",
|
|
@@ -1290,7 +1290,7 @@ function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelectAll, on
|
|
|
1290
1290
|
selectedOrdinals.size > 0 && /* @__PURE__ */ jsxs3("div", {
|
|
1291
1291
|
className: "mt-3 space-y-2",
|
|
1292
1292
|
children: [
|
|
1293
|
-
/* @__PURE__ */ jsx8(Input, {
|
|
1293
|
+
onSend && /* @__PURE__ */ jsx8(Input, {
|
|
1294
1294
|
type: "text",
|
|
1295
1295
|
placeholder: "Destination address...",
|
|
1296
1296
|
value: address,
|
|
@@ -1300,7 +1300,7 @@ function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelectAll, on
|
|
|
1300
1300
|
/* @__PURE__ */ jsxs3("div", {
|
|
1301
1301
|
className: "flex gap-2",
|
|
1302
1302
|
children: [
|
|
1303
|
-
/* @__PURE__ */ jsxs3(Button, {
|
|
1303
|
+
onSend && /* @__PURE__ */ jsxs3(Button, {
|
|
1304
1304
|
variant: "outline",
|
|
1305
1305
|
size: "sm",
|
|
1306
1306
|
className: "flex-1",
|
|
@@ -1321,7 +1321,7 @@ function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelectAll, on
|
|
|
1321
1321
|
title: walletConnected ? undefined : "Connect BRC-100 wallet to sweep",
|
|
1322
1322
|
children: "Sweep to Wallet"
|
|
1323
1323
|
}),
|
|
1324
|
-
/* @__PURE__ */ jsx8(Button, {
|
|
1324
|
+
onBurn && /* @__PURE__ */ jsx8(Button, {
|
|
1325
1325
|
size: "sm",
|
|
1326
1326
|
className: "bg-red-600 hover:bg-red-700 text-white",
|
|
1327
1327
|
onClick: () => {
|
|
@@ -1662,7 +1662,7 @@ function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelectAll, onDeselec
|
|
|
1662
1662
|
selectedOpns.size > 0 && /* @__PURE__ */ jsxs4("div", {
|
|
1663
1663
|
className: "mt-3 space-y-2",
|
|
1664
1664
|
children: [
|
|
1665
|
-
/* @__PURE__ */ jsx9(Input, {
|
|
1665
|
+
onSend && /* @__PURE__ */ jsx9(Input, {
|
|
1666
1666
|
type: "text",
|
|
1667
1667
|
placeholder: "Destination address...",
|
|
1668
1668
|
value: address,
|
|
@@ -1672,7 +1672,7 @@ function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelectAll, onDeselec
|
|
|
1672
1672
|
/* @__PURE__ */ jsxs4("div", {
|
|
1673
1673
|
className: "flex gap-2",
|
|
1674
1674
|
children: [
|
|
1675
|
-
/* @__PURE__ */ jsxs4(Button, {
|
|
1675
|
+
onSend && /* @__PURE__ */ jsxs4(Button, {
|
|
1676
1676
|
variant: "outline",
|
|
1677
1677
|
size: "sm",
|
|
1678
1678
|
className: "flex-1",
|
|
@@ -1693,7 +1693,7 @@ function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelectAll, onDeselec
|
|
|
1693
1693
|
title: walletConnected ? undefined : "Connect BRC-100 wallet to sweep",
|
|
1694
1694
|
children: "Sweep to Wallet"
|
|
1695
1695
|
}),
|
|
1696
|
-
/* @__PURE__ */ jsx9(Button, {
|
|
1696
|
+
onBurn && /* @__PURE__ */ jsx9(Button, {
|
|
1697
1697
|
size: "sm",
|
|
1698
1698
|
className: "bg-red-600 hover:bg-red-700 text-white",
|
|
1699
1699
|
onClick: () => {
|
|
@@ -1800,8 +1800,20 @@ import {
|
|
|
1800
1800
|
sweepOrdinals,
|
|
1801
1801
|
sweepBsv21
|
|
1802
1802
|
} from "@1sat/actions";
|
|
1803
|
+
function getOwner(output) {
|
|
1804
|
+
return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
|
|
1805
|
+
}
|
|
1806
|
+
function buildKeys(outputs, keyMap) {
|
|
1807
|
+
return outputs.map((output) => {
|
|
1808
|
+
const owner = getOwner(output);
|
|
1809
|
+
const key = owner ? keyMap.get(owner) : undefined;
|
|
1810
|
+
if (!key)
|
|
1811
|
+
throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`);
|
|
1812
|
+
return key;
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1803
1815
|
async function executeSweep(params) {
|
|
1804
|
-
const { wallet,
|
|
1816
|
+
const { wallet, keys, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
|
|
1805
1817
|
const ctx = createContext2(wallet, { services: getServices(), chain: "main" });
|
|
1806
1818
|
const result = {
|
|
1807
1819
|
ordinalTxids: [],
|
|
@@ -1812,7 +1824,7 @@ async function executeSweep(params) {
|
|
|
1812
1824
|
onProgress(`Sweeping ${funding.length} BSV UTXOs...`);
|
|
1813
1825
|
try {
|
|
1814
1826
|
const inputs = await prepareSweepInputs(ctx, funding);
|
|
1815
|
-
const bsvResult = await sweepBsv.execute(ctx, { inputs,
|
|
1827
|
+
const bsvResult = await sweepBsv.execute(ctx, { inputs, keys: buildKeys(funding, keys), amount });
|
|
1816
1828
|
if (bsvResult.error)
|
|
1817
1829
|
result.errors.push(`BSV: ${bsvResult.error}`);
|
|
1818
1830
|
else if (bsvResult.txid)
|
|
@@ -1825,7 +1837,7 @@ async function executeSweep(params) {
|
|
|
1825
1837
|
onProgress(`Sweeping ${ordinals.length} ordinals...`);
|
|
1826
1838
|
try {
|
|
1827
1839
|
const inputs = await prepareSweepInputs(ctx, ordinals);
|
|
1828
|
-
const ordResult = await sweepOrdinals.execute(ctx, { inputs,
|
|
1840
|
+
const ordResult = await sweepOrdinals.execute(ctx, { inputs, keys: buildKeys(ordinals, keys) });
|
|
1829
1841
|
if (ordResult.error)
|
|
1830
1842
|
result.errors.push(`Ordinals: ${ordResult.error}`);
|
|
1831
1843
|
else if (ordResult.txid)
|
|
@@ -1853,7 +1865,7 @@ async function executeSweep(params) {
|
|
|
1853
1865
|
tokenId,
|
|
1854
1866
|
amount: "0"
|
|
1855
1867
|
})),
|
|
1856
|
-
|
|
1868
|
+
keys: buildKeys(tokens, keys)
|
|
1857
1869
|
});
|
|
1858
1870
|
if (tokenResult.error)
|
|
1859
1871
|
result.errors.push(`BSV-21 (${tokenId.slice(0, 8)}): ${tokenResult.error}`);
|
|
@@ -2052,8 +2064,9 @@ async function legacyBurnOrdinals(params) {
|
|
|
2052
2064
|
}
|
|
2053
2065
|
|
|
2054
2066
|
// src/components/SweepApp.tsx
|
|
2067
|
+
import { PrivateKey as PrivateKey3 } from "@bsv/sdk";
|
|
2055
2068
|
import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2056
|
-
function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
2069
|
+
function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }) {
|
|
2057
2070
|
const [walletConnected, setWalletConnected] = useState5(!!externalWallet);
|
|
2058
2071
|
const [scanning, setScanning] = useState5(false);
|
|
2059
2072
|
const [scanProgress, setScanProgress] = useState5("");
|
|
@@ -2072,6 +2085,17 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2072
2085
|
const resolveWallet = useCallback2(() => {
|
|
2073
2086
|
return externalWallet ?? getWallet();
|
|
2074
2087
|
}, [externalWallet]);
|
|
2088
|
+
const keyMap = useMemo(() => {
|
|
2089
|
+
if (!legacyKeys)
|
|
2090
|
+
return new Map;
|
|
2091
|
+
const map = new Map;
|
|
2092
|
+
map.set(deriveAddress(legacyKeys.payPk), PrivateKey3.fromWif(legacyKeys.payPk));
|
|
2093
|
+
map.set(deriveAddress(legacyKeys.ordPk), PrivateKey3.fromWif(legacyKeys.ordPk));
|
|
2094
|
+
if (legacyKeys.identityPk) {
|
|
2095
|
+
map.set(deriveAddress(legacyKeys.identityPk), PrivateKey3.fromWif(legacyKeys.identityPk));
|
|
2096
|
+
}
|
|
2097
|
+
return map;
|
|
2098
|
+
}, [legacyKeys]);
|
|
2075
2099
|
const addTx = useCallback2((label, txid, error) => {
|
|
2076
2100
|
setTxHistory((prev) => [...prev, { label, txid, timestamp: new Date, error }]);
|
|
2077
2101
|
}, []);
|
|
@@ -2202,7 +2226,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2202
2226
|
if (!wallet || !legacyKeys || !assets)
|
|
2203
2227
|
return;
|
|
2204
2228
|
await runOperation("Sweep BSV", async () => {
|
|
2205
|
-
const result = await executeSweep({ wallet,
|
|
2229
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
|
|
2206
2230
|
if (result.errors.length > 0)
|
|
2207
2231
|
throw new Error(result.errors[0]);
|
|
2208
2232
|
return result.bsvTxid ?? "";
|
|
@@ -2224,7 +2248,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2224
2248
|
if (selected.length === 0)
|
|
2225
2249
|
return;
|
|
2226
2250
|
await runOperation(`Sweep ${selected.length} ordinal${selected.length !== 1 ? "s" : ""}`, async () => {
|
|
2227
|
-
const result = await executeSweep({ wallet,
|
|
2251
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
|
|
2228
2252
|
if (result.errors.length > 0)
|
|
2229
2253
|
throw new Error(result.errors[0]);
|
|
2230
2254
|
return result.ordinalTxids[0] ?? "";
|
|
@@ -2260,7 +2284,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2260
2284
|
if (selected.length === 0)
|
|
2261
2285
|
return;
|
|
2262
2286
|
await runOperation(`Sweep ${selected.length} domain${selected.length !== 1 ? "s" : ""}`, async () => {
|
|
2263
|
-
const result = await executeSweep({ wallet,
|
|
2287
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
|
|
2264
2288
|
if (result.errors.length > 0)
|
|
2265
2289
|
throw new Error(result.errors[0]);
|
|
2266
2290
|
return result.ordinalTxids[0] ?? "";
|
|
@@ -2333,7 +2357,7 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2333
2357
|
sweepAmount,
|
|
2334
2358
|
onSweepAmountChange: setSweepAmount,
|
|
2335
2359
|
onSweep: handleSweepBsv,
|
|
2336
|
-
onSend: handleSendBsv,
|
|
2360
|
+
onSend: sweepOnly ? undefined : handleSendBsv,
|
|
2337
2361
|
walletConnected
|
|
2338
2362
|
}),
|
|
2339
2363
|
tabs.length > 0 && /* @__PURE__ */ jsxs6(Tabs, {
|
|
@@ -2364,8 +2388,8 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2364
2388
|
onSelectAll: handleSelectAllOrdinals,
|
|
2365
2389
|
onDeselectAll: handleDeselectAllOrdinals,
|
|
2366
2390
|
onSweep: handleSweepOrdinals,
|
|
2367
|
-
onSend: handleSendOrdinals,
|
|
2368
|
-
onBurn: handleBurnOrdinals,
|
|
2391
|
+
onSend: sweepOnly ? undefined : handleSendOrdinals,
|
|
2392
|
+
onBurn: sweepOnly ? undefined : handleBurnOrdinals,
|
|
2369
2393
|
walletConnected
|
|
2370
2394
|
})
|
|
2371
2395
|
}),
|
|
@@ -2378,8 +2402,8 @@ function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }) {
|
|
|
2378
2402
|
onSelectAll: handleSelectAllOpns,
|
|
2379
2403
|
onDeselectAll: handleDeselectAllOpns,
|
|
2380
2404
|
onSweep: handleSweepOpns,
|
|
2381
|
-
onSend: handleSendOpns,
|
|
2382
|
-
onBurn: handleBurnOpns,
|
|
2405
|
+
onSend: sweepOnly ? undefined : handleSendOpns,
|
|
2406
|
+
onBurn: sweepOnly ? undefined : handleBurnOpns,
|
|
2383
2407
|
walletConnected
|
|
2384
2408
|
})
|
|
2385
2409
|
}),
|
package/dist/lib/sweeper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IndexedOutput } from "@1sat/types";
|
|
2
|
-
import type
|
|
2
|
+
import { PrivateKey, type WalletInterface } from "@bsv/sdk";
|
|
3
3
|
export interface SweepResult {
|
|
4
4
|
bsvTxid?: string;
|
|
5
5
|
ordinalTxids: string[];
|
|
@@ -8,7 +8,7 @@ export interface SweepResult {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function executeSweep(params: {
|
|
10
10
|
wallet: WalletInterface;
|
|
11
|
-
|
|
11
|
+
keys: Map<string, PrivateKey>;
|
|
12
12
|
funding: IndexedOutput[];
|
|
13
13
|
ordinals: IndexedOutput[];
|
|
14
14
|
bsv21Tokens: IndexedOutput[];
|
|
@@ -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,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"sweeper.d.ts","sourceRoot":"","sources":["../../src/lib/sweeper.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAeD,wBAAsB,YAAY,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,GAAG,OAAO,CAAC,WAAW,CAAC,CAkEvB"}
|
package/package.json
CHANGED
|
@@ -12,16 +12,17 @@ import { executeSweep } from "../lib/sweeper";
|
|
|
12
12
|
import { legacySendBsv, legacySendOrdinals, legacyBurnOrdinals } from "../lib/legacy-send";
|
|
13
13
|
import { getWallet } from "../lib/wallet";
|
|
14
14
|
import type { LegacyKeys } from "../types";
|
|
15
|
-
import type
|
|
15
|
+
import { PrivateKey, type WalletInterface } from "@bsv/sdk";
|
|
16
16
|
|
|
17
17
|
type TabId = "ordinals" | "opns" | "bsv21" | "bsv20" | "locks";
|
|
18
18
|
|
|
19
19
|
export interface SweepAppProps {
|
|
20
20
|
legacyKeys?: LegacyKeys;
|
|
21
21
|
wallet?: WalletInterface | null;
|
|
22
|
+
sweepOnly?: boolean;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: SweepAppProps) {
|
|
25
|
+
export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet, sweepOnly }: SweepAppProps) {
|
|
25
26
|
const [walletConnected, setWalletConnected] = useState(!!externalWallet);
|
|
26
27
|
const [scanning, setScanning] = useState(false);
|
|
27
28
|
const [scanProgress, setScanProgress] = useState("");
|
|
@@ -43,6 +44,17 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
43
44
|
return externalWallet ?? getWallet();
|
|
44
45
|
}, [externalWallet]);
|
|
45
46
|
|
|
47
|
+
const keyMap = useMemo(() => {
|
|
48
|
+
if (!legacyKeys) return new Map<string, PrivateKey>();
|
|
49
|
+
const map = new Map<string, PrivateKey>();
|
|
50
|
+
map.set(deriveAddress(legacyKeys.payPk), PrivateKey.fromWif(legacyKeys.payPk));
|
|
51
|
+
map.set(deriveAddress(legacyKeys.ordPk), PrivateKey.fromWif(legacyKeys.ordPk));
|
|
52
|
+
if (legacyKeys.identityPk) {
|
|
53
|
+
map.set(deriveAddress(legacyKeys.identityPk), PrivateKey.fromWif(legacyKeys.identityPk));
|
|
54
|
+
}
|
|
55
|
+
return map;
|
|
56
|
+
}, [legacyKeys]);
|
|
57
|
+
|
|
46
58
|
const addTx = useCallback((label: string, txid: string, error?: string) => {
|
|
47
59
|
setTxHistory((prev) => [...prev, { label, txid, timestamp: new Date(), error }]);
|
|
48
60
|
}, []);
|
|
@@ -147,7 +159,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
147
159
|
const wallet = resolveWallet();
|
|
148
160
|
if (!wallet || !legacyKeys || !assets) return;
|
|
149
161
|
await runOperation("Sweep BSV", async () => {
|
|
150
|
-
const result = await executeSweep({ wallet,
|
|
162
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: getSelectedFunding(), ordinals: [], bsv21Tokens: [], amount: sweepAmount ?? undefined, onProgress: setSweepProgress });
|
|
151
163
|
if (result.errors.length > 0) throw new Error(result.errors[0]);
|
|
152
164
|
return result.bsvTxid ?? "";
|
|
153
165
|
});
|
|
@@ -167,7 +179,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
167
179
|
const selected = assets.ordinals.filter((o) => selectedOrdinals.has(o.outpoint));
|
|
168
180
|
if (selected.length === 0) return;
|
|
169
181
|
await runOperation(`Sweep ${selected.length} ordinal${selected.length !== 1 ? "s" : ""}`, async () => {
|
|
170
|
-
const result = await executeSweep({ wallet,
|
|
182
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
|
|
171
183
|
if (result.errors.length > 0) throw new Error(result.errors[0]);
|
|
172
184
|
return result.ordinalTxids[0] ?? "";
|
|
173
185
|
});
|
|
@@ -199,7 +211,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
199
211
|
const selected = assets.opnsNames.filter((o) => selectedOpns.has(o.outpoint));
|
|
200
212
|
if (selected.length === 0) return;
|
|
201
213
|
await runOperation(`Sweep ${selected.length} domain${selected.length !== 1 ? "s" : ""}`, async () => {
|
|
202
|
-
const result = await executeSweep({ wallet,
|
|
214
|
+
const result = await executeSweep({ wallet, keys: keyMap, funding: [], ordinals: selected, bsv21Tokens: [], onProgress: setSweepProgress });
|
|
203
215
|
if (result.errors.length > 0) throw new Error(result.errors[0]);
|
|
204
216
|
return result.ordinalTxids[0] ?? "";
|
|
205
217
|
});
|
|
@@ -248,7 +260,7 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
248
260
|
|
|
249
261
|
{assets && !sweeping && (
|
|
250
262
|
<div className="space-y-3">
|
|
251
|
-
<FundingSection funding={assets.funding} totalBsv={assets.totalBsv} sweepAmount={sweepAmount} onSweepAmountChange={setSweepAmount} onSweep={handleSweepBsv} onSend={handleSendBsv} walletConnected={walletConnected} />
|
|
263
|
+
<FundingSection funding={assets.funding} totalBsv={assets.totalBsv} sweepAmount={sweepAmount} onSweepAmountChange={setSweepAmount} onSweep={handleSweepBsv} onSend={sweepOnly ? undefined : handleSendBsv} walletConnected={walletConnected} />
|
|
252
264
|
|
|
253
265
|
{tabs.length > 0 && (
|
|
254
266
|
<Tabs value={activeTab} onValueChange={(v) => setActiveTab(v as TabId)}>
|
|
@@ -261,10 +273,10 @@ export function SweepApp({ legacyKeys: initialKeys, wallet: externalWallet }: Sw
|
|
|
261
273
|
))}
|
|
262
274
|
</TabsList>
|
|
263
275
|
<TabsContent value="ordinals">
|
|
264
|
-
<OrdinalsSection ordinals={assets.ordinals} selectedOrdinals={selectedOrdinals} onToggle={handleToggleOrdinal} onSelectAll={handleSelectAllOrdinals} onDeselectAll={handleDeselectAllOrdinals} onSweep={handleSweepOrdinals} onSend={handleSendOrdinals} onBurn={handleBurnOrdinals} walletConnected={walletConnected} />
|
|
276
|
+
<OrdinalsSection ordinals={assets.ordinals} selectedOrdinals={selectedOrdinals} onToggle={handleToggleOrdinal} onSelectAll={handleSelectAllOrdinals} onDeselectAll={handleDeselectAllOrdinals} onSweep={handleSweepOrdinals} onSend={sweepOnly ? undefined : handleSendOrdinals} onBurn={sweepOnly ? undefined : handleBurnOrdinals} walletConnected={walletConnected} />
|
|
265
277
|
</TabsContent>
|
|
266
278
|
<TabsContent value="opns">
|
|
267
|
-
<OpnsSection opnsNames={assets.opnsNames} selectedOpns={selectedOpns} onToggle={handleToggleOpns} onSelectAll={handleSelectAllOpns} onDeselectAll={handleDeselectAllOpns} onSweep={handleSweepOpns} onSend={handleSendOpns} onBurn={handleBurnOpns} walletConnected={walletConnected} />
|
|
279
|
+
<OpnsSection opnsNames={assets.opnsNames} selectedOpns={selectedOpns} onToggle={handleToggleOpns} onSelectAll={handleSelectAllOpns} onDeselectAll={handleDeselectAllOpns} onSweep={handleSweepOpns} onSend={sweepOnly ? undefined : handleSendOpns} onBurn={sweepOnly ? undefined : handleBurnOpns} walletConnected={walletConnected} />
|
|
268
280
|
</TabsContent>
|
|
269
281
|
<TabsContent value="bsv21"><Bsv21Section tokens={assets.bsv21Tokens} /></TabsContent>
|
|
270
282
|
<TabsContent value="bsv20"><Bsv20Section tokens={assets.bsv20Tokens} /></TabsContent>
|
|
@@ -51,7 +51,7 @@ function OrdinalCard({ ordinal, isSelected, onToggle }: { ordinal: EnrichedOrdin
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function FundingSection({ funding, totalBsv, sweepAmount, onSweepAmountChange, onSweep, onSend, walletConnected }: {
|
|
54
|
-
funding: IndexedOutput[]; totalBsv: number; sweepAmount: number | null; onSweepAmountChange: (amount: number | null) => void; onSweep: () => void; onSend
|
|
54
|
+
funding: IndexedOutput[]; totalBsv: number; sweepAmount: number | null; onSweepAmountChange: (amount: number | null) => void; onSweep: () => void; onSend?: (destination: string) => void; walletConnected: boolean;
|
|
55
55
|
}) {
|
|
56
56
|
const [address, setAddress] = useState("");
|
|
57
57
|
if (funding.length === 0) return null;
|
|
@@ -77,9 +77,13 @@ export function FundingSection({ funding, totalBsv, sweepAmount, onSweepAmountCh
|
|
|
77
77
|
<Button variant="outline" size="sm" className="h-9 text-xs" onClick={() => onSweepAmountChange(null)} disabled={isMax}>Max</Button>
|
|
78
78
|
</div>
|
|
79
79
|
<div className="mt-3 space-y-2">
|
|
80
|
-
|
|
80
|
+
{onSend && (
|
|
81
|
+
<Input type="text" placeholder="Destination address..." value={address} onChange={(e) => setAddress(e.target.value)} className="font-mono text-xs" />
|
|
82
|
+
)}
|
|
81
83
|
<div className="flex gap-2">
|
|
82
|
-
|
|
84
|
+
{onSend && (
|
|
85
|
+
<Button variant="outline" size="sm" className="flex-1" disabled={!address.trim()} onClick={() => onSend(address.trim())}>Send {displayAmount} sats</Button>
|
|
86
|
+
)}
|
|
83
87
|
<Button size="sm" className="flex-1" onClick={onSweep} disabled={!walletConnected} title={walletConnected ? undefined : "Connect BRC-100 wallet to sweep"}>Sweep to Wallet</Button>
|
|
84
88
|
</div>
|
|
85
89
|
</div>
|
|
@@ -88,7 +92,7 @@ export function FundingSection({ funding, totalBsv, sweepAmount, onSweepAmountCh
|
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
export function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelectAll, onDeselectAll, onSweep, onSend, onBurn, walletConnected }: {
|
|
91
|
-
ordinals: EnrichedOrdinal[]; selectedOrdinals: Set<string>; onToggle: (outpoint: string) => void; onSelectAll: () => void; onDeselectAll: () => void; onSweep: () => void; onSend
|
|
95
|
+
ordinals: EnrichedOrdinal[]; selectedOrdinals: Set<string>; onToggle: (outpoint: string) => void; onSelectAll: () => void; onDeselectAll: () => void; onSweep: () => void; onSend?: (destination: string) => void; onBurn?: () => void; walletConnected: boolean;
|
|
92
96
|
}) {
|
|
93
97
|
const [page, setPage] = useState(0);
|
|
94
98
|
const [address, setAddress] = useState("");
|
|
@@ -127,11 +131,17 @@ export function OrdinalsSection({ ordinals, selectedOrdinals, onToggle, onSelect
|
|
|
127
131
|
)}
|
|
128
132
|
{selectedOrdinals.size > 0 && (
|
|
129
133
|
<div className="mt-3 space-y-2">
|
|
130
|
-
|
|
134
|
+
{onSend && (
|
|
135
|
+
<Input type="text" placeholder="Destination address..." value={address} onChange={(e) => setAddress(e.target.value)} className="font-mono text-xs" />
|
|
136
|
+
)}
|
|
131
137
|
<div className="flex gap-2">
|
|
132
|
-
|
|
138
|
+
{onSend && (
|
|
139
|
+
<Button variant="outline" size="sm" className="flex-1" disabled={!address.trim()} onClick={() => onSend(address.trim())}>Send {selectedOrdinals.size} Ordinal{selectedOrdinals.size !== 1 ? "s" : ""}</Button>
|
|
140
|
+
)}
|
|
133
141
|
<Button size="sm" className="flex-1" onClick={onSweep} disabled={!walletConnected} title={walletConnected ? undefined : "Connect BRC-100 wallet to sweep"}>Sweep to Wallet</Button>
|
|
134
|
-
|
|
142
|
+
{onBurn && (
|
|
143
|
+
<Button size="sm" className="bg-red-600 hover:bg-red-700 text-white" onClick={() => { if (window.confirm(`Permanently burn ${selectedOrdinals.size} ordinal${selectedOrdinals.size !== 1 ? "s" : ""}? This cannot be undone.`)) onBurn(); }}>Burn</Button>
|
|
144
|
+
)}
|
|
135
145
|
</div>
|
|
136
146
|
</div>
|
|
137
147
|
)}
|
|
@@ -5,7 +5,7 @@ import type { EnrichedOrdinal } from "../lib/scanner";
|
|
|
5
5
|
import { getServices } from "../lib/services";
|
|
6
6
|
|
|
7
7
|
export function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelectAll, onDeselectAll, onSweep, onSend, onBurn, walletConnected }: {
|
|
8
|
-
opnsNames: EnrichedOrdinal[]; selectedOpns: Set<string>; onToggle: (outpoint: string) => void; onSelectAll: () => void; onDeselectAll: () => void; onSweep: () => void; onSend
|
|
8
|
+
opnsNames: EnrichedOrdinal[]; selectedOpns: Set<string>; onToggle: (outpoint: string) => void; onSelectAll: () => void; onDeselectAll: () => void; onSweep: () => void; onSend?: (destination: string) => void; onBurn?: () => void; walletConnected: boolean;
|
|
9
9
|
}) {
|
|
10
10
|
const [address, setAddress] = useState("");
|
|
11
11
|
const [resolvedNames, setResolvedNames] = useState<Map<string, string>>(new Map());
|
|
@@ -95,11 +95,17 @@ export function OpnsSection({ opnsNames, selectedOpns, onToggle, onSelectAll, on
|
|
|
95
95
|
</div>
|
|
96
96
|
{selectedOpns.size > 0 && (
|
|
97
97
|
<div className="mt-3 space-y-2">
|
|
98
|
-
|
|
98
|
+
{onSend && (
|
|
99
|
+
<Input type="text" placeholder="Destination address..." value={address} onChange={(e) => setAddress(e.target.value)} className="font-mono text-xs" />
|
|
100
|
+
)}
|
|
99
101
|
<div className="flex gap-2">
|
|
100
|
-
|
|
102
|
+
{onSend && (
|
|
103
|
+
<Button variant="outline" size="sm" className="flex-1" disabled={!address.trim()} onClick={() => onSend(address.trim())}>Send {selectedOpns.size} Domain{selectedOpns.size !== 1 ? "s" : ""}</Button>
|
|
104
|
+
)}
|
|
101
105
|
<Button size="sm" className="flex-1" onClick={onSweep} disabled={!walletConnected} title={walletConnected ? undefined : "Connect BRC-100 wallet to sweep"}>Sweep to Wallet</Button>
|
|
102
|
-
|
|
106
|
+
{onBurn && (
|
|
107
|
+
<Button size="sm" className="bg-red-600 hover:bg-red-700 text-white" onClick={() => { if (window.confirm(`Permanently burn ${selectedOpns.size} domain${selectedOpns.size !== 1 ? "s" : ""}? This cannot be undone.`)) onBurn(); }}>Burn</Button>
|
|
108
|
+
)}
|
|
103
109
|
</div>
|
|
104
110
|
</div>
|
|
105
111
|
)}
|
package/src/lib/sweeper.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
sweepBsv21,
|
|
7
7
|
} from "@1sat/actions";
|
|
8
8
|
import type { IndexedOutput } from "@1sat/types";
|
|
9
|
-
import type
|
|
9
|
+
import { PrivateKey, type WalletInterface } from "@bsv/sdk";
|
|
10
10
|
import { getServices } from "./services";
|
|
11
11
|
|
|
12
12
|
export interface SweepResult {
|
|
@@ -16,16 +16,29 @@ export interface SweepResult {
|
|
|
16
16
|
errors: string[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function getOwner(output: IndexedOutput): string | undefined {
|
|
20
|
+
return output.events?.find((e) => e.startsWith("own:"))?.slice(4);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function buildKeys(outputs: IndexedOutput[], keyMap: Map<string, PrivateKey>): PrivateKey[] {
|
|
24
|
+
return outputs.map((output) => {
|
|
25
|
+
const owner = getOwner(output);
|
|
26
|
+
const key = owner ? keyMap.get(owner) : undefined;
|
|
27
|
+
if (!key) throw new Error(`No key for output ${output.outpoint} (owner: ${owner})`);
|
|
28
|
+
return key;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
export async function executeSweep(params: {
|
|
20
33
|
wallet: WalletInterface;
|
|
21
|
-
|
|
34
|
+
keys: Map<string, PrivateKey>;
|
|
22
35
|
funding: IndexedOutput[];
|
|
23
36
|
ordinals: IndexedOutput[];
|
|
24
37
|
bsv21Tokens: IndexedOutput[];
|
|
25
38
|
amount?: number;
|
|
26
39
|
onProgress: (stage: string) => void;
|
|
27
40
|
}): Promise<SweepResult> {
|
|
28
|
-
const { wallet,
|
|
41
|
+
const { wallet, keys, funding, ordinals, bsv21Tokens, amount, onProgress } = params;
|
|
29
42
|
const ctx = createContext(wallet, { services: getServices(), chain: "main" });
|
|
30
43
|
|
|
31
44
|
const result: SweepResult = {
|
|
@@ -38,7 +51,7 @@ export async function executeSweep(params: {
|
|
|
38
51
|
onProgress(`Sweeping ${funding.length} BSV UTXOs...`);
|
|
39
52
|
try {
|
|
40
53
|
const inputs = await prepareSweepInputs(ctx, funding);
|
|
41
|
-
const bsvResult = await sweepBsv.execute(ctx, { inputs,
|
|
54
|
+
const bsvResult = await sweepBsv.execute(ctx, { inputs, keys: buildKeys(funding, keys), amount });
|
|
42
55
|
if (bsvResult.error) result.errors.push(`BSV: ${bsvResult.error}`);
|
|
43
56
|
else if (bsvResult.txid) result.bsvTxid = bsvResult.txid;
|
|
44
57
|
} catch (e) {
|
|
@@ -50,7 +63,7 @@ export async function executeSweep(params: {
|
|
|
50
63
|
onProgress(`Sweeping ${ordinals.length} ordinals...`);
|
|
51
64
|
try {
|
|
52
65
|
const inputs = await prepareSweepInputs(ctx, ordinals);
|
|
53
|
-
const ordResult = await sweepOrdinals.execute(ctx, { inputs,
|
|
66
|
+
const ordResult = await sweepOrdinals.execute(ctx, { inputs, keys: buildKeys(ordinals, keys) });
|
|
54
67
|
if (ordResult.error) result.errors.push(`Ordinals: ${ordResult.error}`);
|
|
55
68
|
else if (ordResult.txid) result.ordinalTxids.push(ordResult.txid);
|
|
56
69
|
} catch (e) {
|
|
@@ -78,7 +91,7 @@ export async function executeSweep(params: {
|
|
|
78
91
|
tokenId,
|
|
79
92
|
amount: "0",
|
|
80
93
|
})),
|
|
81
|
-
|
|
94
|
+
keys: buildKeys(tokens, keys),
|
|
82
95
|
});
|
|
83
96
|
if (tokenResult.error) result.errors.push(`BSV-21 (${tokenId.slice(0, 8)}): ${tokenResult.error}`);
|
|
84
97
|
else if (tokenResult.txid) result.bsv21Txids.push(tokenResult.txid);
|