mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
Add missing route for getaddressinfo (#1834)
This commit is contained in:
parent
9e8e57505c
commit
4d46094d72
2 changed files with 39 additions and 0 deletions
|
@ -8,6 +8,7 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest
|
||||||
import org.bitcoins.chain.api.ChainApi
|
import org.bitcoins.chain.api.ChainApi
|
||||||
import org.bitcoins.commons.jsonmodels.wallet.CoinSelectionAlgo
|
import org.bitcoins.commons.jsonmodels.wallet.CoinSelectionAlgo
|
||||||
import org.bitcoins.core.Core
|
import org.bitcoins.core.Core
|
||||||
|
import org.bitcoins.core.config.RegTest
|
||||||
import org.bitcoins.core.crypto.ExtPublicKey
|
import org.bitcoins.core.crypto.ExtPublicKey
|
||||||
import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis}
|
import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis}
|
||||||
import org.bitcoins.core.hd._
|
import org.bitcoins.core.hd._
|
||||||
|
@ -37,6 +38,7 @@ import org.bitcoins.crypto.{
|
||||||
}
|
}
|
||||||
import org.bitcoins.node.Node
|
import org.bitcoins.node.Node
|
||||||
import org.bitcoins.wallet.MockWalletApi
|
import org.bitcoins.wallet.MockWalletApi
|
||||||
|
import org.bitcoins.wallet.api.AddressInfo
|
||||||
import org.bitcoins.wallet.models._
|
import org.bitcoins.wallet.models._
|
||||||
import org.scalamock.scalatest.MockFactory
|
import org.scalamock.scalatest.MockFactory
|
||||||
import org.scalatest.wordspec.AnyWordSpec
|
import org.scalatest.wordspec.AnyWordSpec
|
||||||
|
@ -472,6 +474,27 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"get address info" in {
|
||||||
|
|
||||||
|
val key = ECPublicKey.freshPublicKey
|
||||||
|
val hdPath = HDPath.fromString("m/84'/1'/0'/0/0").get
|
||||||
|
|
||||||
|
(mockWalletApi
|
||||||
|
.getAddressInfo(_: BitcoinAddress))
|
||||||
|
.expects(testAddress)
|
||||||
|
.returning(Future.successful(Some(AddressInfo(key, RegTest, hdPath))))
|
||||||
|
|
||||||
|
val route =
|
||||||
|
walletRoutes.handleCommand(
|
||||||
|
ServerCommand("getaddressinfo", Arr(Str(testAddressStr))))
|
||||||
|
|
||||||
|
Get() ~> route ~> check {
|
||||||
|
contentType == `application/json`
|
||||||
|
responseAs[
|
||||||
|
String] == """{"result":"""" + key.hex + " " + hdPath.toString + """","error":null}"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"return a new address with a label" in {
|
"return a new address with a label" in {
|
||||||
(mockWalletApi
|
(mockWalletApi
|
||||||
.getNewAddress(_: Vector[AddressTag]))
|
.getNewAddress(_: Vector[AddressTag]))
|
||||||
|
|
|
@ -317,6 +317,22 @@ case class WalletRoutes(wallet: AnyHDWalletApi, node: Node)(implicit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ServerCommand("getaddressinfo", arr) =>
|
||||||
|
GetAddressInfo.fromJsArr(arr) match {
|
||||||
|
case Failure(err) =>
|
||||||
|
reject(ValidationRejection("failure", Some(err)))
|
||||||
|
case Success(GetAddressInfo(address)) =>
|
||||||
|
complete {
|
||||||
|
wallet.getAddressInfo(address).map {
|
||||||
|
case Some(addressInfo) =>
|
||||||
|
Server.httpSuccess(
|
||||||
|
s"${addressInfo.pubkey.hex} ${addressInfo.path.toString}")
|
||||||
|
case None =>
|
||||||
|
Server.httpSuccess("Wallet does not contain address")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case ServerCommand("createnewaccount", _) =>
|
case ServerCommand("createnewaccount", _) =>
|
||||||
complete {
|
complete {
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Add table
Reference in a new issue