forked from nathanwoodburn/firewalletbrowser
fix: Allow wallet acctions from unencrypted wallets
This commit is contained in:
@@ -122,7 +122,7 @@ HSD_IP: HSD IP address
|
||||
THEME: Theme to use (dark-purple, black)
|
||||
SHOW_EXPIRED: Show expired domains (true/false)
|
||||
EXCLUDE: Comma separated list of wallets to exclude from the wallet list (default primary)
|
||||
EXPLORER_TX: URL for exploring transactions (default https://niami.io/tx/)
|
||||
EXPLORER_TX: URL for exploring transactions (default https://shakeshift.com/transaction/)
|
||||
HSD_NETWORK: Network to connect to (main, regtest, simnet)
|
||||
```
|
||||
|
||||
|
||||
91
account.py
91
account.py
@@ -51,11 +51,13 @@ EXCLUDE = ["primary"]
|
||||
if os.getenv("EXCLUDE") is not None:
|
||||
EXCLUDE = os.getenv("EXCLUDE").split(",")
|
||||
|
||||
|
||||
def hsdConnected():
|
||||
if hsdVersion() == -1:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def hsdVersion(format=True):
|
||||
info = hsd.getInfo()
|
||||
if 'error' in info:
|
||||
@@ -65,6 +67,7 @@ def hsdVersion(format=True):
|
||||
else:
|
||||
return info['version']
|
||||
|
||||
|
||||
def check_account(cookie: str):
|
||||
if cookie is None:
|
||||
return False
|
||||
@@ -80,6 +83,7 @@ def check_account(cookie: str):
|
||||
return False
|
||||
return account
|
||||
|
||||
|
||||
def check_password(cookie: str, password: str):
|
||||
account = check_account(cookie)
|
||||
if account == False:
|
||||
@@ -95,6 +99,7 @@ def check_password(cookie: str, password: str):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def createWallet(account: str, password: str):
|
||||
if not hsdConnected():
|
||||
return {
|
||||
@@ -104,7 +109,8 @@ def createWallet(account: str, password: str):
|
||||
}
|
||||
# Create the account
|
||||
# Python wrapper doesn't support this yet
|
||||
response = requests.put(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}")
|
||||
response = requests.put(
|
||||
f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}")
|
||||
if response.status_code != 200:
|
||||
return {
|
||||
"error": {
|
||||
@@ -116,7 +122,6 @@ def createWallet(account: str, password: str):
|
||||
seed = hsw.getMasterHDKey(account)
|
||||
seed = seed['mnemonic']['phrase']
|
||||
|
||||
|
||||
# Encrypt the wallet (python wrapper doesn't support this yet)
|
||||
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/passphrase",
|
||||
json={"passphrase": password})
|
||||
@@ -127,6 +132,7 @@ def createWallet(account: str, password: str):
|
||||
"password": password
|
||||
}
|
||||
|
||||
|
||||
def importWallet(account: str, password: str, seed: str):
|
||||
if not hsdConnected():
|
||||
return {
|
||||
@@ -141,7 +147,8 @@ def importWallet(account: str, password: str,seed: str):
|
||||
"mnemonic": seed,
|
||||
}
|
||||
|
||||
response = requests.put(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/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:
|
||||
return {
|
||||
"error": {
|
||||
@@ -168,6 +175,7 @@ def listWallets():
|
||||
return response
|
||||
return ['Wallet not connected']
|
||||
|
||||
|
||||
def selectWallet(account: str):
|
||||
# Select wallet
|
||||
response = hsw.rpc_selectWallet(account)
|
||||
@@ -178,6 +186,7 @@ def selectWallet(account: str):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getBalance(account: str):
|
||||
# Get the total balance
|
||||
info = hsw.getBalance('default', account)
|
||||
@@ -200,13 +209,13 @@ def getBalance(account: str):
|
||||
total = total - (domainValue/1000000)
|
||||
locked = locked - (domainValue/1000000)
|
||||
|
||||
|
||||
# Only keep 2 decimal places
|
||||
total = round(total, 2)
|
||||
available = round(available, 2)
|
||||
|
||||
return {'available': available, 'total': total, 'locked': locked}
|
||||
|
||||
|
||||
def getBlockHeight():
|
||||
# Get the block height
|
||||
info = hsd.getInfo()
|
||||
@@ -214,6 +223,7 @@ def getBlockHeight():
|
||||
return 0
|
||||
return info['chain']['height']
|
||||
|
||||
|
||||
def getAddress(account: str):
|
||||
# Get the address
|
||||
info = hsw.getAccountInfo(account, 'default')
|
||||
@@ -221,6 +231,7 @@ def getAddress(account: str):
|
||||
return ''
|
||||
return info['receiveAddress']
|
||||
|
||||
|
||||
def getPendingTX(account: str):
|
||||
pending = 0
|
||||
page = 1
|
||||
@@ -237,11 +248,14 @@ def getPendingTX(account: str):
|
||||
break
|
||||
return pending
|
||||
|
||||
|
||||
def getDomains(account, own=True):
|
||||
if own:
|
||||
response = requests.get(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name?own=true")
|
||||
response = requests.get(
|
||||
f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name?own=true")
|
||||
else:
|
||||
response = requests.get(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name")
|
||||
response = requests.get(
|
||||
f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name")
|
||||
info = response.json()
|
||||
|
||||
if SHOW_EXPIRED:
|
||||
@@ -256,9 +270,9 @@ def getDomains(account,own=True):
|
||||
continue
|
||||
domains.append(domain)
|
||||
|
||||
|
||||
return domains
|
||||
|
||||
|
||||
def getPageTXCache(account, page, size=100):
|
||||
page = f"{page}-{size}"
|
||||
if not os.path.exists(f'cache'):
|
||||
@@ -274,6 +288,7 @@ def getPageTXCache(account,page,size=100):
|
||||
return pageCache[page]['txid']
|
||||
return None
|
||||
|
||||
|
||||
def pushPageTXCache(account, page, txid, size=100):
|
||||
page = f"{page}-{size}"
|
||||
if not os.path.exists(f'cache/{account}_page.json'):
|
||||
@@ -291,6 +306,7 @@ def pushPageTXCache(account,page,txid,size=100):
|
||||
|
||||
return pageCache[page]['txid']
|
||||
|
||||
|
||||
def getTXFromPage(account, page, size=100):
|
||||
if page == 1:
|
||||
return getTransactions(account, 1, size)[-1]['hash']
|
||||
@@ -306,7 +322,6 @@ def getTXFromPage(account,page,size=100):
|
||||
return hash
|
||||
|
||||
|
||||
|
||||
def getTransactions(account, page=1, limit=100):
|
||||
# Get the transactions
|
||||
if hsdVersion() < 7:
|
||||
@@ -324,9 +339,11 @@ def getTransactions(account,page=1,limit=100):
|
||||
lastTX = getTXFromPage(account, page-1, limit)
|
||||
|
||||
if lastTX:
|
||||
response = requests.get(f'http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/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:
|
||||
response = requests.get(f'http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/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:
|
||||
return []
|
||||
|
||||
@@ -342,6 +359,7 @@ def getTransactions(account,page=1,limit=100):
|
||||
pushPageTXCache(account, page, data[-1]['hash'], limit)
|
||||
return data
|
||||
|
||||
|
||||
def getAllTransactions(account):
|
||||
# Get the transactions
|
||||
page = 0
|
||||
@@ -353,6 +371,7 @@ def getAllTransactions(account):
|
||||
page += 1
|
||||
return txs
|
||||
|
||||
|
||||
def check_address(address: str, allow_name: bool = True, return_address: bool = False):
|
||||
# Check if the address is valid
|
||||
if address.startswith('@'):
|
||||
@@ -399,7 +418,6 @@ def check_hip2(domain: str):
|
||||
return address
|
||||
|
||||
|
||||
|
||||
def send(account, address, amount):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -416,6 +434,7 @@ def send(account,address,amount):
|
||||
# response = requests.post(f"http://x:{APIKEY}@{ip}:{HSD_WALLET_PORT}/wallet/{account_name}/unlock",
|
||||
# json={"passphrase": password,"timeout": 10})
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -433,6 +452,7 @@ def send(account,address,amount):
|
||||
"tx": response['result']
|
||||
}
|
||||
|
||||
|
||||
def isOwnDomain(account, name: str):
|
||||
domains = getDomains(account)
|
||||
for domain in domains:
|
||||
@@ -452,6 +472,7 @@ def getDomain(domain: str):
|
||||
}
|
||||
return response['result']
|
||||
|
||||
|
||||
def renewDomain(account, domain):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -466,6 +487,7 @@ def renewDomain(account,domain):
|
||||
response = hsw.sendRENEW(account_name, password, domain)
|
||||
return response
|
||||
|
||||
|
||||
def getDNS(domain: str):
|
||||
# Get the DNS
|
||||
response = hsd.rpc_getNameResource(domain)
|
||||
@@ -484,6 +506,7 @@ def getDNS(domain: str):
|
||||
return []
|
||||
return response['result']['records']
|
||||
|
||||
|
||||
def setDNS(account, domain, records):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -528,10 +551,12 @@ def setDNS(account,domain,records):
|
||||
response = hsw.sendUPDATE(account_name, password, domain, data)
|
||||
return response
|
||||
|
||||
|
||||
def register(account, domain):
|
||||
# Maybe add default dns records?
|
||||
return setDNS(account, domain, '[]')
|
||||
|
||||
|
||||
def getNodeSync():
|
||||
response = hsd.getInfo()
|
||||
if 'error' in response:
|
||||
@@ -541,6 +566,7 @@ def getNodeSync():
|
||||
sync = round(sync, 2)
|
||||
return sync
|
||||
|
||||
|
||||
def getWalletStatus():
|
||||
response = hsw.rpc_getWalletInfo()
|
||||
if 'error' in response and response['error'] != None:
|
||||
@@ -559,7 +585,6 @@ def getWalletStatus():
|
||||
return "Error wallet ahead of node"
|
||||
|
||||
|
||||
|
||||
def getBids(account, domain="NONE"):
|
||||
if domain == "NONE":
|
||||
response = hsw.getWalletBids(account)
|
||||
@@ -577,9 +602,11 @@ def getBids(account, domain="NONE"):
|
||||
bids.append(bid)
|
||||
return bids
|
||||
|
||||
|
||||
def getReveals(account, domain):
|
||||
return hsw.getWalletRevealsByName(domain, account)
|
||||
|
||||
|
||||
def getPendingReveals(account):
|
||||
bids = getBids(account)
|
||||
domains = getDomains(account, False)
|
||||
@@ -626,6 +653,7 @@ def getPendingRedeems(account,password):
|
||||
|
||||
return pending
|
||||
|
||||
|
||||
def getPendingRegisters(account):
|
||||
bids = getBids(account)
|
||||
domains = getDomains(account, False)
|
||||
@@ -638,6 +666,7 @@ def getPendingRegisters(account):
|
||||
pending.append(bid)
|
||||
return pending
|
||||
|
||||
|
||||
def getPendingFinalizes(account, password):
|
||||
tx = createBatch(f'{account}:{password}', [["FINALIZE"]])
|
||||
if 'error' in tx:
|
||||
@@ -696,6 +725,7 @@ def revealAuction(account,domain):
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
def revealAll(account):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -714,7 +744,12 @@ def revealAll(account):
|
||||
return
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
return
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
}
|
||||
}
|
||||
|
||||
return requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={"method": "sendbatch", "params": [[["REVEAL"]]]}).json()
|
||||
except Exception as e:
|
||||
@@ -724,6 +759,7 @@ def revealAll(account):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def redeemAll(account):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -742,7 +778,12 @@ def redeemAll(account):
|
||||
return
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
return
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
}
|
||||
}
|
||||
|
||||
return requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={"method": "sendbatch", "params": [[["REDEEM"]]]}).json()
|
||||
except Exception as e:
|
||||
@@ -752,6 +793,7 @@ def redeemAll(account):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def registerAll(account):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -776,6 +818,7 @@ def registerAll(account):
|
||||
batch.append(["UPDATE", domain['name'], {"records": []}])
|
||||
return sendBatch(account, batch)
|
||||
|
||||
|
||||
def finalizeAll(account):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -789,6 +832,7 @@ def finalizeAll(account):
|
||||
|
||||
return sendBatch(account, [["FINALIZE"]])
|
||||
|
||||
|
||||
def rescan_auction(account, domain):
|
||||
# Get height of the start of the auction
|
||||
response = hsw.rpc_selectWallet(account)
|
||||
@@ -853,7 +897,6 @@ def openAuction(account,domain):
|
||||
}
|
||||
|
||||
|
||||
|
||||
def transfer(account, domain, address):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -875,6 +918,7 @@ def transfer(account,domain,address):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def finalize(account, domain):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -896,6 +940,7 @@ def finalize(account,domain):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -910,6 +955,7 @@ def finalize(account,domain):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def cancelTransfer(account, domain):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -931,6 +977,7 @@ def cancelTransfer(account,domain):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -945,6 +992,7 @@ def cancelTransfer(account,domain):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def revoke(account, domain):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -966,6 +1014,7 @@ def revoke(account,domain):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -980,6 +1029,7 @@ def revoke(account,domain):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def sendBatch(account, batch):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -1001,6 +1051,7 @@ def sendBatch(account, batch):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -1027,6 +1078,7 @@ def sendBatch(account, batch):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def createBatch(account, batch):
|
||||
account_name = check_account(account)
|
||||
password = ":".join(account.split(":")[1:])
|
||||
@@ -1048,6 +1100,7 @@ def createBatch(account, batch):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -1087,6 +1140,7 @@ def rescan():
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def resendTXs():
|
||||
try:
|
||||
response = hsw.walletResend()
|
||||
@@ -1099,7 +1153,6 @@ def resendTXs():
|
||||
}
|
||||
|
||||
|
||||
|
||||
def zapTXs(account):
|
||||
age = 60 * 20 # 20 minutes
|
||||
|
||||
@@ -1136,7 +1189,6 @@ def getxPub(account):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
response = hsw.getAccountInfo(account_name, "default")
|
||||
if 'error' in response:
|
||||
@@ -1167,7 +1219,6 @@ def signMessage(account,domain,message):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
response = hsw.rpc_selectWallet(account_name)
|
||||
if response['error'] is not None:
|
||||
@@ -1178,6 +1229,7 @@ def signMessage(account,domain,message):
|
||||
}
|
||||
response = hsw.rpc_walletPassphrase(password, 10)
|
||||
if response['error'] is not None:
|
||||
if response['error']['message'] != "Wallet is not encrypted.":
|
||||
return {
|
||||
"error": {
|
||||
"message": response['error']['message']
|
||||
@@ -1192,6 +1244,7 @@ def signMessage(account,domain,message):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def verifyMessageWithName(domain, signature, message):
|
||||
try:
|
||||
response = hsd.rpc_verifyMessageWithName(domain, signature, message)
|
||||
@@ -1213,6 +1266,7 @@ def verifyMessage(address,signature,message):
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
def generateReport(account, format="{name},{expiry},{value},{maxBid}"):
|
||||
domains = getDomains(account)
|
||||
|
||||
@@ -1238,5 +1292,6 @@ def generateReport(account,format="{name},{expiry},{value},{maxBid}"):
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
def convertHNS(value: int):
|
||||
return value/1000000
|
||||
10
main.py
10
main.py
@@ -178,7 +178,15 @@ def sendConfirmed():
|
||||
address = request.args.get("address")
|
||||
amount = float(request.args.get("amount"))
|
||||
response = account_module.send(request.cookies.get("account"),address,amount)
|
||||
if 'error' in response:
|
||||
if 'error' in response and response['error'] != None:
|
||||
# If error is a dict get the message
|
||||
if isinstance(response['error'], dict):
|
||||
if 'message' in response['error']:
|
||||
return redirect("/send?message=" + response['error']['message'] + "&address=" + address + "&amount=" + str(amount))
|
||||
else:
|
||||
return redirect("/send?message=" + str(response['error']) + "&address=" + address + "&amount=" + str(amount))
|
||||
|
||||
# If error is a string
|
||||
return redirect("/send?message=" + response['error'] + "&address=" + address + "&amount=" + str(amount))
|
||||
|
||||
return redirect("/success?tx=" + response['tx'])
|
||||
|
||||
@@ -9,7 +9,7 @@ import os
|
||||
info = {
|
||||
"name": "Batching Functions",
|
||||
"description": "This is a plugin that provides multiple functions to batch transactions",
|
||||
"version": "1.0",
|
||||
"version": "1.1",
|
||||
"author": "Nathan.Woodburn/"
|
||||
}
|
||||
# https://hsd-dev.org/api-docs/?shell--cli#sendbatch
|
||||
@@ -394,7 +394,6 @@ def bid(params, authentication):
|
||||
for domain in domains:
|
||||
batch.append(['BID', domain, bid, blind])
|
||||
|
||||
print(batch)
|
||||
response = sendBatch(batch, authentication)
|
||||
if 'error' in response:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user