mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 18:47:38 +01:00
update oracle explorer client to use v2 of the API (#3747)
This commit is contained in:
parent
d8722c3f32
commit
ab8649a6a1
2 changed files with 35 additions and 6 deletions
|
@ -18,18 +18,18 @@ object ExplorerEnv extends StringFactory[ExplorerEnv] {
|
||||||
|
|
||||||
case object Production extends ExplorerEnv {
|
case object Production extends ExplorerEnv {
|
||||||
override val siteUrl: String = "https://oracle.suredbits.com/"
|
override val siteUrl: String = "https://oracle.suredbits.com/"
|
||||||
override val baseUri: String = s"${siteUrl}v1/"
|
override val baseUri: String = s"${siteUrl}v2/"
|
||||||
}
|
}
|
||||||
|
|
||||||
case object Test extends ExplorerEnv {
|
case object Test extends ExplorerEnv {
|
||||||
override val siteUrl: String = "https://test.oracle.suredbits.com/"
|
override val siteUrl: String = "https://test.oracle.suredbits.com/"
|
||||||
override val baseUri: String = s"${siteUrl}v1/"
|
override val baseUri: String = s"${siteUrl}v2/"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For local testing purposes */
|
/** For local testing purposes */
|
||||||
case object Local extends ExplorerEnv {
|
case object Local extends ExplorerEnv {
|
||||||
override val siteUrl: String = "http://localhost:9000/"
|
override val siteUrl: String = "http://localhost:9000/"
|
||||||
override val baseUri: String = s"${siteUrl}v1/"
|
override val baseUri: String = s"${siteUrl}v2/"
|
||||||
}
|
}
|
||||||
|
|
||||||
val all: Vector[ExplorerEnv] = Vector(Production, Test, Local)
|
val all: Vector[ExplorerEnv] = Vector(Production, Test, Local)
|
||||||
|
|
|
@ -16,7 +16,18 @@ import org.bitcoins.explorer.model.{
|
||||||
}
|
}
|
||||||
import org.bitcoins.explorer.picklers.ExplorerPicklers
|
import org.bitcoins.explorer.picklers.ExplorerPicklers
|
||||||
import org.bitcoins.tor.{Socks5ClientTransport, Socks5ProxyParams}
|
import org.bitcoins.tor.{Socks5ClientTransport, Socks5ProxyParams}
|
||||||
import play.api.libs.json.{JsError, JsSuccess, JsValue, Json}
|
import play.api.libs.json.{
|
||||||
|
JsArray,
|
||||||
|
JsBoolean,
|
||||||
|
JsError,
|
||||||
|
JsNull,
|
||||||
|
JsNumber,
|
||||||
|
JsObject,
|
||||||
|
JsString,
|
||||||
|
JsSuccess,
|
||||||
|
JsValue,
|
||||||
|
Json
|
||||||
|
}
|
||||||
|
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
|
@ -137,7 +148,6 @@ case class SbExplorerClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
private def sendRequest(httpReq: HttpRequest): Future[JsValue] = {
|
private def sendRequest(httpReq: HttpRequest): Future[JsValue] = {
|
||||||
|
|
||||||
val responsePayloadF: Future[String] = {
|
val responsePayloadF: Future[String] = {
|
||||||
httpClient
|
httpClient
|
||||||
.singleRequest(httpReq, settings = httpConnectionPoolSettings)
|
.singleRequest(httpReq, settings = httpConnectionPoolSettings)
|
||||||
|
@ -147,6 +157,25 @@ case class SbExplorerClient(
|
||||||
.map(payload => payload.decodeString(ByteString.UTF_8)))
|
.map(payload => payload.decodeString(ByteString.UTF_8)))
|
||||||
}
|
}
|
||||||
|
|
||||||
responsePayloadF.map(Json.parse)
|
val responseJsonF: Future[JsValue] = responsePayloadF.map(Json.parse)
|
||||||
|
|
||||||
|
responseJsonF.flatMap {
|
||||||
|
case x @ (_: JsNumber | _: JsString | _: JsArray | JsNull |
|
||||||
|
_: JsBoolean) =>
|
||||||
|
Future.failed(
|
||||||
|
new RuntimeException(
|
||||||
|
s"Incorrect formatted response from oracle explorer, got=$x"))
|
||||||
|
case obj: JsObject =>
|
||||||
|
val map = obj.value
|
||||||
|
val error = map.get("error")
|
||||||
|
val result = map.get("result")
|
||||||
|
if (error.get != JsNull) {
|
||||||
|
Future.failed(
|
||||||
|
new RuntimeException(
|
||||||
|
s"Error returned by oracle explroer, err=${error}"))
|
||||||
|
} else {
|
||||||
|
Future.successful(result.get)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue