Skip to content

Commit

Permalink
Merge pull request #2177 from zackbalbin/i2174
Browse files Browse the repository at this point in the history
For issue #2174
  • Loading branch information
kushti authored Nov 19, 2024
2 parents 097eeec + 5214736 commit df8b288
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
Binary file added out/production/avldb/scorex/ByteUtils.class
Binary file not shown.
52 changes: 52 additions & 0 deletions src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3261,6 +3261,58 @@ paths:
schema:
$ref: '#/components/schemas/ApiError'

/transactions/unconfirmed/transactionIds:
get:
summary: Get list of unconfirmed transactions ids
operationId: getUnconfirmedTxIds
tags:
- transactions
responses:
'200':
description: List of unconfirmed transaction ids
content:
application/json:
schema:
type: array
items:
type: string
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schema/ApiError'

/transactions/unconfirmed/byTransactionIds:
post:
summary: Get list of unconfirmed transactions by their ids
operationId: getUnconfirmedTxsByIds
tags:
- transactions
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: string
responses:
'200':
description: List of unconfirmed transaction ids
content:
application/json:
schema:
type: array
items:
type: string
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/transactions/unconfirmed/byErgoTree:
parameters:
- in: query
Expand Down
11 changes: 9 additions & 2 deletions src/main/scala/org/ergoplatform/http/api/InfoApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import akka.http.scaladsl.model.ContentTypes
import akka.http.scaladsl.server.Route
import akka.pattern.ask
import io.circe.syntax._
import io.circe.Json
import org.ergoplatform.local.ErgoStatsCollector.{GetNodeInfo, NodeInfo}
import org.ergoplatform.settings.RESTApiSettings
import scorex.core.api.http.ApiResponse
Expand All @@ -19,8 +20,14 @@ case class InfoApiRoute(statsCollector: ActorRef,

override val route: Route = {
(path("info") & get) {
val timeJson = Map("currentTime" -> System.currentTimeMillis().asJson).asJson
ApiResponse((statsCollector ? GetNodeInfo).mapTo[NodeInfo].map(_.asJson.deepMerge(timeJson)))
val timeJson = Map(
"currentTime" -> System.currentTimeMillis().asJson
).asJson
ApiResponse((statsCollector ? GetNodeInfo).mapTo[NodeInfo].map { nodeInfo =>
nodeInfo.asJson.deepMerge(timeJson).deepMerge(Json.obj(
"lastMemPoolUpdateTime" -> nodeInfo.lastMemPoolUpdateTime.asJson
))
})
} ~
(path(".well-known" / "ai-plugin.json") & get) {
getFromResource(".well-known/ai-plugin.json", ContentTypes.`application/json`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ case class TransactionsApiRoute(readersHolder: ActorRef,
getUnconfirmedOutputByBoxIdR ~
getUnconfirmedInputByBoxIdR ~
getUnconfirmedTxsByErgoTreeR ~
getUnconfirmedTxIdsR ~
getUnconfirmedTxByIdR ~
getUnconfirmedTxsByIdsR ~
getUnconfirmedTransactionsR ~
unconfirmedContainsR ~
sendTransactionR ~
Expand Down Expand Up @@ -167,6 +169,29 @@ case class TransactionsApiRoute(readersHolder: ActorRef,
ApiResponse(getMemPool.map(_.modifierById(modifierId)))
}

/** Get list of unconfirmed transaction ids */
def getUnconfirmedTxIdsR: Route =
(pathPrefix("unconfirmed" / "transactionIds") & get) {
ApiResponse(getMemPool.map(_.getAll.map(_.id)))
}

/** Post list of unconfirmed transaction ids and check if they are in the mempool */
def getUnconfirmedTxsByIdsR: Route =
(pathPrefix("unconfirmed" / "transactionIds") & post & entity(as[Json])) { txIds =>
txIds.as[List[String]] match {
case Left(ex) =>
ApiError(StatusCodes.BadRequest, ex.getMessage())
case Right(ids) =>
ApiResponse(
getMemPool.map { pool =>
pool.getAll
.filter(tx => ids.contains(tx.id))
.map(_.id)
}
)
}
}

/** Collect all transactions which inputs or outputs contain given ErgoTree hex */
def getUnconfirmedTxsByErgoTreeR: Route =
(pathPrefix("unconfirmed" / "byErgoTree") & post & entity(as[Json]) & txPaging) { case (body, offset, limit) =>
Expand Down Expand Up @@ -268,4 +293,4 @@ case class TransactionsApiRoute(readersHolder: ActorRef,
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ErgoStatsCollector(readersHolder: ActorRef,
None,
launchTime = System.currentTimeMillis(),
lastIncomingMessageTime = System.currentTimeMillis(),
lastMemPoolUpdateTime = System.currentTimeMillis(),
None,
LaunchParameters,
eip27Supported = true,
Expand Down Expand Up @@ -100,6 +101,7 @@ class ErgoStatsCollector(readersHolder: ActorRef,

private def onMempoolChanged: Receive = {
case ChangedMempool(p) =>
nodeInfo = nodeInfo.copy(lastMemPoolUpdateTime = System.currentTimeMillis())
nodeInfo = nodeInfo.copy(unconfirmedCount = p.size)
}

Expand Down Expand Up @@ -171,6 +173,7 @@ object ErgoStatsCollector {
* @param maxPeerHeight - maximum block height of connected peers
* @param launchTime - when the node was launched (in Java time format, basically, UNIX time * 1000)
* @param lastIncomingMessageTime - when the node received last p2p message (in Java time)
* @param lastMemPoolUpdateTime - when the mempool was last updated (in Java time)
* @param genesisBlockIdOpt - header id of genesis block
* @param parameters - array with network parameters at the moment
* @param eip27Supported - whether EIP-27 locked in
Expand All @@ -193,6 +196,7 @@ object ErgoStatsCollector {
maxPeerHeight : Option[Int],
launchTime: Long,
lastIncomingMessageTime: Long,
lastMemPoolUpdateTime: Long,
genesisBlockIdOpt: Option[String],
parameters: Parameters,
eip27Supported: Boolean,
Expand Down Expand Up @@ -227,6 +231,7 @@ object ErgoStatsCollector {
"peersCount" -> ni.peersCount.asJson,
"launchTime" -> ni.launchTime.asJson,
"lastSeenMessageTime" -> ni.lastIncomingMessageTime.asJson,
"lastMemPoolUpdateTime" -> ni.lastMemPoolUpdateTime.asJson,
"genesisBlockId" -> ni.genesisBlockIdOpt.asJson,
"parameters" -> ni.parameters.asJson,
"eip27Supported" -> ni.eip27Supported.asJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ trait ErgoMemPoolReader extends NodeViewComponent with ContainsModifiers[ErgoTra
* @return recommended fee value for transaction to be proceeded in specified time
*/
def getRecommendedFee(expectedWaitTimeMinutes: Int, txSize: Int) : Long

}

0 comments on commit df8b288

Please sign in to comment.