Пример #1
0
def project():
    # Hardcoded the config for the project
    # It will read user-specific configs also which may override it
    if not hasattr(_project, 'project'):
        project_dir = join(dirname(abspath(nkms_eth.__file__)), 'project')
        project = populus.Project(project_dir)
        project.config['chains.mainnetrpc']['contracts']['backends']['JSONFile']['settings']['file_path'] = REGISTRAR_PATH
        _project.project = project
    return _project.project
Пример #2
0
    def __init__(self):
        self._python_project_name = 'nucypher-kms'

        # This config is persistent and is created in user's .local directory
        self._registrar_path = join(
            appdirs.user_data_dir(self._python_project_name), 'registrar.json')

        # Populus project config
        self._project_dir = join(dirname(abspath(nkms_eth.__file__)),
                                 'project')
        self._populus_project = populus.Project(self._project_dir)
        self.project.config[
            'chains.mainnetrpc.contracts.backends.JSONFile.settings.file_path'] = self._registrar_path
def deploySubscription():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        # Load Populus contract proxy classes
        Subscription = chain.provider.get_contract_factory('Subscription')

        web3 = chain.web3
        print("Web3 provider is", web3.providers)

        # default account from populus perspective
        ownerAddr = web3.eth.defaultAccount

        print("Contracts will be deployed from: {}".format(ownerAddr))

        # defaultGasPrice = web3.eth.gasPrice
        # print("Default Gas Price: " + str(defaultGasPrice))

        # Deploy subscription contract contract
        txhash_subscribe = Subscription.deploy(transaction={"from": ownerAddr})
        print("Deploying subscription, tx hash is", txhash_subscribe)
        subscribe_receipt = utils.check_succesful_tx(web3, txhash_subscribe)
        subscribe_address = subscribe_receipt["contractAddress"]
        print("Subscription contract address is", subscribe_address)

        # Do some contract reads to see everything looks ok
        print("Some checks on deployed contract:")
        print("Subscription token owner: ",
              Subscription.call({
                  'to': subscribe_address
              }).owner())
        print("Subscription initial price: ",
              Subscription.call({
                  'to': subscribe_address
              }).subscriptionPrice())
        print("Subscription collected funds: ",
              Subscription.call({
                  'to': subscribe_address
              }).collectedFunds())
Пример #4
0
def web3_populus_project():
    project = populus.Project()

    # We are working on a testnet
    chain_name = 'ropsten'
    print(
        "Make sure {} chain is running, you can connect to it, or you'll get timeout"
        .format(chain_name))

    # dbg
    ropsten_config = project.config['chains.ropsten.web3']
    print("Ropsten config: {}".format(ropsten_config))

    # with ropsten chain
    with project.get_chain(chain_name) as chain:

        web3 = chain.web3

        check_base_properties(web3)
Пример #5
0
def performTransfer():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        web3 = chain.web3

        DToken = chain.provider.get_contract('DToken')

        print(
            "This script will perform transfer of DTokens, if you don't want to transfer tokens, please abort program"
        )
        input_addr = input("Specify address: ")
        input_amount = input("Specify amount: ")

        print("Token will be send: ")
        print("From: {}".format(web3.eth.defaultAccount))
        print("To: {}".format(input_addr))
        print("Value: {}".format(input_amount))

        defaultGasPrice = web3.eth.gasPrice
        print("Default Gas Price: " + str(defaultGasPrice))

        # call Token transfer as transaction
        # multiple gas price to get fast confirmations
        txhash = DToken.transact({
            'gasPrice': (defaultGasPrice * 5)
        }).transfer(input_addr, int(input_amount))

        print("Transaction hash: {}".format(txhash))

        receipt = utils.check_succesful_tx(web3, txhash)
        print("Transaction was confirmed")
Пример #6
0
def deployDemoContracts():
    project = populus.Project()
    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        web3 = chain.web3
        print("Web3 provider is", web3.providers)

        # loading config file for custom deployment
        with open('deploy/deploy.json', 'r') as conf_json:
            json_data = json.load(conf_json)

            require_address(web3, json_data, "contractsOwner")
            require_address(web3, json_data, "platformReserve")
            require_address(web3, json_data, "gameDeveloper")

            # checking if contract owner is one of the available addresses in web3 provider
            # otherwise there will be not possibile to deploy any contract, and script will be aborted
            contractsOwner = json_data["AccountAddress"]["contractsOwner"]
            if_account_available(web3, contractsOwner, "contracts owner")

            # get other accounts
            platformReserve = json_data["AccountAddress"]["platformReserve"]
            gameDeveloper = json_data["AccountAddress"]["gameDeveloper"]

            # Determine which contracts will be deployed
            givenJoyToken = check_contract_field(web3, json_data, "joyToken")
            givenDeposit = check_contract_field(web3, json_data, "deposit")
            givenDemoGame = check_contract_field(web3, json_data, "demoGame")

            givenEtherSub = check_subscription_contract_field(
                web3, json_data, "ether")
            givenJoySub = check_subscription_contract_field(
                web3, json_data, "joyToken")

            print("Contracts status in deploy.json file:" + "\n\tJoyToken: " +
                  str(givenJoyToken) + "\n\tDeposit: " + str(givenDeposit) +
                  "\n\tDemoGame: " + str(givenDemoGame) +
                  "\n\tSubscription with Ether: " + str(givenEtherSub) +
                  "\n\tSubscription with JoyToken: " + str(givenJoySub))

            if not givenJoyToken:
                deploy_JoyToken(chain, contractsOwner, json_data)
                deploy_Deposit(chain, contractsOwner, json_data)
                deploy_DemoGame(chain, contractsOwner, json_data)
            elif not givenDeposit:
                deploy_Deposit(chain, contractsOwner, json_data)
                deploy_DemoGame(chain, contractsOwner, json_data)
            elif not givenDemoGame:
                deploy_DemoGame(chain, contractsOwner, json_data)

            if not givenEtherSub:
                deploy_EtherSub(chain, contractsOwner, json_data)

            if not givenJoySub:
                deploy_JoySub(chain, contractsOwner, json_data)

            # saving genrated address to a convenient config.json file (update given deploy.json)
            print(
                "Writing updated changes and generated contract addresses in 'deploy/config.json' file..."
            )
            with open('deploy/config.json', 'w') as fp:
                json.dump(json_data, fp, indent=4)
from ico.utils import check_succesful_tx
import populus
import time
from populus.utils.cli import request_account_unlock
from populus.utils.accounts import is_account_locked
from eth_utils import to_wei
from web3 import Web3
from web3.contract import Contract

import uuid

p = populus.Project()
account = "0x"  # Our controller account on Kovan


def import_investor_data(contract: Contract, deploy_address: str, fname: str):
    """Load investor data to a MultiVault contract.

    Pecunio specific data loader.

    :return: List of unconfirmed transaction ids
    """

    assert fname.endswith(".csv")

    txs = []
    with open(fname, "rt") as inp:
        for line in inp:
            address, amount = line.split(",")
            address = address.strip()
            amount = amount.strip()
Пример #8
0
def deployDemoContracts():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        # Load Populus contract proxy classes
        JoyToken = chain.provider.get_contract_factory('JoyToken')
        PlatformDeposit = chain.provider.get_contract_factory('PlatformDeposit')
        JoyGameDemo = chain.provider.get_contract_factory('JoyGameDemo')

        web3 = chain.web3
        print("Web3 provider is", web3.providers)

        # default account from populus perspective
        ownerAddr = web3.eth.defaultAccount;
        print("Contracts will be deployed from: {}".format(ownerAddr))

        defaultGasPrice = web3.eth.gasPrice
        print("Default Gas Price: " + str(defaultGasPrice))
        # multiple gas price to get fast confirmations
        #txhash = DToken.transact({'gasPrice': (defaultGasPrice*5)}).transfer(input_addr,int(input_amount))

        # unlock owner account
        #timeout=100
        #print("acc locked: {}".format(is_account_locked(web3,ownerAddr)))

        # Deploy token contract
        txhash_token = JoyToken.deploy(transaction={"from": ownerAddr})
        print("deploying token, tx hash is", txhash_token)
        receipt = utils.check_succesful_tx(web3, txhash_token)
        token_address = receipt["contractAddress"]
        print("token contract address is", token_address)

        # address needed by deposit contract, it is good to different than owner
        platformReserve_address = input ("Give platform reserve address: ")

        # Deploy deposit contract with token_address
        txhash_deposit = PlatformDeposit.deploy(transaction={"from": ownerAddr}, args=[token_address, platformReserve_address])
        print("Deploying deposit contract, tx hash is", txhash_deposit)
        receipt = utils.check_succesful_tx(web3, txhash_deposit)
        deposit_address = receipt["contractAddress"]
        print("Deposit contract address is", deposit_address)

        # game developer address
        gameDev = input ("Give game developer address: ")

        txhash_game = JoyGameDemo.deploy(transaction={"from": ownerAddr}, args=[deposit_address, gameDev])
        print("Deploying game demo contract, tx hash is", txhash_game)
        receipt = utils.check_succesful_tx(web3, txhash_game)
        game_address = receipt["contractAddress"]
        print("DemoGame contract address is", game_address)

        # Do some contract reads to see everything looks ok
        print("Some checks on deployed contracts:")
        print("Token name: ", JoyToken.call({'to':token_address}).name())
        print("Token symbol: ", JoyToken.call({'to':token_address}).symbol())
        print("Token total supply is: ", JoyToken.call({'to':token_address}).totalSupply())
        print("Token decimal places: ", JoyToken.call({'to':token_address}).decimals())
        print("Deposit owner is: ", PlatformDeposit.call({'to':deposit_address}).owner())
        print("Deposit platformReserve address: ", PlatformDeposit.call({'to':deposit_address}).platformReserve())
        print("Deposit supported Token address: ", PlatformDeposit.call({'to':deposit_address}).m_supportedToken())
        print("Game developer is: ", JoyGameDemo.call({'to':game_address}).gameDev())
        print("Game contract using deposit (address): ", JoyGameDemo.call({'to':game_address}).m_playerDeposits())