示例#1
0
def print_output_and_input(logs, output, txinput, contract_name, contract_path):
    """
    parse_output_from_abi
    """
    abi_path = os.path.join(contract_path, contract_name + ".abi")
    if os.path.isfile(abi_path) is False:
        raise BcosException("parse outpt failed for {} doesn't exist"
                            .format(abi_path))
    try:
        dataParser = DatatypeParser(abi_path)
        # parse txinput
        input_result = dataParser.parse_transaction_input(txinput)
        if input_result is None:
            print_info("WARN", "parsed txinput is None")
            return
        print_info("txinput result", input_result)
        # get function name
        fn_name = input_result["name"]
        output_result = dataParser.parse_receipt_output(fn_name, output)
        if output_result is None:
            print_info("INFO", "empty return, output: {}".format(output))
            return
        print_info("output result", output_result)
        log_result = dataParser.parse_event_logs(logs)
        print_receipt_logs(log_result)
        # print_info("log result", log_result)

    except Exception as e:
        raise BcosException("parse output failed for reason: {}".format(e))
示例#2
0
def parse_input(txinput, contract_name, contract_path):
    """
    parse txinput
    """
    abi_path = os.path.join(contract_path, contract_name + ".abi")
    if os.path.isfile(abi_path) is False:
        raise BcosException("parse txinput failed for {} doesn't exist"
                            .format(abi_path))
    try:
        dataParser = DatatypeParser(abi_path)
        result = dataParser.parse_transaction_input(txinput)
        return result
    except Exception as e:
        raise BcosException("parse txinput failed for reason: {}"
                            .format(e))
示例#3
0
class Poseidon:  # name of abi
    address = None
    contract_abi_string = '''[{"constant": true, "inputs": [{"internalType": "uint256[]", "name": "input", "type": "uint256[]"}], "name": "poseidon", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}]'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result

    # ------------------------------------------
    def poseidon(self, input):
        func_name = 'poseidon'
        args = [input]
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result
示例#4
0
class Test1:  # name of abi
    address = None
    contract_abi_string = '''[{"constant": false, "inputs": [{"internalType": "uint256[4]", "name": "vk", "type": "uint256[4]"}, {"internalType": "uint256[2]", "name": "nfs", "type": "uint256[2]"}], "name": "check_mkroot_nullifiers_hsig_append_nullifiers_state", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}]'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result

    # ------------------------------------------
    def check_mkroot_nullifiers_hsig_append_nullifiers_state(self, vk, nfs):
        func_name = 'check_mkroot_nullifiers_hsig_append_nullifiers_state'
        args = [vk, nfs]
        receipt = self.client.sendRawTransactionGetReceipt(
            self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(
            func_name, receipt['output'])
        return outputresult, receipt
示例#5
0
class HelloWorld:  # name of abi
    address = None
    contract_abi_string = '''[{"constant": false, "inputs": [{"name": "n", "type": "string"}], "name": "set", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "get", "outputs": [{"name": "", "type": "string"}], "payable": false, "stateMutability": "view", "type": "function"}, {"inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor"}, {"anonymous": false, "inputs": [{"indexed": false, "name": "newname", "type": "string"}], "name": "onset", "type": "event", "topic": "0xafb180742c1292ea5d67c4f6d51283ecb11e49f8389f4539bef82135d689e118"}]'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result

    # ------------------------------------------
    def set(self, n):
        func_name = 'set'
        args = [n]
        receipt = self.client.sendRawTransactionGetReceipt(
            self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(
            func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def get(self):
        func_name = 'get'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result
示例#6
0
class TEMPLATE_CLASSNAME:  # name of abi
    address = None
    contract_abi_string = '''TEMPLATE_CONTRACT_ABI'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result
示例#7
0
 def register_eventlog_filter(
         self,
         eventcallback,
         abiparser,
         addresses,
         event_name,
         indexed_value=None,
         fromblock="latest",
         to_block="latest"):
     topics = []
     if event_name is not None:
         topic0 = abiparser.topic_from_event_name(event_name)
         topics.append(topic0)
         event_abi = abiparser.event_name_map[event_name]
     #print("event abi:", event_abi)
     if indexed_value is not None and len(indexed_value) > 0:
         indexedinput = []
         for event_input in event_abi["inputs"]:
             if event_input["indexed"] is True:
                 indexedinput.append((event_input['name'], event_input['type']))
         # print(indexedinput)
         i = 0
         for v in indexed_value:
             itype = indexedinput[i][1]
             topic = DatatypeParser.topic_from_type(itype, v)
             if not (topic is None):
                 topics.append(topic)
             i = i + 1
     # create new filterid by uuid
     seq = uuid.uuid1()
     filterid = seq.hex
     requestJson = self.format_event_register_request(
         fromblock, to_block, addresses, topics, self.client.groupid, filterid)
     requestbytes = ChannelPack.pack_amop_topic_message("", requestJson)
     response = self.client.channel_handler.make_channel_request(
         requestbytes, ChannelPack.CLIENT_REGISTER_EVENT_LOG, ChannelPack.CLIENT_REGISTER_EVENT_LOG)
     (topic, result) = ChannelPack.unpack_amop_topic_message(response)
     dataobj = json.loads(result)
    # print(dataobj)
     if dataobj["result"] == 0:
         self.ecb_manager.set_callback(filterid, eventcallback)
     return dataobj
示例#8
0
class ABICodegen:
    parser = DatatypeParser()
    abi_file = ""
    name = ""
    # four spaces for indent
    indent = "    "
    template = ""
    template_file = "./python_web3/client/codegen_template.py"

    def __init__(self, abi_file):
        if len(abi_file) > 0:
            self.load_abi(abi_file)
        with open(self.template_file, "r") as f:
            self.template = f.read()
            f.close()

    def load_abi(self, abi_file):
        self.abi_file = abi_file
        self.parser.load_abi_file(abi_file)
        fname = os.path.basename(abi_file)
        (self.name, ext) = os.path.splitext(fname)

    def make_function(self, func_abi):
        func_lines = []
        func_def = "def {}(self".format(func_abi["name"])
        args_def = ""
        args_value = ""
        i = 0
        for param in func_abi["inputs"]:
            if i > 0:
                args_def += ", "
                args_value += ", "
            args_def += param["name"]
            if param['type'] == "address":
                args_value += "to_checksum_address({})".format(param["name"])
            else:
                args_value += param["name"]
            i += 1
        if len(args_def) > 0:
            func_def += ", " + args_def
        func_def += "):"
        func_lines.append(func_def)
        func_lines.append("{}func_name = '{}'".format(self.indent,
                                                      func_abi["name"]))
        func_lines.append("{}args = [{}]".format(self.indent, args_value))
        if func_abi["constant"] is False:
            func_lines.append(self.indent + (
                "receipt = self.client.sendRawTransactionGetReceipt"
                "(self.address, self.contract_abi, func_name, args)"))
            func_lines.append(self.indent + (
                "outputresult = self.data_parser.parse_receipt_output"
                "(func_name, receipt['output'])"))
            func_lines.append(self.indent + "return outputresult, receipt")

        if func_abi["constant"] is True:
            func_lines.append(self.indent +
                              ("result = self.client.call(self.address, "
                               "self.contract_abi, func_name, args)"))
            func_lines.append(self.indent + "return result")
        return func_lines

    def gen_all(self):
        all_func_code_line = []
        func_abi_list = filter_by_type("function", self.parser.contract_abi)
        for func_abi in func_abi_list:
            func_lines = self.make_function(func_abi)
            all_func_code_line.append("")
            all_func_code_line.append(
                "# ------------------------------------------")
            all_func_code_line.extend(func_lines)
            # print(func_lines)
        template = self.template
        template = template.replace("TEMPLATE_CLASSNAME", self.name)
        template = template.replace("TEMPLATE_ABIFILE", self.abi_file)
        contract_abi = json.dumps(self.parser.contract_abi).replace("\r", "")
        contract_abi = contract_abi.replace("\n", " ")
        template = template.replace("TEMPLATE_CONTRACT_ABI", contract_abi)
        for line in all_func_code_line:
            if not line:
                template += "\n"
            else:
                template += self.indent + line + "\n"
        return template
示例#9
0
class Groth16Mixer:  # name of abi
    address = None
    contract_abi_string = '''[{"inputs": [{"internalType": "uint256", "name": "mk_depth", "type": "uint256"}, {"internalType": "address", "name": "token", "type": "address"}, {"internalType": "uint256[2]", "name": "Alpha", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Beta1", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Beta2", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Delta1", "type": "uint256[2]"}, {"internalType": "uint256[2]", "name": "Delta2", "type": "uint256[2]"}, {"internalType": "uint256[]", "name": "ABC_coords", "type": "uint256[]"}], "payable": false, "stateMutability": "nonpayable", "type": "constructor"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "string", "name": "message", "type": "string"}], "name": "LogDebug", "type": "event", "topic": "0xd44da6836c8376d1693e8b9cacf1c39b9bed3599164ad6d8e60902515f83938e"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "bytes32", "name": "message", "type": "bytes32"}], "name": "LogDebug", "type": "event", "topic": "0x05e46912c9be87d8a6830598db8544b61884d9d22f3921597a9a6e8a340914b3"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "uint256", "name": "mid", "type": "uint256"}, {"indexed": false, "internalType": "bytes32", "name": "root", "type": "bytes32"}, {"indexed": false, "internalType": "bytes32[2]", "name": "nullifiers", "type": "bytes32[2]"}, {"indexed": false, "internalType": "bytes32[2]", "name": "commitments", "type": "bytes32[2]"}, {"indexed": false, "internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "LogMix", "type": "event", "topic": "0x5b20d7b970f991ad433adaa73d15ec55f2dc64ddfecb9505eb1f94e330ecddf7"}, {"constant": true, "inputs": [{"internalType": "uint256[10]", "name": "primary_inputs", "type": "uint256[10]"}], "name": "assemble_hsig", "outputs": [{"internalType": "bytes32", "name": "hsig", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [{"internalType": "uint256", "name": "index", "type": "uint256"}, {"internalType": "uint256[10]", "name": "primary_inputs", "type": "uint256[10]"}], "name": "assemble_nullifier", "outputs": [{"internalType": "bytes32", "name": "nf", "type": "bytes32"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [{"internalType": "uint256[10]", "name": "primary_inputs", "type": "uint256[10]"}], "name": "assemble_public_values", "outputs": [{"internalType": "uint256", "name": "vpub_in", "type": "uint256"}, {"internalType": "uint256", "name": "vpub_out", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": true, "inputs": [], "name": "get_constants", "outputs": [{"internalType": "uint256", "name": "js_in", "type": "uint256"}, {"internalType": "uint256", "name": "js_out", "type": "uint256"}, {"internalType": "uint256", "name": "num_inputs", "type": "uint256"}], "payable": false, "stateMutability": "pure", "type": "function"}, {"constant": false, "inputs": [{"internalType": "bytes32", "name": "commitment", "type": "bytes32"}], "name": "insert", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "mid", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "uint256[2]", "name": "a", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "b", "type": "uint256[4]"}, {"internalType": "uint256[2]", "name": "c", "type": "uint256[2]"}, {"internalType": "uint256[4]", "name": "vk", "type": "uint256[4]"}, {"internalType": "uint256", "name": "sigma", "type": "uint256"}, {"internalType": "uint256[10]", "name": "input", "type": "uint256[10]"}, {"internalType": "bytes[2]", "name": "ciphertexts", "type": "bytes[2]"}], "name": "mix", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "", "type": "address"}, {"internalType": "address", "name": "", "type": "address"}, {"internalType": "uint256", "name": "", "type": "uint256"}, {"internalType": "bytes", "name": "", "type": "bytes"}], "name": "onBAC001Received", "outputs": [{"internalType": "bytes4", "name": "", "type": "bytes4"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "token", "outputs": [{"internalType": "address", "name": "", "type": "address"}], "payable": false, "stateMutability": "view", "type": "function"}]'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result

    # ------------------------------------------
    def assemble_hsig(self, primary_inputs):
        func_name = 'assemble_hsig'
        args = [primary_inputs]
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result

    # ------------------------------------------
    def assemble_nullifier(self, index, primary_inputs):
        func_name = 'assemble_nullifier'
        args = [index, primary_inputs]
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result

    # ------------------------------------------
    def assemble_public_values(self, primary_inputs):
        func_name = 'assemble_public_values'
        args = [primary_inputs]
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result

    # ------------------------------------------
    def get_constants(self):
        func_name = 'get_constants'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result

    # ------------------------------------------
    def insert(self, commitment):
        func_name = 'insert'
        args = [commitment]
        receipt = self.client.sendRawTransactionGetReceipt(
            self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(
            func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def mid(self):
        func_name = 'mid'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result

    # ------------------------------------------
    def mix(self, a, b, c, vk, sigma, input, ciphertexts):
        func_name = 'mix'
        args = [a, b, c, vk, sigma, input, ciphertexts]
        receipt = self.client.sendRawTransactionGetReceipt(
            self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(
            func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def token(self):
        func_name = 'token'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name,
                                  args)
        return result
示例#10
0
def event_sync():

    indexed_value = None
    try:
        tag = True
        print("check whether existed mixer contract")
        sqlSearchMixer = "select * from contract where conType = %s"
        MIXERTYPE = "mixer"
        mixer_addr = ""
        mysql_pool = MysqlPool()
        db = mysql_pool.steady_connection()
        cursor = db.cursor()
        while tag:
            # db.ping(reconnect=True)
            cursor.execute(sqlSearchMixer, [MIXERTYPE])
            resultMixer = cursor.fetchall()
            db.commit()
            if resultMixer:
                tag = False
                mixer_addr = resultMixer[0]['conAddr']
                print("found mixer contract: ", mixer_addr)
            else:
                print("could not find mixer contract, waiting...")
                time.sleep(10)
        bcos_event = BcosEventCallback()
        bcos_event.setclient(BcosClient())
        print(bcos_event.client.getinfo())
        '''
        print("usage input {},{},{},{}".format(contractname, address, event_name, indexed_value))
        if address == "last":
            cn = ContractNote()
            address = cn.get_last(contractname)
            print("hex address :", address)
            '''
        abifile = "contract/mixer/abi/Groth16Mixer.abi"
        abiparser = DatatypeParser(abifile)
        eventcallback = EventCallbackImpl()
        eventcallback.abiparser = abiparser
        blockNumber = 0
        # maybe change to use cursor.lastrowid to get the last row
        sqlSearch = "select * from merkletree"
        cursor.execute(sqlSearch)
        results = cursor.fetchall()
        if results:
            blockNumber = results[-1]['blockNumber']
        print("blockNumber: ", blockNumber)
        result = bcos_event.register_eventlog_filter(eventcallback, abiparser,
                                                     [mixer_addr], "LogMix",
                                                     indexed_value,
                                                     str(blockNumber + 1))
        #result = bcos_event.register_eventlog_filter(eventcallback02,abiparser, [address], "on_number")

        print("after register LogMix,result:{},all:{}".format(
            result['result'], result))
        print("waiting event...")
        while True:
            # print("waiting event...")
            time.sleep(10)
    except Exception as e:
        print("Exception!")
        import traceback
        traceback.print_exc()
    finally:
        print("event callback finished!")
        if bcos_event.client is not None:
            bcos_event.client.finish()
    sys.exit(-1)
示例#11
0
class BAC001:  # name of abi
    address = None
    contract_abi_string = '''[{"inputs": [{"internalType": "string", "name": "description", "type": "string"}, {"internalType": "string", "name": "shortName", "type": "string"}, {"internalType": "uint8", "name": "minUnit", "type": "uint8"}, {"internalType": "uint256", "name": "totalAmount", "type": "uint256"}], "payable": false, "stateMutability": "nonpayable", "type": "constructor"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "owner", "type": "address"}, {"indexed": true, "internalType": "address", "name": "spender", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}], "name": "Approval", "type": "event", "topic": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "IssuerAdded", "type": "event", "topic": "0x05e7c881d716bee8cb7ed92293133ba156704252439e5c502c277448f04e20c2"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "IssuerRemoved", "type": "event", "topic": "0xaf66545c919a3be306ee446d8f42a9558b5b022620df880517bc9593ec0f2d52"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "from", "type": "address"}, {"indexed": true, "internalType": "address", "name": "to", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "value", "type": "uint256"}, {"indexed": false, "internalType": "bytes", "name": "data", "type": "bytes"}], "name": "Send", "type": "event", "topic": "0x76d4fc8756cf1c2b5aa667285d8c20b304dcd86209b4c34a84fc491867de76f1"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "address", "name": "account", "type": "address"}], "name": "Suspended", "type": "event", "topic": "0x6f123d3d54c84a7960a573b31c221dcd86e13fd849c5adb0c6ca851468cc1ae4"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "SuspenderAdded", "type": "event", "topic": "0xf4fbb5a5e62a703643fe5be0722720f728980fdde74f11d76eca7e13bdc3301d"}, {"anonymous": false, "inputs": [{"indexed": true, "internalType": "address", "name": "account", "type": "address"}], "name": "SuspenderRemoved", "type": "event", "topic": "0x17eb45856cd2283111eeb8a1dddf8a43121889e3ce798241f96d2afed353eaa3"}, {"anonymous": false, "inputs": [{"indexed": false, "internalType": "address", "name": "account", "type": "address"}], "name": "UnSuspended", "type": "event", "topic": "0x349b4285cb8dde314c53fd9d8e8e578381a7375e4f76f9dd9fe07f9960f120a4"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "addIssuer", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "addSuspender", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "owner", "type": "address"}, {"internalType": "address", "name": "spender", "type": "address"}], "name": "allowance", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}], "name": "approve", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "owner", "type": "address"}], "name": "balance", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address[]", "name": "to", "type": "address[]"}, {"internalType": "uint256[]", "name": "values", "type": "uint256[]"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "batchSend", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "subtractedValue", "type": "uint256"}], "name": "decreaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "description", "outputs": [{"internalType": "string", "name": "", "type": "string"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "destroy", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "from", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "destroyFrom", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "spender", "type": "address"}, {"internalType": "uint256", "name": "addedValue", "type": "uint256"}], "name": "increaseAllowance", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "isIssuer", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": true, "inputs": [{"internalType": "address", "name": "account", "type": "address"}], "name": "isSuspender", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "to", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "issue", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "minUnit", "outputs": [{"internalType": "uint8", "name": "", "type": "uint8"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [], "name": "renounceIssuer", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [], "name": "renounceSuspender", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "to", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "send", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": false, "inputs": [{"internalType": "address", "name": "from", "type": "address"}, {"internalType": "address", "name": "to", "type": "address"}, {"internalType": "uint256", "name": "value", "type": "uint256"}, {"internalType": "bytes", "name": "data", "type": "bytes"}], "name": "sendFrom", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "shortName", "outputs": [{"internalType": "string", "name": "", "type": "string"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [], "name": "suspend", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"constant": true, "inputs": [], "name": "suspended", "outputs": [{"internalType": "bool", "name": "", "type": "bool"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": true, "inputs": [], "name": "totalAmount", "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}, {"constant": false, "inputs": [], "name": "unSuspend", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function"}]'''
    contract_abi = None
    data_parser = DatatypeParser()
    client = None

    def __init__(self, address):
        self.client = BcosClient()
        self.address = address
        self.contract_abi = json.loads(self.contract_abi_string)
        self.data_parser.set_abi(self.contract_abi)

    def deploy(self, contract_bin_file):
        result = self.client.deployFromFile(contract_bin_file)
        self.address = result["contractAddress"]
        return result

    # ------------------------------------------
    def addIssuer(self, account):
        func_name = 'addIssuer'
        args = [to_checksum_address(account)]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def addSuspender(self, account):
        func_name = 'addSuspender'
        args = [to_checksum_address(account)]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def allowance(self, owner, spender):
        func_name = 'allowance'
        args = [to_checksum_address(owner), to_checksum_address(spender)]
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def approve(self, spender, value):
        func_name = 'approve'
        args = [to_checksum_address(spender), value]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def balance(self, owner):
        func_name = 'balance'
        args = [to_checksum_address(owner)]
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def batchSend(self, to, values, data):
        func_name = 'batchSend'
        args = [to, values, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def decreaseAllowance(self, spender, subtractedValue):
        func_name = 'decreaseAllowance'
        args = [to_checksum_address(spender), subtractedValue]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def description(self):
        func_name = 'description'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def destroy(self, value, data):
        func_name = 'destroy'
        args = [value, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def destroyFrom(self, from1, value, data):
        func_name = 'destroyFrom'
        args = [to_checksum_address(from1), value, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def increaseAllowance(self, spender, addedValue):
        func_name = 'increaseAllowance'
        args = [to_checksum_address(spender), addedValue]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def isIssuer(self, account):
        func_name = 'isIssuer'
        args = [to_checksum_address(account)]
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def isSuspender(self, account):
        func_name = 'isSuspender'
        args = [to_checksum_address(account)]
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def issue(self, to, value, data):
        func_name = 'issue'
        args = [to_checksum_address(to), value, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def minUnit(self):
        func_name = 'minUnit'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def renounceIssuer(self):
        func_name = 'renounceIssuer'
        args = []
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def renounceSuspender(self):
        func_name = 'renounceSuspender'
        args = []
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def send(self, to, value, data):
        func_name = 'send'
        args = [to_checksum_address(to), value, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def sendFrom(self, from1, to, value, data):
        func_name = 'sendFrom'
        args = [to_checksum_address(from1), to_checksum_address(to), value, data]
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def shortName(self):
        func_name = 'shortName'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def suspend(self):
        func_name = 'suspend'
        args = []
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt

    # ------------------------------------------
    def suspended(self):
        func_name = 'suspended'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def totalAmount(self):
        func_name = 'totalAmount'
        args = []
        result = self.client.call(self.address, self.contract_abi, func_name, args)
        return result

    # ------------------------------------------
    def unSuspend(self):
        func_name = 'unSuspend'
        args = []
        receipt = self.client.sendRawTransactionGetReceipt(self.address, self.contract_abi, func_name, args)
        outputresult = self.data_parser.parse_receipt_output(func_name, receipt['output'])
        return outputresult, receipt