forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defining first endpoints for ledger-service/http-json (digital-asset#…
- Loading branch information
Showing
31 changed files
with
1,120 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load( | ||
"//bazel_tools:scala.bzl", | ||
"da_scala_binary", | ||
"da_scala_library", | ||
"da_scala_test", | ||
) | ||
|
||
http_json_deps = [ | ||
"//3rdparty/jvm/ch/qos/logback:logback_classic", | ||
"//3rdparty/jvm/com/github/pureconfig", | ||
"//3rdparty/jvm/com/github/scopt", | ||
"//3rdparty/jvm/com/typesafe/akka:akka_http", | ||
"//3rdparty/jvm/com/typesafe/akka:akka_http_spray_json", | ||
"//3rdparty/jvm/com/typesafe/akka:akka_slf4j", | ||
"//3rdparty/jvm/com/typesafe/scala_logging", | ||
"//3rdparty/jvm/org/scalaz:scalaz_core", | ||
"//ledger-service/utils", | ||
"//daml-lf/interface", | ||
"//language-support/scala/bindings-akka", | ||
"//ledger-api/rs-grpc-bridge", | ||
] | ||
|
||
da_scala_library( | ||
name = "http-json", | ||
srcs = glob(["src/main/scala/**/*.scala"]), | ||
tags = ["maven_coordinates=com.digitalasset.ledger-service:http-json:__VERSION__"], | ||
deps = http_json_deps, | ||
) | ||
|
||
da_scala_binary( | ||
name = "http-json-bin", | ||
srcs = glob(["src/main/scala/**/*.scala"]), | ||
main_class = "com.digitalasset.http.Main", | ||
deps = [":http-json"] + http_json_deps, | ||
) | ||
|
||
da_scala_test( | ||
name = "tests", | ||
size = "small", | ||
srcs = glob(["src/test/scala/**/*.scala"]), | ||
deps = [ | ||
":http-json", | ||
"//3rdparty/jvm/org/scalacheck", | ||
"//3rdparty/jvm/org/scalaz:scalaz_scalacheck_binding", | ||
"//3rdparty/jvm/org/scalatest:scalatest", | ||
"//ledger/sandbox:sandbox", | ||
] + http_json_deps, | ||
) |
60 changes: 60 additions & 0 deletions
60
ledger-service/http-json/src/main/scala/com/digitalasset/http/ContractsService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset.http | ||
|
||
import akka.stream.Materializer | ||
import akka.stream.scaladsl.Sink | ||
import com.digitalasset.http.ContractsService._ | ||
import com.digitalasset.http.util.FutureUtil.toFuture | ||
import com.digitalasset.ledger.api.v1.transaction_filter.{ | ||
Filters, | ||
InclusiveFilters, | ||
TransactionFilter | ||
} | ||
import com.digitalasset.ledger.api.v1.value.{Identifier, Value} | ||
import com.digitalasset.ledger.client.services.acs.ActiveContractSetClient | ||
import scalaz.\/ | ||
import scalaz.std.string._ | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ContractsService( | ||
resolveTemplateIds: ResolveTemplateIds, | ||
activeContractSetClient: ActiveContractSetClient, | ||
parallelism: Int = 8)(implicit ec: ExecutionContext, mat: Materializer) { | ||
|
||
def lookup( | ||
jwtPayload: domain.JwtPayload, | ||
request: domain.ContractLookupRequest[Value]): Future[Option[domain.ActiveContract[Value]]] = | ||
Future.failed(new RuntimeException("contract lookup not yet supported")) // TODO | ||
|
||
def search(jwtPayload: domain.JwtPayload, request: domain.GetActiveContractsRequest) | ||
: Future[Seq[domain.GetActiveContractsResponse[Value]]] = | ||
search(jwtPayload.party, request.templateIds) | ||
|
||
def search(party: String, templateIds: Set[domain.TemplateId.OptionalPkg]) | ||
: Future[Seq[domain.GetActiveContractsResponse[Value]]] = | ||
for { | ||
templateIds <- toFuture(resolveTemplateIds(templateIds)) | ||
activeContracts <- activeContractSetClient | ||
.getActiveContracts(transactionFilter(party, templateIds), verbose = true) | ||
.mapAsyncUnordered(parallelism)(gacr => | ||
toFuture(domain.GetActiveContractsResponse.fromLedgerApi(gacr))) | ||
.runWith(Sink.seq) | ||
} yield activeContracts | ||
|
||
private def transactionFilter(party: String, templateIds: List[Identifier]): TransactionFilter = { | ||
val filters = | ||
if (templateIds.isEmpty) Filters.defaultInstance | ||
else Filters(Some(InclusiveFilters(templateIds))) | ||
TransactionFilter(Map(party -> filters)) | ||
} | ||
} | ||
|
||
object ContractsService { | ||
final case class Error(message: String) | ||
|
||
type ResolveTemplateIds = | ||
Set[domain.TemplateId.OptionalPkg] => PackageService.Error \/ List[Identifier] | ||
} |
Oops, something went wrong.