@@ -138,9 +138,6 @@ def generate_psbt(tmpl, reward_spk, *, blocktime=None, poolid=None):
138138
139139def get_poolid (args ):
140140 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" )
144141 return args .poolid .encode ('utf8' )
145142 elif args .poolnum is not None :
146143 return b"/signet:%d/" % (args .poolnum )
@@ -336,30 +333,23 @@ class Generate:
336333 return finish_block (block , signet_solution , grind_cmd )
337334
338335def 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 :
343339 if args .max_blocks < 1 :
344- logging .error ("N must be a positive integer" )
340+ logging .error ("--max_blocks must specify a positive integer" )
345341 return 1
346342 max_blocks = args .max_blocks
347343 elif args .ongoing :
348344 max_blocks = None
349345 else :
350346 max_blocks = 1
351347
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
355348 if args .set_block_time is not None and args .set_block_time < 0 :
356349 args .set_block_time = time .time ()
357350 logging .info ("Treating negative block time as current time (%d)" % (args .set_block_time ))
358351
359352 if args .min_nbits :
360- if args .nbits is not None :
361- logging .error ("Cannot specify --nbits and --min-nbits" )
362- return 1
363353 args .nbits = "1e0377ae"
364354 logging .info ("Using nbits=%s" % (args .nbits ))
365355
@@ -521,35 +511,38 @@ def main():
521511 cmds = parser .add_subparsers (help = "sub-commands" )
522512 genpsbt = cmds .add_parser ("genpsbt" , help = "Generate a block PSBT for signing" )
523513 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/)" )
526514
527515 solvepsbt = cmds .add_parser ("solvepsbt" , help = "Solve a signed block PSBT" )
528516 solvepsbt .set_defaults (fn = do_solvepsbt )
529517
530518 generate = cmds .add_parser ("generate" , help = "Mine blocks" )
531519 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)" )
537527 generate .add_argument ("--poisson" , action = "store_true" , help = "Simulate randomised block times" )
538528 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)" )
539529 generate .add_argument ("--backup-delay" , default = 300 , type = int , help = "Seconds to delay before mining blocks reserved for other miners (default=300)" )
540530 generate .add_argument ("--standby-delay" , default = 0 , type = int , help = "Seconds to delay before mining blocks (default=0)" )
541531 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/)" )
544532
545533 calibrate = cmds .add_parser ("calibrate" , help = "Calibrate difficulty" )
546534 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 )
549538
550539 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/)" )
553546
554547 for sp in [solvepsbt , generate , calibrate ]:
555548 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():
559552 args .bcli = lambda * a , input = b"" , ** kwargs : bitcoin_cli (args .cli .split (" " ), list (a ), input = input , ** kwargs )
560553
561554 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
568555 args .derived_addresses = {}
569556
570557 if args .debug :
0 commit comments