Pull over simple syntax changes for {cli,oracleServer,bench,dlcNode,dlcOracle,dlcOracleTest,eclairRpc,lndRpc,lndRpcTest} from #5713 (#5721)

This commit is contained in:
Chris Stewart 2024-10-17 15:41:43 -05:00 committed by GitHub
parent 602725174f
commit 7c07aa0355
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 456 additions and 490 deletions

View File

@ -124,7 +124,7 @@ object CliReaders {
override def arity: Int = 1 override def arity: Int = 1
override def reads: String => ContractDescriptorTLV = { str => override def reads: String => ContractDescriptorTLV = { str =>
upickle.default.read[ContractDescriptorV0TLV](str)( upickle.default.read[ContractDescriptorV0TLV](str)(
Picklers.contractDescriptorV0 using Picklers.contractDescriptorV0
) )
} }
} }

View File

@ -148,8 +148,8 @@ case class OracleRoutes(oracle: DLCOracleApi)(implicit
oracle.findEvent(eventName).map { oracle.findEvent(eventName).map {
case Some(event: OracleEvent) => case Some(event: OracleEvent) =>
val outcomesJson = event.eventDescriptorTLV match { val outcomesJson = event.eventDescriptorTLV match {
case enum: EnumEventDescriptorV0TLV => case e: EnumEventDescriptorV0TLV =>
enum.outcomes.map(outcome => Str(outcome.normStr)) e.outcomes.map(outcome => Str(outcome.normStr))
case decomp: DigitDecompositionEventDescriptorV0TLV => case decomp: DigitDecompositionEventDescriptorV0TLV =>
val digits = 0.until(decomp.numDigits.toInt).map { _ => val digits = 0.until(decomp.numDigits.toInt).map { _ =>
0 0

View File

@ -1,19 +0,0 @@
package org.bitcoins.bench.eclair
import org.bitcoins.bench.eclair.PaymentLog.PaymentLogEntry
import scala.collection.JavaConverters._
object EclairBenchUtil {
def paymentLogValues(): Vector[PaymentLogEntry] = {
PaymentLog.paymentLog
.values()
.asScala
.toVector
}
def convertStrings(strings: Vector[String]): java.util.List[String] = {
strings.asJava
}
}

View File

@ -33,7 +33,7 @@ class DLCServer(
IO(Tcp) ! Tcp.Bind(self, bindAddress) IO(Tcp) ! Tcp.Bind(self, bindAddress)
private[this] var socketOpt: Option[ActorRef] = None private var socketOpt: Option[ActorRef] = None
override def receive: Receive = LoggingReceive { override def receive: Receive = LoggingReceive {
case Tcp.Bound(localAddress) => case Tcp.Bound(localAddress) =>

View File

@ -11,29 +11,28 @@ class DLCOracleAppConfigTest extends DLCOracleAppConfigFixture {
behavior of "DLCOracleAppConfig" behavior of "DLCOracleAppConfig"
it must "start the same oracle twice" in { it must "start the same oracle twice" in { dlcOracleAppConfig =>
dlcOracleAppConfig: DLCOracleAppConfig => val started1F = dlcOracleAppConfig.start()
val started1F = dlcOracleAppConfig.start() val started2F = started1F.flatMap(_ => dlcOracleAppConfig.start())
val started2F = started1F.flatMap(_ => dlcOracleAppConfig.start()) for {
for { _ <- started1F
_ <- started1F _ <- started2F
_ <- started2F dlcOracle1 = new DLCOracle()(dlcOracleAppConfig)
dlcOracle1 = new DLCOracle()(dlcOracleAppConfig) dlcOracle2 = new DLCOracle()(dlcOracleAppConfig)
dlcOracle2 = new DLCOracle()(dlcOracleAppConfig) } yield {
} yield { assert(dlcOracle1.publicKey() == dlcOracle2.publicKey())
assert(dlcOracle1.publicKey == dlcOracle2.publicKey) }
}
} }
it must "initialize the oracle, move the seed somewhere else, and then start the oracle again and get the same pubkeys" in { it must "initialize the oracle, move the seed somewhere else, and then start the oracle again and get the same pubkeys" in {
dlcOracleAppConfig: DLCOracleAppConfig => dlcOracleAppConfig =>
val seedFile = dlcOracleAppConfig.seedPath val seedFile = dlcOracleAppConfig.seedPath
val startedF = dlcOracleAppConfig.start() val startedF = dlcOracleAppConfig.start()
val pubKeyBeforeMoveF = for { val pubKeyBeforeMoveF = for {
_ <- startedF _ <- startedF
dlcOracle = new DLCOracle()(dlcOracleAppConfig) dlcOracle = new DLCOracle()(dlcOracleAppConfig)
} yield { } yield {
dlcOracle.publicKey dlcOracle.publicKey()
} }
// stop old oracle // stop old oracle
@ -69,14 +68,14 @@ class DLCOracleAppConfigTest extends DLCOracleAppConfigFixture {
for { for {
_ <- stoppedF _ <- stoppedF
pubKey1 <- pubKeyBeforeMoveF pubKey1 <- pubKeyBeforeMoveF
pubKey2 <- dlcOracle2F.map(_.publicKey) pubKey2 <- dlcOracle2F.map(_.publicKey())
} yield { } yield {
assert(pubKey1 == pubKey2) assert(pubKey1 == pubKey2)
} }
} }
it must "fail to start the oracle app config if we have different seeds" in { it must "fail to start the oracle app config if we have different seeds" in {
dlcOracleAppConfig: DLCOracleAppConfig => dlcOracleAppConfig =>
val seedFile = dlcOracleAppConfig.seedPath val seedFile = dlcOracleAppConfig.seedPath
val startedF = dlcOracleAppConfig.start() val startedF = dlcOracleAppConfig.start()

View File

@ -59,7 +59,7 @@ case class DLCOracle()(implicit val conf: DLCOracleAppConfig)
private val rValueChainIndex = 0 private val rValueChainIndex = 0
/** The root private key for this oracle */ /** The root private key for this oracle */
private[this] val extPrivateKey: ExtPrivateKeyHardened = { private val extPrivateKey: ExtPrivateKeyHardened = {
WalletStorage.getPrivateKeyFromDisk( WalletStorage.getPrivateKeyFromDisk(
conf.kmConf.seedPath, conf.kmConf.seedPath,
SegWitTestNet3Priv, SegWitTestNet3Priv,
@ -83,10 +83,10 @@ case class DLCOracle()(implicit val conf: DLCOracleAppConfig)
extPrivateKey.deriveChildPrivKey(path).key extPrivateKey.deriveChildPrivKey(path).key
} }
override val publicKey: SchnorrPublicKey = signingKey.schnorrPublicKey override def publicKey(): SchnorrPublicKey = signingKey.schnorrPublicKey
override def stakingAddress(network: BitcoinNetwork): Bech32Address = override def stakingAddress(network: BitcoinNetwork): Bech32Address =
Bech32Address(P2WPKHWitnessSPKV0(publicKey.publicKey), network) Bech32Address(P2WPKHWitnessSPKV0(publicKey().publicKey), network)
protected[bitcoins] val rValueDAO: RValueDAO = RValueDAO() protected[bitcoins] val rValueDAO: RValueDAO = RValueDAO()
protected[bitcoins] val eventDAO: EventDAO = EventDAO() protected[bitcoins] val eventDAO: EventDAO = EventDAO()
@ -283,7 +283,7 @@ case class DLCOracle()(implicit val conf: DLCOracleAppConfig)
oracleAnnouncement = OracleAnnouncementV0TLV( oracleAnnouncement = OracleAnnouncementV0TLV(
announcementSignature = announcementSignature, announcementSignature = announcementSignature,
publicKey = publicKey, publicKey = publicKey(),
eventTLV = eventTLV eventTLV = eventTLV
) )
@ -608,7 +608,7 @@ object DLCOracle {
def fromDatadir(path: Path, configs: Vector[Config])(implicit def fromDatadir(path: Path, configs: Vector[Config])(implicit
ec: ExecutionContext ec: ExecutionContext
): Future[DLCOracle] = { ): Future[DLCOracle] = {
implicit val appConfig = implicit val appConfig: DLCOracleAppConfig =
DLCOracleAppConfig.fromDatadir(datadir = path, configs) DLCOracleAppConfig.fromDatadir(datadir = path, configs)
val masterXpubDAO: MasterXPubDAO = MasterXPubDAO()(ec, appConfig) val masterXpubDAO: MasterXPubDAO = MasterXPubDAO()(ec, appConfig)
val oracle = DLCOracle() val oracle = DLCOracle()
@ -617,9 +617,9 @@ object DLCOracle {
_ <- appConfig.start() _ <- appConfig.start()
_ <- MasterXPubUtil.checkMasterXPub(oracle.getRootXpub, masterXpubDAO) _ <- MasterXPubUtil.checkMasterXPub(oracle.getRootXpub, masterXpubDAO)
differentKeyDbs <- oracle.eventDAO.findDifferentPublicKey( differentKeyDbs <- oracle.eventDAO.findDifferentPublicKey(
oracle.publicKey oracle.publicKey()
) )
fixedDbs = differentKeyDbs.map(_.copy(pubkey = oracle.publicKey)) fixedDbs = differentKeyDbs.map(_.copy(pubkey = oracle.publicKey()))
_ <- oracle.eventDAO.updateAll(fixedDbs) _ <- oracle.eventDAO.updateAll(fixedDbs)
} yield oracle } yield oracle
} }

View File

@ -102,7 +102,7 @@ class EclairRpcClient(
Seq( Seq(
from.map(x => "from" -> x.getEpochSecond.toString), from.map(x => "from" -> x.getEpochSecond.toString),
to.map(x => "to" -> x.getEpochSecond.toString) to.map(x => "to" -> x.getEpochSecond.toString)
).flatten: _* ).flatten*
) )
override def channel(channelId: ChannelId): Future[ChannelResult] = { override def channel(channelId: ChannelId): Future[ChannelResult] = {
@ -111,7 +111,7 @@ class EclairRpcClient(
private def channels(nodeId: Option[NodeId]): Future[Vector[ChannelInfo]] = { private def channels(nodeId: Option[NodeId]): Future[Vector[ChannelInfo]] = {
val params = Seq(nodeId.map(id => "nodeId" -> id.toString)).flatten val params = Seq(nodeId.map(id => "nodeId" -> id.toString)).flatten
eclairCall[Vector[ChannelInfo]]("channels", params: _*) eclairCall[Vector[ChannelInfo]]("channels", params*)
} }
def channels(): Future[Vector[ChannelInfo]] = channels(nodeId = None) def channels(): Future[Vector[ChannelInfo]] = channels(nodeId = None)
@ -130,7 +130,7 @@ class EclairRpcClient(
scriptPubKey.map(x => "scriptPubKey" -> BytesUtil.encodeHex(x.asmBytes)) scriptPubKey.map(x => "scriptPubKey" -> BytesUtil.encodeHex(x.asmBytes))
).flatten ).flatten
eclairCall[ChannelCommandResult]("close", params: _*) eclairCall[ChannelCommandResult]("close", params*)
} }
def close(channelId: ChannelId): Future[ChannelCommandResult] = def close(channelId: ChannelId): Future[ChannelCommandResult] =
@ -193,7 +193,7 @@ class EclairRpcClient(
Some("invoice" -> invoice.toString), Some("invoice" -> invoice.toString),
amountMsat.map(x => "amountMsat" -> x.toBigDecimal.toString) amountMsat.map(x => "amountMsat" -> x.toBigDecimal.toString)
).flatten ).flatten
eclairCall[Vector[Route]]("findroute", params: _*) eclairCall[Vector[Route]]("findroute", params*)
} }
override def forceClose( override def forceClose(
@ -262,7 +262,7 @@ class EclairRpcClient(
// this is unfortunately returned in this format // this is unfortunately returned in this format
// created channel 30bdf849eb9f72c9b41a09e38a6d83138c2edf332cb116dd7cf0f0dfb66be395 // created channel 30bdf849eb9f72c9b41a09e38a6d83138c2edf332cb116dd7cf0f0dfb66be395
val call = eclairCall[String]("open", params: _*) val call = eclairCall[String]("open", params*)
// let's just return the chanId // let's just return the chanId
// format: // format:
// created channel 19e11470b0dd96ed15c56ea8f32e9a3277dcbd570e7392c1c34709adc7ebfdc3 with fundingTxId=c2fdebc7ad0947c3c192730e57bddc77329a2ef3a86ec515ed96ddb07014e119 and fees=24750 sat // created channel 19e11470b0dd96ed15c56ea8f32e9a3277dcbd570e7392c1c34709adc7ebfdc3 with fundingTxId=c2fdebc7ad0947c3c192730e57bddc77329a2ef3a86ec515ed96ddb07014e119 and fees=24750 sat
@ -413,7 +413,7 @@ class EclairRpcClient(
paymentPreimage.map(x => "paymentPreimage" -> x.hex) paymentPreimage.map(x => "paymentPreimage" -> x.hex)
).flatten ).flatten
val responseF = eclairCall[InvoiceResult]("createinvoice", params: _*) val responseF = eclairCall[InvoiceResult]("createinvoice", params*)
responseF.flatMap { res => responseF.flatMap { res =>
Future.fromTry(LnInvoice.fromStringT(res.serialized)) Future.fromTry(LnInvoice.fromStringT(res.serialized))
@ -515,7 +515,7 @@ class EclairRpcClient(
externalId.map(x => "externalId" -> x) externalId.map(x => "externalId" -> x)
).flatten ).flatten
eclairCall[PaymentId]("payinvoice", params: _*) eclairCall[PaymentId]("payinvoice", params*)
} }
override def getReceivedInfo( override def getReceivedInfo(
@ -541,7 +541,7 @@ class EclairRpcClient(
case _: JsError => JsSuccess(None) case _: JsError => JsSuccess(None)
} }
} }
eclairCall[Option[IncomingPayment]]("getreceivedinfo", params: _*)(r) eclairCall[Option[IncomingPayment]]("getreceivedinfo", params*)(r)
} }
override def getSentInfo( override def getSentInfo(
@ -575,7 +575,7 @@ class EclairRpcClient(
externalId.map(x => "externalId" -> x) externalId.map(x => "externalId" -> x)
).flatten ).flatten
eclairCall[PaymentId]("sendtonode", params: _*) eclairCall[PaymentId]("sendtonode", params*)
} }
def sendToRoute( def sendToRoute(
@ -603,7 +603,7 @@ class EclairRpcClient(
parentId.map(x => "parentId" -> x.toString), parentId.map(x => "parentId" -> x.toString),
externalId.map(x => "externalId" -> x) externalId.map(x => "externalId" -> x)
).flatten ).flatten
eclairCall[SendToRouteResult]("sendtoroute", params: _*) eclairCall[SendToRouteResult]("sendtoroute", params*)
} }
override def updateRelayFee( override def updateRelayFee(
@ -640,7 +640,7 @@ class EclairRpcClient(
Seq( Seq(
from.map(x => "from" -> x.toSeconds.toString), from.map(x => "from" -> x.toSeconds.toString),
to.map(x => "to" -> x.toSeconds.toString) to.map(x => "to" -> x.toSeconds.toString)
).flatten: _* ).flatten*
) )
} }
@ -676,7 +676,7 @@ class EclairRpcClient(
Seq( Seq(
from.map(x => "from" -> x.getEpochSecond.toString), from.map(x => "from" -> x.getEpochSecond.toString),
to.map(x => "to" -> x.getEpochSecond.toString) to.map(x => "to" -> x.getEpochSecond.toString)
).flatten: _* ).flatten*
) )
resF.flatMap(xs => resF.flatMap(xs =>
Future.sequence( Future.sequence(
@ -727,7 +727,7 @@ class EclairRpcClient(
private def eclairCall[T](command: String, parameters: (String, String)*)( private def eclairCall[T](command: String, parameters: (String, String)*)(
implicit reader: Reads[T] implicit reader: Reads[T]
): Future[T] = { ): Future[T] = {
val request = buildRequest(getDaemon, command, parameters: _*) val request = buildRequest(getDaemon, command, parameters*)
logger.trace(s"eclair rpc call ${request}") logger.trace(s"eclair rpc call ${request}")
val responseF = sendRequest(request) val responseF = sendRequest(request)
@ -810,7 +810,7 @@ class EclairRpcClient(
HttpRequest( HttpRequest(
method = HttpMethods.POST, method = HttpMethods.POST,
uri, uri,
entity = FormData(params: _*).toEntity entity = FormData(params*).toEntity
) )
.addCredentials( .addCredentials(
HttpCredentials.createBasicHttpCredentials(username, password) HttpCredentials.createBasicHttpCredentials(username, password)

View File

@ -17,7 +17,7 @@ import org.bitcoins.core.wallet.fee._
import org.bitcoins.crypto._ import org.bitcoins.crypto._
import org.bitcoins.testkit.async.TestAsyncUtil import org.bitcoins.testkit.async.TestAsyncUtil
import org.bitcoins.testkit.fixtures.DualLndFixture import org.bitcoins.testkit.fixtures.DualLndFixture
import scodec.bits.{ByteVector, HexStringSyntax} import scodec.bits.ByteVector
import signrpc.SignMethod import signrpc.SignMethod
import scala.concurrent.{Await, Future} import scala.concurrent.{Await, Future}
@ -439,7 +439,8 @@ class LndRpcClientPairTest extends DualLndFixture with LndUtils {
it must "send and receive a custom message" in { params => it must "send and receive a custom message" in { params =>
val (_, lndA, lndB) = params val (_, lndA, lndB) = params
val customMessage = UnknownTLV(BigSizeUInt(48000), hex"0094355324") val customMessage =
UnknownTLV(BigSizeUInt(48000), ByteVector.fromValidHex("0094355324"))
val subscribeF = lndA.subscribeCustomMessages().runWith(Sink.head) val subscribeF = lndA.subscribeCustomMessages().runWith(Sink.head)

View File

@ -142,7 +142,7 @@ case class LndRpcClient(instance: LndInstance, binaryOpt: Option[File] = None)(
// These need to be lazy so we don't try and fetch // These need to be lazy so we don't try and fetch
// the tls certificate before it is generated // the tls certificate before it is generated
private[this] lazy val certStreamOpt: Option[InputStream] = { private lazy val certStreamOpt: Option[InputStream] = {
instance.certFileOpt match { instance.certFileOpt match {
case Some(file) => Some(new FileInputStream(file)) case Some(file) => Some(new FileInputStream(file))
case None => case None =>