diff --git a/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala b/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala index 9d8ff0c507..91cd1ac13d 100644 --- a/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala +++ b/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala @@ -1,8 +1,5 @@ package org.bitcoins.cli -import java.io.File -import java.nio.file.Path -import java.time.Instant import org.bitcoins.cli.CliCommand._ import org.bitcoins.cli.CliReaders._ import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.LockUnspentOutputParameter @@ -36,6 +33,9 @@ import scopt.OParser import ujson._ import upickle.{default => up} +import java.io.File +import java.nio.file.Path +import java.time.Instant import scala.collection.mutable import scala.util.{Failure, Success, Try} @@ -54,7 +54,7 @@ object ConsoleCli { .action((_, conf) => conf.copy(debug = true)) .text("Print debugging information"), opt[Int]("rpcport") - .action((port, conf) => conf.copy(rpcPort = port)) + .action((port, conf) => conf.copy(rpcPortOpt = Some(port))) .text(s"The port to send our rpc request to on the server"), opt[Unit]("version") .action((_, conf) => conf.copy(command = GetVersion)) @@ -1629,27 +1629,47 @@ case class Config( command: CliCommand = CliCommand.NoCommand, network: Option[NetworkParameters] = None, debug: Boolean = false, - rpcPort: Int = 9999 -) + rpcPortOpt: Option[Int] = None) { + + val rpcPort: Int = rpcPortOpt match { + case Some(port) => port + case None => command.defaultPort + } +} object Config { val empty: Config = Config() } -sealed abstract class CliCommand +sealed abstract class CliCommand { + def defaultPort: Int +} object CliCommand { - case object NoCommand extends CliCommand + + case object NoCommand extends CliCommand { + override def defaultPort: Int = 9999 + } trait Broadcastable { def noBroadcast: Boolean } - sealed trait ServerlessCliCommand extends CliCommand + sealed trait ServerlessCliCommand extends CliCommand { + override def defaultPort: Int = 9999 + } + + sealed trait AppServerCliCommand extends CliCommand { + override def defaultPort: Int = 9999 + } + + sealed trait OracleServerCliCommand extends CliCommand { + override def defaultPort: Int = 9998 + } case object GetVersion extends ServerlessCliCommand - case object GetInfo extends CliCommand + case object GetInfo extends AppServerCliCommand // DLC case class CreateDLCOffer( @@ -1658,45 +1678,46 @@ object CliCommand { feeRateOpt: Option[SatoshisPerVirtualByte], locktime: UInt32, refundLT: UInt32) - extends CliCommand + extends AppServerCliCommand - sealed trait AcceptDLCCliCommand extends CliCommand + sealed trait AcceptDLCCliCommand extends AppServerCliCommand case class AcceptDLCOffer(offer: LnMessage[DLCOfferTLV]) extends AcceptDLCCliCommand case class AcceptDLCOfferFromFile(path: Path) extends AcceptDLCCliCommand - sealed trait SignDLCCliCommand extends CliCommand + sealed trait SignDLCCliCommand extends AppServerCliCommand case class SignDLC(accept: LnMessage[DLCAcceptTLV]) extends SignDLCCliCommand case class SignDLCFromFile(path: Path) extends SignDLCCliCommand - sealed trait AddDLCSigsCliCommand extends CliCommand + sealed trait AddDLCSigsCliCommand extends AppServerCliCommand case class AddDLCSigs(sigs: LnMessage[DLCSignTLV]) extends AddDLCSigsCliCommand case class AddDLCSigsFromFile(path: Path) extends AddDLCSigsCliCommand - case class GetDLCFundingTx(contractId: ByteVector) extends CliCommand + case class GetDLCFundingTx(contractId: ByteVector) extends AppServerCliCommand - case class BroadcastDLCFundingTx(contractId: ByteVector) extends CliCommand + case class BroadcastDLCFundingTx(contractId: ByteVector) + extends AppServerCliCommand case class ExecuteDLC( contractId: ByteVector, oracleSigs: Vector[OracleAttestmentTLV], noBroadcast: Boolean) - extends CliCommand + extends AppServerCliCommand with Broadcastable case class ExecuteDLCRefund(contractId: ByteVector, noBroadcast: Boolean) - extends CliCommand + extends AppServerCliCommand with Broadcastable - case object GetDLCs extends CliCommand - case class GetDLC(paramHash: Sha256DigestBE) extends CliCommand + case object GetDLCs extends AppServerCliCommand + case class GetDLC(paramHash: Sha256DigestBE) extends AppServerCliCommand // Wallet case class SendToAddress( @@ -1704,7 +1725,7 @@ object CliCommand { amount: Bitcoins, satoshisPerVirtualByte: Option[SatoshisPerVirtualByte], noBroadcast: Boolean) - extends CliCommand + extends AppServerCliCommand with Broadcastable case class SendFromOutPoints( @@ -1712,94 +1733,105 @@ object CliCommand { destination: BitcoinAddress, amount: Bitcoins, feeRateOpt: Option[SatoshisPerVirtualByte]) - extends CliCommand + extends AppServerCliCommand case class SendWithAlgo( destination: BitcoinAddress, amount: Bitcoins, feeRateOpt: Option[SatoshisPerVirtualByte], algo: CoinSelectionAlgo) - extends CliCommand + extends AppServerCliCommand case class OpReturnCommit( message: String, hashMessage: Boolean, feeRateOpt: Option[SatoshisPerVirtualByte]) - extends CliCommand + extends AppServerCliCommand case class BumpFeeCPFP( txId: DoubleSha256DigestBE, feeRate: SatoshisPerVirtualByte) - extends CliCommand + extends AppServerCliCommand case class BumpFeeRBF( txId: DoubleSha256DigestBE, feeRate: SatoshisPerVirtualByte) - extends CliCommand + extends AppServerCliCommand - case class SignPSBT(psbt: PSBT) extends CliCommand + case class SignPSBT(psbt: PSBT) extends AppServerCliCommand case class LockUnspent( unlock: Boolean, outPoints: Vector[LockUnspentOutputParameter]) - extends CliCommand + extends AppServerCliCommand case class LabelAddress(address: BitcoinAddress, label: AddressLabelTag) - extends CliCommand + extends AppServerCliCommand - case class GetAddressTags(address: BitcoinAddress) extends CliCommand + case class GetAddressTags(address: BitcoinAddress) extends AppServerCliCommand - case class GetAddressLabels(address: BitcoinAddress) extends CliCommand + case class GetAddressLabels(address: BitcoinAddress) + extends AppServerCliCommand - case class DropAddressLabels(address: BitcoinAddress) extends CliCommand + case class DropAddressLabels(address: BitcoinAddress) + extends AppServerCliCommand - case class GetNewAddress(labelOpt: Option[AddressLabelTag]) extends CliCommand - case object GetUtxos extends CliCommand - case object ListReservedUtxos extends CliCommand - case object GetAddresses extends CliCommand - case object GetSpentAddresses extends CliCommand - case object GetFundedAddresses extends CliCommand - case object GetUnusedAddresses extends CliCommand - case object GetAccounts extends CliCommand - case object CreateNewAccount extends CliCommand - case object IsEmpty extends CliCommand - case object WalletInfo extends CliCommand - case class GetBalance(isSats: Boolean) extends CliCommand - case class GetConfirmedBalance(isSats: Boolean) extends CliCommand - case class GetUnconfirmedBalance(isSats: Boolean) extends CliCommand - case class GetAddressInfo(address: BitcoinAddress) extends CliCommand - case class GetTransaction(txId: DoubleSha256DigestBE) extends CliCommand + case class GetNewAddress(labelOpt: Option[AddressLabelTag]) + extends AppServerCliCommand + case object GetUtxos extends AppServerCliCommand + case object ListReservedUtxos extends AppServerCliCommand + case object GetAddresses extends AppServerCliCommand + case object GetSpentAddresses extends AppServerCliCommand + case object GetFundedAddresses extends AppServerCliCommand + case object GetUnusedAddresses extends AppServerCliCommand + case object GetAccounts extends AppServerCliCommand + case object CreateNewAccount extends AppServerCliCommand + case object IsEmpty extends AppServerCliCommand + case object WalletInfo extends AppServerCliCommand + case class GetBalance(isSats: Boolean) extends AppServerCliCommand + case class GetConfirmedBalance(isSats: Boolean) extends AppServerCliCommand + case class GetUnconfirmedBalance(isSats: Boolean) extends AppServerCliCommand + case class GetAddressInfo(address: BitcoinAddress) extends AppServerCliCommand + + case class GetTransaction(txId: DoubleSha256DigestBE) + extends AppServerCliCommand case class KeyManagerPassphraseChange( oldPassword: AesPassword, newPassword: AesPassword) - extends CliCommand - case class KeyManagerPassphraseSet(password: AesPassword) extends CliCommand + extends AppServerCliCommand + + case class KeyManagerPassphraseSet(password: AesPassword) + extends AppServerCliCommand case class ImportSeed( walletName: String, mnemonic: MnemonicCode, passwordOpt: Option[AesPassword]) - extends CliCommand + extends AppServerCliCommand case class ImportXprv( walletName: String, xprv: ExtPrivateKey, passwordOpt: Option[AesPassword]) - extends CliCommand + extends AppServerCliCommand // Node - case object GetPeers extends CliCommand - case object Stop extends CliCommand - case class SendRawTransaction(tx: Transaction) extends CliCommand + case object GetPeers extends AppServerCliCommand + case object Stop extends AppServerCliCommand + case class SendRawTransaction(tx: Transaction) extends AppServerCliCommand // Chain - case object GetBestBlockHash extends CliCommand - case object GetBlockCount extends CliCommand - case object GetFilterCount extends CliCommand - case object GetFilterHeaderCount extends CliCommand - case class GetBlockHeader(hash: DoubleSha256DigestBE) extends CliCommand - case class DecodeRawTransaction(transaction: Transaction) extends CliCommand + case object GetBestBlockHash extends AppServerCliCommand + case object GetBlockCount extends AppServerCliCommand + case object GetFilterCount extends AppServerCliCommand + case object GetFilterHeaderCount extends AppServerCliCommand + + case class GetBlockHeader(hash: DoubleSha256DigestBE) + extends AppServerCliCommand + + case class DecodeRawTransaction(transaction: Transaction) + extends AppServerCliCommand case class Rescan( addressBatchSize: Option[Int], @@ -1807,29 +1839,36 @@ object CliCommand { endBlock: Option[BlockStamp], force: Boolean, ignoreCreationTime: Boolean) - extends CliCommand + extends AppServerCliCommand // PSBT - case class DecodePSBT(psbt: PSBT) extends CliCommand - case class CombinePSBTs(psbts: Seq[PSBT]) extends CliCommand - case class JoinPSBTs(psbts: Seq[PSBT]) extends CliCommand - case class FinalizePSBT(psbt: PSBT) extends CliCommand - case class ExtractFromPSBT(psbt: PSBT) extends CliCommand - case class ConvertToPSBT(transaction: Transaction) extends CliCommand - case class AnalyzePSBT(psbt: PSBT) extends CliCommand + case class DecodePSBT(psbt: PSBT) extends AppServerCliCommand + case class CombinePSBTs(psbts: Seq[PSBT]) extends AppServerCliCommand + case class JoinPSBTs(psbts: Seq[PSBT]) extends AppServerCliCommand + case class FinalizePSBT(psbt: PSBT) extends AppServerCliCommand + case class ExtractFromPSBT(psbt: PSBT) extends AppServerCliCommand + case class ConvertToPSBT(transaction: Transaction) extends AppServerCliCommand + case class AnalyzePSBT(psbt: PSBT) extends AppServerCliCommand + + case class CreateMultisig( + requiredKeys: Int, + keys: Vector[ECPublicKey], + addressType: AddressType) + extends AppServerCliCommand // Oracle - case object GetPublicKey extends CliCommand - case object GetStakingAddress extends CliCommand - case object ListEvents extends CliCommand + case object GetPublicKey extends OracleServerCliCommand + case object GetStakingAddress extends OracleServerCliCommand + case object ListEvents extends OracleServerCliCommand - case class GetEvent(announcementTLV: OracleAnnouncementTLV) extends CliCommand + case class GetEvent(announcementTLV: OracleAnnouncementTLV) + extends OracleServerCliCommand case class CreateEnumEvent( label: String, maturationTime: Instant, outcomes: Seq[String]) - extends CliCommand + extends OracleServerCliCommand case class CreateDigitDecompEvent( eventName: String, @@ -1839,20 +1878,14 @@ object CliCommand { numDigits: Int, unit: String, precision: Int) - extends CliCommand + extends OracleServerCliCommand case class SignEvent(announcementTLV: OracleAnnouncementTLV, outcome: String) - extends CliCommand + extends OracleServerCliCommand case class SignDigits(announcementTLV: OracleAnnouncementTLV, num: Long) - extends CliCommand + extends OracleServerCliCommand case class GetSignatures(announcementTLV: OracleAnnouncementTLV) - extends CliCommand - - case class CreateMultisig( - requiredKeys: Int, - keys: Vector[ECPublicKey], - addressType: AddressType) - extends CliCommand + extends OracleServerCliCommand } diff --git a/app/gui/src/main/scala/org/bitcoins/gui/GlobalData.scala b/app/gui/src/main/scala/org/bitcoins/gui/GlobalData.scala index 07cc772c68..92723bbc57 100644 --- a/app/gui/src/main/scala/org/bitcoins/gui/GlobalData.scala +++ b/app/gui/src/main/scala/org/bitcoins/gui/GlobalData.scala @@ -33,7 +33,7 @@ object GlobalData { case None => Config(debug = debug) case Some(rpcPort) => - Config(debug = debug, rpcPort = rpcPort) + Config(debug = debug, rpcPortOpt = Some(rpcPort)) } lazy val broadcastUrl: String = GlobalData.network match { diff --git a/app/oracle-server/src/main/resources/reference.conf b/app/oracle-server/src/main/resources/reference.conf index 062f51ff0e..7c5ef3733c 100644 --- a/app/oracle-server/src/main/resources/reference.conf +++ b/app/oracle-server/src/main/resources/reference.conf @@ -1,5 +1,6 @@ bitcoin-s { oracle { + rpcport = 9998 hikari-logging = true hikari-logging-interval = 1 minute } @@ -12,4 +13,4 @@ akka { http.server.request-timeout = 10s http.server.parsing.max-content-length = 8m http.client.parsing.max-content-length = 8m -} \ No newline at end of file +} diff --git a/app/oracle-server/src/main/scala/org/bitcoins/oracle/server/OracleServerMain.scala b/app/oracle-server/src/main/scala/org/bitcoins/oracle/server/OracleServerMain.scala index 71c8c89d5c..81a13683b4 100644 --- a/app/oracle-server/src/main/scala/org/bitcoins/oracle/server/OracleServerMain.scala +++ b/app/oracle-server/src/main/scala/org/bitcoins/oracle/server/OracleServerMain.scala @@ -32,15 +32,10 @@ class OracleServerMain(override val args: Array[String]) rpcbindOpt = bindConfOpt, rpcport = rpcport) case None => - conf.rpcPortOpt match { - case Some(rpcport) => - Server(conf = conf, - handlers = routes, - rpcbindOpt = bindConfOpt, - rpcport = rpcport) - case None => - Server(conf = conf, handlers = routes, rpcbindOpt = bindConfOpt) - } + Server(conf = conf, + handlers = routes, + rpcbindOpt = bindConfOpt, + rpcport = conf.rpcPort) } _ <- server.start() diff --git a/app/server-routes/src/main/scala/org/bitcoins/server/routes/Server.scala b/app/server-routes/src/main/scala/org/bitcoins/server/routes/Server.scala index 8c08428575..0eb35e8b63 100644 --- a/app/server-routes/src/main/scala/org/bitcoins/server/routes/Server.scala +++ b/app/server-routes/src/main/scala/org/bitcoins/server/routes/Server.scala @@ -17,7 +17,7 @@ case class Server( conf: AppConfig, handlers: Seq[ServerRoute], rpcbindOpt: Option[String], - rpcport: Int = 9999)(implicit system: ActorSystem) + rpcport: Int)(implicit system: ActorSystem) extends HttpLogger { import system.dispatcher diff --git a/app/server/src/main/resources/reference.conf b/app/server/src/main/resources/reference.conf index a90b8dba2b..016366be2e 100644 --- a/app/server/src/main/resources/reference.conf +++ b/app/server/src/main/resources/reference.conf @@ -18,4 +18,8 @@ bitcoin-s { hikari-logging = true hikari-logging-interval = 1 minute } + + server { + rpcport = 9999 + } } diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala index da10c1d94e..74bc522346 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoinSAppConfig.scala @@ -1,7 +1,5 @@ package org.bitcoins.server -import java.nio.file.{Path, Paths} - import com.typesafe.config.{Config, ConfigFactory} import org.bitcoins.chain.config.ChainAppConfig import org.bitcoins.core.util.StartStopAsync @@ -10,6 +8,7 @@ import org.bitcoins.keymanager.config.KeyManagerAppConfig import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.wallet.config.WalletAppConfig +import java.nio.file.{Path, Paths} import scala.concurrent.{ExecutionContext, Future} /** A unified config class for all submodules of Bitcoin-S @@ -66,13 +65,7 @@ case class BitcoinSAppConfig( resolved } - def rpcPortOpt: Option[Int] = { - if (config.hasPath("bitcoin-s.server.rpcport")) { - Some(config.getInt("bitcoin-s.server.rpcport")) - } else { - None - } - } + def rpcPort: Int = config.getInt("bitcoin-s.server.rpcport") def rpcBindOpt: Option[String] = { if (config.hasPath("bitcoin-s.server.rpcbind")) { diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala index c0e954399d..af395e1ffd 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala @@ -302,19 +302,11 @@ class BitcoinSServerMain(override val args: Array[String]) rpcbindOpt = bindConfOpt, rpcport = rpcport) case None => - conf.rpcPortOpt match { - case Some(rpcport) => - Server(conf = nodeConf, - handlers = - Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes), - rpcbindOpt = bindConfOpt, - rpcport = rpcport) - case None => - Server(conf = nodeConf, - handlers = - Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes), - rpcbindOpt = bindConfOpt) - } + Server(conf = nodeConf, + handlers = + Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes), + rpcbindOpt = bindConfOpt, + rpcport = conf.rpcPort) } } server.start() diff --git a/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala b/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala index 167a52d792..c7ce6f3c3b 100644 --- a/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala +++ b/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala @@ -100,21 +100,11 @@ case class DLCOracleAppConfig( } } - def serverConf: Config = { - config.getConfig("bitcoin-s.server") - } - - def rpcPortOpt: Option[Int] = { - if (serverConf.hasPath("bitcoin-s.server.rpcport")) { - Some(serverConf.getInt("bitcoin-s.server.rpcport")) - } else { - None - } - } + def rpcPort: Int = config.getInt("bitcoin-s.oracle.rpcport") def rpcBindOpt: Option[String] = { - if (config.hasPath("bitcoin-s.server.rpcbind")) { - Some(config.getString("bitcoin-s.server.rpcbind")) + if (config.hasPath("bitcoin-s.oracle.rpcbind")) { + Some(config.getString("bitcoin-s.oracle.rpcbind")) } else { None } diff --git a/docs/config/configuration.md b/docs/config/configuration.md index fd48d86c20..f9e53def03 100644 --- a/docs/config/configuration.md +++ b/docs/config/configuration.md @@ -246,6 +246,12 @@ bitcoin-s { } oracle { + # The port we bind our rpc server on + rpcport = 9999 + + # The ip address we bind our server too + rpcbind = "127.0.0.1" + hikari-logging = true hikari-logging-interval = 1 minute }