/ginop

Blockchain based wrapper for Django.

Primary LanguagePythonMIT LicenseMIT

GINOP

Read here for community information

A wrapper built around django.


Report Bug ยท Request Feature ยท Blog coming soon

๐Ÿ“ฆ Why

Ginop provides a wrapper around a proof of work chain and public-chain connector to allow for your own custom service implementations on the blockchain in django. An idea inspired by The Source Project I was able to bring private chain and public chain connectors together.

๐Ÿ’… Features

  • ๐Ÿš€ API built on top of a blockchain.
  • ๐Ÿ›ก Easily manage your service provider, chain events or api.
  • ๐Ÿš€ Equipped with an proof of work chain and public chain connector.
  • ๐Ÿš€ Easy to set up and integrate.
  • ๐Ÿ›ก Written in Python.

๐Ÿ‘จโ€๐Ÿ’ป Install

pipenv install .

๐Ÿ•น๏ธ Running test

pipenv run pytest tests/

๐Ÿงƒ Starting api

python3 manage.py runserver

๐Ÿ“ต Making migrations

python3 manage.py makemigrations && python3 manage.py migrate

๐Ÿ”จ Usage

  • The ginop API is a service built on top of a proof of work blockchain. This is still in development but will serve as a platform for building services over your own private chain, or over well-known public chains like etherium and more. To use the public chain connectors you need to install Ganache provided by the truffle framework. Here you can connect directly to the truffle framework and write smart contracts, manage blocks and create transactions.

On Chain Platform

Ginop provides in memory blockchain for saftey and security. This decision is based on a cost effective approach to implementing smart contract verification. The onChain approach to web3 workflow will allow self service into your own private chain. This original idea is based on proof of work and will expand deeper into other implementations such as geospatial, sms, and biometric based proof of concepts.

๐Ÿ“ฑ API

  • The API's will be available soon to review as working examples to build off of.
class PrivateChainView(APIView):
    """
    Example endpoint for handling actions on the private chain.
    """
        
    def get(self, request, format=None, *args, **kwargs):
        chain_data = []
        
        for block in blockchain.chain:
            chain_data.append(block.__dict__)
        
        context = json.dumps({"length": len(chain_data),
                        "chain": chain_data})
        
        return Response(context, status=status.HTTP_200_OK)

๐Ÿฆ„ Blocks

Here is a snippet of the blocks.

class Block:
    
    def __init__(self, index, transactions, timestamp, previous_hash, nonce=0):
        self.index: BlockTypes.index = index
        self.transactions: BlockTypes.transactions = transactions
        self.timestamp: BlockTypes.timestamp = timestamp
        self.previous_hash: BlockTypes.previous_hash = previous_hash
        self.nonce: BlockTypes.nonce = nonce
    
    def compute_hash(self):
        block_string = json.dumps(self.__dict__, sort_keys=True)
        return sha256(block_string.encode()).hexdigest()

๐Ÿง  Providers

  • Public providers exist using the truffle framework to connect to in-memory chains like Ganache, or public chains like etherium or others.
class MetaFormat(Enum):
    HTTP_PROVIDER = Web3(Web3.HTTPProvider(os.environ.get('ON_CHAIN_URL')))

    #add your own providers below.
  

๐Ÿ‘‡ Smart Contract (Coming Soon...)

  • dev/ folder is comprised of working scripts for the private chain, public chain providers, and on chain action handlers like writing smart contracts, governing transactions and more. The smart contracts will be written using web3.py.
import json
from web3 import Web3

# Set up web3 connection with Ganache
ganache_url = "http://127.0.0.1:7545"
web3 = Web3(Web3.HTTPProvider(ganache_url))

# Set a default account to sign transactions - this account is unlocked with Ganache
web3.eth.defaultAccount = web3.eth.accounts[0]

# Greeter contract ABI
abi = json.loads('[{"constant":false,"inputs":[{"name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"greeting","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]')

# Greeter contract address - convert to checksum address
address = web3.toChecksumAddress('') # FILL ME IN

# Initialize contract
contract = web3.eth.contract(address=address, abi=abi)\

# Read the default greeting
print(contract.functions.greet().call())

# Set a new greeting
tx_hash = contract.functions.setGreeting('HEELLLLOOOOOO!!!').transact()

# Wait for transaction to be mined
web3.eth.waitForTransactionReceipt(tx_hash)

# Display the new greeting value
print('Updated contract greeting: {}'.format(
    contract.functions.greet().call()
))

๐Ÿ”— Links