lncm / ideas

Ideas for things to be built on meetups.
MIT License
21 stars 4 forks source link

LN invoice generating service #5

Closed meeDamian closed 6 years ago

meeDamian commented 6 years ago

Create a simple service that uses underlying LN node to expose a simple basic-authenticated REST(?) API generating invoices for specified amounts and descriptions and informs about invoice status change (unpaid -> paid|cancelled|expired).

Ideally done as a part of #1, but can also be delayed for the next meetup, if doing it this way would delay things.

copied from notepad:

Desc: Somewhat related and complementing idea #1 - the service would run on Raspberry Pi, have basic authentication, ufw, fail2ban, and would generate invoices upon request. Can be used on personal website as a donation link, can be used by projects like satoshis.place to separate payment machine from code-running machine, can be run as a simple merchant PoS payment integration. Can be used as a vending machine backend, etc, etc

Needed: RBP running a LN node, internet connection and either public IP or Tor hidden service.

nolim1t commented 6 years ago

This is a cool project. I've done some stuff around this before.

meeDamian commented 6 years ago

So current plan:

  1. drop-in binary a. to be run on the same user as LN node b. binary figures out if it's lnd, c-lightning or eclair(?) c. attempts communication & some other checks (avail. capacity?)

  2. Exposes <port-number-to-be-chosen> a. ufw rule needed b. add to uPnP port forwarding script c. Tor Hidden Service(?)

  3. Performs Basic Authentication (w/credentials generated on the 1st run) a. fail2ban integration here would be nice, so that abusers are cut short…

  4. Exposes 3 endpoints:

/invoice endpoint

GET /invoice?amount=<amt-in-satoshis>&desc=<invoice-description>&expire=<seconds>

Takes amount, desc and expire only - all are optional. Default expiry time is 3 minutes. Returns:


{
    "error": "error message, if any",
    "invoice": "bolt11 invoice, if no error",
    "hash": "payment_hash, if no error"
}

/status endpoint

GET /status/<hash>

Takes hash (as returned by /invoice endpoint), does long-polling(?) and terminates only when invoice expires or is paid with either:

"expired"
"paid"
"err: <err-description>"

All stings are quoted to be JSON-valid.

/connstrings endpoint

GET /connstrings

Takes no arguments and returns an array of connstrings, ex:

[
    "032260c3b64b471b7eb0630b4af5d07ca94ff4e759573cbbe1bfb25845c375ed6e@203.150.176.118:9735",
    "032260c3b64b471b7eb0630b4af5d07ca94ff4e759573cbbe1bfb25845c375ed6e@o3s5j4j37nbyzgvbngn3ahpmttvviyensw34klhqzw7in7vfzz646lqd.onion:9735"
]
nolim1t commented 6 years ago

are we going to use satoshis for amount in our invoice endpoint?

AnotherDroog commented 6 years ago

Probably needs to be clearer:

Amount =

meeDamian commented 6 years ago

Using satoshis as int of float?

If int, do we ignore milisats?

If float, why not just use a much more common BTC where both sats and milisats are seamlessly handled?

nolim1t commented 6 years ago

float and millisats (because more "future proof") and is directly supported by the protocol so no conversion.

future proof

AnotherDroog commented 6 years ago

I’ve got my python code to the point where I can start developing against a live API.

Can you share something?

meeDamian commented 6 years ago

I should have stuff ready later today or tomorrow.

meeDamian commented 6 years ago

I edited the description above:

cc. @AnotherDroog

TODO: move above description to lncm/invoicer/README.md

meeDamian commented 6 years ago

Also, with the creation of https://github.com/lncm/invoicer repo, all related issues should go there, and this one gets closed.