diff --git a/build.sbt b/build.sbt index c0b197f74b..360f09f906 100644 --- a/build.sbt +++ b/build.sbt @@ -46,7 +46,8 @@ lazy val rpc = project .in(file("rpc")) .enablePlugins() .dependsOn( - core + core, + coreGen % "test->test" ) publishArtifact in root := false diff --git a/rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala b/rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala index 68749edb06..877573888a 100644 --- a/rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala +++ b/rpc/src/main/scala/org/bitcoins/rpc/jsonmodels/NetworkResult.scala @@ -236,7 +236,7 @@ case class ListTransactionsResult( comment: Option[String], to: Option[String], otheraccount: Option[String], - bip125_replaceable: String, // TODO: Needs to be a - not a _ + bip125_replaceable: String, abandoned: Option[Boolean] ) extends NetworkResult @@ -256,8 +256,8 @@ case class GetTransactionResult( confirmations: Int, generated: Option[Boolean], blockhash: Option[DoubleSha256Digest], - blockIndex: Option[Int], - blockTime: Option[UInt32], + blockindex: Option[Int], + blocktime: Option[UInt32], txid: DoubleSha256Digest, walletconflicts: Vector[DoubleSha256Digest], time: UInt32, @@ -270,7 +270,7 @@ case class GetTransactionResult( case class TransactionDetails( involvesWatchonly: Option[Boolean], - account: String, + account: Option[String], address: Option[BitcoinAddress], category: String, amount: Bitcoins, @@ -292,4 +292,44 @@ case class UnspentOutput( // Naming? case class LockUnspentOutputParameter(txid: DoubleSha256Digest, vout: Int) extends NetworkResult -case class SignRawTransactionResult(hex: Transaction, complete: Boolean) extends NetworkResult \ No newline at end of file +case class SignRawTransactionResult(hex: Transaction, complete: Boolean) extends NetworkResult + +case class GetBlockChainInfoResult( + chain: String, + blocks: Int, + headers: Int, + bestblockhash: DoubleSha256Digest, + difficulty: BigDecimal, + mediantime: Int, + verificationprogress: BigDecimal, + initialblockdownload: Boolean, + chainwork: String, // How should this be handled? + size_on_disk: Int, + pruned: Boolean, + pruneheight: Option[Int], + softforks: Vector[Softfork], + bip9_softforks: Map[String, Bip9Softfork], + warnings: String + ) extends NetworkResult + +case class Softfork( + id: String, + version: Int, + enforce: Option[Map[String, SoftforkProgress]], + reject: SoftforkProgress + ) extends NetworkResult + +case class SoftforkProgress( + status: Option[Boolean], + found: Option[Int], + required: Option[Int], + window: Option[Int] + ) extends NetworkResult + +case class Bip9Softfork( + status: String, + bit: Option[Int], + startTime: Int, + timeout: BigInt, + since: Int + ) extends NetworkResult \ No newline at end of file diff --git a/rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala b/rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala index 3de97f4420..ac7a30bd76 100644 --- a/rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala +++ b/rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonSerializers.scala @@ -16,6 +16,8 @@ import play.api.libs.json.{ Json, Reads, Writes, __ } import play.api.libs.functional.syntax._ object JsonSerializers { + implicit val bigIntReads: Reads[BigInt] = BigIntReads + // Internal Types implicit val doubleSha256DigestReads: Reads[DoubleSha256Digest] = DoubleSha256DigestReads implicit val bitcoinsReads: Reads[Bitcoins] = BitcoinsReads @@ -71,15 +73,76 @@ object JsonSerializers { implicit val rpcTransactionReads: Reads[RpcTransaction] = Json.reads[RpcTransaction] implicit val getBlockWithTransactionsResultReads: Reads[GetBlockWithTransactionsResult] = Json.reads[GetBlockWithTransactionsResult] - implicit val paymentReads: Reads[Payment] = Json.reads[Payment] + implicit val paymentReads: Reads[Payment] = ( + (__ \ "involvesWatchonly").readNullable[Boolean] and + (__ \ "account").read[String] and + (__ \ "address").readNullable[BitcoinAddress] and + (__ \ "category").read[String] and + (__ \ "amount").read[Bitcoins] and + (__ \ "vout").read[Int] and + (__ \ "fee").readNullable[Bitcoins] and + (__ \ "confirmations").read[Int] and + (__ \ "generated").readNullable[Boolean] and + (__ \ "blockhash").readNullable[DoubleSha256Digest] and + (__ \ "blockindex").readNullable[Int] and + (__ \ "blocktime").readNullable[UInt32] and + (__ \ "txid").read[DoubleSha256Digest] and + (__ \ "walletconflicts").read[Vector[DoubleSha256Digest]] and + (__ \ "time").read[UInt32] and + (__ \ "timereceived").read[UInt32] and + (__ \ "bip125-replaceable").read[String] and + (__ \ "comment").readNullable[String] and + (__ \ "to").readNullable[String] and + (__ \ "lastblock").read[DoubleSha256Digest] + )(Payment) implicit val listSinceBlockResultReads: Reads[ListSinceBlockResult] = Json.reads[ListSinceBlockResult] - implicit val listTransactionsResultReads: Reads[ListTransactionsResult] = Json.reads[ListTransactionsResult] + implicit val listTransactionsResultReads: Reads[ListTransactionsResult] = ( + (__ \ "account").read[String] and + (__ \ "address").readNullable[BitcoinAddress] and + (__ \ "category").read[String] and + (__ \ "amount").read[Bitcoins] and + (__ \ "label").readNullable[String] and + (__ \ "vout").readNullable[Int] and + (__ \ "fee").readNullable[Bitcoins] and + (__ \ "confirmations").readNullable[Int] and + (__ \ "trusted").readNullable[Boolean] and + (__ \ "generated").readNullable[Boolean] and + (__ \ "blockhash").readNullable[DoubleSha256Digest] and + (__ \ "blockindex").readNullable[Int] and + (__ \ "blocktime").readNullable[UInt32] and + (__ \ "txid").readNullable[DoubleSha256Digest] and + (__ \ "walletconflicts").readNullable[Vector[DoubleSha256Digest]] and + (__ \ "time").read[UInt32] and + (__ \ "timereceived").readNullable[UInt32] and + (__ \ "comment").readNullable[String] and + (__ \ "to").readNullable[String] and + (__ \ "otheraccount").readNullable[String] and + (__ \ "bip125-replaceable").read[String] and + (__ \ "abandoned").readNullable[Boolean] + )(ListTransactionsResult) implicit val receivedAddressReads: Reads[ReceivedAddress] = Json.reads[ReceivedAddress] implicit val TransactionDetailsReads: Reads[TransactionDetails] = Json.reads[TransactionDetails] - implicit val getTransactionResultReads: Reads[GetTransactionResult] = Json.reads[GetTransactionResult] + implicit val getTransactionResultReads: Reads[GetTransactionResult] = ( + (__ \ "amount").read[Bitcoins] and + (__ \ "fee").readNullable[Bitcoins] and + (__ \ "confirmations").read[Int] and + (__ \ "generated").readNullable[Boolean] and + (__ \ "blockhash").readNullable[DoubleSha256Digest] and + (__ \ "blockindex").readNullable[Int] and + (__ \ "blocktime").readNullable[UInt32] and + (__ \ "txid").read[DoubleSha256Digest] and + (__ \ "walletconflicts").read[Vector[DoubleSha256Digest]] and + (__ \ "time").read[UInt32] and + (__ \ "timereceived").read[UInt32] and + (__ \ "bip125-replaceable").read[String] and + (__ \ "comment").readNullable[String] and + (__ \ "to").readNullable[String] and + (__ \ "details").read[Vector[TransactionDetails]] and + (__ \ "hex").read[Transaction] + )(GetTransactionResult) implicit val unspentOutputReads: Reads[UnspentOutput] = Json.reads[UnspentOutput] @@ -87,6 +150,11 @@ object JsonSerializers { implicit val signRawTransactionResultReads: Reads[SignRawTransactionResult] = Json.reads[SignRawTransactionResult] + implicit val softforkProgressReads: Reads[SoftforkProgress] = Json.reads[SoftforkProgress] + implicit val softforkReads: Reads[Softfork] = Json.reads[Softfork] + implicit val bip9SoftforkReads: Reads[Bip9Softfork] = Json.reads[Bip9Softfork] + implicit val getBlockChainInfoResultReads: Reads[GetBlockChainInfoResult] = Json.reads[GetBlockChainInfoResult] + // Mining Models implicit val miningInfoReads: Reads[GetMiningInfoResult] = Json.reads[GetMiningInfoResult]