synonymdev / react-native-ldk

React Native LDK
MIT License
51 stars 16 forks source link

Fund channels #30

Closed Jasonvdb closed 3 weeks ago

Jasonvdb commented 2 years ago

Right now this lib only allows for receiving channels from the other party (LSP). We should allow channels to be funded locally with a PSBT.

tanx commented 2 years ago

Right now this lib only allows for receiving channels from the other party (LSP). We should allow channels to be funded locally with a PSBT.

@Jasonvdb yes, I just came across this issue when I saw there seems to be no openChannel api. Is there example code that shows how to configure the library for LSP and is there an LSP instance available for testing? Thank you

Jasonvdb commented 2 years ago

I would say the easiest way to get up and running is spin up a local polar network and then run electrumx wired up to that bitcoin node in your network. It'll be much easier for development to have control of the mining.

Once that's setup update constants in the example app with your electrum server details and the LND node connection details that you can find in the polar UI here:

Screen Shot 2022-09-27 at 18 16 49

Then just use the polar terminal for your LND node to open up a channel with your LDK node in your simulator. Get the nodeID of your app tapping "Get info" in the example app. That copies the node ID to the clipboard.

lncli openchannel --node_key=028a088a9730a1e4358e4ff044784eaab1db334a93806b05ff2d4b84967b339cf8 --local_amt=100000 --push_amt=50000 --private=true

Mine a block or 2 with the "Quick Mine" button in Polar and you should be good to go.

We'll look at maybe setting up a open regtest network for this and then make it work out the box with the LSP. But for to get up and running now the above should be good. Ping me or Corey if you have any specific issues with the setup!

tanx commented 2 years ago

@Jasonvdb thanks! Polar is awesome... no idea why I haven't tried it until now. I can't seem to connect to the polar bitcoind rpc port from electrumx though. Opening http://127.0.0.1:18443 in my browser works. So the port is exposed to my host. I'm running the following cmd:

docker run -v /Users/user/electrumx:/data -e DAEMON_URL=http://polaruser:polarpass@127.0.0.1:18443 -e COIN=BitcoinSegwit -p 50001:50001 lukechilds/electrumx

I saw someone else had this issue. I'm not a docker expert myself. Any ideas?

Jasonvdb commented 2 years ago

Great yeah polar is super useful!

Are you getting the same error as in that issue? Or I see your command is missing -e NET=regtest so hopefully that's it?

tanx commented 2 years ago

Nope...

docker run -v /Users/tanx/electrumx:/data -e DAEMON_URL=http://polaruser:polarpass@127.0.0.1:18443 -e COIN=BitcoinSegwit -e NET=regtest -p 50001:50001 lukechilds/electrumx
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.9 (default, Dec 17 2020, 08:26:10)  [GCC 9.3.0]
INFO:Controller:software version: ElectrumX 1.16.0
INFO:Controller:aiorpcX version: 0.18.7
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: <uvloop.EventLoopPolicy object at 0xffff9af90910>
INFO:Controller:reorg limit is 8,000 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:18443/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...

Maybe I need to allow the docker container access to the bitcoind rpc port?

Jasonvdb commented 2 years ago

Ok I managed to replicate, not sure why but it starts working when I replace 127.0.0.1 with my actual network IP 🤷

Quick command I use to get the right IP ifconfig | grep "netmask" or just from network settings.

tanx commented 2 years ago

@Jasonvdb genius! Thanks that did it. Wierd that it doesn't see localhost. Anyhow it works now. LDK client is now connected to electrum :) 🙏