Add extranious json readers, writers, and column mappers (#3325)

This commit is contained in:
benthecarman 2021-06-24 07:37:55 -05:00 committed by GitHub
parent ea26c8b3a3
commit c72c5f84e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -1,19 +1,17 @@
package org.bitcoins.commons.serializers
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{
AddressType,
WalletCreateFundedPsbtOptions
}
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts._
import org.bitcoins.core.currency._
import org.bitcoins.core.number._
import org.bitcoins.core.protocol.BitcoinAddress
import org.bitcoins.core.protocol.ln.LnInvoice
import org.bitcoins.core.protocol.ln.currency.MilliSatoshis
import org.bitcoins.core.protocol.script.{ScriptPubKey, WitnessScriptPubKey}
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput}
import org.bitcoins.core.psbt._
import org.bitcoins.core.script.crypto._
import org.bitcoins.core.util.BytesUtil
import org.bitcoins.crypto.{DoubleSha256Digest, DoubleSha256DigestBE}
import org.bitcoins.crypto._
import play.api.libs.json._
import scala.collection.mutable
@ -56,6 +54,14 @@ object JsonWriters {
override def writes(o: DoubleSha256DigestBE): JsValue = JsString(o.hex)
}
implicit object Sha256DigestWrites extends Writes[Sha256Digest] {
override def writes(o: Sha256Digest): JsValue = JsString(o.hex)
}
implicit object Sha256DigestBEWrites extends Writes[Sha256DigestBE] {
override def writes(o: Sha256DigestBE): JsValue = JsString(o.hex)
}
implicit object ScriptPubKeyWrites extends Writes[ScriptPubKey] {
override def writes(o: ScriptPubKey): JsValue =
@ -102,6 +108,10 @@ object JsonWriters {
Json.toJson(o.map { case (k, v) => (keyString(k), v) })
}
implicit object SatoshisWrites extends Writes[Satoshis] {
override def writes(o: Satoshis): JsValue = JsNumber(o.toBigDecimal)
}
implicit object MilliSatoshisWrites extends Writes[MilliSatoshis] {
override def writes(o: MilliSatoshis): JsValue = JsNumber(o.toBigDecimal)
}
@ -110,6 +120,12 @@ object JsonWriters {
override def writes(addr: AddressType): JsValue = JsString(addr.toString)
}
implicit object LnInvoiceWrites extends Writes[LnInvoice] {
override def writes(invoice: LnInvoice): JsValue = JsString(
invoice.toString)
}
implicit object WalletCreateFundedPsbtOptionsWrites
extends Writes[WalletCreateFundedPsbtOptions] {

View File

@ -239,6 +239,10 @@ class DbCommonsColumnMappers(val profile: JdbcProfile) {
MappedColumnType
.base[CurrencyUnit, Long](_.satoshis.toLong, l => Satoshis(l))
implicit val satoshisMapper: BaseColumnType[Satoshis] =
MappedColumnType
.base[Satoshis, Long](_.toLong, l => Satoshis(l))
implicit val filterTypeMapper: BaseColumnType[FilterType] =
MappedColumnType
.base[FilterType, Short](FilterType.getCode, FilterType.byCode)