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.
Fixing quickstart-scala example and doc (digital-asset#2901)
* Fixing quickstart-scala example * Updating docs * Adding Scala codegen config * Minor cleanup * Apply suggestions from code review Applying doc changes, thanks @bame-da! Co-Authored-By: Bernhard Elsner <40762178+bame-da@users.noreply.github.com>
- Loading branch information
1 parent
0f015e9
commit c982478
Showing
10 changed files
with
104 additions
and
96 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
63 changes: 57 additions & 6 deletions
63
language-support/scala/examples/quickstart-scala/README.md
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 |
---|---|---|
@@ -1,22 +1,73 @@ | ||
# quickstart-scala example | ||
|
||
This example demonstrates how to: | ||
- set up and configure Scala codegen | ||
- set up and configure Scala codegen (see `codegen` configuration in the `./daml.yaml`) | ||
- instantiate a contract and send a corresponding create command to the ledger | ||
- how to exercise a choice and send a corresponding exercise command | ||
- subscribe to receive ledger events and decode them into generated Scala ADTs | ||
|
||
This examples requires a running sandbox. To start a sandbox, run the following command from within a DAML Assistant project directory: | ||
All instructions below assume that you have DAML SDK installed. If you have not installed it yet, please follow these instructions: https://docs.daml.com/getting-started/installation.html | ||
|
||
## Create a quickstart-scala project | ||
``` | ||
daml new ./quickstart-scala quickstart-scala | ||
``` | ||
This should output: | ||
``` | ||
Created a new project in "./quickstart-scala" based on the template "quickstart-scala". | ||
``` | ||
Where: | ||
- `./quickstart-scala` is a project directory name | ||
- `quickstart-scala` is a project template name, to see the entire list of available templates, run: `daml new --list` | ||
|
||
## Compile the DAML project | ||
The DAML code for the IOU example is located in the `./daml` folder. Run the following command to build it: | ||
``` | ||
$ cd ./quickstart-scala | ||
$ daml buld | ||
``` | ||
this should output: | ||
``` | ||
Compiling quickstart to a DAR. | ||
Created .daml/dist/quickstart-0.0.1.dar. | ||
``` | ||
$ daml start | ||
|
||
## Generate Scala classes representing DAML contract templates | ||
``` | ||
$ daml codegen scala | ||
``` | ||
This should generate scala classes in the `./scala-codegen/src/main/scala` directory. See `codegen` configuration in the `daml.yaml` file: | ||
``` | ||
... | ||
codegen: | ||
scala: | ||
package-prefix: com.digitalasset.quickstart.iou.model | ||
output-directory: scala-codegen/src/main/scala | ||
verbosity: 2 | ||
``` | ||
|
||
To run the quickstart-scala example as part of a DAML Assistant project: | ||
## Start Sandbox | ||
This examples requires a running sandbox. To start it, run the following command: | ||
``` | ||
$ daml sandbox ./.daml/dist/quickstart-0.0.1.dar | ||
``` | ||
where `./.daml/dist/quickstart-0.0.1.dar` is the DAR file created in the previous step. | ||
|
||
## Compile and run Scala example | ||
Run the following command from the `quickstart-scala` folder: | ||
``` | ||
$ sbt "application/runMain com.digitalasset.quickstart.iou.IouMain localhost 6865" | ||
``` | ||
If example completes successfully, the above process should terminate and the output should look like this: | ||
``` | ||
<Sent and received messages> | ||
... | ||
11:54:03.865 [run-main-0] INFO - Shutting down... | ||
... | ||
[success] Total time: 7 s, completed Sep 12, 2019, 11:54:04 AM | ||
``` | ||
|
||
To run the quickstart-scala as a standalone project, you have to specify `da.sdk.version` and `dar.file` JVM system properties: | ||
To run the quickstart-scala as a standalone project (not part of the DAML project), or to override the default SDK version configured in the `./SDK_VERSION` file, you have to specify `da.sdk.version` JVM system properties: | ||
``` | ||
$ sbt -Dda.sdk.version=<DA_SDK_VERSION> -Ddar.file=<DAR_FILE_PATH> "application/runMain com.digitalasset.quickstart.iou.IouMain localhost 6865" | ||
$ sbt -Dda.sdk.version=<DA_SDK_VERSION> "application/runMain com.digitalasset.quickstart.iou.IouMain localhost 6865" | ||
``` |
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
22 changes: 22 additions & 0 deletions
22
language-support/scala/examples/quickstart-scala/daml.yaml
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,22 @@ | ||
sdk-version: 0.0.0 | ||
name: quickstart | ||
source: daml | ||
scenario: Main:setup | ||
parties: | ||
- Alice | ||
- Bob | ||
- USD_Bank | ||
- EUR_Bank | ||
version: 0.0.1 | ||
exposed-modules: | ||
- Main | ||
dependencies: | ||
- daml-prim | ||
- daml-stdlib | ||
# <doc-ref:codegen-scala> | ||
codegen: | ||
scala: | ||
package-prefix: com.digitalasset.quickstart.iou.model | ||
output-directory: scala-codegen/src/main/scala | ||
verbosity: 2 | ||
# </doc-ref:codegen-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
8 changes: 0 additions & 8 deletions
8
language-support/scala/examples/quickstart-scala/project/daml.sbt
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
language-support/scala/examples/quickstart-scala/project/project/Artifactory.scala
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
language-support/scala/examples/quickstart-scala/project/project/Versions.scala
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