@1sat/cli 0.0.71 → 0.0.73
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 +47 -47
- package/src/commands/opns.ts +118 -2
- package/src/help.ts +26 -0
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@1sat/cli",
|
|
3
|
+
"version": "0.0.73",
|
|
4
|
+
"description": "CLI for 1Sat Ordinals SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/cli.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"1sat": "./src/cli.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"scripts"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"preinstall": "node scripts/check-bun.cjs",
|
|
16
|
+
"build": "bun build ./src/cli.ts --compile --outfile=bin/1sat --external pg --external pg-native --external pg-query-stream --external tedious --external oracledb --external mysql --external mariadb --external 'mariadb/*'",
|
|
17
|
+
"dev": "bun run src/cli.ts",
|
|
18
|
+
"lint": "biome check src",
|
|
19
|
+
"test": "bun test"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"1sat",
|
|
23
|
+
"bsv",
|
|
24
|
+
"ordinals",
|
|
25
|
+
"cli"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@1sat/actions": "0.0.169",
|
|
30
|
+
"@1sat/client": "0.0.40",
|
|
31
|
+
"@1sat/types": "0.0.33",
|
|
32
|
+
"@1sat/wallet-node": "0.0.54",
|
|
33
|
+
"@1sat/wallet-server": "0.0.23",
|
|
34
|
+
"@bsv/sdk": "^2.0.13",
|
|
35
|
+
"@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.1.21-parity-fix.2",
|
|
36
|
+
"chalk": "^5.0.0",
|
|
37
|
+
"@clack/prompts": "^0.8.0",
|
|
38
|
+
"bitcoin-backup": "^0.0.11",
|
|
39
|
+
"dotenv": "^17.0.0",
|
|
40
|
+
"evlog": "^2.10.0",
|
|
41
|
+
"knex": "^3.1.0",
|
|
42
|
+
"@bopen-io/messagebox-server": "^1.1.5",
|
|
43
|
+
"pg": "^8.11.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/bun": "^1.3.9",
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
|
+
}
|
|
49
49
|
}
|
package/src/commands/opns.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpNS commands - register, deregister, lookup.
|
|
2
|
+
* OpNS commands - register, deregister, lookup, mine.
|
|
3
3
|
*
|
|
4
|
-
* Manage OpNS name identity bindings.
|
|
4
|
+
* Manage OpNS name identity bindings and paid mining jobs.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
getDisplayValue,
|
|
9
9
|
getOpnsNames,
|
|
10
10
|
opnsDeregister as opnsDeregisterAction,
|
|
11
|
+
opnsMine as opnsMineAction,
|
|
12
|
+
opnsMineRefund as opnsMineRefundAction,
|
|
13
|
+
opnsMineStatus as opnsMineStatusAction,
|
|
11
14
|
opnsRegister as opnsRegisterAction,
|
|
12
15
|
} from '@1sat/actions'
|
|
13
16
|
import { confirm, isCancel } from '@clack/prompts'
|
|
@@ -31,6 +34,12 @@ export async function handleOpnsCommand(
|
|
|
31
34
|
return opnsDeregister(rest, opts)
|
|
32
35
|
case 'lookup':
|
|
33
36
|
return opnsLookup(rest, opts)
|
|
37
|
+
case 'mine':
|
|
38
|
+
return opnsMine(rest, opts)
|
|
39
|
+
case 'mine-status':
|
|
40
|
+
return opnsMineStatus(rest, opts)
|
|
41
|
+
case 'mine-refund':
|
|
42
|
+
return opnsMineRefund(rest, opts)
|
|
34
43
|
default:
|
|
35
44
|
printCommandHelp('opns', opts.json)
|
|
36
45
|
if (subcommand && subcommand !== 'help') {
|
|
@@ -126,6 +135,113 @@ async function opnsDeregister(
|
|
|
126
135
|
}
|
|
127
136
|
}
|
|
128
137
|
|
|
138
|
+
async function opnsMine(args: string[], opts: GlobalFlags): Promise<void> {
|
|
139
|
+
const name = extractFlag(args, '--name')
|
|
140
|
+
const serviceUrl = extractFlag(args, '--service')
|
|
141
|
+
const receiveAddress = extractFlag(args, '--receive-address')
|
|
142
|
+
const timeout = extractFlag(args, '--timeout')
|
|
143
|
+
|
|
144
|
+
if (!name) fatal('Missing --name <name>')
|
|
145
|
+
if (!serviceUrl) fatal('Missing --service <url>')
|
|
146
|
+
|
|
147
|
+
if (!opts.yes) {
|
|
148
|
+
const ok = await confirm({
|
|
149
|
+
message: `Pay ${serviceUrl} to mine "${name}"? The full price is charged upfront.`,
|
|
150
|
+
})
|
|
151
|
+
if (isCancel(ok) || !ok) {
|
|
152
|
+
fatal('Mine cancelled.')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const privateKey = await loadKey()
|
|
157
|
+
const { ctx, destroy } = await loadContext(privateKey, {
|
|
158
|
+
chain: opts.chain,
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const result = await opnsMineAction.execute(ctx, {
|
|
163
|
+
name,
|
|
164
|
+
serviceUrl,
|
|
165
|
+
receiveAddress: receiveAddress ?? undefined,
|
|
166
|
+
timeoutMs: timeout ? Number.parseInt(timeout, 10) : undefined,
|
|
167
|
+
})
|
|
168
|
+
if (result.error && !result.jobId) {
|
|
169
|
+
fatal(result.error)
|
|
170
|
+
}
|
|
171
|
+
output(
|
|
172
|
+
opts.json
|
|
173
|
+
? result
|
|
174
|
+
: {
|
|
175
|
+
jobId: result.jobId,
|
|
176
|
+
state: result.state,
|
|
177
|
+
txid: result.txid,
|
|
178
|
+
...(result.error ? { error: result.error } : {}),
|
|
179
|
+
},
|
|
180
|
+
opts,
|
|
181
|
+
)
|
|
182
|
+
} finally {
|
|
183
|
+
await destroy()
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function opnsMineStatus(
|
|
188
|
+
args: string[],
|
|
189
|
+
opts: GlobalFlags,
|
|
190
|
+
): Promise<void> {
|
|
191
|
+
const jobId = extractFlag(args, '--job')
|
|
192
|
+
const serviceUrl = extractFlag(args, '--service')
|
|
193
|
+
|
|
194
|
+
if (!jobId) fatal('Missing --job <paymentTxid>')
|
|
195
|
+
if (!serviceUrl) fatal('Missing --service <url>')
|
|
196
|
+
|
|
197
|
+
const privateKey = await loadKey()
|
|
198
|
+
const { ctx, destroy } = await loadContext(privateKey, {
|
|
199
|
+
chain: opts.chain,
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const result = await opnsMineStatusAction.execute(ctx, {
|
|
204
|
+
jobId,
|
|
205
|
+
serviceUrl,
|
|
206
|
+
})
|
|
207
|
+
if (result.error && !result.state) {
|
|
208
|
+
fatal(result.error)
|
|
209
|
+
}
|
|
210
|
+
output(result, opts)
|
|
211
|
+
} finally {
|
|
212
|
+
await destroy()
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function opnsMineRefund(
|
|
217
|
+
args: string[],
|
|
218
|
+
opts: GlobalFlags,
|
|
219
|
+
): Promise<void> {
|
|
220
|
+
const jobId = extractFlag(args, '--job')
|
|
221
|
+
const serviceUrl = extractFlag(args, '--service')
|
|
222
|
+
|
|
223
|
+
if (!jobId) fatal('Missing --job <paymentTxid>')
|
|
224
|
+
if (!serviceUrl) fatal('Missing --service <url>')
|
|
225
|
+
|
|
226
|
+
const privateKey = await loadKey()
|
|
227
|
+
const { ctx, destroy } = await loadContext(privateKey, {
|
|
228
|
+
chain: opts.chain,
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const result = await opnsMineRefundAction.execute(ctx, {
|
|
233
|
+
jobId,
|
|
234
|
+
serviceUrl,
|
|
235
|
+
})
|
|
236
|
+
if (result.error) {
|
|
237
|
+
fatal(result.error)
|
|
238
|
+
}
|
|
239
|
+
output(result, opts)
|
|
240
|
+
} finally {
|
|
241
|
+
await destroy()
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
129
245
|
async function opnsLookup(_args: string[], opts: GlobalFlags): Promise<void> {
|
|
130
246
|
const privateKey = await loadKey()
|
|
131
247
|
const { ctx, destroy } = await loadContext(privateKey, {
|
package/src/help.ts
CHANGED
|
@@ -503,6 +503,32 @@ export const COMMANDS: CommandSpec[] = [
|
|
|
503
503
|
args: [{ flag: '--outpoint', values: '<txid.vout>', required: true }],
|
|
504
504
|
},
|
|
505
505
|
{ name: 'lookup', description: 'List OpNS names from wallet' },
|
|
506
|
+
{
|
|
507
|
+
name: 'mine',
|
|
508
|
+
description: 'Pay a mine service to mine a name into this wallet',
|
|
509
|
+
args: [
|
|
510
|
+
{ flag: '--name', values: '<name>', required: true },
|
|
511
|
+
{ flag: '--service', values: '<url>', required: true },
|
|
512
|
+
{ flag: '--receive-address', values: '<addr>' },
|
|
513
|
+
{ flag: '--timeout', values: '<ms>' },
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: 'mine-status',
|
|
518
|
+
description: 'Check a mine job; internalize the name if complete',
|
|
519
|
+
args: [
|
|
520
|
+
{ flag: '--job', values: '<paymentTxid>', required: true },
|
|
521
|
+
{ flag: '--service', values: '<url>', required: true },
|
|
522
|
+
],
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: 'mine-refund',
|
|
526
|
+
description: 'Claim the remaining funds of a failed mine job',
|
|
527
|
+
args: [
|
|
528
|
+
{ flag: '--job', values: '<paymentTxid>', required: true },
|
|
529
|
+
{ flag: '--service', values: '<url>', required: true },
|
|
530
|
+
],
|
|
531
|
+
},
|
|
506
532
|
],
|
|
507
533
|
},
|
|
508
534
|
|