Skip to content

Instantly share code, notes, and snippets.

@vindard
Last active August 8, 2021 04:29
Show Gist options
  • Save vindard/8f3f5e0020bdf4d486c04b76e741bd18 to your computer and use it in GitHub Desktop.
Save vindard/8f3f5e0020bdf4d486c04b76e741bd18 to your computer and use it in GitHub Desktop.
Galoy: Notes on the new well-typed code style we'd like to move to

Personal notes for Lightning Service PR

(link: GaloyMoney/blink#426)

domain: primitives

  • added 'Satoshis' and 'TxDenominationCurrency' primitives
  • added value object for 'Satoshis'

domain: expiration

  • moved 'delay' business logic to 'invoice-expiration' domain
  • moved 'getExpiration' logic to 'invoice-expiration' domain
    • added 'InvoiceExpiration' type
  • moved 'getExpiration' call to direct argument of new 'registerInvoice' wrapper

domain: utils

  • added 'toTypedError' and 'unsafeThrowErrAsync' wrapper functions and return type declarations

Inputs for createInvoice

  1. lnd
  • domain: LightningService Created a new 'LightningService' interface with 'registerInvoice' wrapper that returns a 'safe' wrapper around the results of calling 'lightningPayReq.decode'

    • created 'RegisterInvoiceArgs'

    • created a new 'RegisteredInvoice' type (result of calling 'createInvoice' + some wrapping logic)

    • created a 'LightningServiceErrorType' error type

    • domain: LN invoice

      • created new 'decodeInvoice' method to handle results of 'createInvoice' in wrapper Note: it take the request argument (called 'bolt11EncodedInvoice') and adds it right back to the 'paymentRequest' property of the result as a value object to be later accessed at 'lnInvoice.paymentRequest.inner'

      • created new 'EncodedPaymentRequest, PaymentHash, PaymentSecret' types and error types to feed into new 'LNInvoice' type

  • service: LightningService Created a new 'MakeLndService' to wrap the 'lnd' object and return a 'LightningService' Note: internally, the service passes the 'lnd' object to 'createInvoice' still

  1. token
  • Now converted to 'Satoshis' type via 'toSats' method
  1. expires_at
  • Now gotten from the 'invoiceExpirationForCurrency' method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment