def filter_channels(rpc, filter_name, amount=0, unit='msat'): if not is_valid_filter(filter_name): return "Value filter_name's are %s" % ', '.join(channel_filters) if filter_name.lower() == 'pending': return pending_channels(rpc) if filter_name.lower() == 'active': return active_channels(rpc) if filter_name.lower() == 'closed': return closed_channels(rpc) if filter_name.lower() == 'incoming': return incoming_channels(rpc) if filter_name.lower() == 'outgoing': return outgoing_channels(rpc) if filter_name.lower() == 'nochannel': return peers_no_channel(rpc) if filter_name.lower() == 'greater_than': amt = Amount(amount, unit) return channels_greater_than(rpc, amt) if filter_name.lower() == 'less_than': amt = Amount(amount, unit) return channels_less_than(rpc, amt)
def total_payments_no_fees(rpc): return Amount(sum((p['msatoshi'] for p in complete_payments(rpc))), 'msat')
def routing_fees_paid(rpc): return Amount( sum((p['msatoshi_sent'] - p['msatoshi'] for p in complete_payments(rpc))), 'msat')
def active_balance(rpc): return Amount(sum((p['channels'][0]['msatoshi_to_us'] for p in active_channels(rpc))), 'msat')
def reserve_balance(rpc): return Amount(sum((p['channels'][0]['our_channel_reserve_satoshis'] for p in active_channels(rpc))), 'msat')
def funded_incoming_balance(rpc): return Amount(sum((p['channels'][0]['msatoshi_total'] for p in incoming_channels(rpc))), 'msat')
def closed_incoming_balance(rpc): return Amount(sum((p['channels'][0]['msatoshi_total'] - p['channels'][0]['msatoshi_to_us'] for p in closed_channels(rpc))), 'msat')
def pending_balance(rpc): return Amount(sum((p['channels'][0]['msatoshi_to_us'] for p in pending_channels(rpc))), 'msat')
def channels_less_than(rpc, amount): assert type(amount) is Amount return [ p for p in rpc.listpeers()['peers'] if p['channels'] and Amount(p['channels'][0]['msatoshi_total'], 'msat') <= amount ]
def get_node_capacity(rpc, node_id): return Amount( sum((c['satoshis'] for c in rpc.listchannels()['channels'] if c['source'] == node_id)), 'sat')
def onchain_unconfirmed_balance(rpc): return Amount( sum((int(x["value"]) for x in rpc.listfunds()["outputs"] if x["status"] == "unconfirmed")), 'sat')
def onchain_balance(rpc): return Amount(sum((int(x["value"]) for x in rpc.listfunds()["outputs"])), 'sat')
from collections import defaultdict from lib.amount import Amount # Default max channel size (for now) WUMBO = Amount(16777216, 'sat') # Get own node id def nodeid(rpc): return rpc.getinfo()['id'] # Get total onchain funds including unconfirmed def onchain_balance(rpc): return Amount(sum((int(x["value"]) for x in rpc.listfunds()["outputs"])), 'sat') # Get total unconfirmed onchain funds def onchain_confirmed_balance(rpc): return Amount( sum((int(x["value"]) for x in rpc.listfunds()["outputs"] if x["status"] == "confirmed")), 'sat') # Get total confirmed onchain funds def onchain_unconfirmed_balance(rpc): return Amount( sum((int(x["value"]) for x in rpc.listfunds()["outputs"] if x["status"] == "unconfirmed")), 'sat')