@@ -8,48 +8,40 @@ import * as Secp256k1 from "@dashincubator/secp256k1";
8
8
9
9
import Fs from "node:fs/promises" ;
10
10
11
- async function main ( ) {
11
+ /**
12
+ * @typedef ProposalData
13
+ * @prop {"mainnet"|"testnet" } network - The network type, either mainnet or testnet.
14
+ * @prop {String } rpcBasicAuth - Basic authentication credentials for RPC (e.g., `api:null`).
15
+ * @prop {String } rpcBaseUrl - Base URL for the RPC server, adjusted for the network.
16
+ * @prop {String } rpcExplorer - URL for the RPC explorer.
17
+ * @prop {Number } startPeriod - The start period for the proposal.
18
+ * @prop {Number } numPeriods - Number of periods for which the proposal applies.
19
+ * @prop {Number } dashAmount - The amount of Dash for the proposal.
20
+ * @prop {String } proposalUrl - URL of the proposal.
21
+ * @prop {String } proposalName - Name of the proposal.
22
+ * @prop {String } paymentAddr - Payment address for the proposal.
23
+ * @prop {String } burnWif - Wallet Import Format (WIF) key used for the burn address.
24
+ */
25
+
26
+ /**
27
+ * @param {ProposalData } opts
28
+ */
29
+ async function prepAndSubmit ( {
30
+ network,
31
+ rpcBasicAuth,
32
+ rpcBaseUrl,
33
+ rpcExplorer,
34
+ startPeriod,
35
+ numPeriods,
36
+ dashAmount,
37
+ proposalUrl,
38
+ proposalName,
39
+ paymentAddr,
40
+ burnWif,
41
+ } ) {
12
42
/* jshint maxcomplexity: 100 */
13
43
/* jshint maxstatements: 1000 */
14
44
15
- console . info ( "" ) ;
16
- console . info ( "USAGE" ) ;
17
- console . info (
18
- " dashgov draft-proposal [start period] [num periods] <DASH-per-period> <proposal-url> <name> <payment-addr> <./burn-key.wif> [network]" ,
19
- ) ;
20
- console . info ( "" ) ;
21
- console . info ( "EXAMPLE" ) ;
22
- console . info (
23
- " dashgov draft-proposal '1' '3' '100' 'https://example.com/example-proposal' example-proposal yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC ./private-key.wif testnet" ,
24
- ) ;
25
- console . info ( "" ) ;
26
-
27
- /** @type {"mainnet"|"testnet" } */
28
- let network = "mainnet" ;
29
- let rpcBasicAuth = `api:null` ;
30
- let rpcBaseUrl = `https://${ rpcBasicAuth } @rpc.digitalcash.dev/` ;
31
- let rpcExplorer = "https://rpc.digitalcash.dev/" ;
32
-
33
- let isTestnet = takeFlag ( process . argv , [ "--testnet" ] ) ;
34
- if ( isTestnet ) {
35
- rpcBaseUrl = `https://${ rpcBasicAuth } @trpc.digitalcash.dev/` ;
36
- rpcExplorer = "https://trpc.digitalcash.dev/" ;
37
- network = "testnet" ;
38
- }
39
-
40
- let startPeriod = parseInt ( process . argv [ 2 ] || "1" , 10 ) ;
41
- let numPeriods = parseInt ( process . argv [ 3 ] || "1" , 10 ) ;
42
- let dashAmount = parseInt ( process . argv [ 4 ] || "1" , 10 ) ;
43
- let proposalUrl = process . argv [ 5 ] || "" ;
44
- let proposalName = process . argv [ 6 ] || "" ;
45
- let paymentAddr = process . argv [ 7 ] || "" ;
46
- let burnWifPath = process . argv [ 8 ] || "" ;
47
- let burnWif = "" ;
48
- if ( burnWifPath ) {
49
- burnWif = await Fs . readFile ( burnWifPath , "utf8" ) ;
50
- burnWif = burnWif . trim ( ) ;
51
- }
52
-
53
45
/**
54
46
* @param {String } method
55
47
* @param {...any } params
@@ -428,6 +420,65 @@ async function main() {
428
420
}
429
421
}
430
422
423
+ async function main ( ) {
424
+ /** @type {"mainnet"|"testnet" } */
425
+ let network = "mainnet" ;
426
+ let rpcBasicAuth = `api:null` ;
427
+ let rpcBaseUrl = `https://${ rpcBasicAuth } @rpc.digitalcash.dev/` ;
428
+ let rpcExplorer = "https://rpc.digitalcash.dev/" ;
429
+
430
+ let isTestnet = takeFlag ( process . argv , [ "--testnet" ] ) ;
431
+ if ( isTestnet ) {
432
+ rpcBaseUrl = `https://${ rpcBasicAuth } @trpc.digitalcash.dev/` ;
433
+ rpcExplorer = "https://trpc.digitalcash.dev/" ;
434
+ network = "testnet" ;
435
+ }
436
+
437
+ let wantsHelp = takeFlag ( process . argv , [ "--help" , "help" ] ) ;
438
+ let mustHelp = process . argv . length !== 5 && process . argv . length !== 9 ;
439
+ if ( wantsHelp || mustHelp ) {
440
+ console . info ( "" ) ;
441
+ console . info ( "USAGE" ) ;
442
+ console . info (
443
+ " dashgov draft-proposal [start period] [num periods] <DASH-per-period> <proposal-url> <name> <payment-addr> <./burn-key.wif> [network]" ,
444
+ ) ;
445
+ console . info ( "" ) ;
446
+ console . info ( "EXAMPLE" ) ;
447
+ console . info (
448
+ " dashgov draft-proposal '1' '3' '100' 'https://example.com/example-proposal' example-proposal yT6GS8qPrhsiiLHEaTWPYJMwfPPVt2SSFC ./private-key.wif testnet" ,
449
+ ) ;
450
+ console . info ( "" ) ;
451
+ return ;
452
+ }
453
+
454
+ let startPeriod = parseInt ( process . argv [ 2 ] || "1" , 10 ) ;
455
+ let numPeriods = parseInt ( process . argv [ 3 ] || "1" , 10 ) ;
456
+ let dashAmount = parseInt ( process . argv [ 4 ] || "1" , 10 ) ;
457
+ let proposalUrl = process . argv [ 5 ] || "" ;
458
+ let proposalName = process . argv [ 6 ] || "" ;
459
+ let paymentAddr = process . argv [ 7 ] || "" ;
460
+ let burnWifPath = process . argv [ 8 ] || "" ;
461
+ let burnWif = "" ;
462
+ if ( burnWifPath ) {
463
+ burnWif = await Fs . readFile ( burnWifPath , "utf8" ) ;
464
+ burnWif = burnWif . trim ( ) ;
465
+ }
466
+
467
+ await prepAndSubmit ( {
468
+ network,
469
+ rpcBasicAuth,
470
+ rpcBaseUrl,
471
+ rpcExplorer,
472
+ startPeriod,
473
+ numPeriods,
474
+ dashAmount,
475
+ proposalUrl,
476
+ proposalName,
477
+ paymentAddr,
478
+ burnWif,
479
+ } ) ;
480
+ }
481
+
431
482
/**
432
483
* Find, remove, and return the first matching flag from the arguments list
433
484
* @param {Array<String> } argv
0 commit comments