generated from nathanwoodburn/python-webserver-template
feat: Add method for getting domain owner address
All checks were successful
Build Docker / BuildImage (push) Successful in 2m42s
All checks were successful
Build Docker / BuildImage (push) Successful in 2m42s
This commit is contained in:
44
server.py
44
server.py
@@ -86,7 +86,49 @@ def verify_domain():
|
||||
"params": [domain]
|
||||
}
|
||||
)
|
||||
return jsonify(nameInfo.json()), 200
|
||||
# Verify error is none
|
||||
if nameInfo.status_code != 200:
|
||||
return jsonify({"error": "Failed to get name info"}), 500
|
||||
|
||||
# Convert response to JSON
|
||||
try:
|
||||
nameInfo = nameInfo.json()
|
||||
except json.JSONDecodeError:
|
||||
return jsonify({"error": "Failed to decode JSON response"}), 500
|
||||
|
||||
if nameInfo["error"] is not None:
|
||||
return jsonify({"error": nameInfo["error"]}), 500
|
||||
|
||||
# Get .result.info.owner.hash and .result.info.owner.index
|
||||
if "result" not in nameInfo or "info" not in nameInfo["result"]:
|
||||
return jsonify({"error": "Invalid response format"}), 500
|
||||
if "owner" not in nameInfo["result"]["info"]:
|
||||
return jsonify({"error": "Owner not found in response"}), 500
|
||||
if "hash" not in nameInfo["result"]["info"]["owner"] or "index" not in nameInfo["result"]["info"]["owner"]:
|
||||
return jsonify({"error": "Owner hash or index not found in response"}), 500
|
||||
|
||||
owner_hash = nameInfo["result"]["info"]["owner"]["hash"]
|
||||
owner_index = nameInfo["result"]["info"]["owner"]["index"]
|
||||
|
||||
coinInfo = requests.get(f"http://x:{apiKEY}@{host}:12037/coin/{owner_hash}/{owner_index}")
|
||||
if coinInfo.status_code != 200:
|
||||
return jsonify({"error": "Failed to get coin info"}), 500
|
||||
|
||||
# Convert coinInfo response to JSON
|
||||
try:
|
||||
coinInfo = coinInfo.json()
|
||||
except json.JSONDecodeError:
|
||||
return jsonify({"error": "Failed to decode JSON response"}), 500
|
||||
|
||||
if "address" not in coinInfo:
|
||||
return jsonify({"error": "Address not found in coin info"}), 500
|
||||
|
||||
return jsonify({
|
||||
"domain": domain,
|
||||
"owner_hash": owner_hash,
|
||||
"owner_index": owner_index,
|
||||
"address": coinInfo["address"]
|
||||
}), 200
|
||||
|
||||
@app.route("/renew", methods=["POST"])
|
||||
def renew():
|
||||
|
||||
Reference in New Issue
Block a user