Created
November 9, 2023 09:14
-
-
Save kushti/8e47a6683af6c1679f2862c1f3b425a9 to your computer and use it in GitHub Desktop.
Tester.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Tester extends App with ApiCodecs { | |
val s = "0e1631393039303063646462363930366462363530336665" | |
val et = ErgoTreeSerializer.DefaultSerializer.deserializeErgoTree(Base16.decode(s).get) | |
println(et) | |
val jsonString = | |
""" | |
|{ | |
| "boxId": "cde0d35070a2cc7489941fc88d3ad500d7eb42116adc1cbfbcef11ca46f2843c", | |
| "value": 1000000, | |
| "ergoTree": "0e1631393039303063646462363930366462363530336665", | |
| "assets": [ | |
| { | |
| "tokenId": "023d02a3d43b18a9a8e545a8847985b6e70a0603a0d3f2fb92e6c5c7256e3f0a", | |
| "amount": 100 | |
| } | |
| ], | |
| "creationHeight": 801364, | |
| "additionalRegisters": { | |
| "R4": "0e1672657075746174696f6e2d70726f6f662d746f6b656e", | |
| "R5": "0e0e706c61696e2f7478742d75746638", | |
| "R6": "0e046e6f646f", | |
| "R7": "0e34335778364473794c3345427a564d46684d38766a4175726645724a7165584e336e6f5047544558704166374c4c7365424b356450" | |
| }, | |
| "transactionId": "ccc9c598fb6aa4266841b5cebf2968c3ff668e810cb9a649d11cdbcc70548870", | |
| "index": 0 | |
| }""".stripMargin | |
import io.circe.parser._ | |
parse(jsonString) match { | |
case Left(parsingError) => | |
throw new IllegalArgumentException(s"Invalid JSON object: ${parsingError.message}") | |
case Right(json) => // here we use the JSON object | |
val box = ergoBoxDecoder.decodeJson(json).toOption.get | |
println(box.ergoTree) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment