def get_asset_info(asset, at_dt=None): asset_info = config.mongo_db.tracked_assets.find_one({'asset': asset}) if asset not in (config.XCP, config.BTC) and at_dt and asset_info['_at_block_time'] > at_dt: #get the asset info at or before the given at_dt datetime for e in reversed(asset_info['_history']): #newest to oldest if e['_at_block_time'] <= at_dt: asset_info = e break else: #asset was created AFTER at_dt asset_info = None if asset_info is None: return None assert asset_info['_at_block_time'] <= at_dt #modify some of the properties of the returned asset_info for BTC and XCP if asset == config.BTC: if at_dt: start_block_index, end_block_index = database.get_block_indexes_for_dates(end_dt=at_dt) asset_info['total_issued'] = blockchain.get_btc_supply(normalize=False, at_block_index=end_block_index) asset_info['total_issued_normalized'] = blockchain.normalize_quantity(asset_info['total_issued']) else: asset_info['total_issued'] = blockchain.get_btc_supply(normalize=False) asset_info['total_issued_normalized'] = blockchain.normalize_quantity(asset_info['total_issued']) elif asset == config.XCP: #BUG: this does not take end_dt (if specified) into account. however, the deviation won't be too big # as XCP doesn't deflate quickly at all, and shouldn't matter that much since there weren't any/much trades # before the end of the burn period (which is what is involved with how we use at_dt with currently) asset_info['total_issued'] = util.call_jsonrpc_api("get_supply", {'asset': 'XCP'}, abort_on_error=True)['result'] asset_info['total_issued_normalized'] = blockchain.normalize_quantity(asset_info['total_issued']) if not asset_info: raise Exception("Invalid asset: %s" % asset) return asset_info
def get_assets_info(assetsList): assets = assetsList # TODO: change the parameter name at some point in the future...shouldn't be using camel case here if not isinstance(assets, list): raise Exception( "assets must be a list of asset names, even if it just contains one entry" ) assets_info = [] for asset in assets: # BTC and XCP. if asset in [config.BTC, config.XCP]: if asset == config.BTC: supply = blockchain.get_btc_supply(self.proxy, normalize=False) else: supply = util.call_jsonrpc_api("get_supply", {'asset': config.XCP}, abort_on_error=True)['result'] assets_info.append({ 'asset': asset, 'owner': None, 'divisible': True, 'locked': False, 'supply': supply, 'description': '', 'issuer': None }) continue # User-created asset. tracked_asset = config.mongo_db.tracked_assets.find_one( {'asset': asset}, { '_id': 0, '_history': 0 }) if not tracked_asset: continue # asset not found, most likely assets_info.append({ 'asset': asset, 'owner': tracked_asset['owner'], 'divisible': tracked_asset['divisible'], 'locked': tracked_asset['locked'], 'supply': tracked_asset['total_issued'], 'description': tracked_asset['description'], 'issuer': tracked_asset['owner'] }) return assets_info
def get_assets_info(assetsList): assets = assetsList #TODO: change the parameter name at some point in the future...shouldn't be using camel case here if not isinstance(assets, list): raise Exception("assets must be a list of asset names, even if it just contains one entry") assets_info = [] for asset in assets: # BTC and XCP. if asset in [config.BTC, config.XCP]: if asset == config.BTC: supply = blockchain.get_btc_supply(self.proxy, normalize=False) else: supply = util.call_jsonrpc_api("get_supply", {'asset': 'XCP'}, abort_on_error=True)['result'] assets_info.append({ 'asset': asset, 'owner': None, 'divisible': True, 'locked': False, 'supply': supply, 'description': '', 'issuer': None }) continue # User-created asset. tracked_asset = config.mongo_db.tracked_assets.find_one({'asset': asset}, {'_id': 0, '_history': 0}) if not tracked_asset: continue #asset not found, most likely assets_info.append({ 'asset': asset, 'owner': tracked_asset['owner'], 'divisible': tracked_asset['divisible'], 'locked': tracked_asset['locked'], 'supply': tracked_asset['total_issued'], 'description': tracked_asset['description'], 'issuer': tracked_asset['owner']}) return assets_info