mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 06:31:55 +01:00
CLI command for filter and filter header counts (#1063)
This commit is contained in:
parent
f8d77ba261
commit
0c2d324258
4 changed files with 56 additions and 2 deletions
|
@ -36,6 +36,8 @@ object CliCommand {
|
|||
// Chain
|
||||
case object GetBestBlockHash extends CliCommand
|
||||
case object GetBlockCount extends CliCommand
|
||||
case object GetFilterCount extends CliCommand
|
||||
case object GetFilterHeaderCount extends CliCommand
|
||||
case class Rescan(
|
||||
addressBatchSize: Option[Int],
|
||||
startBlock: Option[BlockStamp],
|
||||
|
@ -63,6 +65,14 @@ object Cli extends App {
|
|||
.hidden()
|
||||
.action((_, conf) => conf.copy(command = GetBlockCount))
|
||||
.text(s"Get the block height"),
|
||||
cmd("getfiltercount")
|
||||
.hidden()
|
||||
.action((_, conf) => conf.copy(command = GetFilterCount))
|
||||
.text(s"Get the number of filters"),
|
||||
cmd("getfilterheadercount")
|
||||
.hidden()
|
||||
.action((_, conf) => conf.copy(command = GetFilterHeaderCount))
|
||||
.text(s"Get the number of filter headers"),
|
||||
cmd("getbestblockhash")
|
||||
.hidden()
|
||||
.action((_, conf) => conf.copy(command = GetBestBlockHash))
|
||||
|
@ -211,6 +221,10 @@ object Cli extends App {
|
|||
Seq(up.writeJs(address), up.writeJs(bitcoins)))
|
||||
// height
|
||||
case GetBlockCount => RequestParam("getblockcount")
|
||||
// filter count
|
||||
case GetFilterCount => RequestParam("getfiltercount")
|
||||
// filter header count
|
||||
case GetFilterHeaderCount => RequestParam("getfilterheadercount")
|
||||
// besthash
|
||||
case GetBestBlockHash => RequestParam("getbestblockhash")
|
||||
// peers
|
||||
|
|
|
@ -65,6 +65,34 @@ class RoutesSpec
|
|||
}
|
||||
}
|
||||
|
||||
"return the filter count" in {
|
||||
(mockChainApi.getFilterCount: () => Future[Int])
|
||||
.expects()
|
||||
.returning(Future.successful(1234567890))
|
||||
|
||||
val route =
|
||||
chainRoutes.handleCommand(ServerCommand("getfiltercount", Arr()))
|
||||
|
||||
Get() ~> route ~> check {
|
||||
contentType shouldEqual `application/json`
|
||||
responseAs[String] shouldEqual """{"result":1234567890,"error":null}"""
|
||||
}
|
||||
}
|
||||
|
||||
"return the filter header count" in {
|
||||
(mockChainApi.getFilterHeaderCount: () => Future[Int])
|
||||
.expects()
|
||||
.returning(Future.successful(1234567890))
|
||||
|
||||
val route =
|
||||
chainRoutes.handleCommand(ServerCommand("getfilterheadercount", Arr()))
|
||||
|
||||
Get() ~> route ~> check {
|
||||
contentType shouldEqual `application/json`
|
||||
responseAs[String] shouldEqual """{"result":1234567890,"error":null}"""
|
||||
}
|
||||
}
|
||||
|
||||
"return the best block hash" in {
|
||||
(mockChainApi.getBestBlockHash: () => Future[DoubleSha256DigestBE])
|
||||
.expects()
|
||||
|
|
|
@ -20,6 +20,18 @@ case class ChainRoutes(chain: ChainApi)(implicit system: ActorSystem)
|
|||
Server.httpSuccess(count)
|
||||
}
|
||||
}
|
||||
case ServerCommand("getfiltercount", _) =>
|
||||
complete {
|
||||
chain.getFilterCount().map { count =>
|
||||
Server.httpSuccess(count)
|
||||
}
|
||||
}
|
||||
case ServerCommand("getfilterheadercount", _) =>
|
||||
complete {
|
||||
chain.getFilterHeaderCount().map { count =>
|
||||
Server.httpSuccess(count)
|
||||
}
|
||||
}
|
||||
case ServerCommand("getbestblockhash", _) =>
|
||||
complete {
|
||||
chain.getBestBlockHash.map { hash =>
|
||||
|
|
|
@ -112,7 +112,7 @@ trait ChainApi extends ChainQueryApi {
|
|||
blockHash: DoubleSha256DigestBE): Future[ChainApi]
|
||||
|
||||
/** Gets the number of compact filter headers in the database */
|
||||
def getFilterHeaderCount: Future[Int]
|
||||
def getFilterHeaderCount(): Future[Int]
|
||||
|
||||
/**
|
||||
* Looks up a compact filter header by its height.
|
||||
|
@ -132,7 +132,7 @@ trait ChainApi extends ChainQueryApi {
|
|||
def getFilter(hash: DoubleSha256DigestBE): Future[Option[CompactFilterDb]]
|
||||
|
||||
/** Gets the number of compact filters in the database */
|
||||
def getFilterCount: Future[Int]
|
||||
def getFilterCount(): Future[Int]
|
||||
|
||||
/**
|
||||
* Looks up a compact filter by its height.
|
||||
|
|
Loading…
Add table
Reference in a new issue