Skip to content

Commit 4a6eb8a

Browse files
authored
Merge pull request #156 from guydavis/develop
Allow nft create for self-pool.
2 parents 45bfb2c + 9c0e3ef commit 4a6eb8a

File tree

7 files changed

+160
-100
lines changed

7 files changed

+160
-100
lines changed

CREDITS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ A big thanks to all that contributed with dev and test including:
4747
* ServantDad
4848
* efnats
4949
* myusuf3
50+
* kahn2k
51+
* barkcollar
52+
* dartec
53+
* elexx
54+
5055

5156
## Trademark Notice
5257
CHIA NETWORK INC, CHIA™, the CHIA BLOCKCHAIN™, the CHIA PROTOCOL™, CHIALISP™ and the “leaf Logo” (including the leaf logo alone when it refers to or indicates Chia), are trademarks or registered trademarks of Chia Network, Inc., a Delaware corporation. *There is no affliation between this Machinaris project and the main Chia Network project.*

common/config/globals.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ def is_setup():
6363
# First check if plotter and farmer_pk,pool_pk provided.
6464
if "mode" in os.environ and os.environ['mode'] == 'plotter':
6565
if "farmer_pk" in os.environ and os.environ['farmer_pk'] != 'null' and \
66-
"pool_pk" in os.environ and os.environ['pool_pk'] != 'null':
67-
logging.debug(
68-
"Found plotter mode with farmer_pk and pool_pk provided.")
69-
return True # When plotting don't need private in mnemonic.txt
66+
(("pool_pk" in os.environ and os.environ['pool_pk'] != 'null') or \
67+
("pool_contract_address" in os.environ and os.environ['pool_contract_address'] != 'null')):
68+
logging.info(
69+
"Found plotter mode with farmer_pk and pool_pk/pool_contract_address provided.")
70+
else:
71+
logging.error(
72+
"Found plotter mode WITHOUT farmer_pk and pool_pk/pool_contract_address provided.")
73+
return True # When plotting don't need private in mnemonic.txt
7074
if "mode" in os.environ and 'harvester' in os.environ['mode']:
7175
# Harvester doesn't require a mnemonic private key as farmer's ca already imported.
7276
return True

dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ ENV plots_dir="/plots"
8585
ENV mode="fullnode"
8686
# Required is the 'chia' blockchain, but can optionally add 'flax' too. A comma-separated list.
8787
ENV blockchains="chia"
88-
# If provided then these optional 2 public keys will be set in your plotman.yaml
88+
# If provided then these optional 3 public keys will be set in your plotman.yaml
8989
ENV farmer_pk="null"
9090
ENV pool_pk="null"
91+
ENV pool_contract_address="null"
9192
# If mode=harvester, required for host and port the harvester will your farmer
9293
ENV farmer_address="null"
9394
ENV farmer_port="8447"

scripts/chia_launch.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ for p in ${plots_dir//:/ }; do
3434
chia plots add -d ${p}
3535
done
3636

37-
38-
3937
sed -i 's/localhost/127.0.0.1/g' ~/.chia/mainnet/config/config.yaml
4038

4139
# Start services based on mode selected. Default is 'fullnode'

scripts/start_machinaris.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fi
1313
if [ ${pool_pk} != 'null' ]; then
1414
sed -i "s/^.*pool_pk:.*$/ pool_pk: ${pool_pk}/g" /root/.chia/plotman/plotman.yaml
1515
fi
16+
if [ ${pool_contract_address} != 'null' ]; then
17+
sed -i "s/^.*pool_contract_address:.*$/ pool_contract_address: ${pool_contract_address}/g" /root/.chia/plotman/plotman.yaml
18+
fi
1619
# Import ssh key if exists
1720
if [ -f "/id_rsa" ]; then
1821
echo "/id_rsa exists, trying to import private ssh key"

web/actions/chia.py

Lines changed: 136 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -299,107 +299,151 @@ def get_first_pool_wallet_id():
299299
def process_pool_save(choice, pool_url, current_pool_url):
300300
pool_wallet_id = get_first_pool_wallet_id()
301301
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:
306303
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
307309
elif choice == "join":
308310
if current_pool_url == pool_url:
309311
flash('Already pooling with {0}. No changes made.'.format(pool_url), 'message')
310312
return False
311313
return process_pool_join(choice, pool_url, pool_wallet_id)
312314

313315
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("\nchia 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("\nchia plotnft plotnft leave -y -i 1 --> Executed at: {0}\n".format(time.strftime("%Y%m%d-%H%M%S")))
338337
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
350353

351354
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("\nchia 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")))
393393
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

web/actions/plotman.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ def load_config_replacements():
151151
return replacements
152152

153153
def load_config(plotter):
154-
replacements = load_config_replacements()
154+
replacements = []
155+
try:
156+
replacements = load_config_replacements()
157+
except:
158+
app.logger.info("Unable to load replacements on install with mode={0}".format(os.environ['mode']))
159+
app.logger.info(traceback.format_exc())
155160
lines = []
156161
config = utils.send_get(plotter, "/configs/plotting", debug=False).content.decode('utf-8')
157162
for line in config.splitlines():

0 commit comments

Comments
 (0)