def zchain_address_get_balance(chainId, addr): logger.info('Zchain.Address.GetBalance') chainId = chainId.lower() record_unspent = db.b_balance_unspent.find_one({'chainId': chainId, 'address': addr}) trx_unspent=[] trx_spent = [] balance = 0.0 record_spent = None if record_unspent is not None: trx_unspent = record_unspent.get("trxdata") record_spent = db.b_balance_spent.find_one({'chainId': chainId, 'address': addr}) if record_spent is not None : trx_spent = record_spent.get("trxdata") else: return { 'chainId': chainId, 'address': addr, 'balance': 0 } unspent = [] for trx in trx_unspent : if trx not in trx_spent: unspent.append(trx) for id in unspent: pos1 = len(chainId) id = id[pos1:] pos2 = id.find('I') index = id[pos2 + 1:] id = id[0:pos2] result = "" if sim_btc_plugin.has_key(chainId): result = sim_btc_plugin[chainId].sim_btc_get_transaction(id) elif chainId == "hc": result = hc_plugin.hc_get_transaction(id) if result is "": continue vout = round(float(result.get("vout")[int(index)].get("value")), 8) balance = round(vout + balance, 8) return { 'chainId': chainId, 'address': addr, 'balance': balance }
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
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 = "" if sim_btc_plugin.has_key(chainId): result = sim_btc_plugin[chainId].sim_btc_get_transaction(trxid) elif chainId == "hc": result = hc_plugin.hc_get_transaction(trxid) else: return error_utils.invalid_chainid_type() if result == "": return error_utils.error_response("Cannot query transaction.") return { 'chainId': chainId, 'data': 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 elif chainId == "hc": result = hc_plugin.hc_get_transaction(trxid) 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 elif chainId == "usdt": result = usdt_plugin.omni_get_transaction(trxid) if "vout" in result: is_cache = True try: if "confirmations" in result: if result["confirmations"] <= 7: