コード例 #1
0
class LightningDaemon(object):
    def __init__(self, daemon_rpc):
        self.rpc = LightningRpc(daemon_rpc)

    def invoice_c_lightning(self, msatoshi, label, description):
        expiry = INVOICE_EXPIRY + random.randint(3, 9)
        try:
            result = self.rpc.invoice(msatoshi, label, description,
                                      expiry=expiry)
            logging.info("invoicing daemon. got: %s" %
                         json.dumps(result, indent=1, sort_keys=True))
            return result
        except:
            return None

    def get_c_lightning_invoices(self):
        try:
            return self.rpc.listinvoices()
        except:
            return None
        #logging.info(json.dumps(result, indent=1, sort_keys=True))

    def _delete(self, label, state="paid"):
        try:
            result = self.rpc.delinvoice(label, state)
            return result
        except IOError:
            # unpaid could have expired in the last split second due
            # to a race, so try again
            if state == "unpaid":
                result = self.rpc.delinvoice(label, "expired")
        return result

    def delete(self, label, state="paid"):
        try:
            return self._delete(label, state=state)
        except:
            return None

    def getinfo(self):
        try:
            return self.rpc.getinfo()
        except:
            return None

    def listfunds(self):
        try:
            return self.rpc.listfunds()
        except:
            return None

    def listnodes(self):
        try:
            return self.rpc.listnodes()
        except:
            return None
コード例 #2
0
def main(connect, fund):
    rpc = LightningRpc("/home/bits/.lightning/testnet/lightning-rpc")
    channels = rpc.listchannels()['channels']
    nodes = rpc.listnodes()['nodes']

    pruned = prune_nodes(nodes)
    node_map = build_node_map(pruned)
    merge_channels(node_map, channels)
    eligible = get_eligible(node_map, 2)

    if connect:
        connected = connect_to(rpc, eligible)
        print("connected to {} of {} eligible nodes".format(connected, len(eligible)))

    if fund:
        fund_connected(rpc)