Skip to content

Commit

Permalink
Merge pull request #2094 from ergoplatform/extra-api-bugfix
Browse files Browse the repository at this point in the history
Fixed empty address bug in blockchain API
  • Loading branch information
kushti committed Jan 11, 2024
2 parents 0cd8b30 + 65e948e commit 4930017
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting

private def getBoxesByAddressUnspent(addr: ErgoAddress, offset: Int, limit: Int, sortDir: Direction, unconfirmed: Boolean): Future[Seq[IndexedErgoBox]] =
getHistoryWithMempool.map { case (history, mempool) =>
getAddress(addr)(history) match {
case Some(addr) => addr.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
case None => Seq.empty[IndexedErgoBox]
}
getAddress(addr)(history)
.getOrElse(IndexedErgoAddress(hashErgoTree(addr.script)))
.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
}

private def validateAndGetBoxesByAddressUnspent(address: ErgoAddress,
Expand Down Expand Up @@ -312,10 +311,9 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting

private def getBoxesByErgoTreeUnspent(tree: ErgoTree, offset: Int, limit: Int, sortDir: Direction, unconfirmed: Boolean): Future[Seq[IndexedErgoBox]] =
getHistoryWithMempool.map { case (history, mempool) =>
getAddress(tree)(history) match {
case Some(addr) => addr.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
case None => Seq.empty[IndexedErgoBox]
}
getAddress(tree)(history)
.getOrElse(IndexedErgoAddress(hashErgoTree(tree)))
.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
}

private def getBoxesByErgoTreeUnspentR: Route = (post & pathPrefix("box" / "unspent" / "byErgoTree") & ergoTree & paging & sortDir & unconfirmed) { (tree, offset, limit, dir, unconfirmed) =>
Expand Down Expand Up @@ -352,10 +350,9 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting

private def getBoxesByTokenIdUnspent(id: ModifierId, offset: Int, limit: Int, sortDir: Direction, unconfirmed: Boolean): Future[Seq[IndexedErgoBox]] =
getHistoryWithMempool.map { case (history, mempool) =>
history.typedExtraIndexById[IndexedToken](uniqueId(id)) match {
case Some(token) => token.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
case None => Seq.empty[IndexedErgoBox]
}
history.typedExtraIndexById[IndexedToken](uniqueId(id))
.getOrElse(IndexedToken(id))
.retrieveUtxos(history, mempool, offset, limit, sortDir, unconfirmed)
}

private def getBoxesByTokenIdUnspentR: Route = (get & pathPrefix("box" / "unspent" / "byTokenId") & modifierId & paging & sortDir & unconfirmed) { (id, offset, limit, dir, unconfirmed) =>
Expand Down

0 comments on commit 4930017

Please sign in to comment.