Esempio n. 1
0
def undeploy(config_path=CONFIG_PATH):
    ''' Actually, smart contract cannot undeploy, but I need an function to remove unused intermediate file'''
    config_handler = ConfigHandler(config_path)
    contract_names = config_handler.get_chain_config('Deploy',
                                                     'target_contract_name')
    for contract_name in contract_names.split(','):
        contract_path = os.path.join(
            config_handler.get_chain_config('Output', 'file_path'),
            '{0}.json'.format(contract_name))
        os.unlink(contract_path)
Esempio n. 2
0
 def __init__(self, config=my_config.CONFIG_PATH, mytype='json', path=''):
     if not any(mytype == _ for _ in self._support_types.keys()):
         raise IOError('{0} type not in support_types {1}'.format(
             mytype, self._support_types))
     if not path:
         config_handler = ConfigHandler(config)
         path = config_handler.get_chain_config('DB', 'db_path')
     self._type_db = self._support_types[mytype](path)
     self._onchain_handler = ProvedDBOnChainHandler(config)
Esempio n. 3
0
class ContractHandler():
    def __init__(self, contract_name, config_path=my_config.CONFIG_PATH):
        self._config_handler = ConfigHandler(config_path)

        self._check_contract_name(contract_name)

        file_ipc = self._config_handler.get_chain_config(
            'Ethereum', 'file_ipc')
        self._w3 = Web3(Web3.IPCProvider(file_ipc))

        contract_info = self._get_contract_info(contract_name)
        contract_abi = contract_info['abi']
        contract_address = contract_info['address']
        self._contract_inst = self._w3.eth.contract(contract_address,
                                                    abi=contract_abi)

    def _check_contract_name(self, check_name):
        contract_names = self._config_handler.get_chain_config(
            'Deploy', 'target_contract_name')
        if check_name not in contract_names.split(','):
            raise IOError('Cannot find {0} in config {1}'.format(
                check_name, contract_names))

    def get_w3(self):
        return self._w3

    def get_contract(self):
        return self._contract_inst

    def _get_contract_info(self, contract_name):
        file_path = os.path.join(
            self._config_handler.get_chain_config('Output', 'file_path'),
            '{0}.json'.format(contract_name))
        file_path = os.path.abspath(file_path)
        with open(file_path) as f:
            contract_info = json.load(f)
        return contract_info
Esempio n. 4
0
def get_db_path(config):
    config_handler = ConfigHandler(config)
    return config_handler.get_chain_config('DB', 'db_path')
Esempio n. 5
0
def deploy(config_path=CONFIG_PATH):

    config_handler = ConfigHandler(config_path)

    print('==== Compile smart contract ====')
    cmd = '(cd {0}; truffle compile)'.format(
        config_handler.get_chain_config('Deploy', 'truffle_path'))
    print('run command {0}'.format(cmd))
    os.system(cmd)

    # step 1
    step_one_info = _DeployMultipleSmartContractV0(config_handler,
                                                   {'Register': {}})

    # step 2
    register_info = step_one_info['Register']
    infos = _DeployMultipleSmartContractV0(
        config_handler, {
            'KeysRecordStorageV0': {
                'Register': register_info
            },
            'KeysRecord': {
                'Register': register_info
            },
            'ProvedCRUDStorageV0': {
                'Register': register_info
            },
            'ProvedCRUD': {
                'Register': register_info
            },
            'EventEmitter': {
                'Register': register_info
            },
            'FinaliseRecordStorageV0': {
                'Register': register_info
            },
            'FinaliseRecord': {
                'Register': register_info
            },
            'ProvedDB': {
                'Register': register_info
            },
            'RecordHashStorageV0': {
                'Register': register_info
            },
            'RecordHash': {
                'Register': register_info
            }
        })

    # step 3
    register = Register(config_path)
    register.set_multiple_register({
        'EventEmitter':
        infos['EventEmitter']['contractAddress'],
        'ProvedCRUDStorageInterface':
        infos['ProvedCRUDStorageV0']['contractAddress'],
        'KeysRecordStorageInterface':
        infos['KeysRecordStorageV0']['contractAddress'],
        'FinaliseRecordInterface':
        infos['FinaliseRecordStorageV0']['contractAddress'],
        'RecordHashStorageInterface':
        infos['RecordHashStorageV0']['contractAddress'],
        'KeysRecord':
        infos['KeysRecord']['contractAddress'],
        'ProvedCRUD':
        infos['ProvedCRUD']['contractAddress'],
        'FinaliseRecord':
        infos['FinaliseRecord']['contractAddress']
    })

    # step 4
    register.set_multiple_whitelist([
        infos['RecordHash']['contractAddress'],
        infos['ProvedDB']['contractAddress'],
        infos['KeysRecord']['contractAddress'],
        infos['ProvedCRUD']['contractAddress'],
        infos['FinaliseRecord']['contractAddress'],
        infos['ProvedCRUDStorageV0']['contractAddress'],
        infos['KeysRecordStorageV0']['contractAddress'],
        infos['FinaliseRecordStorageV0']['contractAddress'],
        infos['RecordHashStorageV0']['contractAddress']
    ])