feat: Add support for test networks
All checks were successful
Build Docker / Build Image (push) Successful in 52s
All checks were successful
Build Docker / Build Image (push) Successful in 52s
This commit is contained in:
parent
26633c1c61
commit
8622400427
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
.env
|
.env
|
||||||
|
.env*
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
||||||
templates/assets/css/styles.min.css
|
templates/assets/css/styles.min.css
|
||||||
|
62
account.py
62
account.py
@ -10,17 +10,37 @@ import time
|
|||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
APIKEY = os.getenv("hsd_api")
|
HSD_API = os.getenv("hsd_api")
|
||||||
ip = os.getenv("hsd_ip")
|
HSD_IP = os.getenv("hsd_ip")
|
||||||
if ip is None:
|
if HSD_IP is None:
|
||||||
ip = "localhost"
|
HSD_IP = "localhost"
|
||||||
|
|
||||||
|
HSD_NETWORK = os.getenv("hsd_network")
|
||||||
|
HSD_WALLET_PORT = 12039
|
||||||
|
HSD_NODE_PORT = 12037
|
||||||
|
|
||||||
|
if not HSD_NETWORK:
|
||||||
|
HSD_NETWORK = "main"
|
||||||
|
else:
|
||||||
|
HSD_NETWORK = HSD_NETWORK.lower()
|
||||||
|
|
||||||
|
if HSD_NETWORK == "simnet":
|
||||||
|
HSD_WALLET_PORT = 15039
|
||||||
|
HSD_NODE_PORT = 15037
|
||||||
|
elif HSD_NETWORK == "testnet":
|
||||||
|
HSD_WALLET_PORT = 13039
|
||||||
|
HSD_NODE_PORT = 13037
|
||||||
|
elif HSD_NETWORK == "regtest":
|
||||||
|
HSD_WALLET_PORT = 14039
|
||||||
|
HSD_NODE_PORT = 14037
|
||||||
|
|
||||||
|
|
||||||
show_expired = os.getenv("show_expired")
|
show_expired = os.getenv("show_expired")
|
||||||
if show_expired is None:
|
if show_expired is None:
|
||||||
show_expired = False
|
show_expired = False
|
||||||
|
|
||||||
hsd = api.hsd(APIKEY,ip)
|
hsd = api.hsd(HSD_API,HSD_IP,HSD_NODE_PORT)
|
||||||
hsw = api.hsw(APIKEY,ip)
|
hsw = api.hsw(HSD_API,HSD_IP,HSD_WALLET_PORT)
|
||||||
|
|
||||||
cacheTime = 3600
|
cacheTime = 3600
|
||||||
|
|
||||||
@ -84,7 +104,7 @@ def createWallet(account: str, password: str):
|
|||||||
}
|
}
|
||||||
# Create the account
|
# Create the account
|
||||||
# Python wrapper doesn't support this yet
|
# Python wrapper doesn't support this yet
|
||||||
response = requests.put(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}")
|
response = requests.put(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}")
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@ -98,7 +118,7 @@ def createWallet(account: str, password: str):
|
|||||||
|
|
||||||
|
|
||||||
# Encrypt the wallet (python wrapper doesn't support this yet)
|
# Encrypt the wallet (python wrapper doesn't support this yet)
|
||||||
response = requests.post(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}/passphrase",
|
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/passphrase",
|
||||||
json={"passphrase": password})
|
json={"passphrase": password})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -121,7 +141,7 @@ def importWallet(account: str, password: str,seed: str):
|
|||||||
"mnemonic": seed,
|
"mnemonic": seed,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.put(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}",json=data)
|
response = requests.put(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}",json=data)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@ -219,9 +239,9 @@ def getPendingTX(account: str):
|
|||||||
|
|
||||||
def getDomains(account,own=True):
|
def getDomains(account,own=True):
|
||||||
if own:
|
if own:
|
||||||
response = requests.get(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}/name?own=true")
|
response = requests.get(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name?own=true")
|
||||||
else:
|
else:
|
||||||
response = requests.get(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}/name")
|
response = requests.get(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name")
|
||||||
info = response.json()
|
info = response.json()
|
||||||
|
|
||||||
if show_expired:
|
if show_expired:
|
||||||
@ -304,9 +324,9 @@ def getTransactions(account,page=1,limit=100):
|
|||||||
lastTX = getTXFromPage(account,page-1,limit)
|
lastTX = getTXFromPage(account,page-1,limit)
|
||||||
|
|
||||||
if lastTX:
|
if lastTX:
|
||||||
response = requests.get(f'http://x:{APIKEY}@{ip}:12039/wallet/{account}/tx/history?reverse=true&limit={limit}&after={lastTX}')
|
response = requests.get(f'http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/tx/history?reverse=true&limit={limit}&after={lastTX}')
|
||||||
elif page == 1:
|
elif page == 1:
|
||||||
response = requests.get(f'http://x:{APIKEY}@{ip}:12039/wallet/{account}/tx/history?reverse=true&limit={limit}')
|
response = requests.get(f'http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/tx/history?reverse=true&limit={limit}')
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -344,7 +364,7 @@ def check_address(address: str, allow_name: bool = True, return_address: bool =
|
|||||||
return check_hip2(address[1:])
|
return check_hip2(address[1:])
|
||||||
|
|
||||||
# Check if the address is a valid HNS address
|
# Check if the address is a valid HNS address
|
||||||
response = requests.post(f"http://x:{APIKEY}@{ip}:12037",json={
|
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_NODE_PORT}",json={
|
||||||
"method": "validateaddress",
|
"method": "validateaddress",
|
||||||
"params": [address]
|
"params": [address]
|
||||||
}).json()
|
}).json()
|
||||||
@ -393,7 +413,7 @@ def send(account,address,amount):
|
|||||||
|
|
||||||
response = hsw.rpc_walletPassphrase(password,10)
|
response = hsw.rpc_walletPassphrase(password,10)
|
||||||
# Unlock the account
|
# Unlock the account
|
||||||
# response = requests.post(f"http://x:{APIKEY}@{ip}:12039/wallet/{account_name}/unlock",
|
# response = requests.post(f"http://x:{APIKEY}@{ip}:{HSD_WALLET_PORT}/wallet/{account_name}/unlock",
|
||||||
# json={"passphrase": password,"timeout": 10})
|
# json={"passphrase": password,"timeout": 10})
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return {
|
return {
|
||||||
@ -449,6 +469,9 @@ def getDNS(domain: str):
|
|||||||
return {
|
return {
|
||||||
"error": "No DNS records"
|
"error": "No DNS records"
|
||||||
}
|
}
|
||||||
|
if response['result'] == None:
|
||||||
|
return []
|
||||||
|
|
||||||
if 'records' not in response['result']:
|
if 'records' not in response['result']:
|
||||||
return []
|
return []
|
||||||
return response['result']['records']
|
return response['result']['records']
|
||||||
@ -549,6 +572,9 @@ def getRevealTX(reveal):
|
|||||||
hash = prevout['hash']
|
hash = prevout['hash']
|
||||||
index = prevout['index']
|
index = prevout['index']
|
||||||
tx = hsd.getTxByHash(hash)
|
tx = hsd.getTxByHash(hash)
|
||||||
|
if 'inputs' not in tx:
|
||||||
|
# Check if registered
|
||||||
|
return None
|
||||||
return tx['inputs'][index]['prevout']['hash']
|
return tx['inputs'][index]['prevout']['hash']
|
||||||
|
|
||||||
|
|
||||||
@ -592,7 +618,7 @@ def revealAll(account):
|
|||||||
return
|
return
|
||||||
# Try to send the batch of all renew, reveal and redeem actions
|
# Try to send the batch of all renew, reveal and redeem actions
|
||||||
|
|
||||||
return requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REVEAL"]]]}).json()
|
return requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}",json={"method": "sendbatch","params": [[["REVEAL"]]]}).json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@ -817,7 +843,7 @@ def sendBatch(account, batch):
|
|||||||
"message": response['error']['message']
|
"message": response['error']['message']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response = requests.post(f"http://x:{APIKEY}@{ip}:12039",json={
|
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}",json={
|
||||||
"method": "sendbatch",
|
"method": "sendbatch",
|
||||||
"params": [batch]
|
"params": [batch]
|
||||||
}).json()
|
}).json()
|
||||||
@ -877,7 +903,7 @@ def zapTXs(account):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(f"http://x:{APIKEY}@{ip}:12039/wallet/{account_name}/zap",
|
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account_name}/zap",
|
||||||
json={"age": age,
|
json={"age": age,
|
||||||
"account": "default"
|
"account": "default"
|
||||||
})
|
})
|
||||||
|
15
main.py
15
main.py
@ -860,18 +860,23 @@ def auction(domain):
|
|||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
domainInfo = account_module.getDomain(search_term)
|
domainInfo = account_module.getDomain(search_term)
|
||||||
|
error = request.args.get("error")
|
||||||
|
if error == None:
|
||||||
|
error = ""
|
||||||
|
|
||||||
if 'error' in domainInfo:
|
if 'error' in domainInfo:
|
||||||
return render_template("auction.html", account=account,sync=account_module.getNodeSync(),
|
return render_template("auction.html", account=account,sync=account_module.getNodeSync(),
|
||||||
wallet_status=account_module.getWalletStatus(),
|
wallet_status=account_module.getWalletStatus(),
|
||||||
search_term=search_term, domain=domainInfo['error'])
|
search_term=search_term, domain=domainInfo['error'],
|
||||||
|
error=error)
|
||||||
|
|
||||||
if domainInfo['info'] is None:
|
if domainInfo['info'] is None:
|
||||||
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
|
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
|
||||||
return render_template("auction.html", account=account, sync=account_module.getNodeSync(),
|
return render_template("auction.html", account=account, sync=account_module.getNodeSync(),
|
||||||
wallet_status=account_module.getWalletStatus(),
|
wallet_status=account_module.getWalletStatus(),
|
||||||
search_term=search_term,domain=search_term,next_action=next_action,
|
search_term=search_term,domain=search_term,next_action=next_action,
|
||||||
state="AVAILABLE", next="Open Auction")
|
state="AVAILABLE", next="Open Auction",
|
||||||
|
error=error)
|
||||||
|
|
||||||
state = domainInfo['info']['state']
|
state = domainInfo['info']['state']
|
||||||
next_action = ''
|
next_action = ''
|
||||||
@ -966,7 +971,7 @@ def bid(domain):
|
|||||||
blind = float(blind)
|
blind = float(blind)
|
||||||
|
|
||||||
if bid+blind == 0:
|
if bid+blind == 0:
|
||||||
return redirect("/auction/" + domain+ "?message=Invalid bid amount")
|
return redirect("/auction/" + domain+ "?error=Invalid bid amount")
|
||||||
|
|
||||||
|
|
||||||
# Show confirm page
|
# Show confirm page
|
||||||
@ -1018,7 +1023,7 @@ def bid_confirm(domain):
|
|||||||
float(blind))
|
float(blind))
|
||||||
print(response)
|
print(response)
|
||||||
if 'error' in response:
|
if 'error' in response:
|
||||||
return redirect("/auction/" + domain + "?message=" + response['error']['message'])
|
return redirect("/auction/" + domain + "?error=" + response['error']['message'])
|
||||||
|
|
||||||
return redirect("/success?tx=" + response['hash'])
|
return redirect("/success?tx=" + response['hash'])
|
||||||
|
|
||||||
@ -1037,7 +1042,7 @@ def open_auction(domain):
|
|||||||
|
|
||||||
if 'error' in response:
|
if 'error' in response:
|
||||||
if response['error'] != None:
|
if response['error'] != None:
|
||||||
return redirect("/auction/" + domain + "?message=" + response['error']['message'])
|
return redirect("/auction/" + domain + "?error=" + response['error']['message'])
|
||||||
print(response)
|
print(response)
|
||||||
return redirect("/success?tx=" + response['hash'])
|
return redirect("/success?tx=" + response['hash'])
|
||||||
|
|
||||||
|
@ -36,8 +36,7 @@ def listPlugins(update=False):
|
|||||||
if os.system(f"git clone {importurl} customPlugins/{importPath}") != 0:
|
if os.system(f"git clone {importurl} customPlugins/{importPath}") != 0:
|
||||||
continue
|
continue
|
||||||
elif update:
|
elif update:
|
||||||
if os.system(f"cd customPlugins/{importPath} && git pull") != 0:
|
os.system(f"cd customPlugins/{importPath} && git pull")
|
||||||
continue
|
|
||||||
|
|
||||||
# Import plugins from customPlugins/<importPath>
|
# Import plugins from customPlugins/<importPath>
|
||||||
for file in os.listdir(f"customPlugins/{importPath}"):
|
for file in os.listdir(f"customPlugins/{importPath}"):
|
||||||
|
@ -5,10 +5,10 @@ import threading
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
APIKEY = os.environ.get("hsd_api")
|
KEY = account.HSD_API
|
||||||
ip = os.getenv("hsd_ip")
|
IP = account.HSD_IP
|
||||||
if ip is None:
|
PORT = account.HSD_WALLET_PORT
|
||||||
ip = "localhost"
|
|
||||||
|
|
||||||
if not os.path.exists("user_data"):
|
if not os.path.exists("user_data"):
|
||||||
os.mkdir("user_data")
|
os.mkdir("user_data")
|
||||||
@ -148,9 +148,9 @@ def automations_background(authentication):
|
|||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
return
|
return
|
||||||
# Try to send the batch of all renew, reveal and redeem actions
|
# Try to send the batch of all renew, reveal and redeem actions
|
||||||
requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["RENEW"]]]})
|
requests.post(f"http://x:{KEY}@{IP}:{PORT}",json={"method": "sendbatch","params": [[["RENEW"]]]})
|
||||||
requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REVEAL"]]]})
|
requests.post(f"http://x:{KEY}@{IP}:{PORT}",json={"method": "sendbatch","params": [[["REVEAL"]]]})
|
||||||
requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REDEEM"]]]})
|
requests.post(f"http://x:{KEY}@{IP}:{PORT}",json={"method": "sendbatch","params": [[["REDEEM"]]]})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
@ -500,16 +500,15 @@ def advancedChangeLookahead(params, authentication):
|
|||||||
lookahead = int(lookahead)
|
lookahead = int(lookahead)
|
||||||
wallet = authentication.split(":")[0]
|
wallet = authentication.split(":")[0]
|
||||||
password = ":".join(authentication.split(":")[1:])
|
password = ":".join(authentication.split(":")[1:])
|
||||||
APIKEY = os.getenv("hsd_api")
|
KEY = account.HSD_API
|
||||||
ip = os.getenv("hsd_ip")
|
IP = account.HSD_IP
|
||||||
if ip is None:
|
PORT = account.HSD_WALLET_PORT
|
||||||
ip = "localhost"
|
|
||||||
|
|
||||||
# Unlock wallet
|
# Unlock wallet
|
||||||
response = requests.post(f"http://x:{APIKEY}@{ip}:12039/wallet/{wallet}/unlock",
|
response = requests.post(f"http://x:{KEY}@{IP}:{PORT}/wallet/{wallet}/unlock",
|
||||||
json={"passphrase": password, "timeout": 10})
|
json={"passphrase": password, "timeout": 10})
|
||||||
|
|
||||||
response = requests.patch(f"http://x:{APIKEY}@{ip}:12039/wallet/{wallet}/account/default",
|
response = requests.patch(f"http://x:{KEY}@{IP}:{PORT}/wallet/{wallet}/account/default",
|
||||||
json={"lookahead": lookahead})
|
json={"lookahead": lookahead})
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,12 +50,11 @@ def main(params, authentication):
|
|||||||
batches.append(names[i:i+100])
|
batches.append(names[i:i+100])
|
||||||
|
|
||||||
# Unlock wallet
|
# Unlock wallet
|
||||||
api_key = os.getenv("hsd_api")
|
KEY = account.HSD_API
|
||||||
ip = os.getenv("hsd_ip")
|
IP = account.HSD_IP
|
||||||
if api_key is None:
|
PORT = account.HSD_WALLET_PORT
|
||||||
print("API key not set")
|
|
||||||
return {"status": "API key not set", "transaction": "None"}
|
response = requests.post(f'http://x:{KEY}@{IP}:{PORT}/wallet/{wallet}/unlock',
|
||||||
response = requests.post(f'http://x:{api_key}@{ip}:12039/wallet/{wallet}/unlock',
|
|
||||||
json={'passphrase': password, 'timeout': 600})
|
json={'passphrase': password, 'timeout': 600})
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print("Failed to unlock wallet")
|
print("Failed to unlock wallet")
|
||||||
@ -74,7 +73,7 @@ def main(params, authentication):
|
|||||||
|
|
||||||
batchTX = "[" + ", ".join(batch) + "]"
|
batchTX = "[" + ", ".join(batch) + "]"
|
||||||
responseContent = f'{{"method": "sendbatch","params":[ {batchTX} ]}}'
|
responseContent = f'{{"method": "sendbatch","params":[ {batchTX} ]}}'
|
||||||
response = requests.post(f'http://x:{api_key}@{ip}:12039', data=responseContent)
|
response = requests.post(f'http://x:{KEY}@{IP}:{PORT}', data=responseContent)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print("Failed to create batch",flush=True)
|
print("Failed to create batch",flush=True)
|
||||||
print(f'Status code: {response.status_code}',flush=True)
|
print(f'Status code: {response.status_code}',flush=True)
|
||||||
|
53
plugins/testing.py
Normal file
53
plugins/testing.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import json
|
||||||
|
import account
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# Plugin Data
|
||||||
|
info = {
|
||||||
|
"name": "Testing tools",
|
||||||
|
"description": "Testing tools",
|
||||||
|
"version": "1.0",
|
||||||
|
"author": "Nathan.Woodburn/"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
functions = {
|
||||||
|
"generate":{
|
||||||
|
"name": "Generate blocks",
|
||||||
|
"type": "default",
|
||||||
|
"description": "Generate blocks to your wallet",
|
||||||
|
"params": {
|
||||||
|
"numblocks": {
|
||||||
|
"name":"Number of blocks to generate",
|
||||||
|
"type":"number"
|
||||||
|
},
|
||||||
|
"address": {
|
||||||
|
"name":"Address to generate to",
|
||||||
|
"type":"text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"returns": {
|
||||||
|
"status":
|
||||||
|
{
|
||||||
|
"name": "Status of the function",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def generate(params, authentication):
|
||||||
|
# hsd-cli rpc generatetoaddress $numblocks $address
|
||||||
|
number = params["numblocks"]
|
||||||
|
address = params["address"]
|
||||||
|
if number == "" or int(number) < 1:
|
||||||
|
number = 1
|
||||||
|
|
||||||
|
if address == "":
|
||||||
|
wallet = authentication.split(":")[0]
|
||||||
|
address = account.getAddress(wallet)
|
||||||
|
|
||||||
|
print(f"Generating {number} blocks to {address}")
|
||||||
|
blocks = account.hsd.rpc_generateToAddress(address,number)
|
||||||
|
return {"status": f"Successfully generated {number} blocks to {address}"}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user