@1sat/cli 0.0.18 → 0.0.20
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/package.json +3 -3
- package/src/commands/opns.ts +2 -1
- package/src/commands/ordinals.ts +2 -1
- package/src/commands/sweep.ts +25 -41
- package/src/commands/tokens.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "CLI for 1Sat Ordinals SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/cli.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"keywords": ["1sat", "bsv", "ordinals", "cli"],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@1sat/actions": "0.0.
|
|
20
|
-
"@1sat/client": "0.0.
|
|
19
|
+
"@1sat/actions": "0.0.82",
|
|
20
|
+
"@1sat/client": "0.0.20",
|
|
21
21
|
"@1sat/types": "0.0.14",
|
|
22
22
|
"@1sat/wallet-node": ">=0.0.13",
|
|
23
23
|
"@bsv/sdk": "^2.0.6",
|
package/src/commands/opns.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
getDisplayValue,
|
|
8
9
|
getOpnsNames,
|
|
9
10
|
opnsDeregister as opnsDeregisterAction,
|
|
10
11
|
opnsRegister as opnsRegisterAction,
|
|
@@ -149,7 +150,7 @@ async function opnsLookup(_args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
for (const o of result.outputs) {
|
|
152
|
-
const nameTag = o
|
|
153
|
+
const nameTag = getDisplayValue(o, 'name', 'name') ?? ''
|
|
153
154
|
const publishedTag = o.tags?.find((t) => t === 'opns:published')
|
|
154
155
|
const status = publishedTag ? 'registered' : 'unregistered'
|
|
155
156
|
|
package/src/commands/ordinals.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { basename, extname } from 'node:path'
|
|
|
7
7
|
import {
|
|
8
8
|
cancelListing,
|
|
9
9
|
deriveDepositAddresses,
|
|
10
|
+
getDisplayValue,
|
|
10
11
|
getOrdinals,
|
|
11
12
|
inscribe,
|
|
12
13
|
listOrdinal,
|
|
@@ -83,7 +84,7 @@ async function ordinalsList(_args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
83
84
|
o.tags?.find((t) => t.startsWith('type:'))?.slice(5) ?? 'unknown'
|
|
84
85
|
const originTag =
|
|
85
86
|
o.tags?.find((t) => t.startsWith('origin:'))?.slice(7) ?? ''
|
|
86
|
-
const nameTag = o
|
|
87
|
+
const nameTag = getDisplayValue(o, 'name', 'name') ?? ''
|
|
87
88
|
|
|
88
89
|
console.log(
|
|
89
90
|
` ${formatValue(o.outpoint)} ${formatLabel(typeTag)}${nameTag ? ` ${nameTag}` : ''}${originTag ? ` origin:${originTag}` : ''}`,
|
package/src/commands/sweep.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
prepareSweepInputs,
|
|
9
|
-
|
|
9
|
+
scanAddress,
|
|
10
10
|
sweepBsv,
|
|
11
11
|
sweepBsv21,
|
|
12
12
|
sweepOrdinals,
|
|
@@ -65,7 +65,7 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
65
65
|
fatal('Services required for sweep scan')
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const result = await
|
|
68
|
+
const result = await scanAddress(ctx.services, address)
|
|
69
69
|
|
|
70
70
|
if (opts.json) {
|
|
71
71
|
output(result, opts)
|
|
@@ -81,7 +81,7 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
81
81
|
)
|
|
82
82
|
for (const f of result.funding) {
|
|
83
83
|
console.log(
|
|
84
|
-
` ${formatValue(f.outpoint)} ${formatLabel(`${f.satoshis} sats`)}`,
|
|
84
|
+
` ${formatValue(f.outpoint)} ${formatLabel(`${f.satoshis ?? 0} sats`)}`,
|
|
85
85
|
)
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -101,7 +101,7 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
101
101
|
if (result.bsv21Tokens.length > 0) {
|
|
102
102
|
for (const t of result.bsv21Tokens) {
|
|
103
103
|
console.log(
|
|
104
|
-
` ${formatValue(t.symbol ?? t.tokenId.slice(0, 12))} ${formatLabel('amount:')} ${formatValue(t.totalAmount)} ${formatLabel('UTXOs:')} ${t.
|
|
104
|
+
` ${formatValue(t.symbol ?? t.tokenId.slice(0, 12))} ${formatLabel('amount:')} ${formatValue(t.totalAmount.toString())} ${formatLabel('UTXOs:')} ${t.outputs.length} ${formatLabel('dec:')} ${t.decimals}`,
|
|
105
105
|
)
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -110,13 +110,13 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
110
110
|
`\n ${formatLabel('RUN Tokens:')} ${result.run.length}`,
|
|
111
111
|
)
|
|
112
112
|
if (result.run.length > 0) {
|
|
113
|
-
const runSats = result.run.reduce((sum, r) => sum + r.satoshis, 0)
|
|
113
|
+
const runSats = result.run.reduce((sum, r) => sum + (r.satoshis ?? 0), 0)
|
|
114
114
|
console.log(
|
|
115
115
|
` ${formatLabel('Total locked:')} ${formatValue(runSats)} satoshis (not sweepable)`,
|
|
116
116
|
)
|
|
117
117
|
for (const r of result.run) {
|
|
118
118
|
console.log(
|
|
119
|
-
` ${formatValue(r.outpoint)} ${formatLabel(`${r.satoshis} sats`)}`,
|
|
119
|
+
` ${formatValue(r.outpoint)} ${formatLabel(`${r.satoshis ?? 0} sats`)}`,
|
|
120
120
|
)
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -124,7 +124,7 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
124
124
|
const total =
|
|
125
125
|
result.funding.length +
|
|
126
126
|
result.ordinals.length +
|
|
127
|
-
result.bsv21Tokens.reduce((n, t) => n + t.
|
|
127
|
+
result.bsv21Tokens.reduce((n, t) => n + t.outputs.length, 0)
|
|
128
128
|
console.log(`\n ${total} sweepable UTXO(s) found.`)
|
|
129
129
|
if (result.run.length > 0) {
|
|
130
130
|
console.log(` ${result.run.length} RUN token output(s) excluded.`)
|
|
@@ -157,12 +157,11 @@ async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
157
157
|
fatal('Services required for sweep import')
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
const scan = await scanAddressUtxos(ctx.services, address)
|
|
160
|
+
const scan = await scanAddress(ctx.services, address)
|
|
162
161
|
|
|
163
162
|
const hasFunding = scan.funding.length > 0
|
|
164
163
|
const hasOrdinals = scan.ordinals.length > 0
|
|
165
|
-
const hasTokens = scan.bsv21Tokens.length > 0
|
|
164
|
+
const hasTokens = scan.bsv21Tokens.some((t) => t.isActive && t.outputs.length > 0)
|
|
166
165
|
|
|
167
166
|
if (!hasFunding && !hasOrdinals && !hasTokens) {
|
|
168
167
|
if (scan.run.length > 0) {
|
|
@@ -171,16 +170,17 @@ async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
171
170
|
fatal(`No UTXOs found at ${address}`)
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
// Summarize what will be swept
|
|
175
173
|
const parts: string[] = []
|
|
176
174
|
if (hasFunding)
|
|
177
175
|
parts.push(`${scan.totalFundingSats} sats (${scan.funding.length} UTXOs)`)
|
|
178
176
|
if (hasOrdinals) parts.push(`${scan.ordinals.length} ordinal(s)`)
|
|
179
177
|
if (hasTokens) {
|
|
180
178
|
for (const t of scan.bsv21Tokens) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
if (t.isActive && t.outputs.length > 0) {
|
|
180
|
+
parts.push(
|
|
181
|
+
`${t.totalAmount} ${t.symbol ?? t.tokenId.slice(0, 12)} token(s)`,
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
if (scan.run.length > 0) {
|
|
@@ -198,18 +198,9 @@ async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
198
198
|
|
|
199
199
|
const txids: string[] = []
|
|
200
200
|
|
|
201
|
-
// Convert SweepInput to IndexedOutput shape for prepareSweepInputs
|
|
202
|
-
const toIndexed = (items: Array<{ outpoint: string; satoshis: number }>) =>
|
|
203
|
-
items.map((item) => ({
|
|
204
|
-
outpoint: item.outpoint,
|
|
205
|
-
satoshis: item.satoshis,
|
|
206
|
-
score: 0,
|
|
207
|
-
}))
|
|
208
|
-
|
|
209
201
|
// Sweep BSV funding UTXOs
|
|
210
202
|
if (hasFunding) {
|
|
211
|
-
const inputs = await prepareSweepInputs(ctx,
|
|
212
|
-
|
|
203
|
+
const inputs = await prepareSweepInputs(ctx, scan.funding)
|
|
213
204
|
const result = await sweepBsv.execute(ctx, { inputs, wif })
|
|
214
205
|
if (result.error) {
|
|
215
206
|
fatal(`BSV sweep failed: ${result.error}`)
|
|
@@ -219,8 +210,7 @@ async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
219
210
|
|
|
220
211
|
// Sweep ordinals
|
|
221
212
|
if (hasOrdinals) {
|
|
222
|
-
const inputs = await prepareSweepInputs(ctx,
|
|
223
|
-
|
|
213
|
+
const inputs = await prepareSweepInputs(ctx, scan.ordinals)
|
|
224
214
|
const result = await sweepOrdinals.execute(ctx, { inputs, wif })
|
|
225
215
|
if (result.error) {
|
|
226
216
|
fatal(`Ordinals sweep failed: ${result.error}`)
|
|
@@ -228,27 +218,21 @@ async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
228
218
|
if (result.txid) txids.push(result.txid)
|
|
229
219
|
}
|
|
230
220
|
|
|
231
|
-
// Sweep BSV-21 tokens (one sweep per tokenId)
|
|
221
|
+
// Sweep BSV-21 tokens (one sweep per active tokenId)
|
|
232
222
|
if (hasTokens) {
|
|
233
|
-
for (const
|
|
234
|
-
|
|
235
|
-
ctx,
|
|
236
|
-
toIndexed(tokenGroup.inputs),
|
|
237
|
-
)
|
|
223
|
+
for (const token of scan.bsv21Tokens) {
|
|
224
|
+
if (!token.isActive || token.outputs.length === 0) continue
|
|
238
225
|
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
tokenId:
|
|
242
|
-
amount:
|
|
226
|
+
const inputs = token.outputs.map((out) => ({
|
|
227
|
+
outpoint: out.outpoint,
|
|
228
|
+
tokenId: token.tokenId,
|
|
229
|
+
amount: token.amounts.get(out.outpoint) ?? '0',
|
|
243
230
|
}))
|
|
244
231
|
|
|
245
|
-
const result = await sweepBsv21.execute(ctx, {
|
|
246
|
-
inputs: sweepInputs,
|
|
247
|
-
wif,
|
|
248
|
-
})
|
|
232
|
+
const result = await sweepBsv21.execute(ctx, { inputs, wif })
|
|
249
233
|
if (result.error) {
|
|
250
234
|
fatal(
|
|
251
|
-
`Token sweep failed (${
|
|
235
|
+
`Token sweep failed (${token.symbol ?? token.tokenId.slice(0, 12)}): ${result.error}`,
|
|
252
236
|
)
|
|
253
237
|
}
|
|
254
238
|
if (result.txid) txids.push(result.txid)
|
package/src/commands/tokens.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
getBsv21Balances,
|
|
7
|
+
getDisplayValue,
|
|
7
8
|
listTokens,
|
|
8
9
|
purchaseBsv21,
|
|
9
10
|
sendBsv21,
|
|
@@ -93,8 +94,8 @@ async function tokenList(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
93
94
|
|
|
94
95
|
const filtered = tokenId
|
|
95
96
|
? outputs.filter((o) => {
|
|
96
|
-
const idTag = o.tags?.find((t) => t.startsWith('
|
|
97
|
-
return idTag && idTag.slice(
|
|
97
|
+
const idTag = o.tags?.find((t) => t.startsWith('bsv21:'))
|
|
98
|
+
return idTag && idTag.slice(6) === tokenId
|
|
98
99
|
})
|
|
99
100
|
: outputs
|
|
100
101
|
|
|
@@ -115,9 +116,9 @@ async function tokenList(args: string[], opts: GlobalFlags): Promise<void> {
|
|
|
115
116
|
|
|
116
117
|
for (const o of filtered) {
|
|
117
118
|
const idTag =
|
|
118
|
-
o.tags?.find((t) => t.startsWith('
|
|
119
|
+
o.tags?.find((t) => t.startsWith('bsv21:'))?.slice(6) ?? 'unknown'
|
|
119
120
|
const amtTag = o.tags?.find((t) => t.startsWith('amt:'))?.slice(4) ?? '0'
|
|
120
|
-
const symTag = o
|
|
121
|
+
const symTag = getDisplayValue(o, 'sym', 'sym') ?? ''
|
|
121
122
|
|
|
122
123
|
console.log(
|
|
123
124
|
` ${formatValue(o.outpoint)} ${formatLabel(symTag || idTag.slice(0, 12))} ${formatLabel('amt:')} ${formatValue(amtTag)}`,
|