Skip to main content

Django-Tezos

Project description

djTezos: Django-Tezos

Django-Tezos provides Django Models and uWSGI Spooler (djCall) integration with PyTezos.

Install djTezos

Install djtezos with pip then add djtezos to INSTALLED_APPS.

Run ./manage.py migrate to create tables for djtezos models.

You need a SECRET_KEY that is sufficiently long for AES.

Add Blockchains

Blockchain is the first model you have to manage, you can do it in the admin. For any blockchain, you can choose a Python Provider Class, such as djtezos.tezos.Provider or djtezos.fake.Provider for a mock that you can use in tests.

Example:

tzlocal = Blockchain.objects.create(
    name='tzlocal',
    endpoint='http://tz:8732',
    provider_class='djtezos.tezos.Provider',
    is_active=True,
    confirmation_blocks=1,
)

Run tzlocal with: docker run --name tz --rm --publish 8732:8732 yourlabs/tezos

Add to /etc/hosts: tz on line starting with 127.0.0.1

In gitlab-ci, add:

services:
- name: yourlabs/tezos
  alias: tz

Create accounts

Create an account for a user:

account = user.account_set.create(blockchain=tzlocal)

Users can have as many accounts as you want.

Queue

Transactions are queued in the database with the Transaction model. You can emit 3 types of Transactions.

Deploy a smart contract

Create a Transaction with a contract_code to deploy a smart contract:

    contract = Transaction.objects.create(
        sender=account,
        contract_code=mich,
        contract_name='test',
        args={'int': '1'},
        state='deploy',
    )

You may then retreive it through either of the Transaction model and the Contract proxy model.

Call a smart contract function

Call a smart contract function with a new Transaction:

    call = Transaction.objects.create(
        sender=account,
        contract=contract,
        function='replace',
        args=[3],
        state='deploy',
    )

This calls the replace function with only one arg: an integer of 3.

A Call proxy model is also available to retrieve.

Execute a transfer

Create a transfer on the blockchain:

    transfer = Transaction.objects.create(
        sender=account,
        receiver=account2,
        amount=10000,
        state='deploy',
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djtezos-0.3.3.tar.gz (17.5 kB view details)

Uploaded Source

File details

Details for the file djtezos-0.3.3.tar.gz.

File metadata

  • Download URL: djtezos-0.3.3.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for djtezos-0.3.3.tar.gz
Algorithm Hash digest
SHA256 3947653c74da9ff76c560c5d02b5c345141fad84ae76302f50fd6a224c410371
MD5 f223c4422a28b8aff2f92883ba6aae44
BLAKE2b-256 3290417751915ab7f566fbe5b65855e1f685aa35aad8072d92540c463bc68c08

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page