14
14
* limitations under the License.
15
15
*/
16
16
17
- package fr .acinq .eclair .api
17
+ package fr .acinq .eclair .api . directives
18
18
19
+ import fr .acinq .eclair .api .serde .JsonSupport .serialization
20
+ import akka .http .scaladsl .common .{NameReceptacle , NameUnmarshallerReceptacle }
19
21
import akka .http .scaladsl .marshalling .ToResponseMarshaller
20
22
import akka .http .scaladsl .model .StatusCodes .NotFound
21
23
import akka .http .scaladsl .model .{ContentTypes , HttpResponse }
22
24
import akka .http .scaladsl .server .{Directive1 , Directives , MalformedFormFieldRejection , Route }
23
25
import fr .acinq .bitcoin .ByteVector32
24
26
import fr .acinq .bitcoin .Crypto .PublicKey
25
27
import fr .acinq .eclair .ApiTypes .ChannelIdentifier
26
- import fr .acinq .eclair .api .FormParamExtractors ._
27
- import fr .acinq .eclair .api .JsonSupport ._
28
+ import fr .acinq .eclair .api .serde . FormParamExtractors ._
29
+ import fr .acinq .eclair .api .serde . JsonSupport ._
28
30
import fr .acinq .eclair .payment .PaymentRequest
29
31
import fr .acinq .eclair .{MilliSatoshi , ShortChannelId }
30
32
@@ -34,17 +36,17 @@ import scala.util.{Failure, Success}
34
36
trait ExtraDirectives extends Directives {
35
37
36
38
// named and typed URL parameters used across several routes
37
- val shortChannelIdFormParam = " shortChannelId" .as[ShortChannelId ](shortChannelIdUnmarshaller)
38
- val shortChannelIdsFormParam = " shortChannelIds" .as[List [ShortChannelId ]](shortChannelIdsUnmarshaller)
39
- val channelIdFormParam = " channelId" .as[ByteVector32 ](sha256HashUnmarshaller)
40
- val channelIdsFormParam = " channelIds" .as[List [ByteVector32 ]](sha256HashesUnmarshaller)
41
- val nodeIdFormParam = " nodeId" .as[PublicKey ]
42
- val nodeIdsFormParam = " nodeIds" .as[List [PublicKey ]](pubkeyListUnmarshaller)
43
- val paymentHashFormParam = " paymentHash" .as[ByteVector32 ](sha256HashUnmarshaller)
44
- val fromFormParam = " from" .as[Long ]
45
- val toFormParam = " to" .as[Long ]
46
- val amountMsatFormParam = " amountMsat" .as[MilliSatoshi ]
47
- val invoiceFormParam = " invoice" .as[PaymentRequest ]
39
+ val shortChannelIdFormParam : NameUnmarshallerReceptacle [ ShortChannelId ] = " shortChannelId" .as[ShortChannelId ](shortChannelIdUnmarshaller)
40
+ val shortChannelIdsFormParam : NameUnmarshallerReceptacle [ List [ ShortChannelId ]] = " shortChannelIds" .as[List [ShortChannelId ]](shortChannelIdsUnmarshaller)
41
+ val channelIdFormParam : NameUnmarshallerReceptacle [ ByteVector32 ] = " channelId" .as[ByteVector32 ](sha256HashUnmarshaller)
42
+ val channelIdsFormParam : NameUnmarshallerReceptacle [ List [ ByteVector32 ]] = " channelIds" .as[List [ByteVector32 ]](sha256HashesUnmarshaller)
43
+ val nodeIdFormParam : NameReceptacle [ PublicKey ] = " nodeId" .as[PublicKey ]
44
+ val nodeIdsFormParam : NameUnmarshallerReceptacle [ List [ PublicKey ]] = " nodeIds" .as[List [PublicKey ]](pubkeyListUnmarshaller)
45
+ val paymentHashFormParam : NameUnmarshallerReceptacle [ ByteVector32 ] = " paymentHash" .as[ByteVector32 ](sha256HashUnmarshaller)
46
+ val fromFormParam : NameReceptacle [ Long ] = " from" .as[Long ]
47
+ val toFormParam : NameReceptacle [ Long ] = " to" .as[Long ]
48
+ val amountMsatFormParam : NameReceptacle [ MilliSatoshi ] = " amountMsat" .as[MilliSatoshi ]
49
+ val invoiceFormParam : NameReceptacle [ PaymentRequest ] = " invoice" .as[PaymentRequest ]
48
50
49
51
// custom directive to fail with HTTP 404 (and JSON response) if the element was not found
50
52
def completeOrNotFound [T ](fut : Future [Option [T ]])(implicit marshaller : ToResponseMarshaller [T ]): Route = onComplete(fut) {
0 commit comments