예제 #1
0
    def node_received_payment_cb(self, preimage, msats):
        received_wad = Wad.bitcoin(msats)
        logging.info("node received payment: %s %s" % (preimage, received_wad))

        payment_hash = Bolt11.preimage_to_payment_hash(preimage)
        # find accounts with this payment_hash
        accounts = self.directory.lookup_by_payment_hash(payment_hash)

        if len(accounts) > 1:
            logging.error("can't deal with more than one account with "
                          "a preimage collision yet")
            # TODO deal with this somehow - feed preimage back into lightning
            # node to claim any pending htlcs?
            return

        if len(accounts) == 0:
            logging.error("incoming payment not known")
            return

        account = list(accounts)[0]
        shared_seeds = account.get_all_shared_seeds()
        account.remove_pending(payment_hash)
        account.add_wad(received_wad)
        self.provider_stack.notify_preimage(shared_seeds, preimage, None)
        for ss in shared_seeds:
            account.session_preimage_notified(ss, preimage, True, msats)
예제 #2
0
파일: app.py 프로젝트: moneysocket/stabled
    def _handle_paying_preimage(self, nexus, preimage, request_reference_uuid):
        payment_hash = Bolt11.preimage_to_payment_hash(preimage)
        logging.info("preimage %s payment_hash %s" % (preimage, payment_hash))

        liability_accounts = list(
            self.liabilities.lookup_by_paying_payment_hash(payment_hash))
        assert len(liability_accounts) <= 1, "can't handle collision yet"
        if len(liability_accounts) == 0:
            logging.error("got preimage not associated to liability?")
            return
        liability_account = liability_accounts[0]

        shared_seeds = liability_account.get_all_shared_seeds()

        msats_sent = [
            Bolt11.get_msats(bolt11)
            for ph, bolt11 in liability_account.iter_paying()
            if ph == payment_hash
        ][0]
        liability_account.remove_paying(payment_hash)
        liability_account.subtract_wad(Wad.bitcoin(msats_sent))
        self.liabilities.reindex_account(liability_account)

        if request_reference_uuid in self.pay_requests:
            info = self.pay_requests.pop(request_reference_uuid)
            rrid = info['liability_request_uuid']
        else:
            rrid = None

        self.provider_stack.notify_preimage(shared_seeds, preimage, rrid)