mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 06:31:55 +01:00
Add isEndpoint to numeric contract descriptor serialization (#4033)
* Add isEndpoint to numeric contract descriptor serialization * Fix compile Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
This commit is contained in:
parent
546e030dde
commit
2066447cdc
2 changed files with 48 additions and 4 deletions
|
@ -584,14 +584,50 @@ object Picklers {
|
|||
}
|
||||
}
|
||||
|
||||
implicit val payoutFunctionV0TLVWriter: Writer[PayoutFunctionV0TLV] =
|
||||
implicit val hyperbolaPayoutCurvePieceTLVWriter: Writer[
|
||||
HyperbolaPayoutCurvePieceTLV] = {
|
||||
writer[Obj].comap { piece =>
|
||||
Obj(
|
||||
PicklerKeys.usePositivePiece -> Bool(piece.usePositivePiece),
|
||||
PicklerKeys.translateOutcome -> Num(
|
||||
piece.translateOutcome.toBigDecimal.toDouble),
|
||||
PicklerKeys.translatePayout -> Num(
|
||||
piece.translatePayout.toBigDecimal.toDouble),
|
||||
PicklerKeys.a -> Num(piece.a.toBigDecimal.toDouble),
|
||||
PicklerKeys.b -> Num(piece.b.toBigDecimal.toDouble),
|
||||
PicklerKeys.c -> Num(piece.c.toBigDecimal.toDouble),
|
||||
PicklerKeys.d -> Num(piece.d.toBigDecimal.toDouble)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
implicit val payoutFunctionV0TLVWriter: Writer[PayoutFunctionV0TLV] = {
|
||||
def endpoint(json: Value, isEndpoint: Boolean): Value = json match {
|
||||
case obj: Obj =>
|
||||
//drop old value on the floor if there is one
|
||||
obj.value.put(PicklerKeys.isEndpointKey, Bool(isEndpoint))
|
||||
Obj(obj.value)
|
||||
case v: Value => v
|
||||
}
|
||||
|
||||
writer[Obj].comap { payoutFunc =>
|
||||
val pointsJs = payoutFunc.endpoints.map { point =>
|
||||
writeJs(point)
|
||||
val endPointsJs = payoutFunc.endpoints.map { point =>
|
||||
endpoint(writeJs(point), isEndpoint = true)
|
||||
}
|
||||
|
||||
Obj(PicklerKeys.pointsKey -> pointsJs)
|
||||
val midPointJs = payoutFunc.pieces.flatMap {
|
||||
case polynomialPiece: PolynomialPayoutCurvePieceTLV =>
|
||||
polynomialPiece.midpoints.map { point =>
|
||||
endpoint(writeJs(point), isEndpoint = false)
|
||||
}
|
||||
case hyperbolaPiece: HyperbolaPayoutCurvePieceTLV =>
|
||||
Vector(writeJs(hyperbolaPiece))
|
||||
}
|
||||
|
||||
Obj(PicklerKeys.pointsKey -> (endPointsJs ++ midPointJs))
|
||||
}
|
||||
}
|
||||
|
||||
implicit val payoutFunctionV0TLVReader: Reader[PayoutFunctionV0TLV] = {
|
||||
reader[Obj].map { obj: Obj =>
|
||||
|
|
|
@ -94,6 +94,14 @@ object PicklerKeys {
|
|||
val beginIntervalKey = "beginInterval"
|
||||
val roundingModKey = "roundingMod"
|
||||
|
||||
val usePositivePiece = "usePositivePiece"
|
||||
val translateOutcome = "translateOutcome"
|
||||
val translatePayout = "translatePayout"
|
||||
val a = "a"
|
||||
val b = "b"
|
||||
val c = "c"
|
||||
val d = "d"
|
||||
|
||||
val singleKey = "single"
|
||||
|
||||
val oracleAnnouncementKey = "oracleAnnouncement"
|
||||
|
|
Loading…
Add table
Reference in a new issue