diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 154902a..5720522 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -79,6 +79,7 @@ post-install-commands = [ [tool.hatch.envs.default.scripts] dev = [ "python src/luce/manage.py migrate", + "python scripts/init_luce_registry.py", "python src/luce/manage.py runserver localhost:8000 {args}", ] test = "python src/luce/manage.py test {args}" diff --git a/backend/scripts/entrypoint.sh b/backend/scripts/entrypoint.sh index 058a32e..ca2655e 100755 --- a/backend/scripts/entrypoint.sh +++ b/backend/scripts/entrypoint.sh @@ -40,12 +40,13 @@ python /app/src/luce/manage.py migrate # echo "provider@luce.com | provider" # echo "requester@luce.com | requester" +# python /app/scripts/init_luce_registry.py + + echo "🚀 Access the LUCE backend API on http://localhost:8000" # Start Django on port 8000 python /app/src/luce/manage.py runserver 0.0.0.0:8000 - - # curl -H "Authorization: XXX" -H "Content-Type: application/json" -X POST http://localhost8000/admin/deployRegistry diff --git a/backend/scripts/init_luce_registry.py b/backend/scripts/init_luce_registry.py new file mode 100644 index 0000000..84adf84 --- /dev/null +++ b/backend/scripts/init_luce_registry.py @@ -0,0 +1,28 @@ +import os +from brownie import accounts +from brownie import project, network +import django + + + +p = project.load("brownie", name="BrownieProject") +p.load_config() +network.connect('luce') + +from brownie.project.BrownieProject import LUCERegistry + +DJANGO_SETTINGS_MODULE = 'lucehome.settings' +os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE +django.setup() + +# account[0] as the administrator +contract = LUCERegistry.deploy({'from': accounts[0]}) +receipt = contract.tx +if receipt.status == 1: + contract_address = receipt.contract_address + print("Deploy LUCERegistry contract succeeded") +else: + print("Deploy LUCERegistry contract failed") + +print(contract_address) +print(receipt.status) diff --git a/backend/src/luce/blockchain/models.py b/backend/src/luce/blockchain/models.py index 1cb7bf7..c0559c1 100644 --- a/backend/src/luce/blockchain/models.py +++ b/backend/src/luce/blockchain/models.py @@ -107,7 +107,6 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) def deploy(self): - from brownie import accounts from brownie.project.BrownieProject import PlonkVerifier # 1. deploy contract @@ -125,7 +124,6 @@ class LuceRegistryContract(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) def deploy(self): - # from brownie import accounts from brownie.project.BrownieProject import LUCERegistry # account[0] as the administrator @@ -394,7 +392,7 @@ def deploy(self): print("proof\n" + str(proof['public_signals'])) commitment = { "public_signals": proof['public_signals'] - + } contract = LuceMain.deploy(verifier_address, diff --git a/docker-compose.yml b/docker-compose.yml index d349ef5..9e141a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,7 @@ services: restart: unless-stopped volumes: - ./backend/src:/app/backend/src + - ./backend/scripts:/app/backend/scripts environment: # PostgreSQL config - DJANGO_USE_PSQL=true