mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-24 14:50:46 +01:00
Remove custom rejections
This commit is contained in:
parent
1e79bd18a7
commit
961bf3c1dd
1 changed files with 119 additions and 132 deletions
|
@ -46,13 +46,6 @@ trait NewService extends Directives with Logging with MetaService {
|
|||
complete(StatusCodes.InternalServerError, s"Error: $t")
|
||||
}
|
||||
|
||||
val apiRejectionHandler = RejectionHandler.newBuilder()
|
||||
.handle {
|
||||
case UnknownMethodRejection => complete(StatusCodes.BadRequest, "Wrong method or params combination")
|
||||
case UnknownParamsRejection => complete(StatusCodes.BadRequest, "Wrong params combination")
|
||||
}
|
||||
.result()
|
||||
|
||||
val customHeaders = `Access-Control-Allow-Headers`("Content-Type, Authorization") ::
|
||||
`Access-Control-Allow-Methods`(POST) ::
|
||||
`Cache-Control`(public, `no-store`, `max-age`(0)) :: Nil
|
||||
|
@ -86,138 +79,132 @@ trait NewService extends Directives with Logging with MetaService {
|
|||
case _ => akka.pattern.after(1 second, using = actorSystem.scheduler)(Future.successful(None)) // force a 1 sec pause to deter brute force
|
||||
}
|
||||
|
||||
case object UnknownMethodRejection extends Rejection
|
||||
|
||||
case object UnknownParamsRejection extends Rejection
|
||||
|
||||
val route: Route = {
|
||||
respondWithDefaultHeaders(customHeaders) {
|
||||
handleExceptions(apiExceptionHandler) {
|
||||
handleRejections(apiRejectionHandler) {
|
||||
withRequestTimeoutResponse(timeoutResponse) {
|
||||
authenticateBasicAsync(realm = "Access restricted", userPassAuthenticator) { _ =>
|
||||
post {
|
||||
path("getinfo") {
|
||||
complete(eclairApi.getInfoResponse())
|
||||
withRequestTimeoutResponse(timeoutResponse) {
|
||||
authenticateBasicAsync(realm = "Access restricted", userPassAuthenticator) { _ =>
|
||||
post {
|
||||
path("getinfo") {
|
||||
complete(eclairApi.getInfoResponse())
|
||||
} ~
|
||||
path("help") {
|
||||
complete(help)
|
||||
} ~
|
||||
path("help") {
|
||||
complete(help)
|
||||
} ~
|
||||
path("connect") {
|
||||
formFields("uri".as[String]) { uri =>
|
||||
complete(eclairApi.connect(uri))
|
||||
} ~ formFields("nodeId".as[PublicKey], "host".as[String], "port".as[Int]) { (nodeId, host, port) =>
|
||||
complete(eclairApi.connect(s"$nodeId@$host:$port"))
|
||||
}
|
||||
} ~
|
||||
path("open") {
|
||||
formFields("nodeId".as[PublicKey], "fundingSatoshis".as[Long], "pushMsat".as[Long].?, "fundingFeerateSatByte".as[Long].?, "channelFlags".as[Int].?) {
|
||||
(nodeId, fundingSatoshis, pushMsat, fundingFeerateSatByte, channelFlags) =>
|
||||
complete(eclairApi.open(nodeId, fundingSatoshis, pushMsat, fundingFeerateSatByte, channelFlags))
|
||||
}
|
||||
} ~
|
||||
path("close") {
|
||||
formFields(channelIdNamedParameter, "scriptPubKey".as[ByteVector](binaryDataUnmarshaller).?) { (channelId, scriptPubKey_opt) =>
|
||||
complete(eclairApi.close(Left(channelId), scriptPubKey_opt))
|
||||
} ~ formFields(shortChannelIdNamedParameter, "scriptPubKey".as[ByteVector](binaryDataUnmarshaller).?) { (shortChannelId, scriptPubKey_opt) =>
|
||||
complete(eclairApi.close(Right(shortChannelId), scriptPubKey_opt))
|
||||
}
|
||||
} ~
|
||||
path("forceclose") {
|
||||
formFields(channelIdNamedParameter) { channelId =>
|
||||
complete(eclairApi.forceClose(Left(channelId)))
|
||||
} ~ formFields(shortChannelIdNamedParameter) { shortChannelId =>
|
||||
complete(eclairApi.forceClose(Right(shortChannelId)))
|
||||
}
|
||||
} ~
|
||||
path("updaterelayfee") {
|
||||
formFields(channelIdNamedParameter, "feeBaseMsat".as[Long], "feeProportionalMillionths".as[Long]) { (channelId, feeBase, feeProportional) =>
|
||||
complete(eclairApi.updateRelayFee(channelId.toString, feeBase, feeProportional))
|
||||
}
|
||||
} ~
|
||||
path("peers") {
|
||||
complete(eclairApi.peersInfo())
|
||||
} ~
|
||||
path("channels") {
|
||||
formFields("toRemoteNodeId".as[PublicKey].?) { toRemoteNodeId_opt =>
|
||||
complete(eclairApi.channelsInfo(toRemoteNodeId_opt))
|
||||
}
|
||||
} ~
|
||||
path("channel") {
|
||||
formFields(channelIdNamedParameter) { channelId =>
|
||||
complete(eclairApi.channelInfo(channelId))
|
||||
}
|
||||
} ~
|
||||
path("allnodes") {
|
||||
complete(eclairApi.allnodes())
|
||||
} ~
|
||||
path("allchannels") {
|
||||
complete(eclairApi.allchannels())
|
||||
} ~
|
||||
path("allupdates") {
|
||||
formFields("nodeId".as[PublicKey].?) { nodeId_opt =>
|
||||
complete(eclairApi.allupdates(nodeId_opt))
|
||||
}
|
||||
} ~
|
||||
path("receive") {
|
||||
formFields("description".as[String], "amountMsat".as[Long].?, "expireIn".as[Long].?) { (desc, amountMsat, expire) =>
|
||||
complete(eclairApi.receive(desc, amountMsat, expire))
|
||||
}
|
||||
} ~
|
||||
path("parseinvoice") {
|
||||
formFields("invoice".as[PaymentRequest]) { invoice =>
|
||||
complete(invoice)
|
||||
}
|
||||
} ~
|
||||
path("findRouteByInvoice") {
|
||||
formFields("invoice".as[PaymentRequest], "amountMsat".as[Long].?) {
|
||||
case (invoice@PaymentRequest(_, Some(amount), _, nodeId, _, _), None) => complete(eclairApi.findRoute(nodeId, amount.toLong, invoice.routingInfo))
|
||||
case (invoice, Some(overrideAmount)) => complete(eclairApi.findRoute(invoice.nodeId, overrideAmount, invoice.routingInfo))
|
||||
case _ => reject(MalformedFormFieldRejection("invoice", "The invoice must have an amount or you need to specify one using 'amountMsat'"))
|
||||
}
|
||||
} ~ path("findRouteByNode") {
|
||||
formFields("nodeId".as[PublicKey], "amountMsat".as[Long]) { (nodeId, amount) =>
|
||||
complete(eclairApi.findRoute(nodeId, amount))
|
||||
path("connect") {
|
||||
formFields("uri".as[String]) { uri =>
|
||||
complete(eclairApi.connect(uri))
|
||||
} ~ formFields("nodeId".as[PublicKey], "host".as[String], "port".as[Int]) { (nodeId, host, port) =>
|
||||
complete(eclairApi.connect(s"$nodeId@$host:$port"))
|
||||
}
|
||||
} ~
|
||||
path("sendToInvoice") {
|
||||
formFields("invoice".as[PaymentRequest], "amountMsat".as[Long].?) {
|
||||
case (invoice@PaymentRequest(_, Some(amount), _, nodeId, _, _), None) =>
|
||||
complete(eclairApi.send(nodeId, amount.toLong, invoice.paymentHash, invoice.routingInfo, invoice.minFinalCltvExpiry))
|
||||
case (invoice, Some(overrideAmount)) =>
|
||||
complete(eclairApi.send(invoice.nodeId, overrideAmount, invoice.paymentHash, invoice.routingInfo, invoice.minFinalCltvExpiry))
|
||||
case _ => reject(MalformedFormFieldRejection("invoice", "The invoice must have an amount or you need to specify one using the field 'amountMsat'"))
|
||||
}
|
||||
} ~
|
||||
path("sendToNode") {
|
||||
formFields("amountMsat".as[Long], "paymentHash".as[ByteVector32](sha256HashUnmarshaller), "nodeId".as[PublicKey]) { (amountMsat, paymentHash, nodeId) =>
|
||||
complete(eclairApi.send(nodeId, amountMsat, paymentHash))
|
||||
}
|
||||
} ~
|
||||
path("checkpayment") {
|
||||
formFields("paymentHash".as[ByteVector32](sha256HashUnmarshaller)) { paymentHash =>
|
||||
complete(eclairApi.checkpayment(paymentHash))
|
||||
} ~ formFields("invoice".as[PaymentRequest]) { invoice =>
|
||||
complete(eclairApi.checkpayment(invoice.paymentHash))
|
||||
}
|
||||
} ~
|
||||
path("audit") {
|
||||
formFields("from".as[Long].?, "to".as[Long].?) { (from, to) =>
|
||||
complete(eclairApi.audit(from, to))
|
||||
}
|
||||
} ~
|
||||
path("networkfees") {
|
||||
formFields("from".as[Long].?, "to".as[Long].?) { (from, to) =>
|
||||
complete(eclairApi.networkFees(from, to))
|
||||
}
|
||||
} ~
|
||||
path("channelstats") {
|
||||
complete(eclairApi.channelStats())
|
||||
} ~
|
||||
path("ws") {
|
||||
handleWebSocketMessages(makeSocketHandler)
|
||||
path("open") {
|
||||
formFields("nodeId".as[PublicKey], "fundingSatoshis".as[Long], "pushMsat".as[Long].?, "fundingFeerateSatByte".as[Long].?, "channelFlags".as[Int].?) {
|
||||
(nodeId, fundingSatoshis, pushMsat, fundingFeerateSatByte, channelFlags) =>
|
||||
complete(eclairApi.open(nodeId, fundingSatoshis, pushMsat, fundingFeerateSatByte, channelFlags))
|
||||
}
|
||||
}
|
||||
} ~
|
||||
path("close") {
|
||||
formFields(channelIdNamedParameter, "scriptPubKey".as[ByteVector](binaryDataUnmarshaller).?) { (channelId, scriptPubKey_opt) =>
|
||||
complete(eclairApi.close(Left(channelId), scriptPubKey_opt))
|
||||
} ~ formFields(shortChannelIdNamedParameter, "scriptPubKey".as[ByteVector](binaryDataUnmarshaller).?) { (shortChannelId, scriptPubKey_opt) =>
|
||||
complete(eclairApi.close(Right(shortChannelId), scriptPubKey_opt))
|
||||
}
|
||||
} ~
|
||||
path("forceclose") {
|
||||
formFields(channelIdNamedParameter) { channelId =>
|
||||
complete(eclairApi.forceClose(Left(channelId)))
|
||||
} ~ formFields(shortChannelIdNamedParameter) { shortChannelId =>
|
||||
complete(eclairApi.forceClose(Right(shortChannelId)))
|
||||
}
|
||||
} ~
|
||||
path("updaterelayfee") {
|
||||
formFields(channelIdNamedParameter, "feeBaseMsat".as[Long], "feeProportionalMillionths".as[Long]) { (channelId, feeBase, feeProportional) =>
|
||||
complete(eclairApi.updateRelayFee(channelId.toString, feeBase, feeProportional))
|
||||
}
|
||||
} ~
|
||||
path("peers") {
|
||||
complete(eclairApi.peersInfo())
|
||||
} ~
|
||||
path("channels") {
|
||||
formFields("toRemoteNodeId".as[PublicKey].?) { toRemoteNodeId_opt =>
|
||||
complete(eclairApi.channelsInfo(toRemoteNodeId_opt))
|
||||
}
|
||||
} ~
|
||||
path("channel") {
|
||||
formFields(channelIdNamedParameter) { channelId =>
|
||||
complete(eclairApi.channelInfo(channelId))
|
||||
}
|
||||
} ~
|
||||
path("allnodes") {
|
||||
complete(eclairApi.allnodes())
|
||||
} ~
|
||||
path("allchannels") {
|
||||
complete(eclairApi.allchannels())
|
||||
} ~
|
||||
path("allupdates") {
|
||||
formFields("nodeId".as[PublicKey].?) { nodeId_opt =>
|
||||
complete(eclairApi.allupdates(nodeId_opt))
|
||||
}
|
||||
} ~
|
||||
path("receive") {
|
||||
formFields("description".as[String], "amountMsat".as[Long].?, "expireIn".as[Long].?) { (desc, amountMsat, expire) =>
|
||||
complete(eclairApi.receive(desc, amountMsat, expire))
|
||||
}
|
||||
} ~
|
||||
path("parseinvoice") {
|
||||
formFields("invoice".as[PaymentRequest]) { invoice =>
|
||||
complete(invoice)
|
||||
}
|
||||
} ~
|
||||
path("findRouteByInvoice") {
|
||||
formFields("invoice".as[PaymentRequest], "amountMsat".as[Long].?) {
|
||||
case (invoice@PaymentRequest(_, Some(amount), _, nodeId, _, _), None) => complete(eclairApi.findRoute(nodeId, amount.toLong, invoice.routingInfo))
|
||||
case (invoice, Some(overrideAmount)) => complete(eclairApi.findRoute(invoice.nodeId, overrideAmount, invoice.routingInfo))
|
||||
case _ => reject(MalformedFormFieldRejection("invoice", "The invoice must have an amount or you need to specify one using 'amountMsat'"))
|
||||
}
|
||||
} ~ path("findRouteByNode") {
|
||||
formFields("nodeId".as[PublicKey], "amountMsat".as[Long]) { (nodeId, amount) =>
|
||||
complete(eclairApi.findRoute(nodeId, amount))
|
||||
}
|
||||
} ~
|
||||
path("sendToInvoice") {
|
||||
formFields("invoice".as[PaymentRequest], "amountMsat".as[Long].?) {
|
||||
case (invoice@PaymentRequest(_, Some(amount), _, nodeId, _, _), None) =>
|
||||
complete(eclairApi.send(nodeId, amount.toLong, invoice.paymentHash, invoice.routingInfo, invoice.minFinalCltvExpiry))
|
||||
case (invoice, Some(overrideAmount)) =>
|
||||
complete(eclairApi.send(invoice.nodeId, overrideAmount, invoice.paymentHash, invoice.routingInfo, invoice.minFinalCltvExpiry))
|
||||
case _ => reject(MalformedFormFieldRejection("invoice", "The invoice must have an amount or you need to specify one using the field 'amountMsat'"))
|
||||
}
|
||||
} ~
|
||||
path("sendToNode") {
|
||||
formFields("amountMsat".as[Long], "paymentHash".as[ByteVector32](sha256HashUnmarshaller), "nodeId".as[PublicKey]) { (amountMsat, paymentHash, nodeId) =>
|
||||
complete(eclairApi.send(nodeId, amountMsat, paymentHash))
|
||||
}
|
||||
} ~
|
||||
path("checkpayment") {
|
||||
formFields("paymentHash".as[ByteVector32](sha256HashUnmarshaller)) { paymentHash =>
|
||||
complete(eclairApi.checkpayment(paymentHash))
|
||||
} ~ formFields("invoice".as[PaymentRequest]) { invoice =>
|
||||
complete(eclairApi.checkpayment(invoice.paymentHash))
|
||||
}
|
||||
} ~
|
||||
path("audit") {
|
||||
formFields("from".as[Long].?, "to".as[Long].?) { (from, to) =>
|
||||
complete(eclairApi.audit(from, to))
|
||||
}
|
||||
} ~
|
||||
path("networkfees") {
|
||||
formFields("from".as[Long].?, "to".as[Long].?) { (from, to) =>
|
||||
complete(eclairApi.networkFees(from, to))
|
||||
}
|
||||
} ~
|
||||
path("channelstats") {
|
||||
complete(eclairApi.channelStats())
|
||||
} ~
|
||||
path("ws") {
|
||||
handleWebSocketMessages(makeSocketHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue