Skip to content

Commit

Permalink
chore: added zone rebuild using kupo api
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmorano committed May 31, 2023
1 parent d324c61 commit c28c809
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ Using the above example, we can now build a zone file. Using the
a `.cardano` domain with the data from our example. This is a simple proof of
concept of transaction parsing using a remote API.

* Using [gomaestro] API:
```bash
export MAESTRO_API_KEY=${MAESTRO_API_KEY}
python3 dns.py > cardano.zone
```
* Using [kupo] API:
```bash
pip install cbor2 uplc
python3 dns-kupo.py > cardano.zone
```

The current zone [file](cardano.zone) includes our datum from above.

Expand Down Expand Up @@ -134,3 +140,6 @@ If these conditions are met, mint a token pair:
- If I hold a SLD, I can:
- a. create or edit a DNS record at that SLD, OR
- b. create 3rdLDs on my SLD

[gomaestro]: https://www.gomaestro.org/
[kupo]: https://github.com/CardanoSolutions/kupo/
46 changes: 46 additions & 0 deletions dns-kupo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

import json
import os
import requests
import time
import uplc
import cbor2

ADDRESS = 'addr_test1wqgf0d7rdlamdy46hd5u5wq47ql9chvv8w3k70nyqcfgd2qwpvxpx'
NETWORK = 'iohk-preprod'
KUPO_URL = 'https://d.kupo-api.' + NETWORK + '.dandelion.link'

def main():
custom_headers = {"Content-Type": "application/json"}
utxos = requests.get(f"{KUPO_URL}/matches/{ADDRESS}?unspent", headers=custom_headers, timeout=60)
txs = json.loads(utxos.content.decode())

cardano = dict()
now = int(time.time())

print("$ORIGIN cardano.")
print("$TTL 60")
print("@ IN SOA ns1.cardano. hostmaster.cardano. "+str(now)+" 21600 3600 604800 60")
print(" IN NS ns1.cardano.")
print("ns1.cardano. IN A 172.17.0.1")

for tx in txs:
datum_bytes = json.loads(requests.get(f"{KUPO_URL}/datums/{tx['datum_hash']}", headers=custom_headers, timeout=60).content)['datum']

datum_json = uplc.ast.data_from_cbortag(cbor2.loads(bytes.fromhex(datum_bytes))).to_json()

name = bytes.fromhex(datum_json['fields'][0]['bytes']).decode()
origin = bytes.fromhex(datum_json['fields'][1]['bytes']).decode()
soa_raw = datum_json['fields'][2]['fields']
ns_list = datum_json['fields'][3]['list']

if origin.split(".")[-1] == 'cardano':
cardano[name] = dict({"origin": origin})
for ns in ns_list:
print(name + " IN NS " + bytes.fromhex(ns['bytes']).decode() + ".")
print(bytes.fromhex(ns['bytes']).decode() + ". IN A 172.17.0.1")

if __name__ == '__main__':
main()

0 comments on commit c28c809

Please sign in to comment.