Exemple #1
0
    def handle_invoice_request(self, nexus, msats, request_uuid):
        shared_seed = nexus.get_shared_seed()
        account = self.directory.lookup_by_seed(shared_seed)
        assert account is not None, "shared seed not from known account?"
        shared_seeds = account.get_all_shared_seeds()
        account.session_invoice_requested(shared_seed, msats)

        wad = account.get_wad()
        cap = account.get_cap()
        if cap['msats'] != 0 and (msats + wad['msats'] > cap['msats']):
            # TODO 0 track pending incoming?
            err = "account cap exceeded"
            account.session_error_notified(shared_seed, err)
            self.provider_error(shared_seeds, err, request_uuid)
            return

        bolt11, err = self.lightning.get_invoice(msats)
        if err:
            account.session_error_notified(shared_seed, err)
            self.provider_error(shared_seeds, err, request_uuid)
            return

        payment_hash = Bolt11.get_payment_hash(bolt11)
        account.add_pending(payment_hash, bolt11)
        for ss in shared_seeds:
            account.session_invoice_notified(shared_seed, bolt11)
        self.directory.reindex_account(account)
        self.provider_stack.notify_invoice(shared_seeds, bolt11, request_uuid)
Exemple #2
0
 def consumer_on_error(self, nexus, error_msg, request_reference_uuid):
     print("got error: %s" % error_msg)
     if request_reference_uuid in self.invoice_requests.keys():
         r = self.invoice_requests.pop(request_reference_uuid)
         account_uuid = r['liability_account_uuid']
         liability_account = self.liabilities.lookup_by_uuid(account_uuid)
         shared_seeds = liability_account.get_all_shared_seeds()
         liability_rrid = r['liability_request_uuid']
         self.provider_stack.notify_error(shared_seeds, error_msg,
                                          liability_rrid)
         print("notified provider of invoice error: %s" % error_msg)
     elif request_reference_uuid in self.pay_requests.keys():
         r = self.pay_requests.pop(request_reference_uuid)
         account_uuid = r['liability_account_uuid']
         liability_account = self.liabilities.lookup_by_uuid(account_uuid)
         shared_seeds = liability_account.get_all_shared_seeds()
         liability_rrid = r['liability_request_uuid']
         self.provider_stack.notify_error(shared_seeds, error_msg,
                                          liability_rrid)
         bolt11 = r['bolt11']
         payment_hash = Bolt11.get_payment_hash(bolt11)
         liability.account.remove_paying(payment_hash)
         print("notified provider of pay error: %s" % error_msg)
     else:
         print("unknown error notification: %s" % error_msg)
Exemple #3
0
    def provider_handle_pay_request(self, nexus, bolt11, request_uuid):
        msats = Bolt11.get_msats(bolt11)
        if not msats:
            return "no amount specified in bolt11"
        payment_hash = Bolt11.get_payment_hash(bolt11)
        shared_seed = nexus.get_shared_seed()
        liability_account = self.liabilities.lookup_by_seed(shared_seed)
        spendable_msats = (liability_account.get_msatoshis() -
                           liability_account.get_pending_msatoshis())
        if msats > spendable_msats:
            return "insufficent balance to pay"

        # decide which of our asset accounts will pay the bolt11
        asset_nexus_uuid = self.asset_pool.select_paying_nexus_uuid(msats)
        if not asset_nexus_uuid:
            return "no account capable of receiving"

        liability_account.add_paying(payment_hash, bolt11)
        self.liabilities.reindex_account(liability_account)

        our_request_uuid = self.consumer_stack.request_pay(
            asset_nexus_uuid, bolt11)
        self.pay_requests[our_request_uuid] = {
            'liability_nexus_uuid': nexus.uuid,
            'liability_request_uuid': request_uuid,
            'liability_account_uuid': liability_account.uuid,
            'bolt11': bolt11,
            'asset_nexus_uuid': asset_nexus_uuid
        }
Exemple #4
0
    def terminus_handle_invoice_request(self, shared_seed, msats):
        # TODO - this should be a request-> callback to allow for an
        # asynchronous call to the daemon.

        account = self.directory.lookup_by_seed(shared_seed)
        assert account is not None, "shared seed not from known account?"

        # TODO handle failure
        bolt11 = self.lightning.get_invoice(msats)
        payment_hash = Bolt11.get_payment_hash(bolt11)
        account.add_pending(payment_hash, bolt11)
        self.directory.reindex_account(account)
        return {'bolt11': bolt11}
Exemple #5
0
    def consumer_on_invoice(self, nexus, bolt11, request_reference_uuid):
        if request_reference_uuid not in self.invoice_requests:
            logging.error("got bolt11 not requested? %s" %
                          request_reference_uuid)
            return

        request_info = self.invoice_requests.pop(request_reference_uuid)

        liability_nexus_uuid = request_info['liability_nexus_uuid']
        liability_request_uuid = request_info['liability_request_uuid']
        liability_account_uuid = request_info['liability_account_uuid']
        asset_nexus_uuid = request_info['asset_nexus_uuid']
        msats_requested = request_info['msats_requested']

        liability_account = self.liabilities.lookup_by_uuid(
            liability_account_uuid)

        if asset_nexus_uuid != nexus.uuid:
            logging.info("got bolt11 from different nexus than requested?")

        if not liability_account:
            logging.error("liability account removed?")
            return

        bolt11_msats = Bolt11.get_msats(bolt11)
        if bolt11_msats and bolt11_msats != msats_requested:
            logging.error("got wrong msats amount?")
            return

        bolt11_payment_hash = Bolt11.get_payment_hash(bolt11)
        liability_account.add_pending(bolt11_payment_hash, bolt11)
        self.liabilities.reindex_account(liability_account)

        shared_seeds = liability_account.get_all_shared_seeds()

        self.provider_stack.notify_invoice(shared_seeds, bolt11,
                                           liability_request_uuid)