Example #1
0
 def get_routes(self, pub_key, amount, num_routes):
     request = ln.QueryRoutesRequest(
         pub_key=pub_key,
         amt=amount,
         num_routes=num_routes,
     )
     response = self.stub.QueryRoutes(request)
     return response.routes
Example #2
0
 def check_route(self, node_id, amount):
     try:
         req = lnrpc.QueryRoutesRequest(pub_key=node_id, amt=int(amount/1000), num_routes=1)
         r = self.rpc.stub.QueryRoutes(req)
     except grpc._channel._Rendezvous as e:
         if (str(e).find("unable to find a path to destination") > 0):
             return False
         raise
     return True
Example #3
0
 def get_route(self, pub_key, amount, ignored_edges):
     request = ln.QueryRoutesRequest(
         pub_key=pub_key,
         amt=amount,
         ignored_edges=ignored_edges,
     )
     try:
         response = self.stub.QueryRoutes(request)
         return response.routes
     except:
         return None
Example #4
0
for chan in response.channels:
    request = ln.NodeInfoRequest(pub_key=chan.remote_pubkey)
    r = stub.GetNodeInfo(request, metadata=[('macaroon', macaroon)])
    chan_partner_alias = r.node.alias
    print("%s\t%s\t%f" % (chan_partner_alias, chan.remote_pubkey,
                          (chan.local_balance /
                           (chan.local_balance + chan.remote_balance))))

request = ln.InvoiceSubscription(
    add_index=0,
    settle_index=0,
)
# Query routes for one direction
request = ln.QueryRoutesRequest(
    pub_key=
    "027ce055380348d7812d2ae7745701c9f93e70c1adeb2657f053f91df4f2843c71",
    amt=300000,
    num_routes=5,
)
response = stub.QueryRoutes(request, metadata=[('macaroon', macaroon)])
print(response)
topartner = response.routes

request = ln.GetInfoRequest()
response = stub.GetInfo(request, metadata=[('macaroon', macaroon)])
print(response)
mypub = response.identity_pubkey

request = ln.QueryRoutesRequest(
    pub_key=mypub,
    amt=300000,
    num_routes=5,
def main():

    #get currently connected channels (additional information)
    request_channels = ln.ListChannelsRequest(
        active_only=False,
        inactive_only=False,
        public_only=False,
        private_only=False,
    )
    response_channels = stub.ListChannels(request_channels)

    request_graph = ln.ChannelGraphRequest(include_unannounced=False)

    response_graph = stub.DescribeGraph(request_graph)
    #print(response)

    dict_pubkey_chancount = {}
    current_node_pub_key = getCurrentNodePubKey()

    for edge in response_graph.edges:
        #print(edge)

        #check that capacity is above X
        if edge.capacity is not None and edge.capacity >= minCapacitySat:

            if areChannelFeesLow(edge.node1_policy):
                if (edge.node1_pub not in dict_pubkey_chancount):
                    dict_pubkey_chancount[edge.node1_pub] = 1
                else:
                    current_count = dict_pubkey_chancount.get(edge.node1_pub)
                    dict_pubkey_chancount[edge.node1_pub] = current_count + 1
                #print(edge.node1_pub)

            if areChannelFeesLow(edge.node2_policy):
                if (edge.node2_pub not in dict_pubkey_chancount):
                    dict_pubkey_chancount[edge.node2_pub] = 1
                else:
                    current_count = dict_pubkey_chancount.get(edge.node2_pub)
                    dict_pubkey_chancount[edge.node2_pub] = current_count + 1
                #print(edge.node2_pub)

    routesQueried = 0

    #print sorted by channel count (value)
    for chanCount in sorted(set(dict_pubkey_chancount.values()), reverse=True):
        if chanCount >= minChanCount:

            for pubkey, count in dict_pubkey_chancount.items():
                if (count == chanCount):

                    #get info about remote node
                    request_nodeinfo = ln.NodeInfoRequest(pub_key=pubkey, )
                    response_nodeinfo = stub.GetNodeInfo(request_nodeinfo)
                    node_alias = response_nodeinfo.node.alias

                    #check to see if we're connected
                    connected = False
                    for connectedChannel in response_channels.channels:
                        if (pubkey == connectedChannel.remote_pubkey):
                            connected = True

                    if (connected):
                        connectedText = '(connected)'
                    elif (current_node_pub_key == pubkey):
                        connectedText = '(self)'
                    else:
                        connectedText = ''

                    route_fee = 'n/a'
                    first_hop = 'n/a'
                    hop_count = 0
                    if (count >= minChanCountToCalcRoutes):
                        if (count <= maxChanCountToCalcRoutes):
                            #query route to node (might be computationally expensive)
                            request_route = ln.QueryRoutesRequest(
                                pub_key=pubkey,
                                amt=queryAmountSat,
                            )

                            if (routesQueried < maxRoutesToQuery):
                                routesQueried += 1
                                try:
                                    response_route = stub.QueryRoutes(
                                        request_route)

                                    route_fee = str(response_route.routes[0].
                                                    total_fees) + 'sat'

                                    first_hop = response_route.routes[0].hops[
                                        0].chan_id

                                    hop_count = len(
                                        response_route.routes[0].hops)

                                    time.sleep(pauseBetweenRouteQueriesSeconds)

                                except (KeyboardInterrupt, SystemExit):
                                    raise
                                except Exception as e:
                                    if (hasattr(e, 'details')):
                                        if ('unable to find a path to destination'
                                                in str(e.details)):
                                            route_fee = 'NO PATH!'
                                        else:
                                            route_fee = 'ERROR with details'
                                            print(e.details)
                                            print(str(e))
                                    else:
                                        route_fee = 'UNKNOWN ERROR'
                                        print(str(e))

                                #print(dir(response_route))

                            else:
                                route_fee = '(queries >)'
                        else:
                            route_fee = '(skip >)'
                    else:
                        route_fee = '(skip <)'

                    print(pubkey, ":", '%5s' % count, '%8s' % route_fee,
                          '%11s' % connectedText,
                          '%35s' % node_alias.encode('ascii', 'ignore'),
                          '%12s' % first_hop, '%2s' % hop_count)