Exemplo n.º 1
0
def zchain_multisig_create(chainId, addrs, amount):
    chainId = chainId.lower()
    logger.info('Zchain.Multisig.Create')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(addrs) != list:
        return error_utils.mismatched_parameter_type('addrs', 'ARRAY')
    if type(amount) != int:
        return error_utils.mismatched_parameter_type('amount', 'INTEGER')

    address = ""
    redeemScript = ""
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_create_multisig(addrs, amount)
        if result is not None:
            address = result["address"]
            redeemScript = result["redeemScript"]
            mutisig_record = db.get_collection("b_"+chainId+"_multisig_address").find_one({"address": address})
            if mutisig_record is not None:
                db.get_collection("b_"+chainId+"_multisig_address").remove({"address": address})
            data = {"address": address, "redeemScript": redeemScript, "addr_type":0}
            db.get_collection("b_"+chainId+"_multisig_address").insert_one(data)
    elif chainId == "hc":
        result = hc_plugin.hc_create_multisig(addrs, amount)
        if result is not None:
            address = result["address"]
            redeemScript = result["redeemScript"]
            mutisig_record = db.get_collection("b_hc_multisig_address").find_one({"address": address})
            if mutisig_record is not None:
                db.get_collection("b_hc_multisig_address").remove({"address": address})
            data = {"address": address, "redeemScript": redeemScript, "addr_type":0}
            db.get_collection("b_hc_multisig_address").insert_one(data)
    elif chainId == "btm":
        result = btm_plugin.btm_create_multisig(addrs, amount)
        if result is not None:
            address = result["address"]
            redeemScript = result["redeemScript"]
            mutisig_record = db.get_collection("b_btm_multisig_address").find_one({"address": address})
            if mutisig_record is not None:
                db.get_collection("b_btm_multisig_address").remove({"address": address})
            data = {"address": address, "redeemScript": redeemScript, "addr_type":0}
            db.get_collection("b_btm_multisig_address").insert_one(data)
    elif chainId == "usdt":
        result = usdt_plugin.omni_create_multisig(addrs, amount)
        if result is not None:
            address = result["address"]
            redeemScript = result["redeemScript"]
            mutisig_record = db.get_collection("b_" + chainId + "_multisig_address").find_one({"address": address})
            if mutisig_record is not None:
                db.get_collection("b_" + chainId + "_multisig_address").remove({"address": address})
            data = {"address": address, "redeemScript": redeemScript, "addr_type": 0}
            db.get_collection("b_" + chainId + "_multisig_address").insert_one(data)
    else:
        return error_utils.invalid_chainid_type(chainId)

    return {
        'chainId': chainId,
        'address': address,
        'redeemScript': redeemScript
    }
Exemplo n.º 2
0
def zchain_address_validate(chainId,addr):
    chainId = chainId.lower()
    logger.info("Zchain.Address.validate")
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(addr) != unicode:
        return error_utils.mismatched_parameter_type('addr', 'STRING')
    result = None
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_validate_address(addr)
    elif chainId == "hc":
        result = hc_plugin.hc_validate_address(addr)
    elif chainId == "usdt":
        result = usdt_plugin.omni_validate_address(addr)
    elif chainId == "btm":
        result = btm_plugin.btm_validate_address(addr)
        return {
            "chainId": chainId,
            "valid": result
        }
    elif chainId == "eth" or 'erc'in chainId:
        result = eth_utils.eth_validate_address(addr)
        return {
            "chainId": chainId,
            "valid": result
        }
    else:
        return error_utils.invalid_chainid_type(chainId)

    return {
        "chainId":chainId,
        "valid"  : result.get("isvalid")
    }
Exemplo n.º 3
0
def zchain_transaction_deposit_history(chainId,account ,blockNum, limit):
    chainId = chainId.lower()
    logger.info('Zchain.Transaction.Deposit.History')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(account) != unicode:
        return error_utils.mismatched_parameter_type('account', 'STRING')
    if type(blockNum) != int:
        return error_utils.mismatched_parameter_type('blockNum', 'INTEGER')
    if type(limit) != int:
        return error_utils.mismatched_parameter_type('limit', 'INTEGER')

    depositTrxs = db.b_deposit_transaction.find({"chainId": chainId, "blockNum": {"$gte": blockNum}}, {"_id": 0}).sort(
        "blockNum", pymongo.DESCENDING)
    trxs = list(depositTrxs)
    if len(trxs) == 0:
        blockNum = 0
    else:
        blockNum = trxs[0]['blockNum']

    return {
        'chainId': chainId,
        'blockNum': blockNum,
        'data': trxs
    }
Exemplo n.º 4
0
def zchain_multisig_add(chainId, addrs, amount, addrType):
    logger.info('Zchain.Multisig.Add')
    chainId = chainId.lower()
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(addrs) != list:
        return error_utils.mismatched_parameter_type('addrs', 'ARRAY')
    if type(amount) != int:
        return error_utils.mismatched_parameter_type('amount', 'INTEGER')
    if type(addrType) != int:
        return error_utils.mismatched_parameter_type('addrType', 'INTEGER')

    address = ""
    if sim_btc_plugin.has_key(chainId):
        multisig_addr = sim_btc_plugin[chainId].sim_btc_add_multisig(
            addrs, amount)
        if multisig_addr is not None:
            addr_info = sim_btc_plugin[chainId].sim_btc_validate_address(
                multisig_addr)
            if addr_info == "":
                multisig_record = db.get_collection(
                    "b_" + chainId + "_multisig_address").find_one(
                        {"address": multisig_addr})
                if multisig_record is not None:
                    db.get_collection("b_" + chainId +
                                      "_multisig_address").remove(
                                          {"address": multisig_addr})
                data = {
                    "address": addr_info["address"],
                    "redeemScript": addr_info["hex"],
                    "addr_type": addrType
                }
                db.get_collection("b_" + chainId +
                                  "_multisig_address").insert_one(data)
                address = addr_info["address"]
    elif chainId == "hc":
        multisig_addr = hc_plugin.hc_add_multisig(addrs, amount)
        if multisig_addr is not None:
            addr_info = hc_plugin.hc_validate_address(multisig_addr)
            if addr_info is not None:
                multisig_record = db.get_collection(
                    "b_hc_multisig_address").find_one(
                        {"address": multisig_addr})
                if multisig_record is not None:
                    db.get_collection("b_hc_multisig_address").remove(
                        {"address": multisig_addr})
                data = {
                    "address": addr_info["address"],
                    "redeemScript": addr_info["hex"],
                    "addr_type": addrType
                }
                db.get_collection("b_hc_multisig_address").insert_one(data)
    else:
        return error_utils.invalid_chainid_type()

    return {'chainId': chainId, 'data': address}
Exemplo n.º 5
0
def client_upgrade_check_new_version(clientId, localVersion):
    logger.info('Client.Upgrade.checkNewVersion')
    if type(clientId) != unicode:
        return error_utils.mismatched_parameter_type('clientId', 'STRING')
    if type(localVersion) != unicode:
        return error_utils.mismatched_parameter_type('localVersion', 'STRING')

    return {
        'clientId': clientId,
        'downloadUrl': "/download/hyperexchange_wallet_upgrade.xml"
    }
Exemplo n.º 6
0
def zchain_transaction_all_history(chainId,coinName,desc,contractAddr,contact,payCode):
    logger.info('Zchain.Coin.Add.Request')
    chainId = chainId.lower()
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(coinName) != unicode:
        return error_utils.mismatched_parameter_type('coinName', 'STRING')
    if type(contractAddr) != unicode:
        return error_utils.mismatched_parameter_type('contractAddr', 'STRING')
    if type(payCode) != unicode:
        return error_utils.mismatched_parameter_type('payCode', 'STRING')
    if chainId == "hx":
        #add record to mongodb
        db.get_collection("b_addcoin").insert_one({"chainId":chainId,"coinName":coinName,"desc":desc,"contractAddr":contractAddr,"contact":contact,"payCode":payCode})
    return True
Exemplo n.º 7
0
def zchain_trans_queryTrx(chainId, trxid):
    chainId = chainId.lower()
    logger.info('Zchain.Trans.queryTrans')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = ""
    is_cache = False

    cache_record = db.get_collection("b_query_trans_cache").find_one({"chainId": chainId,"trxid":trxid})
    if cache_record is not None:
        return {
        'chainId': chainId,
        'data': cache_record["result"]
        }
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_get_transaction(trxid)
        if "vout" in result:
            is_cache = True
            try:
                if "confirmations" in result:
                    if result["confirmations"]<=7:
                        is_cache = False
                else:
                    is_cache = False
            except Exception,ex:
                print "query confirmation failed",ex
Exemplo n.º 8
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
    }
Exemplo n.º 9
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
    }
Exemplo n.º 10
0
def zchain_crypt_verify_message(chainId, addr, message, signature):
    chainId = chainId.lower()
    logger.info('Zchain.Crypt.VerifyMessage')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = False

    cache_record = db.get_collection("b_verify_cache").find_one({"chainId": chainId,"addr":addr, "message":message, "signature":signature})
    if cache_record is not None:
        result = True
        return {
        'chainId': chainId,
        'data': result
        }


    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_verify_signed_message(addr, message, signature)
    elif chainId == "hc":
        result = hc_plugin.hc_verify_signed_message(addr, message, signature)

    elif (chainId == 'eth') or ('erc' in chainId):
        #print 1
        result = eth_utils.eth_verify_signed_message(addr, message, signature)
    else:
        return error_utils.invalid_chainid_type(chainId)
    if result:
        db.get_collection("b_verify_cache").insert_one(
            {"chainId": chainId, "addr": addr, "message": message, "signature": signature})

    return {
        'chainId': chainId,
        'data': result
    }
Exemplo n.º 11
0
def zchain_addr_importaddr(chainId, addr):
    logger.info('Zchain.Addr.importAddr')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if sim_btc_plugin.has_key(chainId):
        sim_btc_plugin[chainId].sim_btc_import_addr(addr)
    elif chainId == "hc":
        hc_plugin.hc_import_addr(addr)
    elif chainId == "usdt":
        usdt_plugin.omni_import_addr(addr)
    elif chainId.lower() == 'eth':
        if "erc" in addr:
            temp_chainId = chainId.lower()
            pos = addr.find("erc")
            handle_addr = addr[0:pos]
            asset = db.b_eths_address.find_one({'chainId':temp_chainId,'address':handle_addr})
            if asset == None:
                db.b_eths_address.insert({'chainId': temp_chainId, 'address': handle_addr, 'isContractAddress': True})
            else:
                db.b_eths_address.update({'chainId':temp_chainId,'address':handle_addr},{"$set":{ 'isContractAddress': True}})
        else:
            temp_chainId = chainId.lower()
            asset = db.b_eths_address.find_one({'chainId': temp_chainId, 'address': addr})
            if asset == None:
                db.b_eths_address.insert({'chainId': temp_chainId, 'address': addr, 'isContractAddress': False})
            else:
                db.b_eths_address.update({'chainId':temp_chainId,'address':addr},{"$set":{ 'isContractAddress': False}})
        eth_utils.add_guard_address(addr)
    elif ('erc' in chainId.lower()):
        erc_asset = None
        if erc_chainId_map.has_key(chainId):
            erc_asset = erc_chainId_map[chainId]
        if erc_asset != None:
            if "erc" in addr:
                pos = addr.find("erc")
                handle_addr = addr[0:pos]
                asset = db.b_eths_address.find_one({'chainId': chainId, 'address': handle_addr})
                if asset == None:
                    db.b_eths_address.insert(
                        {'chainId': chainId, 'address': handle_addr, 'isContractAddress': True})
                else:
                    db.b_eths_address.update({'chainId': chainId, 'address': handle_addr},
                                             {"$set": {'isContractAddress': True}})
            else:
                asset = db.b_eths_address.find_one({'chainId': chainId, 'address': addr})
                if asset == None:
                    db.b_eths_address.insert(
                        {'chainId': chainId, 'address': addr, 'isContractAddress': False})
                else:
                    db.b_eths_address.update({'chainId': chainId, 'address': addr},
                                             {"$set": {'isContractAddress': False}})
            eth_utils.add_guard_address(addr)
    else:
        return error_utils.invalid_chainid_type(chainId)
    return {
        'chainId': chainId,
        'data': ""
    }
Exemplo n.º 12
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}
Exemplo n.º 13
0
def zchain_configuration_set(chainId, key, value):
    chainId = chainId.lower()
    logger.info('Zchain.Configure')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(key) != unicode:
        return error_utils.mismatched_parameter_type('key', 'STRING')
    if type(value) != unicode:
        return error_utils.mismatched_parameter_type('value', 'STRING')

    data = {"chainId": chainId, "key": key, "value": value}
    result = True
    try:
        db.b_config.insert_one(data)
    except Exception as e:
        logger.error(str(e))
        result = False
    finally:
        return {"result": result}
Exemplo n.º 14
0
def zchain_withdraw_getinfo(chainId):
    """
    查询提现账户的信�?
    :param chainId:
    :return:
    """
    chainId = chainId.lower()
    logger.info('Zchain.Withdraw.GetInfo')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    records = db.b_config.find_one({'key': 'withdrawaddress'}, {'_id': 0})
    address = ""
    if records == None:
        db.b_config.insert_one({"key": "withdrawaddress", "value": []})
        records = db.b_config.find_one({'key': 'withdrawaddress'}, {'_id': 0})
    for r in records["value"]:
        if r['chainId'] == chainId:
            address = r['address']

    if address == "":
        if chainId == "eth":
            address = eth_utils.eth_create_address()
            # eth_utils.eth_backup()
            records["value"].append({"chainId": "eth", "address": address})
        elif sim_btc_plugin.has_key(chainId):
            address = sim_btc_plugin[chainId].sim_btc_create_withdraw_address()
            sim_btc_plugin.sim_btc_backup_wallet()
            records["value"].append({"chainId": chainId, "address": address})
        elif chainId == "hc":
            address = hc_plugin.hc_create_withdraw_address()
            hc_plugin.hc_backup_wallet()
            records["value"].append({"chainId": chainId, "address": address})
        elif chainId == "etp":
            address = etp_utils.etp_create_withdraw_address()
            records["value"].append({"chainId": "etp", "address": address})
    db.b_config.update({"key": "withdrawaddress"}, {"$set": {"value": records["value"]}})
    balance = 0.0
    if chainId == "eth":
        balance = eth_utils.eth_get_base_balance(address)
    elif sim_btc_plugin.has_key(chainId):
        balance = sim_btc_plugin.sim_btc_get_withdraw_balance()
    elif chainId == "hc":
         balance = hc_plugin.hc_get_withdraw_balance()
    elif chainId == "etp":
        balance = etp_utils.etp_get_addr_balance(address)
    else:
        return error_utils.invalid_chainid_type(chainId)

    return {
        'chainId': chainId,
        'address': address,
        'balance': balance
    }
Exemplo n.º 15
0
def zchain_trans_queryTrx(chainId, trxids):
    chainId = chainId.lower()
    logger.info('Zchain.Trans.queryTransBatch')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if type(trxids) != list:
        return error_utils.mismatched_parameter_type('trxids', 'LIST')
    res_data = {}
    for one_txid in trxids:
        result = ""
        is_cache = False
        cache_record = db.get_collection("b_query_trans_cache").find_one({
            "chainId":
            chainId,
            "trxid":
            one_txid
        })
        if cache_record is not None:
            res_data[one_txid] = cache_record["result"]
            continue
        if sim_btc_plugin.has_key(chainId):
            result = sim_btc_plugin[chainId].sim_btc_get_transaction(one_txid)
            if "vout" in result:
                is_cache = True
                try:
                    if "confirmations" in result:
                        if result["confirmations"] <= 0:
                            is_cache = False
                except Exception, ex:
                    print "query confirmation failed", ex

        elif chainId == "hc":
            result = hc_plugin.hc_get_transaction(one_txid)
            if "vout" in result:
                is_cache = True
                try:
                    if "vin" in result and len(result["vin"]) > 0:
                        if result["vin"][0]["blockheight"] <= 0:
                            is_cache = False
                except Exception, ex:
                    print "query confirmation failed", ex
Exemplo n.º 16
0
def zchain_query_getTrxHistoryByAddress(chainId,address,startBlock,endBlock):
    logger.info('Zchain.Query.getTrxHistoryByAddress')
    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_history_by_address(address,startBlock,endBlock)
    elif 'eth' == chainId:
        result = eth_utils.eth_get_trx_history_by_address(address,startBlock,endBlock)
    else:
        return error_utils.invalid_chainid_type(chainId)
    #print result
    return result
Exemplo n.º 17
0
def zchain_query_getUtxoCount(chainId, address):
    logger.info('Zchain.Query.getUtxoCount')
    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_get_trx_out(address)
    elif chainId == "hc":
        result = hc_plugin.hc_get_trx_out(address)
    else:
        return error_utils.invalid_chainid_type()
    #print result
    return len(result)
Exemplo n.º 18
0
def zchain_query_getEthTrx(chainId,trxid):
    logger.info('Zchain.Query.getEthTrx')
    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(trxid)
    elif 'eth' == chainId:
        result = eth_utils.eth_get_trx(trxid)
    else:
        return error_utils.invalid_chainid_type(chainId)
    #print result
    return result
Exemplo n.º 19
0
def zchain_addr_importaddr(chainId, addr):
    logger.info('Zchain.Addr.importAddr')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    if sim_btc_plugin.has_key(chainId):
        sim_btc_plugin[chainId].sim_btc_import_addr(addr)
    elif chainId == "hc":
        hc_plugin.hc_import_addr(addr)
    else:
        return error_utils.invalid_chainid_type()
    return {
        'chainId': chainId,
        'data': ""
    }
Exemplo n.º 20
0
def zchain_trans_getTrxOuts(chainId, addr):
    chainId = chainId.lower()
    logger.info('Zchain.Trans.getTrxOuts')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = False
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_query_tx_out(addr)
    elif chainId == "hc":
        result = hc_plugin.hc_query_tx_out(addr)
    else:
        return error_utils.invalid_chainid_type()

    return {'chainId': chainId, 'data': result}
Exemplo n.º 21
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
Exemplo n.º 22
0
def zchain_exchange_queryContracts(from_asset, to_asset, limit):
    logger.info('Zchain.Exchange.queryContracts')

    if type(limit) != int:
        return error_utils.mismatched_parameter_type('limit', 'INTEGER')
    if limit <= 0:
        limit = 10

    contracts = db.b_exchange_contracts.find(
        {
            "from_asset": from_asset,
            "to_asset": to_asset
        }, {
            "_id": 0
        }).sort("price").limit(limit)

    return {'data': list(contracts)}
Exemplo n.º 23
0
def zchain_Addr_GetAddErc(chainId,addr,precison):
    logger.info('Zchain.Addr.GetAddErc')

    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    asset = None
    if erc_chainId_map.has_key(chainId):
        asset = erc_chainId_map[chainId]

    if asset is None:
        return {}
    else:
        return{
            'chainId':asset['chainId'],
            'address':asset['address'],
            'precision':asset['precison']
        }
Exemplo n.º 24
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}
Exemplo n.º 25
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}
Exemplo n.º 26
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}
Exemplo n.º 27
0
def zchain_crypt_verify_message(chainId, addr, message, signature):
    chainId = chainId.lower()
    logger.info('Zchain.Crypt.VerifyMessage')
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')

    result = False
    if sim_btc_plugin.has_key(chainId):
        result = sim_btc_plugin[chainId].sim_btc_verify_signed_message(addr, message, signature)
    elif chainId == "hc":
        result = hc_plugin.hc_verify_signed_message(addr, message, signature)
    else:
        return error_utils.invalid_chainid_type()

    return {
        'chainId': chainId,
        'data': result
    }
Exemplo n.º 28
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}
Exemplo n.º 29
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
    }
Exemplo n.º 30
0
def zchain_EthCall(chainId,callData,blockheight):
    logger.info('Zchain.EthCall')
    chainId = chainId.lower()
    if type(chainId) != unicode:
        return error_utils.mismatched_parameter_type('chainId', 'STRING')
    ercchainId = chainId
    if chainId == 'eth':
      ret = eth_utils.eth_call(callData,blockheight)
      return ret
    elif 'erc' in chainId:
        #print ercchainId
        asset = None
        if erc_chainId_map.has_key(ercchainId):
           asset = erc_chainId_map[ercchainId]
        if asset == None:
            return error_utils.invalid_chainid_type(chainId)

        ret = eth_utils.eth_call(callData, blockheight)
        return ret
    return error_utils.invalid_chainid_type()