-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathMantisService.scala
35 lines (33 loc) · 1.53 KB
/
MantisService.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package io.iohk.ethereum.jsonrpc
import io.iohk.ethereum.domain.Address
import io.iohk.ethereum.jsonrpc.MantisService.{GetAccountTransactionsRequest, GetAccountTransactionsResponse}
import io.iohk.ethereum.jsonrpc.server.controllers.JsonRpcBaseController.JsonRpcConfig
import io.iohk.ethereum.transactions.TransactionHistoryService
import io.iohk.ethereum.transactions.TransactionHistoryService.ExtendedTransactionData
import monix.eval.Task
import cats.implicits._
import scala.collection.immutable.NumericRange
object MantisService {
case class GetAccountTransactionsRequest(address: Address, blocksRange: NumericRange[BigInt])
case class GetAccountTransactionsResponse(transactions: List[ExtendedTransactionData])
}
class MantisService(transactionHistoryService: TransactionHistoryService, jsonRpcConfig: JsonRpcConfig) {
def getAccountTransactions(
request: GetAccountTransactionsRequest
): ServiceResponse[GetAccountTransactionsResponse] = {
if (request.blocksRange.length > jsonRpcConfig.accountTransactionsMaxBlocks) {
Task.now(
Left(
JsonRpcError.InvalidParams(
s"""Maximum number of blocks to search is ${jsonRpcConfig.accountTransactionsMaxBlocks}, requested: ${request.blocksRange.length}.
|See: 'mantis.network.rpc.account-transactions-max-blocks' config.""".stripMargin
)
)
)
} else {
transactionHistoryService
.getAccountTransactions(request.address, request.blocksRange)
.map(GetAccountTransactionsResponse(_).asRight)
}
}
}