mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
Removed remaining unsafe cases in JsonReaders
This commit is contained in:
parent
79a3917adc
commit
1718e04f00
4 changed files with 132 additions and 95 deletions
|
@ -2,12 +2,20 @@ package org.bitcoins.rpc.jsonmodels
|
|||
|
||||
import java.net.URI
|
||||
|
||||
import org.bitcoins.core.crypto.{DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest}
|
||||
import org.bitcoins.core.crypto.{
|
||||
DoubleSha256Digest,
|
||||
ECPublicKey,
|
||||
Sha256Hash160Digest
|
||||
}
|
||||
import org.bitcoins.core.currency.Bitcoins
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.{Address, BitcoinAddress}
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput, TransactionWitness}
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
Transaction,
|
||||
TransactionInput,
|
||||
TransactionWitness
|
||||
}
|
||||
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
|
||||
|
||||
sealed abstract class NetworkResult
|
||||
|
@ -93,8 +101,7 @@ case class Node(
|
|||
connected: Option[Boolean],
|
||||
addresses: Option[Vector[NodeAddress]])
|
||||
extends NetworkResult
|
||||
case class NodeAddress(address: URI, connected: String)
|
||||
extends NetworkResult
|
||||
case class NodeAddress(address: URI, connected: String) extends NetworkResult
|
||||
|
||||
case class GetMemPoolEntryResult(
|
||||
size: Int,
|
||||
|
@ -262,12 +269,12 @@ case class ReceivedAddress(
|
|||
extends NetworkResult
|
||||
|
||||
case class ReceivedAccount(
|
||||
involvesWatchonly: Option[Boolean],
|
||||
account: String,
|
||||
amount: Bitcoins,
|
||||
confirmations: Int,
|
||||
lable: Option[String]
|
||||
) extends NetworkResult
|
||||
involvesWatchonly: Option[Boolean],
|
||||
account: String,
|
||||
amount: Bitcoins,
|
||||
confirmations: Int,
|
||||
lable: Option[String]
|
||||
) extends NetworkResult
|
||||
|
||||
case class GetTransactionResult(
|
||||
amount: Bitcoins,
|
||||
|
@ -312,16 +319,19 @@ case class UnspentOutput( // Naming?
|
|||
solvable: Boolean)
|
||||
extends NetworkResult
|
||||
|
||||
case class SignRawTransactionResult(hex: Transaction, complete: Boolean, errors: Option[Vector[SignRawTransactionError]])
|
||||
case class SignRawTransactionResult(
|
||||
hex: Transaction,
|
||||
complete: Boolean,
|
||||
errors: Option[Vector[SignRawTransactionError]])
|
||||
extends NetworkResult
|
||||
|
||||
case class SignRawTransactionError(
|
||||
txid: DoubleSha256Digest,
|
||||
vout: Int,
|
||||
scriptSig: ScriptPubKey,
|
||||
sequence: Int,
|
||||
error: String
|
||||
) extends NetworkResult
|
||||
txid: DoubleSha256Digest,
|
||||
vout: Int,
|
||||
scriptSig: ScriptPubKey,
|
||||
sequence: Int,
|
||||
error: String
|
||||
) extends NetworkResult
|
||||
|
||||
case class GetBlockChainInfoResult(
|
||||
chain: String,
|
||||
|
@ -413,77 +423,79 @@ case class NetTarget(
|
|||
extends NetworkResult
|
||||
|
||||
case class Peer(
|
||||
id: Int,
|
||||
networkInfo: PeerNetworkInfo,
|
||||
version: Int,
|
||||
subver: String,
|
||||
inbound: Boolean,
|
||||
addnode: Boolean,
|
||||
startingheight: Int,
|
||||
banscore: Int,
|
||||
synced_headers: Int,
|
||||
synced_blocks: Int,
|
||||
inflight: Vector[Int],
|
||||
whitelisted: Boolean,
|
||||
bytessent_per_msg: Map[String, Int],
|
||||
bytesrecv_per_msg: Map[String, Int]) extends NetworkResult
|
||||
id: Int,
|
||||
networkInfo: PeerNetworkInfo,
|
||||
version: Int,
|
||||
subver: String,
|
||||
inbound: Boolean,
|
||||
addnode: Boolean,
|
||||
startingheight: Int,
|
||||
banscore: Int,
|
||||
synced_headers: Int,
|
||||
synced_blocks: Int,
|
||||
inflight: Vector[Int],
|
||||
whitelisted: Boolean,
|
||||
bytessent_per_msg: Map[String, Int],
|
||||
bytesrecv_per_msg: Map[String, Int])
|
||||
extends NetworkResult
|
||||
|
||||
case class PeerNetworkInfo(
|
||||
addr: URI,
|
||||
addrbind: URI,
|
||||
addrlocal: Option[URI],
|
||||
services: String,
|
||||
relaytxes: Boolean,
|
||||
lastsend: UInt32,
|
||||
lastrecv: UInt32,
|
||||
bytessent: Int,
|
||||
bytesrecv: Int,
|
||||
conntime: UInt32,
|
||||
timeoffset: Int,
|
||||
pingtime: Option[BigDecimal],
|
||||
minping: Option[BigDecimal],
|
||||
pingwait: Option[BigDecimal]) extends NetworkResult
|
||||
|
||||
addr: URI,
|
||||
addrbind: URI,
|
||||
addrlocal: Option[URI],
|
||||
services: String,
|
||||
relaytxes: Boolean,
|
||||
lastsend: UInt32,
|
||||
lastrecv: UInt32,
|
||||
bytessent: Int,
|
||||
bytesrecv: Int,
|
||||
conntime: UInt32,
|
||||
timeoffset: Int,
|
||||
pingtime: Option[BigDecimal],
|
||||
minping: Option[BigDecimal],
|
||||
pingwait: Option[BigDecimal])
|
||||
extends NetworkResult
|
||||
|
||||
case class GetRawTransactionResult(
|
||||
in_active_blockchain: Option[Boolean],
|
||||
hex: Transaction,
|
||||
txid: DoubleSha256Digest,
|
||||
hash: DoubleSha256Digest,
|
||||
size: Int,
|
||||
vsize: Int,
|
||||
version: Int,
|
||||
locktime: UInt32,
|
||||
vin: Vector[GetRawTransactionVin],
|
||||
vout: Vector[RpcTransactionOutput],
|
||||
blockhash: DoubleSha256Digest,
|
||||
confirmations: Int,
|
||||
time: UInt32,
|
||||
blocktime: UInt32
|
||||
) extends NetworkResult
|
||||
in_active_blockchain: Option[Boolean],
|
||||
hex: Transaction,
|
||||
txid: DoubleSha256Digest,
|
||||
hash: DoubleSha256Digest,
|
||||
size: Int,
|
||||
vsize: Int,
|
||||
version: Int,
|
||||
locktime: UInt32,
|
||||
vin: Vector[GetRawTransactionVin],
|
||||
vout: Vector[RpcTransactionOutput],
|
||||
blockhash: DoubleSha256Digest,
|
||||
confirmations: Int,
|
||||
time: UInt32,
|
||||
blocktime: UInt32
|
||||
) extends NetworkResult
|
||||
|
||||
case class GetRawTransactionVin(
|
||||
txid: Option[DoubleSha256Digest],
|
||||
vout: Option[Int],
|
||||
scriptSig: Option[GetRawTransactionScriptSig],
|
||||
sequence: Option[BigDecimal],
|
||||
txinwitness: Option[Vector[String]] // Should be TransactionWitness?
|
||||
)
|
||||
txid: Option[DoubleSha256Digest],
|
||||
vout: Option[Int],
|
||||
scriptSig: Option[GetRawTransactionScriptSig],
|
||||
sequence: Option[BigDecimal],
|
||||
txinwitness: Option[Vector[String]] // Should be TransactionWitness?
|
||||
)
|
||||
|
||||
case class GetRawTransactionScriptSig(asm: String, hex: ScriptPubKey) // Right???
|
||||
|
||||
case class GetTxOutResult(
|
||||
bestblock: DoubleSha256Digest,
|
||||
confirmations: Int,
|
||||
value: Bitcoins,
|
||||
scriptPubKey: RpcScriptPubKey,
|
||||
coinbase: Boolean) extends NetworkResult
|
||||
bestblock: DoubleSha256Digest,
|
||||
confirmations: Int,
|
||||
value: Bitcoins,
|
||||
scriptPubKey: RpcScriptPubKey,
|
||||
coinbase: Boolean)
|
||||
extends NetworkResult
|
||||
|
||||
case class GetChainTxStatsResult(
|
||||
time: UInt32,
|
||||
txcount: Int,
|
||||
window_block_count: Int,
|
||||
window_tx_count: Option[Int],
|
||||
window_interval: Option[UInt32],
|
||||
txrate: Option[BigDecimal]
|
||||
) extends NetworkResult
|
||||
time: UInt32,
|
||||
txcount: Int,
|
||||
window_block_count: Int,
|
||||
window_tx_count: Option[Int],
|
||||
window_interval: Option[UInt32],
|
||||
txrate: Option[BigDecimal]
|
||||
) extends NetworkResult
|
||||
|
|
|
@ -5,7 +5,12 @@ import java.io.File
|
|||
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, BitcoinAddress, 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
|
||||
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
|
||||
|
@ -72,6 +77,6 @@ case class ImportMultiError(code: Int, message: String) extends WalletResult
|
|||
case class DumpWalletResult(filename: File)
|
||||
|
||||
case class RescanBlockChainResult(
|
||||
start_height: Int,
|
||||
stop_height: Int
|
||||
) extends WalletResult
|
||||
start_height: Int,
|
||||
stop_height: Int
|
||||
) extends WalletResult
|
||||
|
|
|
@ -3,13 +3,26 @@ package org.bitcoins.rpc.serializers
|
|||
import java.io.File
|
||||
import java.net.{InetAddress, URI}
|
||||
|
||||
import org.bitcoins.core.crypto.{DoubleSha256Digest, ECPublicKey, Sha256Hash160Digest}
|
||||
import org.bitcoins.core.crypto.{
|
||||
DoubleSha256Digest,
|
||||
ECPublicKey,
|
||||
Sha256Hash160Digest
|
||||
}
|
||||
import org.bitcoins.core.currency.Bitcoins
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress}
|
||||
import org.bitcoins.core.protocol.{
|
||||
Address,
|
||||
BitcoinAddress,
|
||||
P2PKHAddress,
|
||||
P2SHAddress
|
||||
}
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput, TransactionOutPoint}
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
Transaction,
|
||||
TransactionInput,
|
||||
TransactionOutPoint
|
||||
}
|
||||
import org.bitcoins.core.wallet.fee.BitcoinFeeUnit
|
||||
import org.bitcoins.rpc.jsonmodels._
|
||||
import org.bitcoins.rpc.serializers.JsonReaders._
|
||||
|
@ -208,7 +221,8 @@ object JsonSerializers {
|
|||
implicit val getNetTotalsResultReads: Reads[GetNetTotalsResult] =
|
||||
Json.reads[GetNetTotalsResult]
|
||||
|
||||
implicit val peerNetworkInfoReads: Reads[PeerNetworkInfo] = Json.reads[PeerNetworkInfo]
|
||||
implicit val peerNetworkInfoReads: Reads[PeerNetworkInfo] =
|
||||
Json.reads[PeerNetworkInfo]
|
||||
implicit val peerReads: Reads[Peer] = (
|
||||
(__ \ "id").read[Int] and
|
||||
__.read[PeerNetworkInfo] and
|
||||
|
@ -224,16 +238,20 @@ object JsonSerializers {
|
|||
(__ \ "whitelisted").read[Boolean] and
|
||||
(__ \ "bytessent_per_msg").read[Map[String, Int]] and
|
||||
(__ \ "bytesrecv_per_msg").read[Map[String, Int]]
|
||||
) (Peer)
|
||||
)(Peer)
|
||||
|
||||
implicit val getRawTransactionScriptSigReads: Reads[GetRawTransactionScriptSig] = Json.reads[GetRawTransactionScriptSig]
|
||||
implicit val getRawTransactionVinReads: Reads[GetRawTransactionVin] = Json.reads[GetRawTransactionVin]
|
||||
implicit val getRawTransactionResultReads: Reads[GetRawTransactionResult] = Json.reads[GetRawTransactionResult]
|
||||
implicit val getRawTransactionScriptSigReads: Reads[
|
||||
GetRawTransactionScriptSig] = Json.reads[GetRawTransactionScriptSig]
|
||||
implicit val getRawTransactionVinReads: Reads[GetRawTransactionVin] =
|
||||
Json.reads[GetRawTransactionVin]
|
||||
implicit val getRawTransactionResultReads: Reads[GetRawTransactionResult] =
|
||||
Json.reads[GetRawTransactionResult]
|
||||
|
||||
implicit val getTxOutResultReads: Reads[GetTxOutResult] =
|
||||
Json.reads[GetTxOutResult]
|
||||
|
||||
implicit val getChainTxStatsResultReads: Reads[GetChainTxStatsResult] = Json.reads[GetChainTxStatsResult]
|
||||
implicit val getChainTxStatsResultReads: Reads[GetChainTxStatsResult] =
|
||||
Json.reads[GetChainTxStatsResult]
|
||||
|
||||
// Mining Models
|
||||
implicit val miningInfoReads: Reads[GetMiningInfoResult] =
|
||||
|
@ -267,7 +285,8 @@ object JsonSerializers {
|
|||
implicit val importMultiResultReads: Reads[ImportMultiResult] =
|
||||
Json.reads[ImportMultiResult]
|
||||
|
||||
implicit val dumpWalletResultReads: Reads[DumpWalletResult] = Json.reads[DumpWalletResult]
|
||||
implicit val dumpWalletResultReads: Reads[DumpWalletResult] =
|
||||
Json.reads[DumpWalletResult]
|
||||
|
||||
implicit val rescanBlockChainResultReads: Reads[RescanBlockChainResult] =
|
||||
Json.reads[RescanBlockChainResult]
|
||||
|
|
|
@ -41,9 +41,10 @@ object JsonWriters {
|
|||
override def writes(o: Transaction): JsValue = JsString(o.hex)
|
||||
}
|
||||
|
||||
implicit def mapWrites[K,V](keyString: K => String)(implicit vWrites: Writes[V]): Writes[Map[K,V]] = new Writes[Map[K,V]] {
|
||||
implicit def mapWrites[K, V](keyString: K => String)(
|
||||
implicit vWrites: Writes[V]): Writes[Map[K, V]] = new Writes[Map[K, V]] {
|
||||
override def writes(o: Map[K, V]): JsValue = {
|
||||
Json.toJson(o.map{case (k, v) => (keyString(k), v)})
|
||||
Json.toJson(o.map { case (k, v) => (keyString(k), v) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue