Made many changes as requested by Chris Stewart in code review

This commit is contained in:
nkohen 2018-06-06 15:52:02 -05:00
parent 5389d9187f
commit 53a617fea6
3 changed files with 22 additions and 9 deletions

View File

@ -1,9 +1,9 @@
package org.bitcoins.rpc.jsonmodels
import org.bitcoins.core.crypto.{ DoubleSha256Digest, Sha256Hash160Digest }
import org.bitcoins.core.crypto.{DoubleSha256Digest, Sha256Hash160Digest}
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.{ Address, P2PKHAddress, P2SHAddress }
import org.bitcoins.core.protocol.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress}
import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.Transaction
@ -19,13 +19,13 @@ case class GetWalletInfoResult(
keypoololdest: UInt32,
keypoolsize: Int,
keypoolsize_hd_internal: Int,
paytxfee: Bitcoins,
paytxfee: Bitcoins, // Should be BitcoinFeeUnit
hdmasterkeyid: Sha256Hash160Digest,
unlocked_until: Option[Int]) extends WalletResult
case class BumpFeeResult(
txid: DoubleSha256Digest,
origfee: Bitcoins,
fee: Bitcoins,
fee: Bitcoins, // Should be BitcoinFeeUnit
warnings: String) extends WalletResult
case class CreateMultiSigResult(address: Address, redeemScript: ScriptPubKey) extends WalletResult
@ -46,4 +46,9 @@ case class RpcAccount(
involvesWatchonly: Boolean,
account: String,
amount: Bitcoins,
confirmations: Int) extends WalletResult
confirmations: Int) extends WalletResult
case class RpcAddress(
address: BitcoinAddress,
balance: Bitcoins,
account: Option[String]) extends WalletResult

View File

@ -43,6 +43,7 @@ object JsonSerializers {
implicit val bitcoinAddressWrites: Writes[BitcoinAddress] = BitcoinAddressWrites
implicit val doubleSha256DigestWrites: Writes[DoubleSha256Digest] = DoubleSha256DigestWrites
implicit val scriptPubKeyWrites: Writes[ScriptPubKey] = ScriptPubKeyWrites
implicit val transactionInputWrites: Writes[TransactionInput] = TransactionInputWrites
// Network Models
implicit val networkReads: Reads[Network] = Json.reads[Network]
@ -181,4 +182,6 @@ object JsonSerializers {
implicit val fundRawTransactionResultReads: Reads[FundRawTransactionResult] = Json.reads[FundRawTransactionResult]
implicit val rpcAccoutReads: Reads[RpcAccount] = Json.reads[RpcAccount]
implicit val rpcAddressReads: Reads[RpcAddress] = RpcAddressReads
}

View File

@ -4,22 +4,27 @@ import org.bitcoins.core.crypto.DoubleSha256Digest
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.protocol.BitcoinAddress
import org.bitcoins.core.protocol.script.ScriptPubKey
import org.bitcoins.core.protocol.transaction.TransactionInput
import play.api.libs.json._
object JsonWriters {
implicit object BitcoinsWrites extends Writes[Bitcoins] {
def writes(o: Bitcoins) = JsNumber(o.toBigDecimal)
override def writes(o: Bitcoins): JsValue = JsNumber(o.toBigDecimal)
}
implicit object BitcoinAddressWrites extends Writes[BitcoinAddress] {
def writes(o: BitcoinAddress) = JsString(o.value)
override def writes(o: BitcoinAddress): JsValue = JsString(o.value)
}
implicit object DoubleSha256DigestWrites extends Writes[DoubleSha256Digest] {
def writes(o: DoubleSha256Digest) = JsString(o.hex)
override def writes(o: DoubleSha256Digest): JsValue = JsString(o.hex)
}
implicit object ScriptPubKeyWrites extends Writes[ScriptPubKey] {
def writes(o: ScriptPubKey) = JsString(o.hex)
override def writes(o: ScriptPubKey): JsValue = JsString(o.hex)
}
implicit object TransactionInputWrites extends Writes[TransactionInput] {
override def writes(o: TransactionInput): JsValue = JsObject(Seq(("txid", JsString(o.previousOutput.txId.hex)), ("vout", JsNumber(o.previousOutput.vout.toLong)), ("sequence", JsNumber(o.sequence.toLong))))
}
}