From aa8a2e14a6df541aac30f20c4fbd30452629b0c6 Mon Sep 17 00:00:00 2001 From: Ben Carman Date: Fri, 10 Apr 2020 14:33:37 -0500 Subject: [PATCH] Move Json Reader, Writers, and Serializers to App Commons (#1328) * Move Json Reader, Writers, and Serializers to App Commons * Move app-commons outside of app/ --- app-commons/commons.sbt | 3 + .../bitcoind}/BlockchainResult.scala | 6 +- .../jsonmodels/bitcoind}/NetworkResult.scala | 2 +- .../jsonmodels/bitcoind}/OtherResult.scala | 2 +- .../bitcoind}/RawTransactionResult.scala | 2 +- .../jsonmodels/bitcoind}/RpcOpts.scala | 4 +- .../jsonmodels/bitcoind}/RpcPsbtResult.scala | 2 +- .../jsonmodels/bitcoind}/WalletResult.scala | 4 +- .../jsonmodels/eclair}/EclairModels.scala | 5 +- .../jsonmodels/eclair}/PeerState.scala | 2 +- .../commons/serializers}/JsonReaders.scala | 586 +++++++++++++++++- .../serializers/JsonSerializers.scala | 107 +++- .../commons}/serializers/JsonWriters.scala | 10 +- .../commons/serializers}/Picklers.scala | 8 +- .../commons}/serializers/SerializerUtil.scala | 2 +- .../scala/org/bitcoins/cli/ConsoleCli.scala | 2 +- .../org/bitcoins/server/ChainRoutes.scala | 2 +- .../org/bitcoins/server/WalletRoutes.scala | 2 +- .../bitcoins/bench/eclair/EclairBench.scala | 2 +- .../bitcoins/bench/eclair/PaymentLog.scala | 6 +- .../rpc/common/BlockchainRpcTest.scala | 7 +- .../bitcoins/rpc/common/MessageRpcTest.scala | 2 +- .../bitcoins/rpc/common/MultisigRpcTest.scala | 2 +- .../org/bitcoins/rpc/common/P2PRpcTest.scala | 5 +- .../rpc/common/RawTransactionRpcTest.scala | 5 +- .../org/bitcoins/rpc/common/UTXORpcTest.scala | 3 +- .../org/bitcoins/rpc/common/UtilRpcTest.scala | 2 +- .../bitcoins/rpc/common/WalletRpcTest.scala | 9 +- .../rpc/v16/BitcoindV16RpcClientTest.scala | 4 +- .../rpc/v17/BitcoindV17RpcClientTest.scala | 10 +- .../org/bitcoins/rpc/v17/PsbtRpcTest.scala | 6 +- .../rpc/v18/BitcoindV18RpcClientTest.scala | 2 +- .../rpc/v19/BitcoindV19RpcClientTest.scala | 2 +- .../rpc/client/common/BlockchainRpc.scala | 4 +- .../bitcoins/rpc/client/common/Client.scala | 5 +- .../rpc/client/common/DescriptorRpc.scala | 4 +- .../rpc/client/common/MempoolRpc.scala | 14 +- .../rpc/client/common/MiningRpc.scala | 10 +- .../rpc/client/common/MultisigRpc.scala | 8 +- .../bitcoins/rpc/client/common/NodeRpc.scala | 6 +- .../bitcoins/rpc/client/common/P2PRpc.scala | 9 +- .../bitcoins/rpc/client/common/PsbtRpc.scala | 4 +- .../rpc/client/common/RawTransactionRpc.scala | 15 +- .../rpc/client/common/TransactionRpc.scala | 9 +- .../bitcoins/rpc/client/common/UTXORpc.scala | 6 +- .../bitcoins/rpc/client/common/UtilRpc.scala | 8 +- .../rpc/client/common/WalletRpc.scala | 7 +- .../rpc/client/v16/BitcoindV16RpcClient.scala | 15 +- .../rpc/client/v16/V16AccountRpc.scala | 6 +- .../bitcoins/rpc/client/v16/V16SendRpc.scala | 10 +- .../rpc/client/v17/BitcoindV17RpcClient.scala | 23 +- .../bitcoins/rpc/client/v17/V17LabelRpc.scala | 6 +- .../rpc/client/v18/BitcoindV18RpcClient.scala | 30 +- .../rpc/client/v18/V18AssortedRpc.scala | 8 +- .../rpc/client/v19/BitcoindV19RpcClient.scala | 23 +- .../rpc/client/v19/V19BlockFilterRpc.scala | 4 +- build.sbt | 26 +- .../chain/blockchain/ChainHandlerTest.scala | 4 +- .../eclair/rpc/EclairRpcClientTest.scala | 9 + .../bitcoins/eclair/rpc/api/EclairApi.scala | 19 + .../eclair/rpc/client/EclairRpcClient.scala | 6 +- project/Deps.scala | 33 +- .../testkit/chain/ChainUnitTest.scala | 2 +- .../org/bitcoins/testkit/chain/SyncUtil.scala | 2 +- .../eclair/rpc/EclairRpcTestUtil.scala | 6 + .../testkit/rpc/BitcoindRpcTestUtil.scala | 19 +- .../bitcoins/wallet/TrezorAddressTest.scala | 2 +- 67 files changed, 934 insertions(+), 246 deletions(-) create mode 100644 app-commons/commons.sbt rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/BlockchainResult.scala (99%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/NetworkResult.scala (98%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/OtherResult.scala (99%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/RawTransactionResult.scala (98%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/RpcOpts.scala (98%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/RpcPsbtResult.scala (98%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind}/WalletResult.scala (98%) rename {eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair}/EclairModels.scala (98%) rename {eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/network => app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair}/PeerState.scala (87%) rename {eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client => app-commons/src/main/scala/org/bitcoins/commons/serializers}/JsonReaders.scala (51%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc => app-commons/src/main/scala/org/bitcoins/commons}/serializers/JsonSerializers.scala (90%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc => app-commons/src/main/scala/org/bitcoins/commons}/serializers/JsonWriters.scala (97%) rename {app/picklers/src/main/scala/org/bitcoins/picklers => app-commons/src/main/scala/org/bitcoins/commons/serializers}/Picklers.scala (92%) rename {bitcoind-rpc/src/main/scala/org/bitcoins/rpc => app-commons/src/main/scala/org/bitcoins/commons}/serializers/SerializerUtil.scala (98%) diff --git a/app-commons/commons.sbt b/app-commons/commons.sbt new file mode 100644 index 0000000000..60421b9e1c --- /dev/null +++ b/app-commons/commons.sbt @@ -0,0 +1,3 @@ +name := "bitcoin-s-app-commons" + +libraryDependencies ++= Deps.appCommons(scalaVersion.value) diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/BlockchainResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/BlockchainResult.scala similarity index 99% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/BlockchainResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/BlockchainResult.scala index 7388eff319..2379d58adc 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/BlockchainResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/BlockchainResult.scala @@ -1,12 +1,12 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind +import org.bitcoins.core.config.NetworkParameters import org.bitcoins.core.crypto.DoubleSha256DigestBE import org.bitcoins.core.currency.Bitcoins +import org.bitcoins.core.gcs.GolombFilter import org.bitcoins.core.number.{Int32, UInt32} import org.bitcoins.core.protocol.blockchain.BlockHeader import org.bitcoins.core.wallet.fee.BitcoinFeeUnit -import org.bitcoins.core.config.NetworkParameters -import org.bitcoins.core.gcs.GolombFilter sealed abstract class BlockchainResult diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/NetworkResult.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/NetworkResult.scala index 3258cf94d7..a618387eb2 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/NetworkResult.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind import java.net.URI diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/OtherResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/OtherResult.scala similarity index 99% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/OtherResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/OtherResult.scala index 016db6c4ca..6d8a48a626 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/OtherResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/OtherResult.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind import org.bitcoins.core.crypto.{ DoubleSha256Digest, diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RawTransactionResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RawTransactionResult.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RawTransactionResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RawTransactionResult.scala index 10f46a002c..c66f7db50d 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RawTransactionResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RawTransactionResult.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind import org.bitcoins.core.crypto.DoubleSha256DigestBE import org.bitcoins.core.currency.Bitcoins diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RpcOpts.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcOpts.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RpcOpts.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcOpts.scala index 74efd7892d..f6dfe7b2e7 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RpcOpts.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcOpts.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.client.common +package org.bitcoins.commons.jsonmodels.bitcoind import org.bitcoins.core.crypto.{DoubleSha256DigestBE, ECPrivateKey} import org.bitcoins.core.currency.Bitcoins @@ -6,7 +6,7 @@ import org.bitcoins.core.number.UInt32 import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.script.{ScriptPubKey, WitnessScriptPubKey} import org.bitcoins.core.protocol.transaction.TransactionInput -import org.bitcoins.rpc.serializers.JsonWriters._ +import org.bitcoins.commons.serializers.JsonWriters._ import play.api.libs.json.{Json, Writes} object RpcOpts { diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RpcPsbtResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcPsbtResult.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RpcPsbtResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcPsbtResult.scala index a0986e8d71..aaf274c4a2 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/RpcPsbtResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/RpcPsbtResult.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind import org.bitcoins.core.crypto.{ECDigitalSignature, ECPublicKey} import org.bitcoins.core.currency.Bitcoins diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/WalletResult.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/WalletResult.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/WalletResult.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/WalletResult.scala index 6df31b0220..a02614b0d3 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/WalletResult.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/bitcoind/WalletResult.scala @@ -1,8 +1,9 @@ -package org.bitcoins.rpc.jsonmodels +package org.bitcoins.commons.jsonmodels.bitcoind import java.io.File import java.time.ZonedDateTime +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.LabelPurpose import org.bitcoins.core.crypto.{ DoubleSha256DigestBE, ECPublicKey, @@ -17,7 +18,6 @@ import org.bitcoins.core.protocol.script.{ScriptPubKey, WitnessVersion} import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.core.script.ScriptType import org.bitcoins.core.wallet.fee.BitcoinFeeUnit -import org.bitcoins.rpc.client.common.RpcOpts.LabelPurpose sealed abstract class WalletResult diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairModels.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/EclairModels.scala similarity index 98% rename from eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairModels.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/EclairModels.scala index 35dc80c8f1..e78538dec1 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairModels.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/EclairModels.scala @@ -1,9 +1,10 @@ -package org.bitcoins.eclair.rpc.api +package org.bitcoins.commons.jsonmodels.eclair import java.net.InetSocketAddress import java.time.Instant import java.util.UUID +import org.bitcoins.commons.serializers.JsonReaders._ import org.bitcoins.core.crypto.{ DoubleSha256Digest, DoubleSha256DigestBE, @@ -20,7 +21,6 @@ import org.bitcoins.core.protocol.ln.{ PaymentPreimage, ShortChannelId } -import org.bitcoins.eclair.rpc.network.PeerState import play.api.libs.json.JsObject import scala.concurrent.duration.FiniteDuration @@ -185,7 +185,6 @@ case class ChannelResult( feeBaseMsat: Option[MilliSatoshis], feeProportionalMillionths: Option[FeeProportionalMillionths], data: JsObject) { - import org.bitcoins.eclair.rpc.client.JsonReaders._ lazy val shortChannelId: Option[ShortChannelId] = (data \ "shortChannelId").validate[ShortChannelId].asOpt } diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/network/PeerState.scala b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/PeerState.scala similarity index 87% rename from eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/network/PeerState.scala rename to app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/PeerState.scala index cc8703dbf0..d2b16713ec 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/network/PeerState.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/jsonmodels/eclair/PeerState.scala @@ -1,4 +1,4 @@ -package org.bitcoins.eclair.rpc.network +package org.bitcoins.commons.jsonmodels.eclair sealed abstract class PeerState diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/JsonReaders.scala b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonReaders.scala similarity index 51% rename from eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/JsonReaders.scala rename to app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonReaders.scala index 3e1049a4e0..f4a4846bd8 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/JsonReaders.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonReaders.scala @@ -1,31 +1,585 @@ -package org.bitcoins.eclair.rpc.client +package org.bitcoins.commons.serializers -import java.net.InetSocketAddress -import java.time.Instant +import java.io.File +import java.net.{InetAddress, InetSocketAddress, URI} +import java.time._ import java.util.UUID -import org.bitcoins.core.crypto.{ - DoubleSha256Digest, - DoubleSha256DigestBE, - ECDigitalSignature, - Sha256Digest -} -import org.bitcoins.core.currency.Satoshis +import org.bitcoins.commons.jsonmodels._ +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.LabelPurpose +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.jsonmodels.eclair._ +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.core.config._ +import org.bitcoins.core.crypto._ +import org.bitcoins.core.currency.{Bitcoins, Satoshis} +import org.bitcoins.core.number.{Int32, UInt32, UInt64} +import org.bitcoins.core.p2p.ServiceIdentifier +import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock} import org.bitcoins.core.protocol.ln._ -import org.bitcoins.core.protocol.ln.channel.{ChannelState, FundedChannelId} -import org.bitcoins.core.protocol.ln.currency.{MilliSatoshis, PicoBitcoins} +import org.bitcoins.core.protocol.ln.channel._ +import org.bitcoins.core.protocol.ln.currency._ import org.bitcoins.core.protocol.ln.fee.FeeProportionalMillionths import org.bitcoins.core.protocol.ln.node.NodeId -import org.bitcoins.eclair.rpc.api._ -import org.bitcoins.eclair.rpc.network.PeerState -import org.bitcoins.rpc.serializers.SerializerUtil +import org.bitcoins.core.protocol.script.{ + ScriptPubKey, + ScriptSignature, + WitnessVersion, + WitnessVersion0 +} +import org.bitcoins.core.protocol.transaction._ +import org.bitcoins.core.protocol.{ + Address, + BitcoinAddress, + P2PKHAddress, + P2SHAddress +} +import org.bitcoins.core.script.ScriptType +import org.bitcoins.core.script.crypto.HashType +import org.bitcoins.core.wallet.fee.{BitcoinFeeUnit, SatoshisPerByte} import play.api.libs.json._ import scala.concurrent.duration._ import scala.util.{Failure, Success, Try} object JsonReaders { - import org.bitcoins.rpc.serializers.JsonReaders._ + + /** + * Tries to prase the provided JSON into a map with keys of + * type `K` and values of type `V` + */ + def mapReads[K, V](js: JsValue)( + implicit readsK: Reads[K], + readsV: Reads[V]): JsResult[Map[K, V]] = { + js.validate[JsObject].flatMap { jsObj => + val jsResults: scala.collection.Seq[(JsResult[K], JsResult[V])] = + jsObj.fields.map { + case (key, value) => JsString(key).validate[K] -> value.validate[V] + } + + val allErrors: scala.collection.Seq[( + JsPath, + scala.collection.Seq[JsonValidationError])] = + jsResults.collect { + case (JsError(keyErrors), _) => keyErrors + case (_, JsError(valueErrors)) => valueErrors + }.flatten + + if (allErrors.nonEmpty) { + JsError(allErrors) + } else { + JsSuccess(jsResults.collect { + case (JsSuccess(k, _), JsSuccess(v, _)) => + k -> v + }.toMap) + } + } + } + + implicit object ZonedDateTimeReads extends Reads[ZonedDateTime] { + override def reads(json: JsValue): JsResult[ZonedDateTime] = + SerializerUtil.processJsNumberBigInt[ZonedDateTime]( + bigInt => + ZonedDateTime.ofInstant(Instant.ofEpochSecond(bigInt.toLong), + ZoneOffset.UTC))(json) + } + + implicit object LocalDateTimeReads extends Reads[LocalDateTime] { + override def reads(json: JsValue): JsResult[LocalDateTime] = + SerializerUtil.processJsNumberBigInt[LocalDateTime]( + bigInt => + LocalDateTime.ofInstant(Instant.ofEpochSecond(bigInt.toLong), + ZoneId.systemDefault()))(json) + } + + implicit object BigIntReads extends Reads[BigInt] { + override def reads(json: JsValue): JsResult[BigInt] = + SerializerUtil.processJsNumber[BigInt](_.toBigInt)(json) + } + + implicit object Sha256DigestReads extends Reads[Sha256Digest] { + override def reads(json: JsValue): JsResult[Sha256Digest] = + SerializerUtil.processJsString[Sha256Digest](Sha256Digest.fromHex)(json) + } + + implicit object RipeMd160DigestReads extends Reads[RipeMd160Digest] { + override def reads(json: JsValue): JsResult[RipeMd160Digest] = + SerializerUtil.processJsString[RipeMd160Digest](RipeMd160Digest.fromHex)( + json) + } + + implicit object RipeMd160DigestBEReads extends Reads[RipeMd160DigestBE] { + override def reads(json: JsValue): JsResult[RipeMd160DigestBE] = + SerializerUtil.processJsString[RipeMd160DigestBE]( + RipeMd160DigestBE.fromHex)(json) + } + + implicit object DoubleSha256DigestReads extends Reads[DoubleSha256Digest] { + override def reads(json: JsValue): JsResult[DoubleSha256Digest] = + SerializerUtil.processJsString[DoubleSha256Digest]( + DoubleSha256Digest.fromHex)(json) + } + + implicit object DoubleSha256DigestBEReads + extends Reads[DoubleSha256DigestBE] { + override def reads(json: JsValue): JsResult[DoubleSha256DigestBE] = + SerializerUtil.processJsString[DoubleSha256DigestBE]( + DoubleSha256DigestBE.fromHex)(json) + } + + implicit object BitcoinsReads extends Reads[Bitcoins] { + override def reads(json: JsValue): JsResult[Bitcoins] = + SerializerUtil.processJsNumber[Bitcoins](Bitcoins(_))(json) + } + + implicit object SatoshisReads extends Reads[Satoshis] { + override def reads(json: JsValue): JsResult[Satoshis] = + SerializerUtil.processJsNumber[Satoshis](num => Satoshis(num.toBigInt))( + json) + } + + implicit object BlockHeaderReads extends Reads[BlockHeader] { + override def reads(json: JsValue): JsResult[BlockHeader] = + SerializerUtil.processJsString[BlockHeader](BlockHeader.fromHex)(json) + } + + implicit object Int32Reads extends Reads[Int32] { + override def reads(json: JsValue): JsResult[Int32] = json match { + case JsNumber(n) => + n.toBigIntExact match { + case Some(num) => JsSuccess(Int32(num)) + case None => SerializerUtil.buildErrorMsg("Int32", n) + } + case JsString(s) => JsSuccess(Int32.fromHex(s)) + case err @ (JsNull | _: JsBoolean | _: JsArray | _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsnumber", err) + } + } + + implicit object UInt32Reads extends Reads[UInt32] { + override def reads(json: JsValue): JsResult[UInt32] = json match { + case JsNumber(n) => + n.toBigIntExact match { + case Some(num) => + if (num >= 0) { + JsSuccess(UInt32(num)) + } else { + SerializerUtil.buildErrorMsg("positive_value", num) + } + case None => SerializerUtil.buildErrorMsg("UInt32", n) + } + case JsString(s) => JsSuccess(UInt32.fromHex(s)) + case err @ (JsNull | _: JsBoolean | _: JsArray | _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsnumber", err) + } + } + + implicit object UInt64Reads extends Reads[UInt64] { + override def reads(json: JsValue): JsResult[UInt64] = json match { + case JsNumber(n) => + n.toBigIntExact match { + case Some(num) => + if (num >= 0) { + JsSuccess(UInt64(num)) + } else { + SerializerUtil.buildErrorMsg("positive_value", num) + } + case None => SerializerUtil.buildErrorMsg("UInt32", n) + } + case JsString(s) => JsSuccess(UInt64.fromHex(s)) + case err @ (JsNull | _: JsBoolean | _: JsArray | _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsnumber", err) + } + } + + implicit object LabelPurposeReads extends Reads[LabelPurpose] { + override def reads(json: JsValue): JsResult[LabelPurpose] = + json match { + case JsString("send") => JsSuccess(LabelPurpose.Send) + case JsString("receive") => JsSuccess(LabelPurpose.Receive) + // TODO better error message? + case err => + SerializerUtil.buildErrorMsg(expected = "send or receive", err) + } + } + + implicit object WitnessVersionReads extends Reads[WitnessVersion] { + override def reads(json: JsValue): JsResult[WitnessVersion] = + json match { + case JsNumber(num) if num == 0 => JsSuccess(WitnessVersion0) + case JsNumber(num) if num != 0 => + SerializerUtil.buildErrorMsg("Expected witness_version 0", num) + case err => + SerializerUtil.buildErrorMsg("Expected numerical witness_version", + err) + } + } + + implicit object AddressReads extends Reads[Address] { + override def reads(json: JsValue): JsResult[Address] = json match { + case JsString(s) => + Address.fromString(s) match { + case Success(address) => JsSuccess(address) + case Failure(err) => + SerializerUtil.buildErrorMsg("address", err) + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsArray | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsstring", err) + } + } + + // Errors for Unit return types are caught in RpcClient::checkUnit + implicit object UnitReads extends Reads[Unit] { + override def reads(json: JsValue): JsResult[Unit] = JsSuccess(()) + } + + implicit object InetAddressReads extends Reads[InetAddress] { + override def reads(json: JsValue): JsResult[InetAddress] = + SerializerUtil.processJsString[InetAddress](InetAddress.getByName)(json) + } + + implicit object ECDigitalSignatureReads extends Reads[ECDigitalSignature] { + override def reads(json: JsValue): JsResult[ECDigitalSignature] = { + SerializerUtil.processJsString(ECDigitalSignature.fromHex)(json) + } + } + + implicit object ScriptPubKeyReads extends Reads[ScriptPubKey] { + override def reads(json: JsValue): JsResult[ScriptPubKey] = + SerializerUtil.processJsString[ScriptPubKey](ScriptPubKey.fromAsmHex)( + json) + } + + implicit object BlockReads extends Reads[Block] { + override def reads(json: JsValue): JsResult[Block] = + SerializerUtil.processJsString[Block](Block.fromHex)(json) + } + + implicit object Sha256Hash160DigestReads extends Reads[Sha256Hash160Digest] { + override def reads(json: JsValue): JsResult[Sha256Hash160Digest] = + SerializerUtil.processJsString[Sha256Hash160Digest]( + Sha256Hash160Digest.fromHex)(json) + } + + implicit object ECPublicKeyReads extends Reads[ECPublicKey] { + override def reads(json: JsValue): JsResult[ECPublicKey] = + SerializerUtil.processJsString[ECPublicKey](ECPublicKey.fromHex)(json) + } + + implicit object P2PKHAddressReads extends Reads[P2PKHAddress] { + override def reads(json: JsValue): JsResult[P2PKHAddress] = json match { + case JsString(s) => + P2PKHAddress.fromString(s) match { + case Success(address) => JsSuccess(address) + case Failure(err) => + SerializerUtil.buildErrorMsg("p2pkhaddress", err) + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsArray | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsstring", err) + } + } + + implicit object P2SHAddressReads extends Reads[P2SHAddress] { + override def reads(json: JsValue): JsResult[P2SHAddress] = json match { + case JsString(s) => + P2SHAddress.fromString(s) match { + case Success(address) => JsSuccess(address) + case Failure(err) => + SerializerUtil.buildErrorMsg("p2shaddress", err) + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsArray | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsstring", err) + } + } + + implicit object ScriptSignatureReads extends Reads[ScriptSignature] { + override def reads(json: JsValue): JsResult[ScriptSignature] = + SerializerUtil.processJsString[ScriptSignature]( + ScriptSignature.fromAsmHex)(json) + } + + implicit object TransactionInputReads extends Reads[TransactionInput] { + override def reads(json: JsValue): JsResult[TransactionInput] = { + (json \ "sequence").validate[UInt32].flatMap { sequence => + (json \ "coinbase").validate[String] match { + case s: JsSuccess[String] => + JsSuccess( + CoinbaseInput(ScriptSignature.fromAsmHex(s.value), sequence)) + case _ => + (json \ "txid").validate[DoubleSha256DigestBE].flatMap { txid => + (json \ "vout").validate[UInt32].flatMap { vout => + (json \ "scriptSig" \ "hex") + .validate[ScriptSignature] + .flatMap { scriptSig => + JsSuccess( + TransactionInput(TransactionOutPoint(txid.flip, vout), + scriptSig, + sequence)) + } + } + } + } + } + } + } + + implicit object BitcoinAddressReads extends Reads[BitcoinAddress] { + override def reads(json: JsValue): JsResult[BitcoinAddress] = json match { + case JsString(s) => + BitcoinAddress.fromString(s) match { + case Success(address) => + JsSuccess(address) + case Failure(err) => + SerializerUtil.buildErrorMsg("address", err) + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsArray | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsstring", err) + } + } + + implicit object MerkleBlockReads extends Reads[MerkleBlock] { + override def reads(json: JsValue): JsResult[MerkleBlock] = + SerializerUtil.processJsString[MerkleBlock](MerkleBlock.fromHex)(json) + } + + implicit object TransactionReads extends Reads[Transaction] { + override def reads(json: JsValue): JsResult[Transaction] = + SerializerUtil.processJsString[Transaction](Transaction.fromHex)(json) + } + + implicit object TransactionOutPointReads extends Reads[TransactionOutPoint] { + private case class OutPoint(txid: DoubleSha256DigestBE, vout: UInt32) + override def reads(json: JsValue): JsResult[TransactionOutPoint] = { + implicit val outPointReads: Reads[OutPoint] = Json.reads[OutPoint] + json.validate[OutPoint] match { + case JsSuccess(op, _) => + JsSuccess(TransactionOutPoint(op.txid.flip, op.vout)) + case JsError(err) => + JsError(s"Could not parse TransactionOutPoint, got ${err.toString()}") + } + } + } + + implicit object RpcAddressReads extends Reads[RpcAddress] { + + def reads(json: JsValue): JsResult[RpcAddress] = json match { + case array: JsArray => + val bitcoinResult = array.value.find(_.isInstanceOf[JsNumber]) match { + case Some(JsNumber(n)) => JsSuccess(Bitcoins(n)) + case Some( + err @ (JsNull | _: JsBoolean | _: JsString | _: JsArray | + _: JsObject)) => + SerializerUtil.buildJsErrorMsg("jsnumber", err) + case None => JsError("error.expected.balance") + } + bitcoinResult.flatMap { bitcoins => + val jsStrings = + array.value + .filter(_.isInstanceOf[JsString]) + .map(_.asInstanceOf[JsString].value) + val addressResult = jsStrings.find(BitcoinAddress.isValid) match { + case Some(s) => + BitcoinAddress.fromString(s) match { + case Success(a) => JsSuccess(a) + case Failure(err) => + SerializerUtil.buildErrorMsg("address", err) + } + case None => JsError("error.expected.address") + } + addressResult.flatMap { address => + val account = jsStrings.find(s => !BitcoinAddress.isValid(s)) + JsSuccess(RpcAddress(address, bitcoins, account)) + } + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsString | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsarray", err) + } + } + + implicit object HashTypeReads extends Reads[HashType] { + override def reads(json: JsValue): JsResult[HashType] = + SerializerUtil.processJsString { + case "ALL" => HashType.sigHashAll + case "NONE" => HashType.sigHashNone + case "SINGLE" => HashType.sigHashSingle + case "ALL|ANYONECANPAY" => HashType.sigHashAllAnyoneCanPay + case "NONE|ANYONECANPAY" => HashType.sigHashNoneAnyoneCanPay + case "SINGLE|ANYONECANPAY" => HashType.sigHashSingleAnyoneCanPay + }(json) + } + + implicit object FinalizedPsbtReads extends Reads[FinalizedPsbt] { + override def reads(json: JsValue): JsResult[FinalizedPsbt] = + (json \ "complete").validate[Boolean].flatMap { completed => + if (completed) { + (json \ "hex").validate[Transaction].flatMap { tx => + JsSuccess(FinalizedPsbt(tx)) + } + } else { + JsError("PSBT was not completed!") + } + } + } + + implicit object NonFinalizedPsbtReads extends Reads[NonFinalizedPsbt] { + override def reads(json: JsValue): JsResult[NonFinalizedPsbt] = + if ((json \ "hex").isDefined) { + JsError("PSBT was submitted as a serialized hex transaction!") + } else { + (json \ "psbt").validate[String].map(NonFinalizedPsbt) + } + } + + implicit object FinalizePsbtResultReads extends Reads[FinalizePsbtResult] { + override def reads(json: JsValue): JsResult[FinalizePsbtResult] = + if ((json \ "hex").isDefined) { + json.validate[FinalizedPsbt] + } else { + json.validate[NonFinalizedPsbt] + } + } + + implicit object RpcPsbtOutputReads extends Reads[RpcPsbtOutput] { + override def reads(json: JsValue): JsResult[RpcPsbtOutput] = + for { + redeemScript <- (json \ "redeem_script").validateOpt[RpcPsbtScript] + witnessScript <- (json \ "witness_script").validateOpt[RpcPsbtScript] + unknown <- (json \ "unknown").validateOpt[Map[String, String]] + bip32Derivs <- (json \ "bip32_derivs") + .validateOpt[Vector[PsbtBIP32Deriv]] + } yield RpcPsbtOutput(redeemScript, witnessScript, bip32Derivs, unknown) + } + + implicit object PsbtBIP32DerivsReads extends Reads[PsbtBIP32Deriv] { + override def reads(json: JsValue): JsResult[PsbtBIP32Deriv] = + for { + pubkey <- (json \ "pubkey").validate[ECPublicKey] + masterFingerprint <- (json \ "master_fingerprint").validate[String] + path <- (json \ "path").validate[String] + } yield PsbtBIP32Deriv(pubkey = pubkey, + masterFingerprint = masterFingerprint, + path = path) + } + + implicit object RpcPsbtScriptReads extends Reads[RpcPsbtScript] { + override def reads(json: JsValue): JsResult[RpcPsbtScript] = + for { + asm <- (json \ "asm").validate[String] + hex <- (json \ "hex").validate[ScriptPubKey] + scriptType <- (json \ "type").validateOpt[ScriptType] + address <- (json \ "address").validateOpt[BitcoinAddress] + } yield RpcPsbtScript(asm = asm, + hex = hex, + scriptType = scriptType, + address = address) + } + + implicit object MapPubKeySignatureReads + extends Reads[Map[ECPublicKey, ECDigitalSignature]] { + override def reads( + json: JsValue): JsResult[Map[ECPublicKey, ECDigitalSignature]] = + JsonReaders.mapReads(json)(implicitly[Reads[ECPublicKey]], + implicitly[Reads[ECDigitalSignature]]) + } + + implicit object RpcPsbtInputReads extends Reads[RpcPsbtInput] { + override def reads(json: JsValue): JsResult[RpcPsbtInput] = + for { + nonWitnessUtxo <- (json \ "non_witness_utxo") + .validateOpt[RpcTransaction] + witnessUtxo <- (json \ "witness_utxo").validateOpt[PsbtWitnessUtxoInput] + finalScriptSig <- (json \ "final_scriptSig").validateOpt[RpcPsbtScript] + redeemScript <- (json \ "redeem_script").validateOpt[RpcPsbtScript] + sighash <- (json \ "sighash").validateOpt[HashType] + partialSignatures <- (json \ "partial_signatures") + .validateOpt[Map[ECPublicKey, ECDigitalSignature]] + witnessScript <- (json \ "witness_script").validateOpt[RpcPsbtScript] + bip32Derivs <- (json \ "bi32_derivs") + .validateOpt[Vector[PsbtBIP32Deriv]] + finalScriptWitness <- JsSuccess(None) // todo(torkelrogstad) find an example of this + unknown <- (json \ "unknown").validateOpt[Map[String, String]] + } yield { + bitcoind.RpcPsbtInput( + nonWitnessUtxo = nonWitnessUtxo, + witnessUtxo = witnessUtxo, + partialSignatures = partialSignatures, + sighash = sighash, + redeemScript = redeemScript, + witnessScript = witnessScript, + bip32Derivs = bip32Derivs, + finalScriptSig = finalScriptSig, + finalScriptwitness = finalScriptWitness, + unknown = unknown + ) + } + + } + + implicit object ScriptTypeReads extends Reads[ScriptType] { + override def reads(json: JsValue): JsResult[ScriptType] = + json + .validate[String] + .map(ScriptType.fromStringExn) + } + + implicit object TestMempoolAcceptResultReads + extends Reads[TestMempoolAcceptResult] { + override def reads(json: JsValue): JsResult[TestMempoolAcceptResult] = + for { + txid <- (json \ "txid").validate[DoubleSha256DigestBE] + allowed <- (json \ "allowed").validate[Boolean] + rejectReason <- (json \ "reject-reason").validateOpt[String] + } yield TestMempoolAcceptResult(txid, allowed, rejectReason) + } + + // Currently takes in BTC/kB + implicit object BitcoinFeeUnitReads extends Reads[BitcoinFeeUnit] { + override def reads(json: JsValue): JsResult[BitcoinFeeUnit] = + SerializerUtil.processJsNumber[BitcoinFeeUnit](num => + SatoshisPerByte(Satoshis((num * 100000).toBigInt)))(json) + } + + implicit object FileReads extends Reads[File] { + override def reads(json: JsValue): JsResult[File] = + SerializerUtil.processJsString[File](new File(_))(json) + } + + implicit object URIReads extends Reads[URI] { + override def reads(json: JsValue): JsResult[URI] = + SerializerUtil.processJsString[URI](str => new URI("http://" + str))(json) + } + + implicit object NetworkParamsReads extends Reads[NetworkParameters] { + + def reads(json: JsValue): JsResult[NetworkParameters] = + json.validate[String].map(_.toLowerCase()).map { + case "regtest" => RegTest + case "main" => MainNet + case "test" => TestNet3 + } + } + + implicit object ServiceIdentifierReads extends Reads[ServiceIdentifier] { + override def reads(json: JsValue): JsResult[ServiceIdentifier] = + json match { + case JsString(s) => + Try(ServiceIdentifier.fromString(s)) match { + case Success(serviceIdentifier) => JsSuccess(serviceIdentifier) + case Failure(err) => + SerializerUtil.buildJsErrorMsg( + s"Unexpected Service Identifier: $err", + json) + } + case err @ (JsNull | _: JsBoolean | _: JsNumber | _: JsArray | + _: JsObject) => + SerializerUtil.buildJsErrorMsg("jsstring", err) + } + } implicit val feeProportionalMillionthsReads: Reads[ FeeProportionalMillionths] = Reads { js => diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonSerializers.scala similarity index 90% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala rename to app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonSerializers.scala index 73cc3249df..127fdd03ea 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonSerializers.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.serializers +package org.bitcoins.commons.serializers import java.io.File import java.net.{InetAddress, URI} @@ -22,11 +22,105 @@ import org.bitcoins.core.protocol.{ } import org.bitcoins.core.script.ScriptType import org.bitcoins.core.wallet.fee.{BitcoinFeeUnit, SatoshisPerKiloByte} -import org.bitcoins.rpc.client.common.RpcOpts.AddressType -import org.bitcoins.rpc.jsonmodels._ -import org.bitcoins.rpc.serializers.JsonReaders._ -import org.bitcoins.rpc.serializers.JsonWriters._ +import org.bitcoins.commons.serializers.JsonReaders._ +import org.bitcoins.commons.serializers.JsonWriters._ import java.time.LocalDateTime + +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType +import org.bitcoins.commons.jsonmodels.bitcoind.{ + AddressInfoResult, + AnalyzePsbtInput, + AnalyzePsbtResult, + ArrayOfWalletsInput, + BalanceInfo, + Bip9Softfork, + BlockTransaction, + BumpFeeResult, + ChainTip, + CreateWalletResult, + DecodePsbtResult, + DecodeScriptResult, + DeriveAddressesResult, + DumpWalletResult, + EmbeddedResult, + EstimateSmartFeeResult, + FeeInfo, + FinalizePsbtResult, + FinalizedPsbt, + FundRawTransactionResult, + GetBalancesResult, + GetBlockChainInfoResult, + GetBlockHeaderResult, + GetBlockResult, + GetBlockTemplateResult, + GetBlockWithTransactionsResult, + GetChainTxStatsResult, + GetDescriptorInfoResult, + GetMemPoolEntryResultPostV19, + GetMemPoolEntryResultPreV19, + GetMemPoolInfoResult, + GetMemPoolResultPostV19, + GetMemPoolResultPreV19, + GetMemoryInfoResult, + GetMiningInfoResult, + GetNetTotalsResult, + GetNetworkInfoResult, + GetNodeAddressesResult, + GetRawTransactionResult, + GetRawTransactionScriptSig, + GetRawTransactionVin, + GetRpcInfoResult, + GetTransactionResult, + GetTxOutResult, + GetTxOutSetInfoResult, + GetWalletInfoResult, + ImportMultiError, + ImportMultiResult, + LabelResult, + ListSinceBlockResult, + ListTransactionsResult, + ListWalletDirResult, + MemoryManager, + MultiSigResult, + NetTarget, + Network, + NetworkAddress, + Node, + NodeAddress, + NodeBan, + NonFinalizedPsbt, + Payment, + Peer, + PeerNetworkInfo, + PsbtBIP32Deriv, + PsbtMissingData, + PsbtWitnessUtxoInput, + ReceivedAccount, + ReceivedAddress, + ReceivedLabel, + RescanBlockChainResult, + RpcAccount, + RpcAddress, + RpcCommands, + RpcPsbtInput, + RpcPsbtOutput, + RpcPsbtScript, + RpcScriptPubKey, + RpcTransaction, + RpcTransactionOutput, + SetWalletFlagResult, + SignRawTransactionError, + SignRawTransactionResult, + Softfork, + SoftforkProgress, + SubmitHeaderResult, + TestMempoolAcceptResult, + TransactionDetails, + UnspentOutput, + ValidateAddressResultImpl, + WalletCreateFundedPsbtResult, + WalletProcessPsbtResult +} import play.api.libs.functional.syntax._ import play.api.libs.json._ @@ -75,6 +169,7 @@ object JsonSerializers { implicit val scriptSignatureReads: Reads[ScriptSignature] = ScriptSignatureReads + implicit val addressTypeWrites: Writes[AddressType] = AddressTypeWrites implicit val bitcoinsWrites: Writes[Bitcoins] = BitcoinsWrites implicit val bitcoinAddressWrites: Writes[BitcoinAddress] = BitcoinAddressWrites @@ -225,8 +320,6 @@ object JsonSerializers { implicit val getTxOutSetInfoResultReads: Reads[GetTxOutSetInfoResult] = Json.reads[GetTxOutSetInfoResult] - implicit val addressTypeWrites: Writes[AddressType] = AddressTypeWrites - implicit object Bip32PathFormats extends Format[BIP32Path] { override def reads(json: JsValue): JsResult[BIP32Path] = json.validate[String].map(BIP32Path.fromString) diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonWriters.scala b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonWriters.scala similarity index 97% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonWriters.scala rename to app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonWriters.scala index 148502411c..17f993eee9 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonWriters.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/serializers/JsonWriters.scala @@ -1,5 +1,9 @@ -package org.bitcoins.rpc.serializers +package org.bitcoins.commons.serializers +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddressType, + WalletCreateFundedPsbtOptions +} import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.number.UInt32 @@ -9,10 +13,6 @@ import org.bitcoins.core.protocol.script.ScriptPubKey import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput} import org.bitcoins.core.script.crypto._ import org.bitcoins.core.util.BitcoinSUtil -import org.bitcoins.rpc.client.common.RpcOpts.{ - AddressType, - WalletCreateFundedPsbtOptions -} import play.api.libs.json._ import scala.collection.mutable diff --git a/app/picklers/src/main/scala/org/bitcoins/picklers/Picklers.scala b/app-commons/src/main/scala/org/bitcoins/commons/serializers/Picklers.scala similarity index 92% rename from app/picklers/src/main/scala/org/bitcoins/picklers/Picklers.scala rename to app-commons/src/main/scala/org/bitcoins/commons/serializers/Picklers.scala index 1d2c0de7c7..2b1394755c 100644 --- a/app/picklers/src/main/scala/org/bitcoins/picklers/Picklers.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/serializers/Picklers.scala @@ -1,18 +1,18 @@ -package org.bitcoins +package org.bitcoins.commons.serializers import org.bitcoins.core.crypto.ExtPublicKey -import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp} import org.bitcoins.core.currency.{Bitcoins, Satoshis} import org.bitcoins.core.protocol.transaction.Transaction +import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp} import org.bitcoins.core.psbt.PSBT import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte import upickle.default._ -package object picklers { +object Picklers { import org.bitcoins.core.crypto.DoubleSha256DigestBE implicit val bitcoinAddressPickler: ReadWriter[BitcoinAddress] = readwriter[String] - .bimap(_.value, BitcoinAddress.fromStringExn(_)) + .bimap(_.value, BitcoinAddress.fromStringExn) implicit val bitcoinsPickler: ReadWriter[Bitcoins] = readwriter[Double].bimap(_.toBigDecimal.toDouble, Bitcoins(_)) diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/SerializerUtil.scala b/app-commons/src/main/scala/org/bitcoins/commons/serializers/SerializerUtil.scala similarity index 98% rename from bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/SerializerUtil.scala rename to app-commons/src/main/scala/org/bitcoins/commons/serializers/SerializerUtil.scala index f16d16efdc..f4952920f9 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/SerializerUtil.scala +++ b/app-commons/src/main/scala/org/bitcoins/commons/serializers/SerializerUtil.scala @@ -1,4 +1,4 @@ -package org.bitcoins.rpc.serializers +package org.bitcoins.commons.serializers import play.api.libs.json._ 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 4bdb54a860..380266e0c5 100644 --- a/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala +++ b/app/cli/src/main/scala/org/bitcoins/cli/ConsoleCli.scala @@ -8,7 +8,7 @@ import org.bitcoins.core.protocol.transaction.{EmptyTransaction, Transaction} import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp} import org.bitcoins.core.psbt.PSBT import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte -import org.bitcoins.picklers._ +import org.bitcoins.commons.serializers.Picklers._ import scopt.OParser import ujson.{Num, Str} import upickle.{default => up} diff --git a/app/server/src/main/scala/org/bitcoins/server/ChainRoutes.scala b/app/server/src/main/scala/org/bitcoins/server/ChainRoutes.scala index f8d8a0be02..df5954ae36 100644 --- a/app/server/src/main/scala/org/bitcoins/server/ChainRoutes.scala +++ b/app/server/src/main/scala/org/bitcoins/server/ChainRoutes.scala @@ -6,7 +6,7 @@ import akka.http.scaladsl.server.Directives._ import akka.stream.ActorMaterializer import org.bitcoins.chain.api.ChainApi -import org.bitcoins.picklers._ +import org.bitcoins.commons.serializers.Picklers._ case class ChainRoutes(chain: ChainApi)(implicit system: ActorSystem) extends ServerRoute { diff --git a/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala b/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala index dcb6494a74..41c9f647eb 100644 --- a/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala +++ b/app/server/src/main/scala/org/bitcoins/server/WalletRoutes.scala @@ -7,7 +7,7 @@ import akka.stream.ActorMaterializer import org.bitcoins.core.currency._ import org.bitcoins.core.wallet.fee.SatoshisPerByte import org.bitcoins.node.Node -import org.bitcoins.picklers._ +import org.bitcoins.commons.serializers.Picklers._ import org.bitcoins.wallet.api.UnlockedWalletApi import scala.concurrent.Future diff --git a/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala b/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala index e5c5951e9c..203d6d0704 100644 --- a/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala +++ b/bench/src/main/scala/org/bitcoins/bench/eclair/EclairBench.scala @@ -4,8 +4,8 @@ import java.io.File import java.nio.file.{Files, StandardOpenOption} import akka.actor.ActorSystem +import org.bitcoins.commons.jsonmodels.eclair.PaymentId import org.bitcoins.core.protocol.ln.currency._ -import org.bitcoins.eclair.rpc.api.PaymentId import org.bitcoins.testkit.async.TestAsyncUtil import org.bitcoins.testkit.eclair.rpc.EclairRpcTestUtil diff --git a/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala b/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala index 0553ee17b6..7ead0d7afb 100644 --- a/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala +++ b/bench/src/main/scala/org/bitcoins/bench/eclair/PaymentLog.scala @@ -3,13 +3,13 @@ package org.bitcoins.bench.eclair import java.util.concurrent.ConcurrentHashMap import java.util.function.BiFunction -import org.bitcoins.core.crypto.Sha256Digest -import org.bitcoins.eclair.rpc.api.WebSocketEvent.{ +import org.bitcoins.commons.jsonmodels.eclair.{PaymentId, WebSocketEvent} +import org.bitcoins.commons.jsonmodels.eclair.WebSocketEvent.{ PaymentFailed, PaymentReceived, PaymentSent } -import org.bitcoins.eclair.rpc.api.{PaymentId, WebSocketEvent} +import org.bitcoins.core.crypto.Sha256Digest import scala.concurrent.Promise diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/BlockchainRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/BlockchainRpcTest.scala index 7fb38e6c92..f23d6a48c6 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/BlockchainRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/BlockchainRpcTest.scala @@ -1,15 +1,18 @@ package org.bitcoins.rpc.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddNodeArgument, + AddressType +} +import org.bitcoins.core.config.RegTest import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.number.UInt32 import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} -import org.bitcoins.rpc.client.common.RpcOpts.{AddNodeArgument, AddressType} import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest import scala.concurrent.Future -import org.bitcoins.core.config.RegTest class BlockchainRpcTest extends BitcoindRpcTest { diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MessageRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MessageRpcTest.scala index 2241b8354c..21cbf63083 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MessageRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MessageRpcTest.scala @@ -1,9 +1,9 @@ package org.bitcoins.rpc.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.protocol.P2PKHAddress import org.bitcoins.rpc.client.common.BitcoindRpcClient -import org.bitcoins.rpc.client.common.RpcOpts.AddressType import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MultisigRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MultisigRpcTest.scala index 68b3e420c4..a2897b3d8f 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MultisigRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/MultisigRpcTest.scala @@ -1,9 +1,9 @@ package org.bitcoins.rpc.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.protocol.P2PKHAddress import org.bitcoins.rpc.client.common.BitcoindRpcClient -import org.bitcoins.rpc.client.common.RpcOpts.AddressType import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/P2PRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/P2PRpcTest.scala index e8841aabef..db2ed5620d 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/P2PRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/P2PRpcTest.scala @@ -2,9 +2,12 @@ package org.bitcoins.rpc.common import java.net.URI +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddNodeArgument, + SetBanCommand +} import org.bitcoins.core.number.UInt32 import org.bitcoins.rpc.client.common.BitcoindRpcClient -import org.bitcoins.rpc.client.common.RpcOpts.{AddNodeArgument, SetBanCommand} import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/RawTransactionRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/RawTransactionRpcTest.scala index 5a0dc9710b..e0ff4e708c 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/RawTransactionRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/RawTransactionRpcTest.scala @@ -1,5 +1,6 @@ package org.bitcoins.rpc.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.number.UInt32 import org.bitcoins.core.protocol.script.{ @@ -11,12 +12,12 @@ import org.bitcoins.core.protocol.transaction.{ TransactionInput, TransactionOutPoint } -import org.bitcoins.rpc.client.common.{BitcoindRpcClient, RpcOpts} +import org.bitcoins.rpc.BitcoindException.InvalidAddressOrKey +import org.bitcoins.rpc.client.common.BitcoindRpcClient import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest import scala.concurrent.Future -import org.bitcoins.rpc.BitcoindException.InvalidAddressOrKey class RawTransactionRpcTest extends BitcoindRpcTest { lazy val clientsF: Future[(BitcoindRpcClient, BitcoindRpcClient)] = diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UTXORpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UTXORpcTest.scala index 803dc1ddb2..fb058307b7 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UTXORpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UTXORpcTest.scala @@ -1,6 +1,7 @@ package org.bitcoins.rpc.common -import org.bitcoins.rpc.client.common.{BitcoindRpcClient, RpcOpts} +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts +import org.bitcoins.rpc.client.common.BitcoindRpcClient import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UtilRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UtilRpcTest.scala index 446192707e..bac132ee6d 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UtilRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/UtilRpcTest.scala @@ -1,10 +1,10 @@ package org.bitcoins.rpc.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.protocol.P2PKHAddress import org.bitcoins.core.script.ScriptType import org.bitcoins.rpc.client.common.BitcoindRpcClient -import org.bitcoins.rpc.client.common.RpcOpts.AddressType import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala index 039d8fc9e8..7fc26fbd47 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala @@ -3,6 +3,7 @@ package org.bitcoins.rpc.common import java.io.File import java.util.Scanner +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts import org.bitcoins.core.crypto.{ DoubleSha256DigestBE, ECPrivateKey, @@ -17,12 +18,8 @@ import org.bitcoins.core.protocol.transaction.{ } import org.bitcoins.core.protocol.{BitcoinAddress, P2PKHAddress} import org.bitcoins.core.wallet.fee.SatoshisPerByte -import org.bitcoins.rpc.client.common.RpcOpts.AddressType -import org.bitcoins.rpc.client.common.{ - BitcoindRpcClient, - BitcoindVersion, - RpcOpts -} +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType +import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} import org.bitcoins.rpc.util.RpcUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v16/BitcoindV16RpcClientTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v16/BitcoindV16RpcClientTest.scala index e893f09833..3b1f9274a9 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v16/BitcoindV16RpcClientTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v16/BitcoindV16RpcClientTest.scala @@ -1,5 +1,6 @@ package org.bitcoins.rpc.v16 +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.SignRawTransactionOutputParameter import org.bitcoins.core.crypto.{DoubleSha256DigestBE, ECPrivateKey} import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.number.UInt32 @@ -10,7 +11,7 @@ import org.bitcoins.core.protocol.transaction.{ TransactionInput, TransactionOutPoint } -import org.bitcoins.rpc.client.common.RpcOpts.SignRawTransactionOutputParameter +import org.bitcoins.rpc.client.common.BitcoindVersion import org.bitcoins.rpc.client.v16.BitcoindV16RpcClient import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil @@ -20,7 +21,6 @@ import scala.async.Async.{async, await} import scala.concurrent.Future import scala.concurrent.duration.DurationInt import scala.util.Properties -import org.bitcoins.rpc.client.common.BitcoindVersion class BitcoindV16RpcClientTest extends BitcoindRpcTest { lazy val clientsF: Future[(BitcoindV16RpcClient, BitcoindV16RpcClient)] = diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala index 1d7108a49b..606ea1b275 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala @@ -1,5 +1,10 @@ package org.bitcoins.rpc.v17 +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddressType, + LabelPurpose, + SignRawTransactionOutputParameter +} import org.bitcoins.core.config.RegTest import org.bitcoins.core.crypto.{DoubleSha256DigestBE, ECPrivateKey} import org.bitcoins.core.currency.Bitcoins @@ -7,11 +12,6 @@ import org.bitcoins.core.number.UInt32 import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.script.ScriptPubKey import org.bitcoins.core.protocol.transaction.TransactionInput -import org.bitcoins.rpc.client.common.RpcOpts.{ - AddressType, - LabelPurpose, - SignRawTransactionOutputParameter -} import org.bitcoins.rpc.client.v17.BitcoindV17RpcClient import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala index 97c3462bde..cb494c6cfa 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala @@ -1,4 +1,8 @@ package org.bitcoins.rpc.v17 +import org.bitcoins.commons.jsonmodels.bitcoind.{ + FinalizedPsbt, + NonFinalizedPsbt +} import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.number.UInt32 import org.bitcoins.core.protocol.script.ScriptSignature @@ -7,9 +11,7 @@ import org.bitcoins.core.protocol.transaction.{ TransactionInput, TransactionOutPoint } -import org.bitcoins.rpc.client.common.RpcOpts.AddressType import org.bitcoins.rpc.client.v17.BitcoindV17RpcClient -import org.bitcoins.rpc.jsonmodels.{FinalizedPsbt, NonFinalizedPsbt} import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/BitcoindV18RpcClientTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/BitcoindV18RpcClientTest.scala index c5c77275a7..31b52c28b5 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/BitcoindV18RpcClientTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/BitcoindV18RpcClientTest.scala @@ -1,8 +1,8 @@ package org.bitcoins.rpc.v18 import org.bitcoins.chain.models.BlockHeaderDbHelper +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddNodeArgument import org.bitcoins.core.protocol.blockchain.RegTestNetChainParams import org.bitcoins.rpc.client.common.BitcoindVersion -import org.bitcoins.rpc.client.common.RpcOpts.AddNodeArgument import org.bitcoins.rpc.client.v18.BitcoindV18RpcClient import org.bitcoins.testkit.chain.BlockHeaderHelper import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v19/BitcoindV19RpcClientTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v19/BitcoindV19RpcClientTest.scala index 6c94fa3be5..d2fdc6cbde 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v19/BitcoindV19RpcClientTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v19/BitcoindV19RpcClientTest.scala @@ -1,7 +1,7 @@ package org.bitcoins.rpc.v19 +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.WalletFlag import org.bitcoins.core.gcs.{BlockFilter, FilterType} import org.bitcoins.rpc.client.common.BitcoindVersion -import org.bitcoins.rpc.client.common.RpcOpts.WalletFlag import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.util.BitcoindRpcTest diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BlockchainRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BlockchainRpc.scala index 3f89f55f39..440d6927bd 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BlockchainRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BlockchainRpc.scala @@ -1,9 +1,9 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader} -import org.bitcoins.rpc.jsonmodels._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsBoolean, JsNumber, JsString} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala index 6ac9eae180..eefa6a7fec 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala @@ -12,9 +12,8 @@ import org.bitcoins.core.config.{MainNet, NetworkParameters, RegTest, TestNet3} import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStop} import org.bitcoins.rpc.config.BitcoindInstance -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.rpc.util.AsyncUtil -import play.api.libs.json._ import scala.concurrent._ import scala.concurrent.duration.DurationInt @@ -26,8 +25,10 @@ import org.bitcoins.rpc.config.BitcoindAuthCredentials.CookieBased import org.bitcoins.rpc.config.BitcoindAuthCredentials.PasswordBased import java.nio.file.Path +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts import org.bitcoins.rpc.config.BitcoindAuthCredentials import org.bitcoins.rpc.BitcoindException +import play.api.libs.json._ /** * This is the base trait for Bitcoin Core diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/DescriptorRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/DescriptorRpc.scala index 2b860d55a5..b3b596a105 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/DescriptorRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/DescriptorRpc.scala @@ -1,11 +1,11 @@ package org.bitcoins.rpc.client.common -import org.bitcoins.rpc.jsonmodels.{ +import org.bitcoins.commons.jsonmodels.bitcoind.{ DeriveAddressesResult, GetDescriptorInfoResult } +import org.bitcoins.commons.serializers.JsonSerializers._ import play.api.libs.json.{JsString, Json} -import org.bitcoins.rpc.serializers.JsonSerializers._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MempoolRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MempoolRpc.scala index ada4206d7c..82b87bcb71 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MempoolRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MempoolRpc.scala @@ -1,18 +1,10 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.serializers.JsonReaders._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.rpc.client.common.BitcoindVersion._ -import org.bitcoins.rpc.jsonmodels.{ - GetMemPoolEntryResult, - GetMemPoolEntryResultPostV19, - GetMemPoolEntryResultPreV19, - GetMemPoolInfoResult, - GetMemPoolResult, - GetMemPoolResultPostV19, - GetMemPoolResultPreV19 -} -import org.bitcoins.rpc.serializers.JsonReaders._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsBoolean, JsString} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MiningRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MiningRpc.scala index 3a385d4b19..5185196c98 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MiningRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MiningRpc.scala @@ -1,11 +1,15 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.{ + GetBlockTemplateResult, + GetMiningInfoResult, + RpcOpts +} +import org.bitcoins.commons.serializers.JsonReaders._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.core.currency.Satoshis import org.bitcoins.core.protocol.BitcoinAddress -import org.bitcoins.rpc.jsonmodels.{GetBlockTemplateResult, GetMiningInfoResult} -import org.bitcoins.rpc.serializers.JsonReaders._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsNumber, JsString, Json} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MultisigRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MultisigRpc.scala index 241f9bbb99..6c9d378742 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MultisigRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/MultisigRpc.scala @@ -1,11 +1,11 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.MultiSigResult +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ import org.bitcoins.core.crypto.ECPublicKey import org.bitcoins.core.protocol.P2PKHAddress -import org.bitcoins.rpc.client.common.RpcOpts.AddressType -import org.bitcoins.rpc.jsonmodels.MultiSigResult -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ import play.api.libs.json.{JsArray, JsNumber, JsString, Json} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/NodeRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/NodeRpc.scala index c89cae6c9a..2e775fb7eb 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/NodeRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/NodeRpc.scala @@ -1,9 +1,9 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.GetMemoryInfoResult import org.bitcoins.core.number.UInt32 -import org.bitcoins.rpc.jsonmodels.GetMemoryInfoResult -import org.bitcoins.rpc.serializers.JsonReaders -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonReaders +import org.bitcoins.commons.serializers.JsonSerializers._ import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/P2PRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/P2PRpc.scala index 9645231ad6..19d032bf1b 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/P2PRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/P2PRpc.scala @@ -2,10 +2,13 @@ package org.bitcoins.rpc.client.common import java.net.URI +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddNodeArgument, + SetBanCommand +} +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.protocol.blockchain.Block -import org.bitcoins.rpc.client.common.RpcOpts.{AddNodeArgument, SetBanCommand} -import org.bitcoins.rpc.jsonmodels._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsBoolean, JsNumber, JsString} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/PsbtRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/PsbtRpc.scala index af27a04c63..688ff56919 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/PsbtRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/PsbtRpc.scala @@ -1,7 +1,7 @@ package org.bitcoins.rpc.client.common -import org.bitcoins.rpc.jsonmodels.AnalyzePsbtResult -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.jsonmodels.bitcoind.AnalyzePsbtResult +import org.bitcoins.commons.serializers.JsonSerializers._ import play.api.libs.json.{JsString, Json} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RawTransactionRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RawTransactionRpc.scala index 8b1635b411..6017492025 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RawTransactionRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/RawTransactionRpc.scala @@ -1,17 +1,18 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.{ + FundRawTransactionResult, + GetRawTransactionResult, + RpcOpts, + RpcTransaction +} +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ import org.bitcoins.core.crypto.DoubleSha256DigestBE import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput} import org.bitcoins.rpc.client.common.BitcoindVersion._ -import org.bitcoins.rpc.jsonmodels.{ - FundRawTransactionResult, - GetRawTransactionResult, - RpcTransaction -} -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/TransactionRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/TransactionRpc.scala index 216aad0fe8..0e6bc23199 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/TransactionRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/TransactionRpc.scala @@ -1,12 +1,15 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{ + AddressType, + FeeEstimationMode +} +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis} import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.blockchain.MerkleBlock -import org.bitcoins.rpc.client.common.RpcOpts.{AddressType, FeeEstimationMode} -import org.bitcoins.rpc.jsonmodels._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UTXORpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UTXORpc.scala index 6ccad0e533..215909b763 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UTXORpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UTXORpc.scala @@ -1,10 +1,10 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.{RpcOpts, UnspentOutput} +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.transaction.TransactionOutPoint -import org.bitcoins.rpc.jsonmodels.UnspentOutput -import org.bitcoins.rpc.serializers.JsonSerializers._ -import play.api.libs.json.{JsBoolean, JsNumber, Json} +import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UtilRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UtilRpc.scala index a3dae2ee4e..194bdc1368 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UtilRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/UtilRpc.scala @@ -1,13 +1,13 @@ package org.bitcoins.rpc.client.common -import org.bitcoins.core.protocol.BitcoinAddress -import org.bitcoins.core.protocol.script.ScriptPubKey -import org.bitcoins.rpc.jsonmodels.{ +import org.bitcoins.commons.jsonmodels.bitcoind.{ DecodeScriptResult, ValidateAddressResult, ValidateAddressResultImpl } -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.core.protocol.BitcoinAddress +import org.bitcoins.core.protocol.script.ScriptPubKey import play.api.libs.json.{JsString, Json} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/WalletRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/WalletRpc.scala index beb52e905c..fe0d58d538 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/WalletRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/WalletRpc.scala @@ -1,5 +1,6 @@ package org.bitcoins.rpc.client.common +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType import org.bitcoins.core.crypto.{ DoubleSha256Digest, DoubleSha256DigestBE, @@ -11,9 +12,9 @@ import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.blockchain.MerkleBlock import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.rpc.client.common.BitcoindVersion._ -import org.bitcoins.rpc.client.common.RpcOpts.AddressType -import org.bitcoins.rpc.jsonmodels._ -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.jsonmodels.bitcoind._ +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/BitcoindV16RpcClient.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/BitcoindV16RpcClient.scala index 6431e627c5..8adfeba9a3 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/BitcoindV16RpcClient.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/BitcoindV16RpcClient.scala @@ -1,18 +1,17 @@ package org.bitcoins.rpc.client.v16 import akka.actor.ActorSystem +import org.bitcoins.commons.jsonmodels.bitcoind.{ + RpcOpts, + SignRawTransactionResult +} +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.core.script.crypto.HashType -import org.bitcoins.rpc.client.common.{ - BitcoindRpcClient, - BitcoindVersion, - RpcOpts -} +import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} import org.bitcoins.rpc.config.BitcoindInstance -import org.bitcoins.rpc.jsonmodels.SignRawTransactionResult -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ import play.api.libs.json._ import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16AccountRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16AccountRpc.scala index 020034611f..506f4d24f8 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16AccountRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16AccountRpc.scala @@ -1,11 +1,11 @@ package org.bitcoins.rpc.client.v16 +import org.bitcoins.commons.jsonmodels.bitcoind.ReceivedAccount +import org.bitcoins.commons.serializers.JsonReaders._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.rpc.client.common.Client -import org.bitcoins.rpc.jsonmodels.ReceivedAccount -import org.bitcoins.rpc.serializers.JsonReaders._ -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsBoolean, JsNumber, JsString} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16SendRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16SendRpc.scala index 77916fbcef..3688afc34f 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16SendRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v16/V16SendRpc.scala @@ -1,16 +1,14 @@ package org.bitcoins.rpc.client.v16 +import org.bitcoins.commons.serializers.JsonReaders._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.DoubleSha256DigestBE -import org.bitcoins.core.currency.Bitcoins +import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit} import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.rpc.client.common.Client -import org.bitcoins.rpc.serializers.JsonReaders._ -import org.bitcoins.rpc.serializers.JsonSerializers._ -import play.api.libs.json.{JsNumber, JsString} +import play.api.libs.json.{JsNumber, JsString, Json} import scala.concurrent.Future -import org.bitcoins.core.currency.CurrencyUnit -import play.api.libs.json.Json /** * RPC calls related to transaction sending diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/BitcoindV17RpcClient.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/BitcoindV17RpcClient.scala index eda6d6746a..50d18d551f 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/BitcoindV17RpcClient.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/BitcoindV17RpcClient.scala @@ -1,22 +1,19 @@ package org.bitcoins.rpc.client.v17 import akka.actor.ActorSystem -import org.bitcoins.core.crypto.ECPrivateKey -import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.script.crypto.HashType -import org.bitcoins.rpc.client.common.{ - BitcoindRpcClient, - BitcoindVersion, - RpcOpts -} -import org.bitcoins.rpc.config.BitcoindInstance -import org.bitcoins.rpc.jsonmodels.{ +import org.bitcoins.commons.jsonmodels.bitcoind.{ + RpcOpts, SignRawTransactionResult, TestMempoolAcceptResult } -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ -import play.api.libs.json.{JsArray, JsBoolean, JsString, Json} +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ +import org.bitcoins.core.crypto.ECPrivateKey +import org.bitcoins.core.protocol.transaction.Transaction +import org.bitcoins.core.script.crypto.HashType +import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} +import org.bitcoins.rpc.config.BitcoindInstance +import play.api.libs.json._ import scala.concurrent.Future import scala.util.Try diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/V17LabelRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/V17LabelRpc.scala index 1a73e2d0c6..286e048ccc 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/V17LabelRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v17/V17LabelRpc.scala @@ -1,11 +1,11 @@ package org.bitcoins.rpc.client.v17 +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.LabelPurpose +import org.bitcoins.commons.jsonmodels.bitcoind.{LabelResult, ReceivedLabel} +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.currency.Bitcoins import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.rpc.client.common.Client -import org.bitcoins.rpc.client.common.RpcOpts.LabelPurpose -import org.bitcoins.rpc.jsonmodels.{LabelResult, ReceivedLabel} -import org.bitcoins.rpc.serializers.JsonSerializers._ import play.api.libs.json.{JsBoolean, JsNumber, JsString} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/BitcoindV18RpcClient.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/BitcoindV18RpcClient.scala index 4d8c77d017..a1c7e01cc3 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/BitcoindV18RpcClient.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/BitcoindV18RpcClient.scala @@ -1,31 +1,25 @@ package org.bitcoins.rpc.client.v18 import akka.actor.ActorSystem +import org.bitcoins.commons.jsonmodels.bitcoind.{ + RpcOpts, + SignRawTransactionResult +} +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ +import org.bitcoins.core.crypto.ECPrivateKey +import org.bitcoins.core.protocol.transaction.Transaction +import org.bitcoins.core.script.crypto.HashType import org.bitcoins.rpc.client.common.{ BitcoindRpcClient, BitcoindVersion, DescriptorRpc, - RpcOpts -} -import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} -import org.bitcoins.rpc.client.common.{ - BitcoindRpcClient, - BitcoindVersion, - PsbtRpc, - RpcOpts + PsbtRpc } import org.bitcoins.rpc.config.BitcoindInstance - -import scala.util.Try -import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.crypto.ECPrivateKey -import org.bitcoins.core.script.crypto.HashType -import org.bitcoins.rpc.jsonmodels.SignRawTransactionResult -import play.api.libs.json.Json -import play.api.libs.json.JsString +import play.api.libs.json._ import scala.concurrent.Future -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ +import scala.util.Try /** * Class for creating a BitcoindV18 instance that can access RPCs diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/V18AssortedRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/V18AssortedRpc.scala index 67e6895faf..de99de76cd 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/V18AssortedRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v18/V18AssortedRpc.scala @@ -1,12 +1,12 @@ package org.bitcoins.rpc.client.v18 -import org.bitcoins.core.protocol.blockchain.BlockHeader -import org.bitcoins.rpc.client.common.Client -import org.bitcoins.rpc.jsonmodels.{ +import org.bitcoins.commons.jsonmodels.bitcoind.{ GetNodeAddressesResult, GetRpcInfoResult, ListWalletDirResult } -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.core.protocol.blockchain.BlockHeader +import org.bitcoins.rpc.client.common.Client import play.api.libs.json.{JsString, Json} import scala.concurrent.Future diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/BitcoindV19RpcClient.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/BitcoindV19RpcClient.scala index 7d66041dee..4715fbdadf 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/BitcoindV19RpcClient.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/BitcoindV19RpcClient.scala @@ -1,27 +1,26 @@ package org.bitcoins.rpc.client.v19 import akka.actor.ActorSystem +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.WalletFlag +import org.bitcoins.commons.jsonmodels.bitcoind.{ + GetBalancesResult, + RpcOpts, + SetWalletFlagResult, + SignRawTransactionResult +} +import org.bitcoins.commons.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonWriters._ import org.bitcoins.core.crypto.ECPrivateKey import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.core.script.crypto.HashType -import org.bitcoins.rpc.client.common.RpcOpts.WalletFlag import org.bitcoins.rpc.client.common.{ BitcoindRpcClient, BitcoindVersion, DescriptorRpc, - PsbtRpc, - RpcOpts + PsbtRpc } import org.bitcoins.rpc.config.BitcoindInstance -import org.bitcoins.rpc.jsonmodels.{ - GetBalancesResult, - SetWalletFlagResult, - SignRawTransactionResult -} -import play.api.libs.json.Json -import play.api.libs.json.JsString -import org.bitcoins.rpc.serializers.JsonSerializers._ -import org.bitcoins.rpc.serializers.JsonWriters._ +import play.api.libs.json._ import scala.concurrent.Future import scala.util.Try diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/V19BlockFilterRpc.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/V19BlockFilterRpc.scala index d10202cd64..a76ee8c46a 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/V19BlockFilterRpc.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/v19/V19BlockFilterRpc.scala @@ -1,10 +1,10 @@ package org.bitcoins.rpc.client.v19 +import org.bitcoins.commons.jsonmodels.bitcoind.GetBlockFilterResult +import org.bitcoins.commons.serializers.JsonReaders.DoubleSha256DigestBEReads import org.bitcoins.core.crypto.DoubleSha256DigestBE import org.bitcoins.core.gcs.{BlockFilter, FilterType} import org.bitcoins.rpc.client.common.Client -import org.bitcoins.rpc.jsonmodels.GetBlockFilterResult -import org.bitcoins.rpc.serializers.JsonReaders.DoubleSha256DigestBEReads import play.api.libs.json._ import scala.concurrent.Future diff --git a/build.sbt b/build.sbt index e21b89e3d3..8a66130402 100644 --- a/build.sbt +++ b/build.sbt @@ -30,7 +30,12 @@ lazy val benchSettings: Seq[Def.SettingsDefinition] = { import Projects._ lazy val core = project in file("core") -lazy val bitcoindRpc = project in file("bitcoind-rpc") +lazy val bitcoindRpc = project + .in(file("bitcoind-rpc")) + .settings(CommonSettings.prodSettings: _*) + .dependsOn( + appCommons + ) lazy val eclairRpc = project in file("eclair-rpc") // quoting the val name this way makes it appear as @@ -57,7 +62,6 @@ lazy val `bitcoin-s` = project keyManagerTest, node, nodeTest, - picklers, wallet, walletTest, appServer, @@ -201,11 +205,18 @@ lazy val coreTest = project testkit ) +lazy val appCommons = project + .in(file("app-commons")) + .settings(CommonSettings.prodSettings: _*) + .dependsOn( + core % testAndCompile + ) + lazy val appServer = project .in(file("app/server")) .settings(CommonSettings.prodSettings: _*) .dependsOn( - picklers, + appCommons, node, chain, wallet, @@ -221,18 +232,11 @@ lazy val appServerTest = project testkit ) -// internal picklers used by server -// and CLI -lazy val picklers = project - .in(file("app/picklers")) - .settings(CommonSettings.prodSettings: _*) - .dependsOn(core % testAndCompile) - lazy val cli = project .in(file("app/cli")) .settings(CommonSettings.prodSettings: _*) .dependsOn( - picklers + appCommons ) lazy val cliTest = project diff --git a/chain-test/src/test/scala/org/bitcoins/chain/blockchain/ChainHandlerTest.scala b/chain-test/src/test/scala/org/bitcoins/chain/blockchain/ChainHandlerTest.scala index f559975377..ea38763dd0 100644 --- a/chain-test/src/test/scala/org/bitcoins/chain/blockchain/ChainHandlerTest.scala +++ b/chain-test/src/test/scala/org/bitcoins/chain/blockchain/ChainHandlerTest.scala @@ -51,7 +51,7 @@ class ChainHandlerTest extends ChainUnitTest { val arrStr = source.getLines.next source.close() - import org.bitcoins.rpc.serializers.JsonReaders.BlockHeaderReads + import org.bitcoins.commons.serializers.JsonReaders.BlockHeaderReads val headersResult: Vector[BlockHeader] = Json.parse(arrStr).validate[Vector[BlockHeader]].get @@ -82,7 +82,7 @@ class ChainHandlerTest extends ChainUnitTest { val arrStr = source.getLines.next source.close() - import org.bitcoins.rpc.serializers.JsonReaders.BlockHeaderReads + import org.bitcoins.commons.serializers.JsonReaders.BlockHeaderReads val headersResult = Json.parse(arrStr).validate[Vector[BlockHeader]] if (headersResult.isError) { fail(headersResult.toString) diff --git a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala index 9232d8a2b6..092b6e4df0 100644 --- a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala +++ b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala @@ -3,6 +3,15 @@ package org.bitcoins.eclair.rpc import java.nio.file.Files import java.time.Instant +import org.bitcoins.commons.jsonmodels.eclair.{ + ChannelResult, + ChannelUpdate, + IncomingPaymentStatus, + InvoiceResult, + OpenChannelInfo, + OutgoingPaymentStatus, + WebSocketEvent +} import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits, Satoshis} import org.bitcoins.core.number.UInt64 import org.bitcoins.core.protocol.BitcoinAddress diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairApi.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairApi.scala index 78b3d39b54..07c459b215 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairApi.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/api/EclairApi.scala @@ -3,6 +3,25 @@ package org.bitcoins.eclair.rpc.api import java.net.InetSocketAddress import java.time.Instant +import org.bitcoins.commons.jsonmodels.eclair.{ + AuditResult, + ChannelDesc, + ChannelInfo, + ChannelResult, + ChannelStats, + ChannelUpdate, + GetInfoResult, + IncomingPayment, + InvoiceResult, + NetworkFeesResult, + NodeInfo, + OutgoingPayment, + PaymentId, + PeerInfo, + SendToRouteResult, + UsableBalancesResult, + WebSocketEvent +} import org.bitcoins.core.crypto.Sha256Digest import org.bitcoins.core.currency.{CurrencyUnit, Satoshis} import org.bitcoins.core.protocol.ln.channel.{ChannelId, FundedChannelId} diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala index 1742f3abfa..5480322e4d 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala @@ -16,6 +16,8 @@ import akka.http.scaladsl.model.ws.{Message, TextMessage, WebSocketRequest} import akka.stream.ActorMaterializer import akka.stream.scaladsl.{Flow, Sink, Source} import akka.util.ByteString +import org.bitcoins.commons.jsonmodels.eclair._ +import org.bitcoins.commons.serializers.JsonReaders._ import org.bitcoins.core.crypto.Sha256Digest import org.bitcoins.core.currency.{CurrencyUnit, Satoshis} import org.bitcoins.core.protocol.ln.channel.{ChannelId, FundedChannelId} @@ -33,8 +35,7 @@ import org.bitcoins.core.util.{BitcoinSUtil, FutureUtil, StartStop} import org.bitcoins.core.wallet.fee.SatoshisPerByte import org.bitcoins.eclair.rpc.api._ import org.bitcoins.eclair.rpc.config.EclairInstance -import org.bitcoins.eclair.rpc.network.{NodeUri, PeerState} -import org.bitcoins.rpc.serializers.JsonReaders._ +import org.bitcoins.eclair.rpc.network.NodeUri import org.bitcoins.rpc.util.AsyncUtil import org.slf4j.LoggerFactory import play.api.libs.json._ @@ -52,7 +53,6 @@ class EclairRpcClient(val instance: EclairInstance, binary: Option[File] = None) implicit system: ActorSystem) extends EclairApi with StartStop[EclairRpcClient] { - import JsonReaders._ implicit val m = ActorMaterializer.create(system) private val logger = LoggerFactory.getLogger(this.getClass) diff --git a/project/Deps.scala b/project/Deps.scala index 2d010ed334..444494d46a 100644 --- a/project/Deps.scala +++ b/project/Deps.scala @@ -71,10 +71,10 @@ object Deps { val scalaFx = "org.scalafx" %% "scalafx" % V.scalaFxV withSources () withJavadoc () lazy val osName = System.getProperty("os.name") match { - case n if n.startsWith("Linux") => "linux" - case n if n.startsWith("Mac") => "mac" + case n if n.startsWith("Linux") => "linux" + case n if n.startsWith("Mac") => "mac" case n if n.startsWith("Windows") => "win" - case _ => throw new Exception("Unknown platform!") + case _ => throw new Exception("Unknown platform!") } // Not sure if all of these are needed, some might be possible to remove lazy val javaFxBase = "org.openjfx" % s"javafx-base" % V.javaFxV classifier osName withSources () withJavadoc () @@ -84,7 +84,13 @@ object Deps { lazy val javaFxMedia = "org.openjfx" % s"javafx-media" % V.javaFxV classifier osName withSources () withJavadoc () lazy val javaFxSwing = "org.openjfx" % s"javafx-swing" % V.javaFxV classifier osName withSources () withJavadoc () lazy val javaFxWeb = "org.openjfx" % s"javafx-web" % V.javaFxV classifier osName withSources () withJavadoc () - lazy val javaFxDeps = List(javaFxBase, javaFxControls, javaFxFxml, javaFxGraphics, javaFxMedia, javaFxSwing, javaFxWeb) + lazy val javaFxDeps = List(javaFxBase, + javaFxControls, + javaFxFxml, + javaFxGraphics, + javaFxMedia, + javaFxSwing, + javaFxWeb) val playJson = "com.typesafe.play" %% "play-json" % V.playv withSources () withJavadoc () val typesafeConfig = "com.typesafe" % "config" % V.typesafeConfigV withSources () withJavadoc () @@ -122,7 +128,7 @@ object Deps { val scalacheck = "org.scalacheck" %% "scalacheck" % V.scalacheck withSources () withJavadoc () val scalaTest = "org.scalatest" %% "scalatest" % V.scalaTest withSources () withJavadoc () - val scalaTestPlus = "org.scalatestplus" %% "scalacheck-1-14" % V.scalaTestPlus withSources() withJavadoc() + val scalaTestPlus = "org.scalatestplus" %% "scalacheck-1-14" % V.scalaTestPlus withSources () withJavadoc () } object Test { @@ -147,6 +153,13 @@ object Deps { val chainTest = List() + def appCommons(scalaVersion: String) = List( + if (scalaVersion.startsWith("2.11")) Compile.oldMicroPickle + else Compile.newMicroPickle, + Compile.playJson, + Compile.slf4j + ) + val core = List( Compile.bouncycastle, Compile.scodec, @@ -177,8 +190,6 @@ object Deps { val bitcoindRpc = List( Compile.akkaHttp, Compile.akkaStream, - Compile.playJson, - Compile.slf4j, Compile.typesafeConfig ) @@ -203,7 +214,6 @@ object Deps { Compile.logback, Compile.sqlite, Compile.slickHikari, - Test.scalaTest ) @@ -221,11 +231,6 @@ object Deps { val gui = List(Compile.scalaFx) ++ Compile.javaFxDeps - def picklers(scalaVersion: String) = List( - if (scalaVersion.startsWith("2.11")) Compile.oldMicroPickle - else Compile.newMicroPickle - ) - def server(scalaVersion: String) = List( if (scalaVersion.startsWith("2.11")) Compile.oldMicroPickle else Compile.newMicroPickle, @@ -272,7 +277,7 @@ object Deps { def keyManager(scalaVersion: String) = List( if (scalaVersion.startsWith("2.11")) Compile.oldMicroJson - else Compile.newMicroJson, + else Compile.newMicroJson ) val keyManagerTest = List( diff --git a/testkit/src/main/scala/org/bitcoins/testkit/chain/ChainUnitTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/chain/ChainUnitTest.scala index e2c64b00c9..a1a0fa1470 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/chain/ChainUnitTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/chain/ChainUnitTest.scala @@ -348,7 +348,7 @@ object ChainUnitTest extends ChainVerificationLogger { val arrStr = source.getLines.next source.close() - import org.bitcoins.rpc.serializers.JsonReaders.BlockHeaderReads + import org.bitcoins.commons.serializers.JsonReaders.BlockHeaderReads val headersResult = Json.parse(arrStr).validate[Vector[BlockHeader]] headersResult match { diff --git a/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala index 1332327e64..58a73e88bc 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala @@ -10,7 +10,7 @@ import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader} import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil} import org.bitcoins.rpc.client.common.BitcoindRpcClient import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient -import org.bitcoins.rpc.jsonmodels.GetBlockFilterResult +import org.bitcoins.commons.jsonmodels.bitcoind.GetBlockFilterResult import org.bitcoins.wallet.Wallet import scala.concurrent.{ExecutionContext, Future} diff --git a/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala index 13b9b78e2c..b58b62a0e0 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala @@ -6,6 +6,12 @@ import java.nio.file.Files import akka.actor.ActorSystem import com.typesafe.config.{Config, ConfigFactory} +import org.bitcoins.commons.jsonmodels.eclair.{ + IncomingPaymentStatus, + OutgoingPayment, + OutgoingPaymentStatus, + PaymentId +} import org.bitcoins.core.compat.JavaConverters._ import org.bitcoins.core.config.RegTest import org.bitcoins.core.crypto.Sha256Digest diff --git a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala index 7344dd636f..f5a7c12d86 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala @@ -6,6 +6,13 @@ import java.nio.file.{Files, Path, Paths} import akka.actor.ActorSystem import akka.stream.ActorMaterializer +import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddNodeArgument +import org.bitcoins.commons.jsonmodels.bitcoind.{ + GetBlockWithTransactionsResult, + GetTransactionResult, + RpcOpts, + SignRawTransactionResult +} import org.bitcoins.core.compat.JavaConverters._ import org.bitcoins.core.config.RegTest import org.bitcoins.core.crypto.{ @@ -31,12 +38,7 @@ import org.bitcoins.rpc.client.common.BitcoindVersion.{ V18, _ } -import org.bitcoins.rpc.client.common.RpcOpts.AddNodeArgument -import org.bitcoins.rpc.client.common.{ - BitcoindRpcClient, - BitcoindVersion, - RpcOpts -} +import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} import org.bitcoins.rpc.client.v16.BitcoindV16RpcClient import org.bitcoins.rpc.client.v17.BitcoindV17RpcClient import org.bitcoins.rpc.client.v18.BitcoindV18RpcClient @@ -47,11 +49,6 @@ import org.bitcoins.rpc.config.{ BitcoindInstance, ZmqConfig } -import org.bitcoins.rpc.jsonmodels.{ - GetBlockWithTransactionsResult, - GetTransactionResult, - SignRawTransactionResult -} import org.bitcoins.rpc.util.{AsyncUtil, RpcUtil} import org.bitcoins.testkit.util.{FileUtil, TestkitBinaries} import org.bitcoins.util.ListUtil diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/TrezorAddressTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/TrezorAddressTest.scala index a9de4cab36..4ce1843f18 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/TrezorAddressTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/TrezorAddressTest.scala @@ -1,7 +1,7 @@ package org.bitcoins.wallet import com.typesafe.config.{Config, ConfigFactory} -import org.bitcoins.rpc.serializers.JsonSerializers._ +import org.bitcoins.commons.serializers.JsonSerializers._ import org.bitcoins.core.crypto.{ExtPublicKey, MnemonicCode} import org.bitcoins.core.hd._ import org.bitcoins.core.protocol.BitcoinAddress