-
Notifications
You must be signed in to change notification settings - Fork 6
Driver documentation
Like the rider, the driver does most of his activities on nostr, though there are a few more parts where he interacts with the escrow to redeem his lightning voucher. The most important lines of driver.html (in this commit, used throughout) are on 184-309. These lines listen for ride requests (i.e. nostr posts of kind 60) and populates a div called request_listings with all ride requests that haven't expired yet. (Remember, ride requests, by default, have a 5 minute expiration time.) They also check for private messages (on lines 222-257). If they see a direct message from a rider they accepted, they decrypt the message and pass its contents to a function called decideMessageTypeAndNextSteps() which is defined on lines 1179-1136. If the message is of type "agree" (line 1183), that means the user agreed to let this driver take them to their destination. The following lines (1184-1193) get the rider's lightning voucher (except for the preimage) from the text of the rider's "agree" message and it checks if this voucher is pending on lightning escrow's website (using a function called provePendingOwnership() that is defined on lines 577-666). If the voucher is still pending, the following lines (1195-1220) tell the driver to go pick up the rider and they show him a link to the rider's location on google maps. Then (on line 1221) they fire off a function called sendLocation() (defined on lines 1280-1314) which uses nostr dms to tell the rider where the driver is located every 10 seconds. The sendLocation function also (on lines 1282-1299) checks a variable called "i-picked-up-my-rider" which says whether the driver is within 200 feet of the rider's location (this variable is set by the watchUsersPosition() function on lines 103-113). If the "i-picked-up-my-rider" variable is set to true, driver.html instructs the driver to take the rider to their destination and gives them the coordinates in a Google Maps link. (This logic is defined on lines 1282-1299.)
Another important thing that decideMessageTypeAndNextSteps() does is lines 1223-1235. These lines listen for a message from the rider containing the preimage the driver needs to settle their lightning voucher. If they get it they run a function called proveFullOwnership(). proveFullOwnership() is defined on lines 667-835 and it checks that the rider's preimage is the one they need, then (if that checks out) it gets an invoice from the user's node (see lines 795-801 -- these utilize a function called makeInvoice() which is defined on 1075-1176) using the preimage provided in the lightning voucher, then they pass that invoice to lightning escrow to ask them to pay it (see lines 806-829 -- these lines utilize a function called settleVoucher() which is defined on lines 962-990). The makeInvoice() function, btw, uses the driver's invoice macaroon to run a function called loopChecker() (defined on lines 1029-1062) which checks whether lightning escrow attempted to pay the driver's invoice. If it detects that they did make a payment attempt and the driver's node now has an invoice in an Accepted state, it runs a function called settleInvoice() (defined on lines 991-1028) which uses the preimage provided in the lightning voucher to settle the invoice that lightning escrow paid. This act delivers the preimage to lightning escrow, who then uses it to reimburse themselves with the rider's money.
Those are all of the important functions in driver.html