Example #1
0
def zchain_trans_broadcastTrx(chainId, trx):
    logger.info('Zchain.Trans.broadcastTrx')
    global last_clean_broadcast_cache_time
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    md = hashlib.md5()
    md.update(trx)
    trxId = md.hexdigest()

    broad_cast_record = db.get_collection("b_broadcast_trans_cache").find_one({
        "chainId":
        chainId,
        "trx":
        trxId,
        "effectiveTime": {
            "$gt": int(time.time()) - 10
        }
    })
    if broad_cast_record is not None:
        if broad_cast_record['result'] == "":
            return error_utils.error_response("Cannot broadcast transactions.")
        return {'chainId': chainId, 'data': broad_cast_record['result']}

    result = ""
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_broadcaset_trx(trx)
    elif chainId == "hc":
        result = hc_plugin.hc_broadcaset_trx(trx)
    elif chainId.lower() == "eth":
        result = eth_utils.eth_send_raw_transaction(trx)
    elif 'erc' in chainId.lower():
        result = eth_utils.eth_send_raw_transaction(trx)
    else:
        return error_utils.invalid_chainid_type()

    db.get_collection("b_broadcast_trans_cache").insert_one({
        "chainId":
        chainId,
        "trx":
        trxId,
        "effectiveTime":
        int(time.time()),
        "result":
        result
    })
    if int(time.time()) - last_clean_broadcast_cache_time > 10 * 60:
        db.get_collection("b_broadcast_trans_cache").delete_many(
            {"effectiveTime": {
                "$lt": int(time.time()) - 10
            }})
        last_clean_broadcast_cache_time = int(time.time())
    if result == "":
        return error_utils.error_response("Cannot broadcast transactions.")

    return {'chainId': chainId, 'data': result}
Example #2
0
def zchain_trans_decodeTrx(chainId, trx_hex):
    chainId = chainId.lower()
    logger.info('Zchain.Trans.DecodeTrx')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = ""
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_decode_hex_transaction(trx_hex)
    elif chainId == "hc":
        result = hc_plugin.hc_decode_hex_transaction(trx_hex)
    elif chainId == "usdt":
        result = usdt_plugin.omni_decode_hex_transaction(trx_hex)
    elif chainId == "btm":
        result = btm_plugin.btm_decode_hex_transaction(trx_hex)
    else:
        return error_utils.invalid_chainid_type(chainId)

    if result == "":
        return error_utils.error_response("Cannot create transaction.")

    return {
        'chainId': chainId,
        'data': result
    }
Example #3
0
def zchain_trans_createFullSendTrx(chainId, from_addr,dest_info):
    logger.info('Zchain.Trans.createTrx')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    chainId = chainId.lower()
    result = {}
    if sim_btc_plugin.has_key(chainId):
        is_fast_record = db.get_collection("b_config").find_one({"key": "is_fast"})
        is_fast = False
        if is_fast_record is not None:
            is_fast = bool(is_fast_record["value"])
        result = sim_btc_plugin[chainId].sim_btc_create_transaction(from_addr,dest_info,is_fast,True)
    elif chainId == "hc":
        result = hc_plugin.hc_create_transaction(from_addr, dest_info)
    elif chainId == "usdt":
        result = usdt_plugin.omni_create_transaction(from_addr,dest_info)
    elif chainId == "btm":
        result = btm_plugin.btm_create_transaction(from_addr, dest_info)
    else:
        return error_utils.invalid_chainid_type(chainId)

    if result == {}:
        return error_utils.error_response("Cannot create transaction.")

    return {
        'chainId': chainId,
        'data': result
    }
Example #4
0
def zchain_trans_getEthTrxCount(chainId, addr, indexFormat):
    logger.info('Zchain.Trans.getEthTrxCount')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    chainId = chainId.lower()
    result = {}
    if 'erc' in chainId:
        result = eth_utils.eth_get_trx_count(addr,indexFormat)
    elif 'eth' == chainId:
        result = eth_utils.eth_get_trx_count(addr, indexFormat)
    else:
        return error_utils.invalid_chainid_type(chainId)
    if result == {}:
        return error_utils.error_response("Cannot eth trx count.")
    #print result
    return result
Example #5
0
def zchain_trans_CombineTrx(chainId, transactions):
    logger.info('Zchain.Trans.CombineTrx')
    chainId = chainId.lower()
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = ""
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_combine_trx(transactions)
    elif chainId == "hc":
        result = hc_plugin.hc_combine_trx(transactions)
    else:
        return error_utils.invalid_chainid_type()

    if result == "":
        return error_utils.error_response("Cannot combine transaction.")

    return {'chainId': chainId, 'data': result}
Example #6
0
def zchain_trans_createTrx(chainId, from_addr, dest_info):
    logger.info('Zchain.Trans.createTrx')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    chainId = chainId.lower()
    result = {}
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_create_transaction(
            from_addr, dest_info)
    elif chainId == "hc":
        result = hc_plugin.hc_create_transaction(from_addr, dest_info)
    else:
        return error_utils.invalid_chainid_type()

    if result == {}:
        return error_utils.error_response("Cannot create transaction.")

    return {'chainId': chainId, 'data': result}
Example #7
0
def zchain_Trans_sign(chainId, addr, trx_hex, redeemScript):
    logger.info('Zchain.Trans.Sign')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    signed_trx = ""
    if sim_btc_plugin.has_key(chainId):
        signed_trx = sim_btc_plugin[chainId].sim_btc_sign_transaction(
            addr, redeemScript, trx_hex)
    elif chainId == "hc":
        signed_trx = hc_plugin.hc_sign_transaction(addr, redeemScript, trx_hex)
    else:
        return error_utils.invalid_chainid_type()

    if signed_trx == "":
        return error_utils.error_response("Cannot sign trans.")

    return {'chainId': chainId, 'data': signed_trx}
Example #8
0
def zchain_crypt_sign(chainId, addr, message):
    logger.info('Zchain.Crypt.Sign')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    signed_message = ""
    if sim_btc_plugin.has_key(chainId):
        signed_message = sim_btc_plugin[chainId].sim_btc_sign_message(
            addr, message)
    elif chainId == "hc":
        signed_message = hc_plugin.hc_sign_message(addr, message)
    else:
        return error_utils.invalid_chainid_type()

    if signed_message == "":
        return error_utils.error_response("Cannot sign message.")

    return {'chainId': chainId, 'data': signed_message}
Example #9
0
def zchain_trans_broadcastTrx(chainId, trx):
    logger.info('Zchain.Trans.broadcastTrx')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = ""
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_broadcaset_trx(trx)
    elif chainId == "hc":
        result = hc_plugin.hc_broadcaset_trx(trx)
    else:
        return error_utils.invalid_chainid_type()

    if result == "":
        return error_utils.error_response("Cannot broadcast transactions.")

    return {
        'chainId': chainId,
        'data': result
    }
Example #10
0
def zchain_query_getBlockHeight(chainId):
    logger.info('Zchain.Query.getBlockHeight')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    chainId = chainId.lower()
    result = {}
    if 'erc' in chainId:
        result = eth_utils.eth_get_block_height()
    elif 'eth' == chainId:
        result = eth_utils.eth_get_block_height()
    elif 'hc' == chainId:
        cache_record = db.get_collection("b_config").find_one({"key" : "hcsyncblocknum"})
        if cache_record is not None:
            result = int(cache_record["value"])
        else:
            result=0
    else:
        return error_utils.invalid_chainid_type()
    if result == {}:
        return error_utils.error_response("Cannot eth trx count.")
    #print result
    return result
Example #11
0
        result = btm_plugin.btm_get_transaction(trxid)
        if "outputs" in result:
            is_cache = True

    elif chainId == "eth" or "erc" in chainId:
        source,respit = eth_utils.get_transaction_data(trxid)
        so_re_dic = {'source_trx':source,'respit_trx':respit}
        if "input" in source:
            is_cache = True
        if source != None and respit != None:
            result = so_re_dic
    else:
        return error_utils.invalid_chainid_type(chainId)

    if result == "":
        return error_utils.error_response("Cannot query transaction.")
    if result.has_key("vin"):
        for i in range(len(result["vin"])):
            result["vin"][i]["scriptSig"]={"asm":"","hex":""}
    if is_cache:
        db.get_collection("b_query_trans_cache").insert_one(
            {"chainId": chainId, "trxid": trxid,"result":result})
    return {
        'chainId': chainId,
        'data': result
    }

@jsonrpc.method('Zchain.Trans.queryTransBatch(chainId=str, trxids=list)')
def zchain_trans_queryTrx(chainId, trxids):
    chainId = chainId.lower()
    logger.info('Zchain.Trans.queryTransBatch')