@@ -299,107 +299,151 @@ def get_first_pool_wallet_id():
299
299
def process_pool_save (choice , pool_url , current_pool_url ):
300
300
pool_wallet_id = get_first_pool_wallet_id ()
301
301
if choice == "self" :
302
- if not current_pool_url :
303
- flash ('Already self pooling your own solo plots. No changes made.' , 'message' )
304
- return False
305
- if pool_wallet_id :
302
+ if current_pool_url and pool_wallet_id :
306
303
return process_pool_leave (choice , pool_wallet_id )
304
+ elif not pool_wallet_id :
305
+ return process_self_pool ()
306
+ else :
307
+ flash ('Already self-pooling your own NFT. No changes made.' , 'message' )
308
+ return False
307
309
elif choice == "join" :
308
310
if current_pool_url == pool_url :
309
311
flash ('Already pooling with {0}. No changes made.' .format (pool_url ), 'message' )
310
312
return False
311
313
return process_pool_join (choice , pool_url , pool_wallet_id )
312
314
313
315
def process_pool_leave (choice , wallet_id ):
314
- app .logger .info ("Attempting to leave pool." )
315
- proc = Popen ("{0} plotnft leave -y -i {1}" .format (CHIA_BINARY , wallet_id ), stdout = PIPE , stderr = PIPE , shell = True )
316
- try :
317
- outs , errs = proc .communicate (timeout = 90 )
318
- except TimeoutExpired :
319
- proc .kill ()
320
- proc .communicate ()
321
- app .logger .info (traceback .format_exc ())
322
- flash ('Timed out while leaving Chia pool!' , 'danger' )
323
- flash (str (ex ), 'warning' )
324
- return False
325
- if errs :
326
- app .logger .info ("{0}" .format (errs .decode ('utf-8' )))
327
- flash ('Error while leaving Chia pool.' , 'danger' )
328
- flash (errs .decode ('utf-8' ), 'warning' )
329
- return False
330
- if outs : # Chia outputs their errors to stdout, not stderr, so must check.
331
- stdout_lines = outs .decode ('utf-8' ).splitlines ()
332
- out_file = '/root/.chia/mainnet/log/plotnft.log'
333
- with open (out_file , 'a' ) as f :
334
- f .write ("\n chia plotnft plotnft leave -y -i 1 --> Executed at: {0}\n " .format (time .strftime ("%Y%m%d-%H%M%S" )))
335
- for line in stdout_lines :
336
- f .write (line )
337
- f .write ("\n **********************************************************************\n " )
316
+ app .logger .info ("Attempting to leave pool." )
317
+ proc = Popen ("{0} plotnft leave -y -i {1}" .format (CHIA_BINARY , wallet_id ), stdout = PIPE , stderr = PIPE , shell = True )
318
+ try :
319
+ outs , errs = proc .communicate (timeout = 90 )
320
+ except TimeoutExpired :
321
+ proc .kill ()
322
+ proc .communicate ()
323
+ app .logger .info (traceback .format_exc ())
324
+ flash ('Timed out while leaving Chia pool!' , 'danger' )
325
+ flash (str (ex ), 'warning' )
326
+ return False
327
+ if errs :
328
+ app .logger .info ("{0}" .format (errs .decode ('utf-8' )))
329
+ flash ('Error while leaving Chia pool.' , 'danger' )
330
+ flash (errs .decode ('utf-8' ), 'warning' )
331
+ return False
332
+ if outs : # Chia outputs their errors to stdout, not stderr, so must check.
333
+ stdout_lines = outs .decode ('utf-8' ).splitlines ()
334
+ out_file = '/root/.chia/mainnet/log/plotnft.log'
335
+ with open (out_file , 'a' ) as f :
336
+ f .write ("\n chia plotnft plotnft leave -y -i 1 --> Executed at: {0}\n " .format (time .strftime ("%Y%m%d-%H%M%S" )))
338
337
for line in stdout_lines :
339
- if "Error" in line :
340
- flash ('Error while leaving Chia pool.' , 'danger' )
341
- flash (line , 'warning' )
342
- return False
343
- try : # Trigger a status update
344
- requests .get ("http://localhost:8927/plotnfts/" , timeout = 5 )
345
- except :
346
- app .logger .info (traceback .format_exc ())
347
- time .sleep (5 )
348
- flash ('Successfully left pool, switching to self plotting. Please wait a while to complete, then refresh page. See below for details.' , 'success' )
349
- return True
338
+ f .write (line )
339
+ f .write ("\n **********************************************************************\n " )
340
+ for line in stdout_lines :
341
+ if "Error" in line :
342
+ flash ('Error while leaving Chia pool.' , 'danger' )
343
+ flash (line , 'warning' )
344
+ return False
345
+ time .sleep (15 )
346
+ try : # Trigger a status update
347
+ requests .get ("http://localhost:8927/plotnfts/" , timeout = 5 )
348
+ except :
349
+ app .logger .info (traceback .format_exc ())
350
+ time .sleep (5 )
351
+ flash ('Successfully left pool, switching to self plotting. Please wait a while to complete, then refresh page. See below for details.' , 'success' )
352
+ return True
350
353
351
354
def process_pool_join (choice , pool_url , pool_wallet_id ):
352
- app .logger .info ("Attempting to join pool at URL: {0} with wallet_id: {1}" .format (pool_url , pool_wallet_id ))
353
- try :
354
- if not pool_url .strip ():
355
- raise Exception ("Empty pool URL provided." )
356
- result = urllib .parse .urlparse (pool_url )
357
- if result .scheme != 'https' :
358
- raise Exception ("Non-HTTPS scheme provided." )
359
- if not result .netloc :
360
- raise Exception ("No hostname or IP provided." )
361
- except Exception as ex :
362
- app .logger .info (traceback .format_exc ())
363
- flash ('{0}' .format (str (ex )), 'danger' )
364
- return False
365
- if pool_wallet_id :
366
- cmd = "{0} plotnft join -y -u {1} -i {2}" .format (CHIA_BINARY , pool_url , pool_wallet_id )
367
- else : # Both creating NFT and joining pool in one setp
368
- cmd = "{0} plotnft create -y -u {1} -s pool" .format (CHIA_BINARY , pool_url )
369
- app .logger .info ("Executing: {0}" .format (cmd ))
370
- proc = Popen (cmd , stdout = PIPE , stderr = PIPE , shell = True )
371
- try :
372
- outs , errs = proc .communicate (timeout = 90 )
373
- except TimeoutExpired :
374
- proc .kill ()
375
- proc .communicate ()
376
- app .logger .info (traceback .format_exc ())
377
- flash ('Timed out while joining Chia pool!' , 'danger' )
378
- flash (str (ex ), 'warning' )
379
- return False
380
- if errs :
381
- app .logger .info ("{0}" .format (errs .decode ('utf-8' )))
382
- flash ('Error while joining Chia pool. Please double-check pool URL: {0}' .format (pool_url ), 'danger' )
383
- flash (errs .decode ('utf-8' ), 'warning' )
384
- return False
385
- if outs : # Chia outputs their errors to stdout, not stderr, so must check.
386
- stdout_lines = outs .decode ('utf-8' ).splitlines ()
387
- out_file = '/root/.chia/mainnet/log/plotnft.log'
388
- with open (out_file , 'a' ) as f :
389
- f .write ("\n chia plotnft create -y -u {0} -s pool --> Executed at: {1}\n " .format (pool_url , time .strftime ("%Y%m%d-%H%M%S" )))
390
- for line in stdout_lines :
391
- f .write (line )
392
- f .write ("\n **********************************************************************\n " )
355
+ app .logger .info ("Attempting to join pool at URL: {0} with wallet_id: {1}" .format (pool_url , pool_wallet_id ))
356
+ try :
357
+ if not pool_url .strip ():
358
+ raise Exception ("Empty pool URL provided." )
359
+ result = urllib .parse .urlparse (pool_url )
360
+ if result .scheme != 'https' :
361
+ raise Exception ("Non-HTTPS scheme provided." )
362
+ if not result .netloc :
363
+ raise Exception ("No hostname or IP provided." )
364
+ except Exception as ex :
365
+ app .logger .info (traceback .format_exc ())
366
+ flash ('{0}' .format (str (ex )), 'danger' )
367
+ return False
368
+ if pool_wallet_id : # Just joining a pool with existing NFT
369
+ cmd = "{0} plotnft join -y -u {1} -i {2}" .format (CHIA_BINARY , pool_url , pool_wallet_id )
370
+ else : # Both creating NFT and joining pool in one setp
371
+ cmd = "{0} plotnft create -y -u {1} -s pool" .format (CHIA_BINARY , pool_url )
372
+ app .logger .info ("Executing: {0}" .format (cmd ))
373
+ proc = Popen (cmd , stdout = PIPE , stderr = PIPE , shell = True )
374
+ try :
375
+ outs , errs = proc .communicate (timeout = 90 )
376
+ except TimeoutExpired :
377
+ proc .kill ()
378
+ proc .communicate ()
379
+ app .logger .info (traceback .format_exc ())
380
+ flash ('Timed out while joining Chia pool!' , 'danger' )
381
+ flash (str (ex ), 'warning' )
382
+ return False
383
+ if errs :
384
+ app .logger .info ("{0}" .format (errs .decode ('utf-8' )))
385
+ flash ('Error while joining Chia pool. Please double-check pool URL: {0}' .format (pool_url ), 'danger' )
386
+ flash (errs .decode ('utf-8' ), 'warning' )
387
+ return False
388
+ if outs : # Chia outputs their errors to stdout, not stderr, so must check.
389
+ stdout_lines = outs .decode ('utf-8' ).splitlines ()
390
+ out_file = '/root/.chia/mainnet/log/plotnft.log'
391
+ with open (out_file , 'a' ) as f :
392
+ f .write ("\n {0} --> Executed at: {1}\n " .format (cmd , time .strftime ("%Y%m%d-%H%M%S" )))
393
393
for line in stdout_lines :
394
- if "Error" in line :
395
- flash ('Error while joining Chia pool. Please double-check pool URL: {0}' .format (pool_url ), 'danger' )
396
- flash (line , 'warning' )
397
- return False
398
- time .sleep (15 )
399
- try : # Trigger a status update
400
- requests .get ("http://localhost:8927/plotnfts/" , timeout = 5 )
401
- except :
402
- app .logger .info (traceback .format_exc ())
403
- time .sleep (5 )
404
- flash ('Successfully joined {0} pool by creating Chia NFT. Please wait a while to complete, then refresh page. See below for details.' .format (pool_url ), 'success' )
405
- return True
394
+ f .write (line )
395
+ f .write ("\n **********************************************************************\n " )
396
+ for line in stdout_lines :
397
+ if "Error" in line :
398
+ flash ('Error while joining Chia pool. Please double-check pool URL: {0}' .format (pool_url ), 'danger' )
399
+ flash (line , 'warning' )
400
+ return False
401
+ time .sleep (15 )
402
+ try : # Trigger a status update
403
+ requests .get ("http://localhost:8927/plotnfts/" , timeout = 5 )
404
+ except :
405
+ app .logger .info (traceback .format_exc ())
406
+ time .sleep (5 )
407
+ flash ('Successfully joined {0} pool by creating Chia NFT. Please wait a while to complete, then refresh page. See below for details.' .format (pool_url ), 'success' )
408
+ return True
409
+
410
+ def process_self_pool ():
411
+ app .logger .info ("Attempting to create NFT for self-pooling." )
412
+ cmd = "{0} plotnft create -y -s local" .format (CHIA_BINARY )
413
+ app .logger .info ("Executing: {0}" .format (cmd ))
414
+ proc = Popen (cmd , stdout = PIPE , stderr = PIPE , shell = True )
415
+ try :
416
+ outs , errs = proc .communicate (timeout = 90 )
417
+ except TimeoutExpired :
418
+ proc .kill ()
419
+ proc .communicate ()
420
+ app .logger .info (traceback .format_exc ())
421
+ flash ('Timed out while creating NFT!' , 'danger' )
422
+ flash (str (ex ), 'warning' )
423
+ return False
424
+ if errs :
425
+ app .logger .info ("{0}" .format (errs .decode ('utf-8' )))
426
+ flash ('Error while creating NFT.' , 'danger' )
427
+ flash (errs .decode ('utf-8' ), 'warning' )
428
+ return False
429
+ if outs : # Chia outputs their errors to stdout, not stderr, so must check.
430
+ stdout_lines = outs .decode ('utf-8' ).splitlines ()
431
+ out_file = '/root/.chia/mainnet/log/plotnft.log'
432
+ with open (out_file , 'a' ) as f :
433
+ f .write ("\n {0} --> Executed at: {1}\n " .format (cmd , time .strftime ("%Y%m%d-%H%M%S" )))
434
+ for line in stdout_lines :
435
+ f .write (line )
436
+ f .write ("\n **********************************************************************\n " )
437
+ for line in stdout_lines :
438
+ if "Error" in line :
439
+ flash ('Error while creating self-pooling NFT' , 'danger' )
440
+ flash (line , 'warning' )
441
+ return False
442
+ time .sleep (15 )
443
+ try : # Trigger a status update
444
+ requests .get ("http://localhost:8927/plotnfts/" , timeout = 5 )
445
+ except :
446
+ app .logger .info (traceback .format_exc ())
447
+ time .sleep (5 )
448
+ flash ('Successfully created a NFT for self-pooling. Please wait a while to complete, then refresh page. See below for details.' , 'success' )
449
+ return True
0 commit comments