BlueWallet / LndHub

Wrapper for Lightning Network Daemon. It provides separate accounts for end-users
http://LndHub.io
MIT License
793 stars 198 forks source link

Request: Method to give existing channel funds to arbitrary account. #192

Open junderw opened 3 years ago

junderw commented 3 years ago

Explanation:

  1. On LND, I have X channels open with local balances of A, B, C.
  2. I install LNDHub, create a wallet.
  3. My wallet balance is 0 and the only way I can get balance on it is by "charging it" via BlueWallet on-chain, or receiving an LN payment.
  4. LND won't let me pay an invoice created by itself, so the only method is on-chain "charging" which is a waste, since I already have A + B + C total LN balance available to me.

Request:

  1. On first boot of LNDHub from fresh slate, create a default user with a balance of 100% of all channels local balance at the time of first boot.
  2. This user's backup can be shown for users to "load" the account into their BlueWallet.
  3. The default user ID and the default user initial balance are persisted, and used to calculate the "true" balance of the default user moving forward. (so calculateBalance would add an if statement for if U.isDefaultUser() to add the instance's default user initial balance.)

Some issues that might pop up:

How to keep the backup of that user secure? I would guess showing it only once is fine but tbh if you have access to the box with lndhub you can mess with redis and also probably swipe the admin macaroon anyways... but for umbrel if you just put it on the landing page anyone with port access to the umbrel (anyone on my local network) can see the backup if you put it on the landing page... so it'll be difficult...

Maybe the first time the default user actually loads the backup, it changes things up so that the second person who tried to load that default user backup will always fail, and the first person is given a new backup for the default user. (rotate creds on first load?)

Overtorment commented 3 years ago

i talked to umbrel guys, and the simplest solution might be: adding "admin" account credentials straight to config.js during install.

the balance would not be awarded to it, instead, balance for this account would be simply current channelBalance, so admin user could spend all his channel coins anytime he wants.

what do you think?

junderw commented 3 years ago

As long as the admin credentials are randomly generated on install that sounds fine. If it's the same credentials for everyone, then all I need is your onion URL to access your admin account.

pinheadmz commented 3 years ago

Joining this issue, I also am interested in this feature. I may just modify lndhub /getbalance to return lnd channelbalance since I am the only user of this hub (created my wallet then disabled /create)

lndhub-admin commented 3 years ago

maybe the new Admin Extension could have a component that makes a Admin wallet or where Admin can fund any account wallet.

the "LND won't let me pay an invoice created by itself," is to make a payinvoice --allow_self_payment call to LND that the Admin Extension component could do.

se :

https://github.com/BlueWallet/LndHub/issues/196

https://github.com/BlueWallet/LndHub/pull/239

lndhub-admin commented 3 years ago

Screenshot 2021-06-28 at 10 57 16

lndhub-admin commented 3 years ago

https://github.com/lndhub-admin/LndHub-Admin-Extension

xraid commented 3 years ago

I am contemplating creating a GRANT component using the LndHub-Admin toolbox.

A component screen-card where accounts in system is showing in a table and where one can specify amount units and send.

The send is from LndHub operator = admins LND wallet funds.

When chosen a account(user) and specify amount click send after filling in the adminPin, the component will create a invoice from account(user) credentials and then that amount gets Granted to account(user) in the LndHub Ledger.

Would the above suffice as functionality for case mentioned in this Request issue ?

lndhub-admin commented 3 years ago

aha ... this triggered a associating problem of accounts being unnamed on the LndHub side I now know howto get accounts named from a BlueWallet connected to a LndHub Admin enabled LND. This without touching BlueWallet repo as a start and proof of concept, whereby later if find tasty there could be a formalized add in BlueWallet also enabling and securing a sync of wallet account card "named" and its representation in LndHub ...

junderw commented 3 years ago

Any progress on this?

xraid commented 3 years ago

i started some work on it but left it for more prioritized projects :

this way DB would be correctly intact and new balance would show up in account invoice was created for.

or meanwhile unless somebody wants a UI for the functionality use a payment over network as hinted here : https://github.com/BlueWallet/LndHub/issues/295#issuecomment-924058937

xraid commented 3 years ago

if interested in hints coding it, further discussions can be had here : https://t.me/joinchat/L31KXn9TlDNmMTY0

jblachly commented 2 years ago

Very much interested in this.

Use case / user story:

I have an LND node with, say, 1M sats. My child wants to be paid an allowance in sats, so I agree to transfer 10,000 sats monthly. Because we want to remain non-custodial, Bluewallet thru LNDHub makes sense. (Wallet of Satoshi, custodial; Phoenix and Muun non-custodial, but require new channels that will eat up huge fees).

LNDHub itself handles accounting just fine when the to/from are on the same node.

However, I have no way -- other than using on-chain activity or transfer out to a different Lightning Wallet then back in -- to fund an initial BlueWallet balance for myself.

What would be ideal is a command line admin tool to "instantiate" a balance, not greater than the sum of all un-allocated (in LNDHub's view) local channel funds, in an arbitrary LNDHub account.

I looked directly at the Redis keyspace to see if this were possible, but it appears not: Balance is computed directly from past lightning transactions.

Question 1: Is it possible to "synthesize" transactions to make this happen?

Question 2: The LNDHub schema documentation [1] describes a key, balance_for_{userid} = {int} but this does not appear in my Redis keyspace. Does this refer to on-chain balance? (I haven't made any on-chain transactions) (Found in the code -- this key is deprecated and balance is computed directly: https://github.com/BlueWallet/LndHub/blob/7f9463bbbcbfa7bdba9726d472dd6de29a877ecb/class/User.js#L134-L136 )

[1] https://github.com/BlueWallet/LndHub/blob/master/doc/schema.md

xraid commented 2 years ago

one can imagine a script that help in paying a invoice generated on account holders behalf or for edutainment let account holder create invoice in wallet, script would payout to invoice ...

same would go for case where one make invoice in wallet and pay oneself from LND and then pay invoice to other account

what script would do is either just pay a invoice from LND or generate invoice and pay in one swoop ...


easiest for Your case is create a account in BlueWallet and then a invoice

in terminal at node

lncli sendpayment --pay_req "invoice" --allow_self_payment

from this account distribute further ...