Skip to content

Commit

Permalink
Merge pull request #2162 from mgpai22/token-post
Browse files Browse the repository at this point in the history
Token post
  • Loading branch information
kushti authored Jun 1, 2024
2 parents 53c8ed0 + e4a1d5e commit 653584d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6636,7 +6636,36 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/blockchain/tokens:
post:
summary: Retrieve minting information about a list of tokens
operationId: getTokensByIds
tags:
- blockchain
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: string
description: Token ID
responses:
'200':
description: Array of tokens with the provided IDs
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/IndexedToken'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
/blockchain/balance:
post:
summary: Retrieve confirmed and unconfirmed balance of an address
Expand Down
11 changes: 11 additions & 0 deletions src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
getBoxesByErgoTreeR ~
getBoxesByErgoTreeUnspentR ~
getTokenInfoByIdR ~
getTokenInfoByIdsR ~
getAddressBalanceTotalR ~
getAddressBalanceTotalGetRoute
}
Expand Down Expand Up @@ -326,6 +327,12 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
}
}

private def getTokenInfoByIds(ids: Seq[ModifierId]): Future[Seq[IndexedToken]] = {
getHistory.map { history =>
ids.flatMap(id => history.typedExtraIndexById[IndexedToken](uniqueId(id)))
}
}

private def getTokenInfoById(id: ModifierId): Future[Option[IndexedToken]] = {
getHistory.map { history =>
history.typedExtraIndexById[IndexedToken](uniqueId(id))
Expand All @@ -336,6 +343,10 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
ApiResponse(getTokenInfoById(id))
}

private def getTokenInfoByIdsR: Route = (post & pathPrefix("tokens") & entity(as[Seq[ModifierId]])) { ids =>
ApiResponse(getTokenInfoByIds(ids))
}

private def getBoxesByTokenId(id: ModifierId, offset: Int, limit: Int): Future[(Seq[IndexedErgoBox],Long)] =
getHistory.map { history =>
history.typedExtraIndexById[IndexedToken](uniqueId(id)) match {
Expand Down

0 comments on commit 653584d

Please sign in to comment.