class Traffic(object):
    def __init__(self,
                 contract_name='traffic',
                 sol_file=path + 'traffic.sol',
                 abi_file=path + 'traffic.abi',
                 bin_file=path + 'traffic.bin'):

        self.contractManager = ContractManager(sol_file,
                                               abi_file,
                                               bin_file,
                                               DEBUG=True)
        result, self.contractAddress = self.contractManager.checkContractExit(
            contract_name)
        if result is False:
            self.contract_abi, self.contract_info = self.contractManager.deploy(
            )
            self.contractAddress = self.contract_info["contractAddress"]
        else:
            self.contract_abi, self.contractAddress = self.contractManager.getContractInfo(
                self.contractAddress)

    def constructJsonRecord(self, UUID, Url, FileMd5, Size, StorageIP,
                            RemoteFileId, GroupName):
        Temp = {
            "UUID": UUID,
            "Url": Url,
            "FileMd5": FileMd5,
            "Size": Size,
            "StorageIP": StorageIP,
            "RemoteFileId": RemoteFileId,
            "GroupName": GroupName
        }
        return json.dumps(Temp)

    # insert update
    def set(self, UUID, Url, FileMd5, Size, StorageIP, RemoteFileId,
            GroupName):
        JsonRecord = self.constructJsonRecord(UUID, Url, FileMd5, Size,
                                              StorageIP, RemoteFileId,
                                              GroupName)
        args = [UUID, JsonRecord]
        try:
            txhash = self.contractManager.transaction(self.contract_abi,
                                                      self.contractAddress,
                                                      args)
            return txhash
        except:
            traceback.print_exc()
            return None

    def get(self, UUID):
        args = [UUID]
        try:
            response = self.contractManager.call(self.contractAddress,
                                                 self.contract_abi, "get",
                                                 args)
            return response
        except:
            traceback.print_exc()
            return None
    def __init__(self,
                 contract_name='traffic',
                 sol_file=path + 'traffic.sol',
                 abi_file=path + 'traffic.abi',
                 bin_file=path + 'traffic.bin'):

        self.contractManager = ContractManager(sol_file,
                                               abi_file,
                                               bin_file,
                                               DEBUG=True)
        result, self.contractAddress = self.contractManager.checkContractExit(
            contract_name)
        if result is False:
            self.contract_abi, self.contract_info = self.contractManager.deploy(
            )
            self.contractAddress = self.contract_info["contractAddress"]
        else:
            self.contract_abi, self.contractAddress = self.contractManager.getContractInfo(
                self.contractAddress)
示例#3
0
class Update(object):
    def __init__(self,
                 contract_name='update',
                 sol_file=path + 'update.sol',
                 abi_file=path + 'update.abi',
                 bin_file=path + 'update.bin'):

        self.contractManager = ContractManager(sol_file,
                                               abi_file,
                                               bin_file,
                                               DEBUG=True)
        # checkContractExit这个函数出问题了
        result, self.contractAddress = self.contractManager.checkContractExit(
            contract_name)
        if result is False:
            self.contract_abi, self.contract_info = self.contractManager.deploy(
            )
            self.contractAddress = self.contract_info["contractAddress"]
        else:
            self.contract_abi, self.contractAddress = self.contractManager.getContractInfo(
                self.contractAddress)

    # try, catch

    def set(self, weights, sum):
        args = [weights, sum]
        try:
            receipt = self.contractManager.transaction(self.contract_abi,
                                                       self.contractAddress,
                                                       'set', args)
            return receipt
        except:
            traceback.print_exc()
            return None

    def get(self):
        args = []
        try:
            response = self.contractManager.call(self.contractAddress,
                                                 self.contract_abi, "get",
                                                 args)
            return response
        except:
            traceback.print_exc()
            return None

    def clean(self, sum):
        args = [sum]
        try:
            receipt = self.contractManager.transaction(self.contract_abi,
                                                       self.contractAddress,
                                                       'clean', args)
            return receipt['transactionHash']
        except:
            traceback.print_exc()
            return None
class Tianwen(object):
    def __init__(self,
                 contract_name='TianwenKV',
                 sol_file=path + 'TianwenKV.sol',
                 abi_file=path + 'TianwenKV.abi',
                 bin_file=path + 'TianwenKV.bin'):

        self.contractManager = ContractManager(sol_file,
                                               abi_file,
                                               bin_file,
                                               DEBUG=True)
        # checkContractExit这个函数出问题了
        result, self.contractAddress = self.contractManager.checkContractExit(
            contract_name)
        if result is False:
            self.contract_abi, self.contract_info = self.contractManager.deploy(
            )
            self.contractAddress = self.contract_info["contractAddress"]
        else:
            self.contract_abi, self.contractAddress = self.contractManager.getContractInfo(
                self.contractAddress)

    # try, catch
    def constructJsonRecord(self, item_Element, item_N_line, item_O_XH,
                            item_O_XFe, item_O_loge, item_C_XH, item_C_XFe,
                            item_C_loge):
        record = {
            "item_Element": item_Element,
            "item_N_line": item_N_line,
            "item_O_XH": item_O_XH,
            "item_O_XFe": item_O_XFe,
            "item_O_loge": item_O_loge,
            "item_C_XH": item_C_XH,
            "item_C_XFe": item_C_XFe,
            "item_C_loge": item_C_loge
        }
        return json.dumps(record)

    def set(self, item_Element, item_N_line, item_O_XH, item_O_XFe,
            item_O_loge, item_C_XH, item_C_XFe, item_C_loge):
        JsonRecord = self.constructJsonRecord(item_Element, item_N_line,
                                              item_O_XH, item_O_XFe,
                                              item_O_loge, item_C_XH,
                                              item_C_XFe, item_C_loge)
        args = [item_Element, JsonRecord]
        try:
            txhash = self.contractManager.transaction(self.contract_abi,
                                                      self.contractAddress,
                                                      args)
            return txhash
        except:
            traceback.print_exc()
            return None

    def get(self, item_Element):
        args = [item_Element]
        try:
            response = self.contractManager.call(self.contractAddress,
                                                 self.contract_abi, "get",
                                                 args)
            return response
        except:
            traceback.print_exc()
            return None