feat: Cleanup urls in account module
All checks were successful
Build Docker / Build Image (push) Successful in 1m12s
All checks were successful
Build Docker / Build Image (push) Successful in 1m12s
This commit is contained in:
58
account.py
58
account.py
@@ -109,8 +109,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(
|
response = requests.put(get_wallet_api_url(f"wallet/{account}"))
|
||||||
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": {
|
||||||
@@ -123,7 +122,7 @@ def createWallet(account: str, password: str):
|
|||||||
seed = seed['mnemonic']['phrase']
|
seed = seed['mnemonic']['phrase']
|
||||||
|
|
||||||
# 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:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/passphrase",
|
response = requests.post(get_wallet_api_url(f"/wallet/{account}/passphrase"),
|
||||||
json={"passphrase": password})
|
json={"passphrase": password})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -147,8 +146,7 @@ def importWallet(account: str, password: str, seed: str):
|
|||||||
"mnemonic": seed,
|
"mnemonic": seed,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.put(
|
response = requests.put(get_wallet_api_url(f"/wallet/{account}"), json=data)
|
||||||
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": {
|
||||||
@@ -251,11 +249,9 @@ def getPendingTX(account: str):
|
|||||||
|
|
||||||
def getDomains(account, own=True):
|
def getDomains(account, own=True):
|
||||||
if own:
|
if own:
|
||||||
response = requests.get(
|
response = requests.get(get_wallet_api_url(f"/wallet/{account}/name?own=true"))
|
||||||
f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/name?own=true")
|
|
||||||
else:
|
else:
|
||||||
response = requests.get(
|
response = requests.get(get_wallet_api_url(f"/wallet/{account}/name"))
|
||||||
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:
|
||||||
@@ -339,11 +335,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(
|
response = requests.get(get_wallet_api_url(f"/wallet/{account}/tx/history?reverse=true&limit={limit}&after={lastTX}"))
|
||||||
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(
|
response = requests.get(get_wallet_api_url(f"/wallet/{account}/tx/history?reverse=true&limit={limit}"))
|
||||||
f'http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account}/tx/history?reverse=true&limit={limit}')
|
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -383,7 +377,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:{HSD_API}@{HSD_IP}:{HSD_NODE_PORT}", json={
|
response = requests.post(get_node_api_url(), json={
|
||||||
"method": "validateaddress",
|
"method": "validateaddress",
|
||||||
"params": [address]
|
"params": [address]
|
||||||
}).json()
|
}).json()
|
||||||
@@ -431,8 +425,6 @@ 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}:{HSD_WALLET_PORT}/wallet/{account_name}/unlock",
|
|
||||||
# json={"passphrase": password,"timeout": 10})
|
|
||||||
if response['error'] is not None:
|
if response['error'] is not None:
|
||||||
if response['error']['message'] != "Wallet is not encrypted.":
|
if response['error']['message'] != "Wallet is not encrypted.":
|
||||||
return {
|
return {
|
||||||
@@ -474,7 +466,7 @@ def getDomain(domain: str):
|
|||||||
|
|
||||||
def getAddressFromCoin(coinhash: str, coinindex = 0):
|
def getAddressFromCoin(coinhash: str, coinindex = 0):
|
||||||
# Get the address from the hash
|
# Get the address from the hash
|
||||||
response = requests.get(f"http://x:{HSD_API}@{HSD_IP}:{HSD_NODE_PORT}/coin/{coinhash}/{coinindex}")
|
response = requests.get(get_node_api_url(f"coin/{coinhash}/{coinindex}"))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return "No Owner"
|
return "No Owner"
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@@ -775,7 +767,7 @@ def revealAll(account):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={"method": "sendbatch", "params": [[["REVEAL"]]]}).json()
|
return requests.post(get_wallet_api_url(), json={"method": "sendbatch", "params": [[["REVEAL"]]]}).json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@@ -809,7 +801,7 @@ def redeemAll(account):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={"method": "sendbatch", "params": [[["REDEEM"]]]}).json()
|
return requests.post(get_wallet_api_url(), json={"method": "sendbatch", "params": [[["REDEEM"]]]}).json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"error": {
|
"error": {
|
||||||
@@ -1081,7 +1073,7 @@ def sendBatch(account, batch):
|
|||||||
"message": response['error']['message']
|
"message": response['error']['message']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={
|
response = requests.post(get_wallet_api_url(), json={
|
||||||
"method": "sendbatch",
|
"method": "sendbatch",
|
||||||
"params": [batch]
|
"params": [batch]
|
||||||
}).json()
|
}).json()
|
||||||
@@ -1130,7 +1122,7 @@ def createBatch(account, batch):
|
|||||||
"message": response['error']['message']
|
"message": response['error']['message']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}", json={
|
response = requests.post(get_wallet_api_url(), json={
|
||||||
"method": "createbatch",
|
"method": "createbatch",
|
||||||
"params": [batch]
|
"params": [batch]
|
||||||
}).json()
|
}).json()
|
||||||
@@ -1190,7 +1182,7 @@ def zapTXs(account):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}/wallet/{account_name}/zap",
|
response = requests.post(get_wallet_api_url(f"/wallet/{account_name}/zap"),
|
||||||
json={"age": age,
|
json={"age": age,
|
||||||
"account": "default"
|
"account": "default"
|
||||||
})
|
})
|
||||||
@@ -1319,3 +1311,25 @@ def generateReport(account, format="{name},{expiry},{value},{maxBid}"):
|
|||||||
|
|
||||||
def convertHNS(value: int):
|
def convertHNS(value: int):
|
||||||
return value/1000000
|
return value/1000000
|
||||||
|
return value/1000000
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_api_url(path=''):
|
||||||
|
"""Construct a URL for the HSD node API."""
|
||||||
|
base_url = f"http://x:{HSD_API}@{HSD_IP}:{HSD_NODE_PORT}"
|
||||||
|
if path:
|
||||||
|
# Ensure path starts with a slash if it's not empty
|
||||||
|
if not path.startswith('/'):
|
||||||
|
path = f'/{path}'
|
||||||
|
return f"{base_url}{path}"
|
||||||
|
return base_url
|
||||||
|
|
||||||
|
def get_wallet_api_url(path=''):
|
||||||
|
"""Construct a URL for the HSD wallet API."""
|
||||||
|
base_url = f"http://x:{HSD_API}@{HSD_IP}:{HSD_WALLET_PORT}"
|
||||||
|
if path:
|
||||||
|
# Ensure path starts with a slash if it's not empty
|
||||||
|
if not path.startswith('/'):
|
||||||
|
path = f'/{path}'
|
||||||
|
return f"{base_url}{path}"
|
||||||
|
return base_url
|
||||||
|
|||||||
Reference in New Issue
Block a user