@@ -138,9 +138,6 @@ def generate_psbt(tmpl, reward_spk, *, blocktime=None, poolid=None):
138
138
139
139
def get_poolid (args ):
140
140
if args .poolid is not None :
141
- if args .poolnum is not None :
142
- logging .error ("Can only specify one of --poolid and --poolnum" )
143
- raise Exception ("bad arguments" )
144
141
return args .poolid .encode ('utf8' )
145
142
elif args .poolnum is not None :
146
143
return b"/signet:%d/" % (args .poolnum )
@@ -336,30 +333,23 @@ class Generate:
336
333
return finish_block (block , signet_solution , grind_cmd )
337
334
338
335
def do_generate (args ):
339
- if args .max_blocks is not None :
340
- if args .ongoing :
341
- logging .error ("Cannot specify both --ongoing and --max-blocks" )
342
- return 1
336
+ if args .set_block_time is not None :
337
+ max_blocks = 1
338
+ elif args .max_blocks is not None :
343
339
if args .max_blocks < 1 :
344
- logging .error ("N must be a positive integer" )
340
+ logging .error ("--max_blocks must specify a positive integer" )
345
341
return 1
346
342
max_blocks = args .max_blocks
347
343
elif args .ongoing :
348
344
max_blocks = None
349
345
else :
350
346
max_blocks = 1
351
347
352
- if args .set_block_time is not None and max_blocks != 1 :
353
- logging .error ("Cannot specify --ongoing or --max-blocks > 1 when using --set-block-time" )
354
- return 1
355
348
if args .set_block_time is not None and args .set_block_time < 0 :
356
349
args .set_block_time = time .time ()
357
350
logging .info ("Treating negative block time as current time (%d)" % (args .set_block_time ))
358
351
359
352
if args .min_nbits :
360
- if args .nbits is not None :
361
- logging .error ("Cannot specify --nbits and --min-nbits" )
362
- return 1
363
353
args .nbits = "1e0377ae"
364
354
logging .info ("Using nbits=%s" % (args .nbits ))
365
355
@@ -521,35 +511,38 @@ def main():
521
511
cmds = parser .add_subparsers (help = "sub-commands" )
522
512
genpsbt = cmds .add_parser ("genpsbt" , help = "Generate a block PSBT for signing" )
523
513
genpsbt .set_defaults (fn = do_genpsbt )
524
- genpsbt .add_argument ("--poolnum" , default = None , type = int , help = "Identify blocks that you mine" )
525
- genpsbt .add_argument ("--poolid" , default = None , type = str , help = "Identify blocks that you mine (eg: /signet:1/)" )
526
514
527
515
solvepsbt = cmds .add_parser ("solvepsbt" , help = "Solve a signed block PSBT" )
528
516
solvepsbt .set_defaults (fn = do_solvepsbt )
529
517
530
518
generate = cmds .add_parser ("generate" , help = "Mine blocks" )
531
519
generate .set_defaults (fn = do_generate )
532
- generate .add_argument ("--ongoing" , action = "store_true" , help = "Keep mining blocks" )
533
- generate .add_argument ("--max-blocks" , default = None , type = int , help = "Max blocks to mine (default=1)" )
534
- generate .add_argument ("--set-block-time" , default = None , type = int , help = "Set block time (unix timestamp)" )
535
- generate .add_argument ("--nbits" , default = None , type = str , help = "Target nBits (specify difficulty)" )
536
- generate .add_argument ("--min-nbits" , action = "store_true" , help = "Target minimum nBits (use min difficulty)" )
520
+ howmany = generate .add_mutually_exclusive_group ()
521
+ howmany .add_argument ("--ongoing" , action = "store_true" , help = "Keep mining blocks" )
522
+ howmany .add_argument ("--max-blocks" , default = None , type = int , help = "Max blocks to mine (default=1)" )
523
+ howmany .add_argument ("--set-block-time" , default = None , type = int , help = "Set block time (unix timestamp); implies --max-blocks=1" )
524
+ nbit_target = generate .add_mutually_exclusive_group ()
525
+ nbit_target .add_argument ("--nbits" , default = None , type = str , help = "Target nBits (specify difficulty)" )
526
+ nbit_target .add_argument ("--min-nbits" , action = "store_true" , help = "Target minimum nBits (use min difficulty)" )
537
527
generate .add_argument ("--poisson" , action = "store_true" , help = "Simulate randomised block times" )
538
528
generate .add_argument ("--multiminer" , default = None , type = str , help = "Specify which set of blocks to mine (eg: 1-40/100 for the first 40%%, 2/3 for the second 3rd)" )
539
529
generate .add_argument ("--backup-delay" , default = 300 , type = int , help = "Seconds to delay before mining blocks reserved for other miners (default=300)" )
540
530
generate .add_argument ("--standby-delay" , default = 0 , type = int , help = "Seconds to delay before mining blocks (default=0)" )
541
531
generate .add_argument ("--max-interval" , default = 1800 , type = int , help = "Maximum interblock interval (seconds)" )
542
- generate .add_argument ("--poolnum" , default = None , type = int , help = "Identify blocks that you mine" )
543
- generate .add_argument ("--poolid" , default = None , type = str , help = "Identify blocks that you mine (eg: /signet:1/)" )
544
532
545
533
calibrate = cmds .add_parser ("calibrate" , help = "Calibrate difficulty" )
546
534
calibrate .set_defaults (fn = do_calibrate )
547
- calibrate .add_argument ("--nbits" , type = str , default = None )
548
- calibrate .add_argument ("--seconds" , type = int , default = None )
535
+ calibrate_by = calibrate .add_mutually_exclusive_group ()
536
+ calibrate_by .add_argument ("--nbits" , type = str , default = None )
537
+ calibrate_by .add_argument ("--seconds" , type = int , default = None )
549
538
550
539
for sp in [genpsbt , generate ]:
551
- sp .add_argument ("--address" , default = None , type = str , help = "Address for block reward payment" )
552
- sp .add_argument ("--descriptor" , default = None , type = str , help = "Descriptor for block reward payment" )
540
+ payto = sp .add_mutually_exclusive_group (required = True )
541
+ payto .add_argument ("--address" , default = None , type = str , help = "Address for block reward payment" )
542
+ payto .add_argument ("--descriptor" , default = None , type = str , help = "Descriptor for block reward payment" )
543
+ pool = sp .add_mutually_exclusive_group ()
544
+ pool .add_argument ("--poolnum" , default = None , type = int , help = "Identify blocks that you mine" )
545
+ pool .add_argument ("--poolid" , default = None , type = str , help = "Identify blocks that you mine (eg: /signet:1/)" )
553
546
554
547
for sp in [solvepsbt , generate , calibrate ]:
555
548
sp .add_argument ("--grind-cmd" , default = None , type = str , required = (sp == calibrate ), help = "Command to grind a block header for proof-of-work" )
@@ -559,12 +552,6 @@ def main():
559
552
args .bcli = lambda * a , input = b"" , ** kwargs : bitcoin_cli (args .cli .split (" " ), list (a ), input = input , ** kwargs )
560
553
561
554
if hasattr (args , "address" ) and hasattr (args , "descriptor" ):
562
- if args .address is None and args .descriptor is None :
563
- sys .stderr .write ("Must specify --address or --descriptor\n " )
564
- return 1
565
- elif args .address is not None and args .descriptor is not None :
566
- sys .stderr .write ("Only specify one of --address or --descriptor\n " )
567
- return 1
568
555
args .derived_addresses = {}
569
556
570
557
if args .debug :
0 commit comments