Add listreservedutxos cli command (#2247)

This commit is contained in:
Ben Carman 2020-11-07 09:08:33 -06:00 committed by GitHub
parent 491c42bc95
commit b02eb07cf0
3 changed files with 32 additions and 1 deletions

View file

@ -578,6 +578,9 @@ object ConsoleCli {
cmd("getutxos")
.action((_, conf) => conf.copy(command = GetUtxos))
.text("Returns list of all wallet utxos"),
cmd("listreservedutxos")
.action((_, conf) => conf.copy(command = ListReservedUtxos))
.text("Returns list of all reserved wallet utxos"),
cmd("getaddresses")
.action((_, conf) => conf.copy(command = GetAddresses))
.text("Returns list of all wallet addresses currently being watched"),
@ -1114,6 +1117,8 @@ object ConsoleCli {
val requestParam: RequestParam = command match {
case GetUtxos =>
RequestParam("getutxos")
case ListReservedUtxos =>
RequestParam("listreservedutxos")
case GetAddresses =>
RequestParam("getaddresses")
case GetSpentAddresses =>
@ -1529,6 +1534,7 @@ object CliCommand {
case class GetNewAddress(labelOpt: Option[AddressLabelTag]) extends CliCommand
case object GetUtxos extends CliCommand
case object ListReservedUtxos extends CliCommand
case object GetAddresses extends CliCommand
case object GetSpentAddresses extends CliCommand
case object GetFundedAddresses extends CliCommand

View file

@ -350,6 +350,23 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
}
"return the reserved wallet utxos" in {
(mockWalletApi
.listUtxos(_: TxoState))
.expects(TxoState.Reserved)
.returning(Future.successful(Vector(spendingInfoDb)))
val route =
walletRoutes.handleCommand(ServerCommand("listreservedutxos", Arr()))
Get() ~> route ~> check {
assert(contentType == `application/json`)
assert(
responseAs[String] == """{"result":[{"outpoint":"000000000000000000000000000000000000000000000000000000000000000000000000","value":-1}],"error":null}""")
}
}
"return the wallet addresses" in {
val addressDb = LegacyAddressDb(
LegacyHDPath(HDCoinType.Testnet, 0, HDChainType.External, 0),

View file

@ -8,7 +8,7 @@ import org.bitcoins.core.api.wallet.AnyHDWalletApi
import org.bitcoins.core.api.wallet.db.SpendingInfoDb
import org.bitcoins.core.currency._
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.wallet.utxo.AddressLabelTagType
import org.bitcoins.core.wallet.utxo.{AddressLabelTagType, TxoState}
import org.bitcoins.crypto.NetworkElement
import ujson._
@ -329,6 +329,14 @@ case class WalletRoutes(wallet: AnyHDWalletApi)(implicit system: ActorSystem)
}
}
case ServerCommand("listreservedutxos", _) =>
complete {
wallet.listUtxos(TxoState.Reserved).map { utxos =>
val json = utxos.map(spendingInfoDbToJson)
Server.httpSuccess(json)
}
}
case ServerCommand("getaddresses", _) =>
complete {
wallet.listAddresses().map { addressDbs =>