Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts info endpoint #542

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ explorer {
"aud"
]
coingecko-uri = "https://api.coingecko.com/api/v3"
market-chart-days = 366
market-chart-days = 365
market-chart-days = ${?EXPLORER_MARKET_CHART_DAYS}
}
}
Expand Down
251 changes: 251 additions & 0 deletions app/src/main/resources/explorer-backend-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6196,6 +6196,111 @@
}
}
},
"/contracts/{contract_address}/current-liveness": {
"get": {
"tags": [
"Contracts"
],
"description": "Get contract liveness",
"operationId": "getContractsContract_addressCurrent-liveness",
"parameters": [
{
"name": "contract_address",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "address"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ContractLiveness"
},
"example": {
"parent": "26JbotDoUoNzwVACg1YLaNTZKAJvoBDWiXJMnokZxCzvd",
"creation": {
"blockHash": "bdaf9dc514ce7d34b6474b8ca10a3dfb93ba997cb9d5ff1ea724ebe2af48abe5",
"txHash": "503bfb16230888af4924aa8f8250d7d348b862e267d75d3147f1998050b6da69",
"timestamp": 1611041396892
}
}
}
}
},
"400": {
"description": "BadRequest",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BadRequest"
},
"example": {
"detail": "Something bad in the request"
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Unauthorized"
},
"example": {
"detail": "You shall not pass"
}
}
}
},
"404": {
"description": "NotFound",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFound"
},
"example": {
"resource": "wallet-name",
"detail": "wallet-name not found"
}
}
}
},
"500": {
"description": "InternalServerError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InternalServerError"
},
"example": {
"detail": "Ouch"
}
}
}
},
"503": {
"description": "ServiceUnavailable",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ServiceUnavailable"
},
"example": {
"detail": "Self clique unsynced"
}
}
}
}
}
}
},
"/contracts/{contract_address}/parent": {
"get": {
"tags": [
Expand Down Expand Up @@ -7169,6 +7274,49 @@
}
}
},
"ContractLiveness": {
"required": [
"creation"
],
"type": "object",
"properties": {
"parent": {
"type": "string",
"format": "address"
},
"creation": {
"$ref": "#/components/schemas/ContractLivenessLocation"
},
"destruction": {
"$ref": "#/components/schemas/ContractLivenessLocation"
},
"interfaceId": {
"$ref": "#/components/schemas/StdInterfaceId"
}
}
},
"ContractLivenessLocation": {
"required": [
"blockHash",
"txHash",
"timestamp"
],
"type": "object",
"properties": {
"blockHash": {
"type": "string",
"format": "block-hash"
},
"txHash": {
"type": "string",
"format": "32-byte-hash"
},
"timestamp": {
"type": "integer",
"format": "int64"
}
}
},
"ContractOutput": {
"required": [
"hint",
Expand Down Expand Up @@ -7281,6 +7429,17 @@
}
}
},
"FungibleToken": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"FungibleTokenMetadata": {
"required": [
"id",
Expand Down Expand Up @@ -7460,6 +7619,28 @@
}
}
},
"NFT": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NFTCollection": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NFTCollectionMetadata": {
"required": [
"address",
Expand All @@ -7476,6 +7657,17 @@
}
}
},
"NFTCollectionWithRoyalty": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NFTMetadata": {
"required": [
"id",
Expand All @@ -7502,6 +7694,17 @@
}
}
},
"NonStandard": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NotFound": {
"required": [
"detail",
Expand Down Expand Up @@ -7709,6 +7912,39 @@
}
}
},
"StdInterfaceId": {
"oneOf": [
{
"$ref": "#/components/schemas/FungibleToken"
},
{
"$ref": "#/components/schemas/NFT"
},
{
"$ref": "#/components/schemas/NFTCollection"
},
{
"$ref": "#/components/schemas/NFTCollectionWithRoyalty"
},
{
"$ref": "#/components/schemas/NonStandard"
},
{
"$ref": "#/components/schemas/Unknown"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"FungibleToken": "#/components/schemas/FungibleToken",
"NFT": "#/components/schemas/NFT",
"NFTCollection": "#/components/schemas/NFTCollection",
"NFTCollectionWithRoyalty": "#/components/schemas/NFTCollectionWithRoyalty",
"NonStandard": "#/components/schemas/NonStandard",
"Unknown": "#/components/schemas/Unknown"
}
}
},
"SubContracts": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -7940,6 +8176,21 @@
}
}
},
"Unknown": {
"required": [
"id",
"type"
],
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"Val": {
"oneOf": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import sttp.tapir.generic.auto._
import org.alephium.api.Endpoints.jsonBody
import org.alephium.explorer.api.BaseEndpoint
import org.alephium.explorer.api.EndpointExamples._
import org.alephium.explorer.api.model.{ContractParent, Pagination, SubContracts}
import org.alephium.explorer.api.model.{ContractLiveness, ContractParent, Pagination, SubContracts}
import org.alephium.protocol.model.Address

trait ContractsEndpoints extends BaseEndpoint with QueryParams {
Expand All @@ -32,6 +32,13 @@ trait ContractsEndpoints extends BaseEndpoint with QueryParams {
.tag("Contracts")
.in("contracts")

val getContractInfo: BaseEndpoint[Address.Contract, ContractLiveness] =
contractsEndpoint.get
.in(path[Address.Contract]("contract_address"))
.in("current-liveness")
.out(jsonBody[ContractLiveness])
.description("Get contract liveness")

val getParentAddress: BaseEndpoint[Address.Contract, ContractParent] =
contractsEndpoint.get
.in(path[Address.Contract]("contract_address"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ object EndpointExamples extends EndpointsExamples {
lockedBalance = U256.Two
)

private val contractInfo =
ContractLiveness(
Some(addressContract),
ContractLiveness.Location(
blockHash,
txId,
ts
),
None,
None
)

private val contractParent =
ContractParent(Some(address1))

Expand Down Expand Up @@ -343,6 +355,9 @@ object EndpointExamples extends EndpointsExamples {
implicit val contractParentExample: List[Example[ContractParent]] =
simpleExample(contractParent)

implicit val contractInfoExample: List[Example[ContractLiveness]] =
simpleExample(contractInfo)

implicit val subContractsExample: List[Example[SubContracts]] =
simpleExample(subContracts)

Expand Down
Loading
Loading