Skip to content

Commit

Permalink
Read bitcoin core wallet name from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
araspitzu committed Mar 3, 2020
1 parent 411fb84 commit 44e009e
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ You will find detailed guides and frequently asked questions there.
:warning: Eclair requires Bitcoin Core 0.17.1 or higher. If you are upgrading an existing wallet, you need to create a new address and send all your funds to that address.

Eclair needs a _synchronized_, _segwit-ready_, **_zeromq-enabled_**, _wallet-enabled_, _non-pruning_, _tx-indexing_ [Bitcoin Core](https://github.com/bitcoin/bitcoin) node.
Eclair will use the default unnamed wallet in Bitcoin Core, you can have more than one wallet but make sure there is always the default wallet available.
Any BTC found in the wallet can be used to fund the channels you choose to open and the BTC from closed channels will return to this wallet.
You can configure your Bitcoin Node to use either `p2sh-segwit` addresses or `bech32` addresses, Eclair is compatible with both modes.
Eclair will use the default unnamed wallet in Bitcoin Core, if you want it to use a different wallet adjust the configuration `eclair.bitcoind.walletname` to use yours, please
refer to the configuration section below for more information. Any BTC found in the wallet can be used to fund the channels you choose to open and the BTC from closed channels will return
to this wallet. You can configure your Bitcoin Node to use either `p2sh-segwit` addresses or `bech32` addresses, Eclair is compatible with both modes.
If your Bitcoin Core wallet has "non-segwit UTXOs" (outputs that are neither `p2sh-segwit` or `bech32`), you must send them to a `p2sh-segwit` or `bech32` address.

Run bitcoind with the following minimal `bitcoin.conf`:
Expand Down Expand Up @@ -111,6 +111,7 @@ name | description
eclair.api.password | API password (BASIC) | "" (must be set if the API is enabled)
eclair.bitcoind.rpcuser | Bitcoin Core RPC user | foo
eclair.bitcoind.rpcpassword | Bitcoin Core RPC password | bar
eclair.bitcoind.walletname | Bitcoin Core wallet name | ""
eclair.bitcoind.zmqblock | Bitcoin Core ZMQ block address | "tcp://127.0.0.1:29000"
eclair.bitcoind.zmqtx | Bitcoin Core ZMQ tx address | "tcp://127.0.0.1:29000"
eclair.gui.unit | Unit in which amounts are displayed (possible values: msat, sat, bits, mbtc, btc) | btc
Expand Down
1 change: 1 addition & 0 deletions eclair-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ eclair {
rpcport = 8332
rpcuser = "foo"
rpcpassword = "bar"
walletname = ""
zmqblock = "tcp://127.0.0.1:29000"
zmqtx = "tcp://127.0.0.1:29000"
}
Expand Down
3 changes: 2 additions & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Setup(datadir: File,
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))
implicit val timeout = Timeout(30 seconds)
Expand Down Expand Up @@ -380,7 +381,7 @@ case object BitcoinZMQConnectionTimeoutException extends RuntimeException("could

case object BitcoinRPCConnectionException extends RuntimeException("could not connect to bitcoind using json-rpc")

case object BitcoinWalletDisabledException extends RuntimeException("bitcoind must have wallet support enabled")
case object BitcoinWalletDisabledException extends RuntimeException("wrong wallet name or wallet disabled")

case object EmptyAPIPasswordException extends RuntimeException("must set a password for the json-rpc api")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.json4s.jackson.Serialization

import scala.concurrent.{ExecutionContext, Future}

class BasicBitcoinJsonRPCClient(user: String, password: String, host: String = "127.0.0.1", port: Int = 8332, ssl: Boolean = false)(implicit http: SttpBackend[Future, Nothing]) extends BitcoinJsonRPCClient {
class BasicBitcoinJsonRPCClient(user: String, password: String, walletName: String, host: String = "127.0.0.1", port: Int = 8332, ssl: Boolean = false)(implicit http: SttpBackend[Future, Nothing]) extends BitcoinJsonRPCClient {

val scheme = if (ssl) "https" else "http"
implicit val formats = DefaultFormats.withBigDecimal
Expand All @@ -43,7 +43,7 @@ class BasicBitcoinJsonRPCClient(user: String, password: String, host: String = "
KamonExt.timeFuture("bitcoin.rpc.basic.invoke.time") {
for {
res <- sttp
.post(uri"$scheme://$host:$port/wallet/") // wallet/ specifies to use the default bitcoind wallet, named ""
.post(uri"$scheme://$host:$port/wallet/$walletName")
.body(requests)
.auth.basic(user, password)
.response(asJson[Seq[JsonRPCResponse]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import scala.concurrent.{ExecutionContext, Future}
/**
* Created by PM on 26/04/2016.
*/
class TestBitcoinClient()(implicit system: ActorSystem) extends ExtendedBitcoinClient(new BasicBitcoinJsonRPCClient("", "", "", 0)(http = null)) {
class TestBitcoinClient()(implicit system: ActorSystem) extends ExtendedBitcoinClient(new BasicBitcoinJsonRPCClient("", "", "", "", 0)(http = null)) {

import scala.concurrent.ExecutionContext.Implicits.global

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport")) {

Expand Down Expand Up @@ -105,6 +106,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))
val wallet = new BitcoinCoreWallet(bitcoinClient)
Expand Down Expand Up @@ -138,6 +140,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))
val wallet = new BitcoinCoreWallet(bitcoinClient)
Expand Down Expand Up @@ -198,6 +201,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))
val wallet = new BitcoinCoreWallet(bitcoinClient)
Expand Down Expand Up @@ -239,6 +243,7 @@ class BitcoinCoreWalletSpec extends TestKit(ActorSystem("test")) with BitcoindSe
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))
val wallet = new BitcoinCoreWallet(bitcoinClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ trait BitcoindService extends Logging {
}

bitcoind = s"$PATH_BITCOIND -datadir=$PATH_BITCOIND_DATADIR".run()
bitcoinrpcclient = new BasicBitcoinJsonRPCClient(user = "foo", password = "bar", host = "localhost", port = bitcoindRpcPort)
bitcoinrpcclient = new BasicBitcoinJsonRPCClient(user = "foo", password = "bar", walletName = "", host = "localhost", port = bitcoindRpcPort)
bitcoincli = system.actorOf(Props(new Actor {
override def receive: Receive = {
case BitcoinReq(method) => bitcoinrpcclient.invoke(method) pipeTo sender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ExtendedBitcoinClientSpec extends TestKit(ActorSystem("test")) with Bitcoi
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class BitcoinCoreFeeProviderSpec extends TestKit(ActorSystem("test")) with Bitco
val bitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport"))

Expand Down Expand Up @@ -115,6 +116,7 @@ class BitcoinCoreFeeProviderSpec extends TestKit(ActorSystem("test")) with Bitco
val mockBitcoinClient = new BasicBitcoinJsonRPCClient(
user = config.getString("bitcoind.rpcuser"),
password = config.getString("bitcoind.rpcpassword"),
walletName = config.getString("bitcoind.walletname"),
host = config.getString("bitcoind.host"),
port = config.getInt("bitcoind.rpcport")) {
override def invoke(method: String, params: Any*)(implicit ec: ExecutionContext): Future[JValue] = method match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AnnouncementsBatchValidationSpec extends FunSuite {

implicit val system = ActorSystem("test")
implicit val sttpBackend = OkHttpFutureBackend()
implicit val extendedBitcoinClient = new ExtendedBitcoinClient(new BasicBitcoinJsonRPCClient(user = "foo", password = "bar", host = "localhost", port = 18332))
implicit val extendedBitcoinClient = new ExtendedBitcoinClient(new BasicBitcoinJsonRPCClient(user = "foo", password = "bar", walletName = "", host = "localhost", port = 18332))

val channels = for (i <- 0 until 50) yield {
// let's generate a block every 10 txs so that we can compute short ids
Expand Down

0 comments on commit 44e009e

Please sign in to comment.