def init_account_info(db): GlobalVariable.db_account_list = [] GlobalVariable.account_list = [] GlobalVariable.withdraw_account = [] records = db.b_chain_account.find({"chainId": "etp"}) for one_account in records: GlobalVariable.db_account_list.append(one_account["address"]) withdraw_data = db.b_config.find_one({"key": "withdrawaddress"}) if withdraw_data is not None: for data in withdraw_data["value"]: if data["chainId"] == "etp": GlobalVariable.withdraw_account.append(data["address"]) break ret = etp_request("listaccounts", []) json_data = json.loads(ret) if json_data.get("accounts") is None: raise Exception("get_all_account_list") acc_list = json_data.get("accounts") for account in acc_list : ret = etp_request("listaccounts", [account.get("name"),account.get("name")]) json_data = json.loads(ret) if json_data.get("addresses") is not None : addr_list = json_data.get("addresses") for addr in addr_list : GlobalVariable.account_list.append(addr) GlobalVariable.all_care_account = [] GlobalVariable.all_care_account.extend(GlobalVariable.account_list) GlobalVariable.all_care_account.extend(GlobalVariable.db_account_list) GlobalVariable.all_care_account.extend(GlobalVariable.withdraw_account)
def collect_block( db_pool, block_num_fetch): # height就是ret,ret 为string header_response = etp_request("fetch-header",["-t",block_num_fetch]) json_header = json.loads(header_response) block_info = BlockInfo() block_info.from_header_resp(json_header) #获取交易信息 block_response=etp_request("getblock",[block_info.block_id, True]) json_block = json.loads(block_response) block_info.from_trx_resp(json_block.get('txs').get('transactions')) block = db_pool.b_block txs = json_block.get('txs').get('transactions') for tx in txs : block_info.trx_count += 1 if need_to_skip(tx) : continue tx_data=collect_pretty_transaction(db_pool,block_info,tx) if tx_data is None : continue update_input_output_tx_data(db_pool,tx,tx_data) mongo_data = block.find_one({"blockHash": block_info.block_id}) # print {"blockHash":block_info.block_id} if mongo_data == None: block.insert(block_info.get_json_data()) else: block.update({"blockHash": block_info.block_id}, {"$set": block_info.get_json_data()}) return block_info
def get_latest_block_num(db): ret = etp_request("fetch-height",[]) safe_block = db.b_config.find_one({"key": "etpsafeblock"})["value"] try: ret=int(ret) except: ret=int(safe_block) return ret - int(safe_block)
def get_amount_from_previous_outputs(hash,addr): trx_response = etp_request("fetch-tx",[hash]) trx = json.loads(trx_response).get("transaction") amount=0 for output in trx.get("outputs"): if output.get('address') == addr : amount += float(output.get('value'))/float(1000000000) ''' elif output.get('attachment').get('type') == 'asset-transfer': if amount.has_key(output.get('attachment').get('symbol')) : amount[output.get('attachment').get('symbol')] += float(output.get('attachment').get('quantity'))/float(100000000) else: amount[output.get('attachment').get('symbol')] = float(output.get('attachment').get('quantity'))/float(100000000) ''' return amount
def get_all_account_list(): ret = etp_request("getnewaccount",['hzkai','12345678']) print ret json_data = json.loads(ret)