forked from ergoplatform/explorer-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ergoplatform/master
merge latest
- Loading branch information
Showing
17 changed files
with
470 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
87 changes: 87 additions & 0 deletions
87
...lorer-api/src/main/scala/org/ergoplatform/explorer/http/api/v1/models/AnyOutputInfo.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.ergoplatform.explorer.http.api.v1.models | ||
|
||
import derevo.circe.{decoder, encoder} | ||
import derevo.derive | ||
import io.circe.Json | ||
import org.ergoplatform.explorer._ | ||
import org.ergoplatform.explorer.db.models.AnyOutput | ||
import org.ergoplatform.explorer.db.models.aggregates.AnyAsset | ||
import org.ergoplatform.explorer.http.api.models.AssetInstanceInfo | ||
import sttp.tapir.{Schema, SchemaType, Validator} | ||
|
||
@derive(encoder, decoder) | ||
final case class AnyOutputInfo( | ||
boxId: BoxId, | ||
transactionId: TxId, | ||
headerId: Option[BlockId], | ||
value: Long, | ||
index: Int, | ||
globalIndex: Option[Long], | ||
creationHeight: Int, | ||
settlementHeight: Option[Int], | ||
ergoTree: HexString, | ||
ergoTreeConstants: String, | ||
ergoTreeScript: String, | ||
address: Address, | ||
assets: List[AssetInstanceInfo], | ||
additionalRegisters: Json, | ||
spentTransactionId: Option[TxId], | ||
mainChain: Option[Boolean] | ||
) | ||
|
||
object AnyOutputInfo { | ||
|
||
implicit val schema: Schema[AnyOutputInfo] = | ||
Schema | ||
.derived[AnyOutputInfo] | ||
.modify(_.boxId)(_.description("Id of the box")) | ||
.modify(_.transactionId)(_.description("Id of the transaction that created the box")) | ||
.modify(_.headerId)(_.description("Id of the block a box included in")) | ||
.modify(_.value)(_.description("Value of the box in nanoERG")) | ||
.modify(_.index)(_.description("Index of the output in a transaction")) | ||
.modify(_.globalIndex)(_.description("Global index of the output in the blockchain")) | ||
.modify(_.creationHeight)(_.description("Height at which the box was created")) | ||
.modify(_.settlementHeight)(_.description("Height at which the box got fixed in blockchain")) | ||
.modify(_.ergoTree)(_.description("Serialized ergo tree")) | ||
.modify(_.address)(_.description("An address derived from ergo tree")) | ||
.modify(_.spentTransactionId)(_.description("Id of the transaction this output was spent by")) | ||
|
||
implicit val validator: Validator[AnyOutputInfo] = schema.validator | ||
|
||
implicit private def registersSchema: Schema[Json] = | ||
Schema( | ||
SchemaType.SOpenProduct( | ||
Schema(SchemaType.SString[Json]()) | ||
)(_ => Map.empty) | ||
) | ||
|
||
def apply( | ||
o: AnyOutput, | ||
assets: List[AnyAsset] | ||
): AnyOutputInfo = { | ||
val (ergoTreeConstants, ergoTreeScript) = PrettyErgoTree | ||
.fromHexString(o.ergoTree) | ||
.fold( | ||
_ => ("", ""), | ||
tree => (tree.constants, tree.script) | ||
) | ||
AnyOutputInfo( | ||
o.boxId, | ||
o.txId, | ||
o.headerId, | ||
o.value, | ||
o.index, | ||
o.globalIndex, | ||
o.creationHeight, | ||
o.settlementHeight, | ||
o.ergoTree, | ||
ergoTreeConstants, | ||
ergoTreeScript, | ||
o.address, | ||
assets.sortBy(_.index).map(AssetInstanceInfo(_)), | ||
o.additionalRegisters, | ||
o.spendingTxId, | ||
o.mainChain | ||
) | ||
} | ||
} |
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
modules/explorer-core/src/main/scala/org/ergoplatform/explorer/db/models/AnyOutput.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.ergoplatform.explorer.db.models | ||
|
||
import io.circe.Json | ||
import org.ergoplatform.explorer._ | ||
|
||
final case class AnyOutput( | ||
boxId: BoxId, | ||
txId: TxId, | ||
headerId: Option[BlockId], | ||
value: Long, | ||
creationHeight: Int, | ||
settlementHeight: Option[Int], | ||
index: Int, | ||
globalIndex: Option[Long], | ||
ergoTree: HexString, | ||
ergoTreeTemplateHash: ErgoTreeTemplateHash, | ||
address: Address, | ||
additionalRegisters: Json, | ||
timestamp: Option[Long], | ||
mainChain: Option[Boolean], | ||
spendingTxId: Option[TxId] | ||
) | ||
|
14 changes: 14 additions & 0 deletions
14
...xplorer-core/src/main/scala/org/ergoplatform/explorer/db/models/aggregates/AnyAsset.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.ergoplatform.explorer.db.models.aggregates | ||
|
||
import org.ergoplatform.explorer.{BlockId, BoxId, TokenId, TokenType} | ||
|
||
final case class AnyAsset( | ||
tokenId: TokenId, | ||
boxId: BoxId, | ||
headerId: Option[BlockId], | ||
index: Int, | ||
amount: Long, | ||
name: Option[String], | ||
decimals: Option[Int], | ||
`type`: Option[TokenType] | ||
) |
This file contains 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
Oops, something went wrong.