317 lines
9.9 KiB
Python
317 lines
9.9 KiB
Python
import json
|
|
import account
|
|
import requests
|
|
import os
|
|
import subprocess
|
|
|
|
path = os.path.realpath("customPlugins/firesales-plugin")
|
|
userData = os.path.realpath(f"user_data/firesales/{account.HSD_NETWORK}")
|
|
|
|
# Plugin Data
|
|
info = {
|
|
"name": "FireSales",
|
|
"description": "Manage FireSales listings",
|
|
"version": "1.0",
|
|
"author": "Nathan.Woodburn/"
|
|
}
|
|
|
|
# Functions
|
|
functions = {
|
|
"init": {
|
|
"name": "Init",
|
|
"description": "Install prerequisites for atomic swaps",
|
|
"type":"default",
|
|
"params": {},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status"
|
|
}
|
|
}
|
|
},
|
|
"startListingTransfer": {
|
|
"name": "Start Listing Transfer",
|
|
"description": "Start listing transfer. You will need to wait 2 days to send the finalize before listing",
|
|
"type":"default",
|
|
"params": {
|
|
"domain": {
|
|
"type": "text",
|
|
"name": "Domain to list"
|
|
}
|
|
},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status"
|
|
},
|
|
"txid": {
|
|
"type": "tx",
|
|
"name": "Transaction ID"
|
|
}
|
|
}
|
|
},
|
|
"finalizeListingTransfer": {
|
|
"name": "Finalize Listing Transfer",
|
|
"description": "Finalize listing transfer",
|
|
"type":"default",
|
|
"params": {
|
|
"domain": {
|
|
"type": "text",
|
|
"name": "Domain to list"
|
|
}
|
|
},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status"
|
|
},
|
|
"txid": {
|
|
"type": "tx",
|
|
"name": "Transaction ID"
|
|
}
|
|
}
|
|
},
|
|
"createListing": {
|
|
"name": "CreateListing",
|
|
"description": "CreateListing a new domain",
|
|
"type":"default",
|
|
"params": {
|
|
"domain": {
|
|
"type": "text",
|
|
"name": "Domain to list"
|
|
},
|
|
"price": {
|
|
"type": "number",
|
|
"name": "Price of the domain"
|
|
}
|
|
},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status of the listing"
|
|
}
|
|
}
|
|
},
|
|
"list": {
|
|
"name": "List",
|
|
"description": "List a new domain",
|
|
"type":"default",
|
|
"params": {
|
|
"domain": {
|
|
"type": "text",
|
|
"name": "Domain to list"
|
|
},
|
|
"price": {
|
|
"type": "number",
|
|
"name": "Price of the domain"
|
|
},
|
|
"contact": {
|
|
"type": "text",
|
|
"name": "Contact info"
|
|
},
|
|
"description": {
|
|
"type": "longText",
|
|
"name": "Listing description"
|
|
}
|
|
},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status of the listing"
|
|
}
|
|
}
|
|
},
|
|
"delete": {
|
|
"name": "Delete",
|
|
"description": "Delete a listing",
|
|
"type":"default",
|
|
"params": {
|
|
"domain": {
|
|
"type": "text",
|
|
"name": "Domain to list"
|
|
}
|
|
},
|
|
"returns": {
|
|
"status": {
|
|
"type": "text",
|
|
"name": "Status"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def init(params, authentication):
|
|
# Install npm packages
|
|
if not os.path.exists(f'{path}/node_modules'):
|
|
try:
|
|
result = subprocess.run(["npm", "install", ], capture_output=True, text=True, cwd=path)
|
|
if result.returncode != 0:
|
|
return {"status": "Error: " + result.stderr}
|
|
except:
|
|
return {"status": "Error: Failed to install npm packages"}
|
|
|
|
# Install js patch files
|
|
# Copy shakedex/main.js to node_modules/shakedex/src/cli/main.js
|
|
try:
|
|
result = subprocess.run(["cp", f'{path}/shakedex/main.js', f'{path}/node_modules/shakedex/src/cli/main.js'], capture_output=True, text=True, cwd=path)
|
|
if result.returncode != 0:
|
|
return {"status": "Error: " + result.stderr}
|
|
except:
|
|
return {"status": "Error: Failed to install js patch files"}
|
|
|
|
# Copy shakedex/index.js to node_modules/shakedex/src/index.js
|
|
try:
|
|
result = subprocess.run(["cp", f'{path}/shakedex/context.js', f'{path}/node_modules/shakedex/src/context.js'], capture_output=True, text=True, cwd=path)
|
|
if result.returncode != 0:
|
|
return {"status": "Error: " + result.stderr}
|
|
except:
|
|
return {"status": "Error: Failed to install js patch files"}
|
|
|
|
return {"status": "Success"}
|
|
|
|
|
|
def startListingTransfer(params, authentication):
|
|
domain = params["domain"]
|
|
# Generate command
|
|
wallet = authentication.split(":")[0]
|
|
passphrase = authentication.split(":")[1]
|
|
api_key = os.getenv("hsd_api")
|
|
host = os.getenv("hsd_ip")
|
|
if host is None:
|
|
host = "127.0.0.1"
|
|
|
|
# node node_modules/shakedex/bin/shakedex transfer-lock domain -n main -w wallet -a key -p ./data --httphost host
|
|
process = subprocess.Popen(
|
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "transfer-lock", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
|
text=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT
|
|
)
|
|
# Wait for the process to finish
|
|
stdout, stderr = process.communicate()
|
|
print(f"STDOUT: {stdout}")
|
|
|
|
if stderr is None:
|
|
stderr = stdout
|
|
|
|
if process.returncode != 0:
|
|
return {"status": f"Error: {stderr}", "txid": None}
|
|
|
|
txhash:str = stdout.split(" hash ")[1]
|
|
txhash = txhash.split("\n")[0].rstrip('.')
|
|
return {"status": "Success", "txid": txhash}
|
|
|
|
def finalizeListingTransfer(params, authentication):
|
|
domain = params["domain"]
|
|
# Generate command
|
|
wallet = authentication.split(":")[0]
|
|
passphrase = authentication.split(":")[1]
|
|
api_key = os.getenv("hsd_api")
|
|
host = os.getenv("hsd_ip")
|
|
if host is None:
|
|
host = "127.0.0.1"
|
|
|
|
process = subprocess.Popen(
|
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "finalize-lock", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
|
text=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT
|
|
)
|
|
# Wait for the process to finish
|
|
stdout, stderr = process.communicate()
|
|
print(f"STDOUT: {stdout}")
|
|
|
|
if stderr is None:
|
|
stderr = stdout
|
|
|
|
if process.returncode != 0:
|
|
return {"status": f"Error: {stderr}", "txid": None}
|
|
|
|
txhash:str = stdout.split(" hash ")[1]
|
|
txhash = txhash.split("\n")[0].rstrip('.')
|
|
return {"status": "Success", "txid": txhash}
|
|
|
|
def createListing(params, authentication):
|
|
domain = params["domain"]
|
|
price = params["price"]
|
|
# Generate command
|
|
wallet = authentication.split(":")[0]
|
|
passphrase = authentication.split(":")[1]
|
|
api_key = os.getenv("hsd_api")
|
|
host = os.getenv("hsd_ip")
|
|
if host is None:
|
|
host = "127.0.0.1"
|
|
|
|
process = subprocess.Popen(
|
|
["node", f"{path}/node_modules/shakedex/bin/shakedex", "create-auction", domain, "-n", account.HSD_NETWORK, "-w", wallet, "-a", api_key, "-p", f"{userData}", "--httphost", host, "-P", passphrase],
|
|
text=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT
|
|
)
|
|
# Wait for the process to finish
|
|
stdout, stderr = process.communicate()
|
|
print(f"STDOUT: {stdout}")
|
|
|
|
if stderr is None:
|
|
stderr = stdout
|
|
|
|
if process.returncode != 0:
|
|
return {"status": f"Error: {stderr}", "txid": None}
|
|
|
|
txhash:str = stdout.split(" hash ")[1]
|
|
txhash = txhash.split("\n")[0].rstrip('.')
|
|
return {"status": "Success", "txid": txhash}
|
|
|
|
def list(params, authentication):
|
|
domain = params["domain"]
|
|
price = params["price"]
|
|
contact = params["contact"]
|
|
description = params["description"]
|
|
|
|
# Generate message
|
|
message = requests.get("https://sales.firewallet.au/api/v1/listing-message?domain=" + domain + "&price=" + str(price) + "&contact=" + contact + "&description=" + description)
|
|
message = message.json()
|
|
|
|
if message['success'] != True:
|
|
return {"status": "Error: " + message['error']}
|
|
|
|
# Sign message
|
|
signature = account.signMessage(authentication,domain,message['message'])
|
|
|
|
if signature['error'] != None:
|
|
return {"status": "Error: " + signature['error']}
|
|
|
|
# Send message
|
|
response = requests.post("https://sales.firewallet.au/api/v1/list",json=
|
|
{
|
|
"domain": domain,
|
|
"price": price,
|
|
"contact": contact,
|
|
"description": description,
|
|
"signature": signature['result']
|
|
})
|
|
|
|
response = response.json()
|
|
if response['success'] != True:
|
|
return {"status": "Error: " + response['error']}
|
|
|
|
|
|
return {"status": "Success<br><a href='https://sales.firewallet.au' target='_blank'>View listing</a>"}
|
|
|
|
def delete(params, authentication):
|
|
domain = params["domain"]
|
|
signature = account.signMessage(authentication,domain,f'FS: {domain}')
|
|
if signature['error'] != None:
|
|
return {"status": "Error: " + signature['error']}
|
|
|
|
response = requests.post("https://sales.firewallet.au/api/v1/delete",json=
|
|
{
|
|
"domain": domain,
|
|
"signature": signature['result']
|
|
})
|
|
response = response.json()
|
|
if response['success'] != True:
|
|
return {"status": "Error: " + response['error']}
|
|
|
|
|
|
return {"status": "Success"} |