diff --git a/docs/applications/escrow-payment/.gitattributes b/docs/applications/escrow-payment/.gitattributes deleted file mode 100644 index 00a51aff..00000000 --- a/docs/applications/escrow-payment/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# These are explicitly windows files and should use crlf -*.bat text eol=crlf - diff --git a/docs/applications/escrow-payment/.gitignore b/docs/applications/escrow-payment/.gitignore deleted file mode 100644 index be8ace73..00000000 --- a/docs/applications/escrow-payment/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# custom -cfssl -build -.idea - - -# Ignore Gradle project-specific cache directory -.gradle - -.settings/ -bin/ - diff --git a/docs/applications/escrow-payment/Makefile b/docs/applications/escrow-payment/Makefile deleted file mode 100644 index 1bef205b..00000000 --- a/docs/applications/escrow-payment/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -SHELL := /bin/bash - -##### BUILD -.PHONY: build -build: - @echo "Building ScalarDL escrow demo CLI" - @./gradlew build - -#### ScalarDL -.PHONY: register-cert assemble register-contracts clear register-all - -register-all: register-cert register-contracts - -register-cert: - @echo "Registering certificate ..." - @client/bin/scalardl register-cert --properties client.properties - -assemble: clear - @echo "Building contracts ..." - @./gradlew assemble - -register-contracts: assemble - @echo "Registering contracts ..." - @client/bin/scalardl register-contract --properties client.properties --contract-id AddAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.AddAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/AddAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id AddItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.AddItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/AddItem.class - @client/bin/scalardl register-contract --properties client.properties --contract-id AddOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.AddOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/AddOrder.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CancelOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.CancelOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/CancelOrder.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ChargeAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ChargeAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ChargeAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id SetOrderToReceivedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.class - @client/bin/scalardl register-contract --properties client.properties --contract-id SetOrderToShippedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ViewAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.ViewItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/ViewItem.class - @client/bin/scalardl register-contract --properties client.properties --contract-id DebitEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CreditEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CreditAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id DebitAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewOrderHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.ViewOrderHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewEscrowAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.class - -clear: - @rm -rf build - - -#### Scenario test -.PHONY: run-complete-order-scenario run-cancel-order-scenario all -run-complete-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 6000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="order shipped -id order_1 -s seller_1" - @./gradlew run --args="order received -id order_1 -b buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="account view -id seller_1" - @./gradlew run --args="escrow view -b buyer_1 -s seller_1" - -run-cancel-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 50000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 10000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="order cancel -id order_1 -a buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - - - - - diff --git a/docs/applications/escrow-payment/README.mdx b/docs/applications/escrow-payment/README.mdx deleted file mode 100644 index d6e3a4d5..00000000 --- a/docs/applications/escrow-payment/README.mdx +++ /dev/null @@ -1,250 +0,0 @@ -# ScalarDL Escrow payment CLI - -The following is a simple Java CLI application to try out and test [ScalarDL](https://github.com/scalar-labs/scalardl). PicoCLI is used as a CLI framework. - -ScalarDL has support and SDK for multiple languages. In this example, JAVA is used. - -As this is just a sample project, all commands can be run via Gradle. This is not a production-ready example and is only provided as study material. - -Please check out the mentioned Makefile commands and the official ScalarDL documentation to see which commands are being executed. - - - -## Introduction - -### Escrow - -Instead of directly transferring the funds from account A to account B an intermediary account is -introduced. The funds are locked in this intermediary account until both parties agreed that the -transaction is completed. Should something go wrong both the buyer and the seller cannot access the -funds until the issue is resolved. - -The following is a typical Escrow payment flow: - -- Registered buyer with account A, buys an item from a registered seller with account B -- An order entry is created and the order is set to the `open` status -- An escrow account between the two parties is created -- Account A is credited and the funds are moved to the escrow account -- The seller updates the order and notifies of shipment of the package -- The order is updated and set to the `shipped` status -- After receiving the package, the buyer updates the order and marks it as received -- The Escrow account is credited and the funds are moved to account B. -- The order is closed and marked with status `complete` - -Order cancellation is possible but only while the order is still in the `open` status. After the -goods are shipped, the order cannot be cancelled in the current implementation - - - -## Features - -This CLI application provides to most important actions to simulate an escrow payment flow. Extra -actions are supported for data lookup and monitoring. - -The following actions are supported: - -**Account** - -- register a new account -- add funds, charge, an account -- view account history - -**Item** - -- register a new item -- view item details - -**Order** - -- create a new order -- Mark an order as shipped -- Mark and order as received (complete an order) -- Cancel an order -- View order history - -**Escrow Account** - -- View escrow account history - - - -## Prerequisites - -- Docker - -- Makefile - -- Java - - - -## Setup - -### ScalarDL - -The code to start up the ScalarDL server is not included in this repository. To get ScalarDL up and running quickly, please clone the [following repository](https://github.com/scalar-labs/scalardl-samples) and follow the provided instructions on how to get started with ScalarDL. - -### Certificate - -An example certificate is used but is enough for the example. The certiticate can be loaded -via `make register-certificate` - -### Contracts - -All the contract names have an added suffix. This is the name of the certificate owner which in this -case is `foo`. This is not required and only done to make sure the contract names are unique. - -The contracts can be loaded via `make register-contracts` - -### Client SDK - -The Java client SDK requires a `client.properties` file to work. Currently the same settings as the -scalar examples projects are used. - -### Test scenarios - -Two example test scenarios are provided to see the payment and order cancellation flow in practice. - -The scenarios can be run via `make run-complete-order-scenario` and `make run-cancel-order-scenario` - - - -## Usage - -### Build - -The application can be build via `./gradlew build` or by running the `make build` Makefile command. - -### CLI commands - -#### Account - -Management of the accounts via CLI. - -##### Create account - -Create a new account by supplying the `id` which is string and can be anything. The account -automatically will have it's `balance` set to 0 and `created_at` set to the current timestamp. - -*Command* - -``` -./gradlew run --args="account add -id -n " -``` - -##### View account history - -Retrieve the account history. - -*Command* - -``` -./gradlew run --args="account view -id " -``` - -##### Charge account - -Add funds to the account's balance. - -*Command* - -``` -./gradlew run --args="account charge -id -a " -``` - -#### Item - -Management of the items via CLI. - -##### Create item - -Create a new item by providing an `id`, a `price` and `seller`, which is the account Id, and an -item `name`. - -*Command* - -``` -./gradlew run --args="item add -id -p -s " -``` - -##### View item - -View item details - -*Command* - -``` -./gradlew run --args="item view -id " -``` - -#### Order - -Management of the orders via CLI. - -##### Create order - -Create a new order by providing an `id`, a `item id` and `buyer`, which is the account Id. - -*Command* - -``` -./gradlew run --args="order add -id -b -i " -``` - -##### Cancel order - -Cancel an order that is currently in `open` status. Orders cannot be cancelled anymore when in -another state. A `account id` is required and validated. If the order does not belong to the -specified account, it can not be cancelled. - -*Command* - -``` -./gradlew run --args="order cancel -id -a " -``` - -##### Mark order item as shipped - -Update the order as a seller to notify the buyer the item has been shipped. - -*Command* - -``` -./gradlew run --args="order shipped -id -s " -``` - -##### Mark order item as received - -Update the order as a buyer to notify the seller the item has been received. The order will be -completed. - -*Command* - -``` -./gradlew run --args="order received -id -b " -``` - -##### View order history - -View the history for one order. - -*Command* - -``` -./gradlew run --args="order view -id " -``` - -#### Escrow account - -Management of the escrow accounts via CLI. - -##### View escrow account history - -View the activity and update history for one specific escrow account between buyer and seller - -*Command* - -``` -./gradlew run --args="escrow view -b -s " -``` - diff --git a/docs/applications/escrow-payment/build.gradle b/docs/applications/escrow-payment/build.gradle deleted file mode 100644 index 283ad318..00000000 --- a/docs/applications/escrow-payment/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.1/userguide/building_java_projects.html - */ - -plugins { - // Apply the application plugin to add support for building a CLI application in Java. - id 'application' -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -dependencies { - // Use JUnit test framework. - testImplementation 'junit:junit:4.13.2' - - // This dependency is used by the application. - implementation 'com.google.guava:guava:30.1-jre' - implementation group: 'info.picocli', name: 'picocli', version: '4.6.1' - implementation group: 'com.scalar-labs', name: 'scalardl-java-client-sdk', version: '3.0.1' - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2' - - testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.14.0' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.2.0' - testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0' - testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.3.1' - testImplementation 'org.hashids:hashids:1.0.3' -} - -application { - // Define the main class for the application. - mainClass = 'com.ypeckstadt.escrow.Main' -} - -test { - useJUnitPlatform() -} diff --git a/docs/applications/escrow-payment/client.properties b/docs/applications/escrow-payment/client.properties deleted file mode 100644 index 2794d227..00000000 --- a/docs/applications/escrow-payment/client.properties +++ /dev/null @@ -1,29 +0,0 @@ -# Optional. A hostname or an IP address of the server. Use localhost by default if not specified. -# It assuems that there is a single endpoint that is given by DNS or a load balancer. -#scalar.dl.client.server.host=localhost -# Optional. A port number of the server. Use 50051 by default if not specified. -#scalar.dl.client.server.port=50051 -# Optional. A port number of the server for privileged services. Use 50052 by default if not specified. -#scalar.dl.client.server.privileged_port=50052 -# Required. The holder ID of a certificate. -# It must be configured for each private key and unique in the system. -scalar.dl.client.cert_holder_id=foo -# Optional. The version of the certificate. Use 1 by default if not specified. -# Use another bigger integer if you need to change your private key. -#scalar.dl.client.cert_version=1 -# Required. The path of the certificate file. -scalar.dl.client.cert_path=./fixture/client.pem -# Required. The path of a corresponding private key file to the certificate. -# Exceptionally it can be empty in some requests to privileged services -# such as registerCertificate and registerFunction since they don't need a signature. -scalar.dl.client.private_key_path=./fixture/client-key.pem -# Optional. A flag to enable TLS communication. False by default. -#scalar.dl.client.tls.enabled=false -# Optional. A custom CA root certificate for TLS communication. -# If the issuing certificate authority is known to the client, it can be empty. -#scalar.dl.client.tls.ca_root_cert_path=/path/to/ca-root-cert -# Optional. An authorization credential. (e.g. authorization: Bearer token) -# If this is given, clients will add "authorization: " http/2 header. -#scalar.dl.client.authorization.credential=credential -# Experimental. Proxy server -#scalar.dl.client.proxy.server=localhost:10051 diff --git a/docs/applications/escrow-payment/fixture/client-key.pem b/docs/applications/escrow-payment/fixture/client-key.pem deleted file mode 100644 index ed5fbd4a..00000000 --- a/docs/applications/escrow-payment/fixture/client-key.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIJHySQ7Dsapydvq06ismdaD38kqZXDe7TQq/0/nokUwHoAoGCCqGSM49 -AwEHoUQDQgAEUjQhpkHcHYagBompS7Lxfx9QdIwW1WWxBtZ+z6KEEh8xrQInJIaM -FOPtIskQ6oPdKnuxMf3T1h3sVjW6pIwi3w== ------END EC PRIVATE KEY----- diff --git a/docs/applications/escrow-payment/fixture/client.pem b/docs/applications/escrow-payment/fixture/client.pem deleted file mode 100644 index 7aacf6a7..00000000 --- a/docs/applications/escrow-payment/fixture/client.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICjTCCAjKgAwIBAgIUacmufnXYLxwZkSssxVjBePp4zoUwCgYIKoZIzj0EAwIw -bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf -MB0GA1UEChMWU2NhbGFyIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2NhbGFy -IEludGVybWVkaWF0ZSBDQTAeFw0yMTA2MzAwMzA4MDBaFw0yNDA2MjkwMzA4MDBa -MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ -bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC -AARSNCGmQdwdhqAGialLsvF/H1B0jBbVZbEG1n7PooQSHzGtAickhowU4+0iyRDq -g90qe7Ex/dPWHexWNbqkjCLfo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE -DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTRioMqi4AZX+dU -Y1+YAVtyWMtMszAfBgNVHSMEGDAWgBQgvyjyoVxJUr2q5UpJng2NUCjgAjAxBggr -BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq -BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG -SM49BAMCA0kAMEYCIQCYTdQjk6kNJxOWoGUAsXMGhiTWtrPKrZxxvJjkD87/4QIh -APfY/gpIqfSu71YWIdRDbk2McECIRgHkXTd8ArIKUz8C ------END CERTIFICATE----- diff --git a/docs/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties b/docs/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a97150..00000000 --- a/docs/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/docs/applications/escrow-payment/gradlew b/docs/applications/escrow-payment/gradlew deleted file mode 100755 index 744e882e..00000000 --- a/docs/applications/escrow-payment/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/docs/applications/escrow-payment/gradlew.bat b/docs/applications/escrow-payment/gradlew.bat deleted file mode 100644 index 107acd32..00000000 --- a/docs/applications/escrow-payment/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/docs/applications/escrow-payment/settings.gradle b/docs/applications/escrow-payment/settings.gradle deleted file mode 100644 index 6a00f360..00000000 --- a/docs/applications/escrow-payment/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/7.1/userguide/multi_project_builds.html - */ - -rootProject.name = 'scalardl-escrow-demo-java' -include('app') diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java deleted file mode 100644 index ff93a903..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ypeckstadt.escrow; - -import com.ypeckstadt.escrow.command.account.AccountCommand; -import com.ypeckstadt.escrow.command.escrowAccount.EscrowAccountCommand; -import com.ypeckstadt.escrow.command.item.ItemCommand; -import com.ypeckstadt.escrow.command.order.OrderCommand; -import java.io.IOException; -import picocli.CommandLine; - -@CommandLine.Command( - name = "app", - description = "ScalarDL escrow demo CLI", - mixinStandardHelpOptions = true, - version = "1.0", - subcommands = { - AccountCommand.class, - ItemCommand.class, - OrderCommand.class, - EscrowAccountCommand.class - }) -public class Main { - public static void main(String[] args) throws IOException { - // Display the help if no arguments are passed - String[] commandArgs = args.length != 0 ? args : new String[] {"--help"}; - int exitCode = new CommandLine(new Main()).execute(commandArgs); - System.exit(exitCode); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java deleted file mode 100644 index 7b337e0b..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "account", - description = "manage accounts", - subcommands = { - AddAccountCommand.class, - ViewAccountHistoryCommand.class, - ChargeAccountCommand.class - }) -public class AccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java deleted file mode 100644 index 9eb6fc52..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.ypeckstadt.escrow.contract.account.AddAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ACCOUNT ID", - description = "the account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "the account owner's name", - required = true) - String name; - - @Override - public Integer call() throws Exception { - - // Add account - JsonObject argument = - Json.createObjectBuilder() - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(AddAccount.class.getSimpleName(), argument, true); - LOG.info("The account has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java deleted file mode 100644 index 67ef333e..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; - -import com.ypeckstadt.escrow.contract.account.ChargeAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "charge") -public class ChargeAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ChargeAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-a", "--amount"}, - paramLabel = "AMOUNT", - description = "amount to charge", - required = true) - int amount; - - @Override - public Integer call() throws Exception { - // Charge account - JsonObject argument = - Json.createObjectBuilder() - .add(ChargeAccount.AMOUNT, amount) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(ChargeAccount.class.getSimpleName(), argument, true); - LOG.info("Funds have been added to the account successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java deleted file mode 100644 index 74b71e96..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.account.ViewAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "the account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ACCOUNT_ID, accountId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java deleted file mode 100644 index ddb34d84..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "escrow", - description = "view escrow accounts history", - subcommands = { - ViewEscrowAccountHistoryCommand.class, - }) -public class EscrowAccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java deleted file mode 100644 index 9ddf9215..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewEscrowAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewEscrowAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "ID", - description = "buyer account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "ID", - description = "seller account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(ViewEscrowAccountHistory.BUYER_ACCOUNT_ID, buyerAccountId) - .add(ViewEscrowAccountHistory.SELLER_ACCOUNT_ID, sellerAccountId) - .build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewEscrowAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java deleted file mode 100644 index 9d7c0c1e..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.ypeckstadt.escrow.contract.item.AddItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "item id", - required = true) - String itemId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "item name", - required = true) - String name; - - @CommandLine.Option( - names = {"-p", "--price"}, - paramLabel = "PRICE", - description = "item price", - required = true) - int price; - - @CommandLine.Option( - names = {"-s", "--seller"}, - paramLabel = "SELLER", - description = "seller's account id", - required = true) - String seller; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(AddItem.NAME, name) - .add(AddItem.SELLER_ACCOUNT_ID, seller) - .add(AddItem.PRICE, price) - .add(AddItem.TIMESTAMP, new Date().getTime()) - .add(AddItem.ID, itemId) - .build(); - - try { - executeContract(AddItem.class.getSimpleName(), argument, true); - LOG.info("The item has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java deleted file mode 100644 index 7b74e24a..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "item", - description = "manage items", - subcommands = { - AddItemCommand.class, - ViewItemCommand.class, - }) -public class ItemCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java deleted file mode 100644 index d6a5b9df..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.item.ViewItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--itemId"}, - paramLabel = "ITEM", - description = "the item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ViewItem.ID, itemId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewItem.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java deleted file mode 100644 index 4e2caa0f..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.AddOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyer"}, - paramLabel = "BUYER", - description = "buyer's account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-i", "--item"}, - paramLabel = "ITEM", - description = "item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - // Add order - JsonObject argument = - Json.createObjectBuilder() - .add(AddOrder.ID, orderId) - .add(AddOrder.BUYER_ACCOUNT_ID, buyerAccountId) - .add(AddOrder.ITEM_ID, itemId) - .add(AddOrder.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(AddOrder.class.getSimpleName(), argument, true); - LOG.info( - "The order has been added successfully. Waiting for the seller to mark the item as" - + " shipped."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java deleted file mode 100644 index 3e147c2b..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.CancelOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "cancel") -public class CancelOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(CancelOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-a", "--accountId"}, - paramLabel = "ACCOUNT", - description = "buyer or seller account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(CancelOrder.ACCOUNT_ID, accountId) - .add(CancelOrder.TIMESTAMP, new Date().getTime()) - .add(CancelOrder.ID, orderId) - .build(); - - try { - executeContract(CancelOrder.class.getSimpleName(), argument, true); - LOG.info("The order has been cancelled successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java deleted file mode 100644 index dcec55ff..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "order", - description = "manage orders", - subcommands = { - ViewOrderHistoryCommand.class, - AddOrderCommand.class, - ShippedItemsOrderCommand.class, - ReceivedItemsOrderCommand.class, - CancelOrderCommand.class, - }) -public class OrderCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java deleted file mode 100644 index 60028162..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "received") -public class ReceivedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ReceivedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "BUYER ID", - description = "the buyer's account id", - required = true) - String buyerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToReceivedStatus.ID, orderId) - .add(SetOrderToReceivedStatus.BUYER_ACCOUNT_ID, buyerAccountId) - .add(SetOrderToReceivedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToReceivedStatus.class.getSimpleName(), argument, true); - LOG.info("The order has completed."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java deleted file mode 100644 index 3bbbbbd8..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "shipped") -public class ShippedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ShippedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "SELLER ID", - description = "the seller's account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToShippedStatus.ID, orderId) - .add(SetOrderToShippedStatus.SELLER_ACCOUNT_ID, sellerAccountId) - .add(SetOrderToShippedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToShippedStatus.class.getSimpleName(), argument, true); - LOG.info( - "The order has been updated successfully. Waiting for the buyer to mark the item as" - + " received."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java deleted file mode 100644 index 981d6e48..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.order.ViewOrderHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewOrderHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewOrderHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ID", - description = "the order id", - required = true) - String orderId; - - @Override - public Integer call() throws Exception { - - // prepare contract arguments - JsonObject argument = Json.createObjectBuilder().add(ViewOrderHistory.ID, orderId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewOrderHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java deleted file mode 100644 index d8d504be..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ypeckstadt.escrow.common; - -public class Constants { - // Account related json names - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ACCOUNT_ID = "id"; - public static final String ACCOUNT_NAME = "name"; - public static final String ACCOUNT_TIMESTAMP = "timestamp"; - public static final String ACCOUNT_BALANCE = "balance"; - public static final String ACCOUNT_BALANCE_CHANGE = "balance_change"; - - // Contract error messages - public static final String CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR = - "wrong or missing arguments to create an account"; - public static final String CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR = - "an account with this id already exists"; -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java deleted file mode 100644 index 9d9fe551..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddAccount extends Contract { - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(ACCOUNT_NAME) - || !argument.containsKey(ACCOUNT_TIMESTAMP)) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - // Get field data - String name = argument.getString(ACCOUNT_NAME); - long timestamp = argument.getJsonNumber(ACCOUNT_TIMESTAMP).longValue(); - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ACCOUNT_ID, accountId) - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_BALANCE, 0) - .add(ACCOUNT_BALANCE_CHANGE, 0) - .add(ACCOUNT_TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java deleted file mode 100644 index 9e81ee00..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class ChargeAccount extends Contract { - - public static final String ID = "id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - public static final String NAME = "name"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to charge an account"); - } - - // get input data - String accountId = argument.getString(ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if account exists - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - Optional optionalAsset = ledger.get(assetId); - if (!optionalAsset.isPresent()) { - throw new ContractContextException("the provided account does not exist"); - } - - // calculate new balance - JsonObject assetData = optionalAsset.get().data(); - int newBalance = assetData.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, assetData.get(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java deleted file mode 100644 index d8da2b17..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditAccount extends Contract { - - public static final String ACCOUNT_ID = "account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to credit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // check balance - JsonObject account = asset.get().data(); - int balance = account.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the account has insufficient funds"); - } - - // credit account - int newBalance = balance - amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java deleted file mode 100644 index dbbae076..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditEscrowAccount extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - public static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to credit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - if (!optionalEscrowAccount.isPresent()) { - throw new ContractContextException("no escrow account was found"); - } - - // calculate new balance - int newBalance = optionalEscrowAccount.get().data().getInt(BALANCE) - amount; - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java deleted file mode 100644 index 1dccc696..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitAccount extends Contract { - - private static final String ACCOUNT_ID = "account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ID = "id"; - private static final String NAME = "name"; - private static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to debit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // debit balance - JsonObject account = asset.get().data(); - int newBalance = account.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java deleted file mode 100644 index 8a720dc0..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitEscrowAccount extends Contract { - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to debit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check buyer's account sufficient funds - JsonObject buyerAccount = optionalBuyerAsset.get().data(); - int balance = buyerAccount.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the buyer's account has insufficient funds"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - - // calculate new balance - int newBalance = amount; - if (optionalEscrowAccount.isPresent()) { - newBalance += optionalEscrowAccount.get().data().getInt(BALANCE); - } - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java deleted file mode 100644 index 9cd00cc6..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewAccountHistory extends Contract { - - public static final String ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - private static final String HISTORY = "account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for account lookup"); - } - - // Determine asset id - String accountId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + accountId; - - // Retrieve account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no account with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String name = data.getString(NAME); - int balance = data.getInt(BALANCE); - int balanceChange = data.getInt(BALANCE_CHANGE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(NAME, name) - .add(BALANCE, balance) - .add(BALANCE_CHANGE, balanceChange) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java deleted file mode 100644 index 0014d639..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.ypeckstadt.escrow.contract.escrowAccount; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.*; - -public class ViewEscrowAccountHistory extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String HISTORY = "escrow_account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) || !argument.containsKey(SELLER_ACCOUNT_ID)) { - throw new ContractContextException("missing ID argument for escrow account lookup"); - } - - // Determine asset id - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String assetId = ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - - // Retrieve escrow account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException( - "no escrow account between this seller and buyer was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String orderId = data.getString(ORDER_ID); - int balance = data.getInt(BALANCE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(BALANCE, balance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java deleted file mode 100644 index baba5a59..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddItem extends Contract { - - public static final String ITEM_ASSET_TYPE = "item"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(NAME) - || !argument.containsKey(PRICE) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an item"); - } - - // get field data from arguments - String itemId = argument.getString(ID); - String name = argument.getString(NAME); - int price = argument.getInt(PRICE); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - - // determine asset id - String assetId = ITEM_ASSET_TYPE + "_" + itemId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException("an item with this id already exists"); - } - - // validate the seller has an account - String accountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - asset = ledger.get(accountAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("the provided seller does not have an account"); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, itemId) - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(TIMESTAMP, timestamp); - - // add item - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java deleted file mode 100644 index 1638aa58..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; - -public class ViewItem extends Contract { - - public static final String ASSET_TYPE = "item"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for item lookup"); - } - - // Determine asset id - String itemId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + itemId; - - // Retrieve item - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("no item with this id was found"); - } - - // get field data - JsonObject data = asset.get().data(); - String id = data.getString(ID); - String name = data.getString(NAME); - String seller = data.getString(SELLER_ACCOUNT_ID); - int price = data.getInt(PRICE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // asset json object builder - return Json.createObjectBuilder() - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, seller) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java deleted file mode 100644 index 8cb9385c..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddOrder extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String ITEM_ID = "item_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String ID = "id"; - - private static final String ITEM_ASSET_TYPE = "item"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ID = "account_id"; - private static final String ITEM_PRICE = "price"; - private static final String TOTAL = "total"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ORDER_ID = "order_id"; - private static final String STATUS = "status"; - private static final String DEBIT_ESCROW_ACCOUNT_CONTRACT = "DebitEscrowAccount_foo"; - private static final String CREDIT_ACCOUNT_CONTRACT = "CreditAccount_foo"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ITEM_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an order"); - } - - // get field data from arguments - String itemId = argument.getString(ITEM_ID); - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String orderId = argument.getString(ID); - - // determine asset ids - String itemAssetId = ITEM_ASSET_TYPE + "_" + itemId; - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - - // check if the item exists - Optional optionalItemAsset = ledger.get(itemAssetId); - if (!optionalItemAsset.isPresent()) { - throw new ContractContextException("the item does not exist"); - } - - // check if the buyer's account exists - Optional optionalBuyerAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAccountAsset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // get json object data - JsonObject item = optionalItemAsset.get().data(); - int itemPrice = item.getInt(ITEM_PRICE); - String sellerAccountId = item.getString(SELLER_ACCOUNT_ID); - - // Debit escrow and credit are split into 2 separate contracts to not make the contract to heavy - // and test calling external contracts. - // In a normal situation both actions will always follow each other so it makes more sense to - // put it into one contract - - // Debit escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, itemPrice) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Credit buyer's account - JsonObject creditArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, itemPrice) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ACCOUNT_CONTRACT, ledger, creditArguments); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_OPEN) - .add(TOTAL, itemPrice) - .add(TIMESTAMP, timestamp); - - // add order record - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java deleted file mode 100644 index 2c8b0e57..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CancelOrder extends Contract { - - public static final String ID = "id"; - public static final String ACCOUNT_ID = "account_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String STATUS = "status"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String ORDER_STATUS_CANCELLED = "cancelled"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String TOTAL = "total"; - private static final String AMOUNT = "amount"; - private static final String ORDER_ID = "order_id"; - private static final String ITEM_ID = "item_id"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to cancel an order"); - } - - // Get input data - String orderId = argument.getString(ID); - - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - - // check if order exists - Optional asset = ledger.get(orderAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("no order with this id was found"); - } - - // Get order data - JsonObject order = asset.get().data(); - String orderStatus = order.getString(STATUS); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - long timestamp = order.getJsonNumber(TIMESTAMP).longValue(); - String itemId = order.getString(ITEM_ID); - - // check order status ,if still in open mode, cant be cancelled after - if (!orderStatus.equals(ORDER_STATUS_OPEN)) { - throw new ContractContextException("the order cannot be cancelled anymore"); - } - - // make sure the account id is a seller or buyer - if (!accountId.equals(buyerAccountId) && !accountId.equals(sellerAccountId)) { - throw new ContractContextException("the order does not belong to the account"); - } - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit buyer account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - // update order, set to cancelled status - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_CANCELLED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java deleted file mode 100644 index 76fbec83..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToReceivedStatus extends Contract { - - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_COMPLETE = "complete"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - private static final String ACCOUNT_ID = "account_id"; - private static final String TOTAL = "total"; - private static final String ORDER_ID = "order_id"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as received"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if buyer's account exists - Optional optionalAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if the order belongs to the buyer - JsonObject order = optionalOrderAsset.get().data(); - String orderBuyerAccountId = order.getString(BUYER_ACCOUNT_ID); - if (!buyerAccountId.equals(orderBuyerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the buyer"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_COMPLETE) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit Seller account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java deleted file mode 100644 index 410aac54..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToShippedStatus extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_SHIPPED = "shipped"; - private static final String TOTAL = "total"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as shipped"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if seller's account exists - Optional optionalAccountAsset = ledger.get(sellerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check if the order belongs to the seller - JsonObject order = optionalOrderAsset.get().data(); - String orderSellerAccountId = order.getString(SELLER_ACCOUNT_ID); - if (!sellerAccountId.equals(orderSellerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the seller"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_SHIPPED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java deleted file mode 100644 index 344fe68b..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewOrderHistory extends Contract { - - public static final String ID = "id"; - - private static final String ASSET_TYPE = "order"; - private static final String TIMESTAMP = "timestamp"; - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String TOTAL = "total"; - - private static final String HISTORY = "order_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for order lookup"); - } - - // Determine asset id - String orderId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + orderId; - - // Retrieve order history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no order with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String itemId = data.getString(ITEM_ID); - String buyerAccountId = data.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = data.getString(SELLER_ACCOUNT_ID); - String status = data.getString(STATUS); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - int total = data.getInt(TOTAL); - - // build json object result - JsonObject order = - Json.createObjectBuilder() - .add(ID, id) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, status) - .add(TOTAL, total) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(order); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java b/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java deleted file mode 100644 index 61d3de7f..00000000 --- a/docs/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.ypeckstadt.escrow.dl; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.scalar.dl.client.config.ClientConfig; -import com.scalar.dl.client.service.ClientModule; -import com.scalar.dl.client.service.ClientService; -import com.scalar.dl.ledger.model.ContractExecutionResult; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public abstract class LedgerClientExecutor { - - private static final Logger LOG = LogManager.getLogger(LedgerClientExecutor.class); - private static final String CLIENT_PROPERTIES = "client.properties"; - - private ClientConfig loadClientConfig() throws Exception { - File file = new File(System.getProperty("user.dir") + File.separator + CLIENT_PROPERTIES); - return new ClientConfig(file); - } - - protected ContractExecutionResult executeContract( - String contractName, JsonObject contractParameter, boolean useCertHolderIdSuffix) - throws Exception { - ClientConfig config = loadClientConfig(); - - // Custom naming convention to make sure the contract Id is unique, not required and contractId - // can be anything - // just make sure the contractId is set to the same value as specified when registering the - // contract on the ledger - String contractId = - useCertHolderIdSuffix ? contractName + "_" + config.getCertHolderId() : contractName; - - Injector injector = Guice.createInjector(new ClientModule(config)); - ClientService service = injector.getInstance(ClientService.class); - JsonObject object = - (contractParameter != null) ? contractParameter : Json.createObjectBuilder().build(); - return service.executeContract(contractId, object); - } - - /** - * Pretty print the json to the standard output - * - * @param json the json to print - */ - protected void prettyPrintJson(JsonObject jsonObject) { - if (jsonObject != null) { - System.out.println("[Return]"); - Map config = new HashMap<>(1); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonWriterFactory factory = Json.createWriterFactory(config); - JsonWriter writer = factory.createWriter(System.out); - writer.writeObject(jsonObject); - System.out.println(""); - writer.close(); - } - } -} diff --git a/docs/applications/escrow-payment/src/main/resources/log4j2.properties b/docs/applications/escrow-payment/src/main/resources/log4j2.properties deleted file mode 100644 index a3f65c97..00000000 --- a/docs/applications/escrow-payment/src/main/resources/log4j2.properties +++ /dev/null @@ -1,18 +0,0 @@ -name=PropertiesConfig -property.filename = logs -appenders = console, file - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -appender.file.type = File -appender.file.name = LOGFILE -appender.file.fileName=${filename}/propertieslogs.log -appender.file.layout.type=PatternLayout -appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -rootLogger.level = info -rootLogger.appenderRefs = stdout -rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/docs/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java b/docs/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java deleted file mode 100644 index ad63ded5..00000000 --- a/docs/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ASSET_TYPE; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_NAME; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.crypto.CertificateEntry.Key; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -public class AddAccountTest { - - private static final String MOCKED_HOLDER_ID = "mockedHolderId"; - - @Mock private Ledger ledger; - @Mock private Key mockedKey; - @Spy private AddAccount addAccount; - - @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); - when(addAccount.getCertificateKey()).thenReturn(mockedKey); - when(mockedKey.getHolderId()).thenReturn(MOCKED_HOLDER_ID); - } - - @Test - public void invoke_InsertNonexistentAccount_ShouldInsertAccount() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, null); - - // Act - JsonObject invokeResult = addAccount.invoke(ledger, argument, Optional.of(properties)); - assertEquals(invokeResult, null); - } - - @Test - public void invoke_ArgumentsMissing_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = Json.createObjectBuilder().build(); - JsonObject properties = prepareProperties(); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - @Test - public void invoke_InsertExistentAccount_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, mock(Asset.class)); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - private JsonObject prepareArgument() { - return Json.createObjectBuilder() - .add(ACCOUNT_ID, "1") - .add(ACCOUNT_NAME, "name") - .add(ACCOUNT_TIMESTAMP, System.currentTimeMillis()) - .build(); - } - - private JsonObject prepareProperties() { - return Json.createObjectBuilder().build(); - } - - private void mockLedgerGetCall(JsonObject argument, Asset result) { - when(ledger.get(getAssetId(argument))).thenReturn(Optional.ofNullable(result)); - } - - private String getAssetId(JsonObject argument) { - return ACCOUNT_ASSET_TYPE + "_" + argument.getString(ACCOUNT_ID); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitattributes b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitattributes deleted file mode 100644 index 00a51aff..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# These are explicitly windows files and should use crlf -*.bat text eol=crlf - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitignore b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitignore deleted file mode 100644 index be8ace73..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# custom -cfssl -build -.idea - - -# Ignore Gradle project-specific cache directory -.gradle - -.settings/ -bin/ - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/Makefile b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/Makefile deleted file mode 100644 index 1bef205b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -SHELL := /bin/bash - -##### BUILD -.PHONY: build -build: - @echo "Building ScalarDL escrow demo CLI" - @./gradlew build - -#### ScalarDL -.PHONY: register-cert assemble register-contracts clear register-all - -register-all: register-cert register-contracts - -register-cert: - @echo "Registering certificate ..." - @client/bin/scalardl register-cert --properties client.properties - -assemble: clear - @echo "Building contracts ..." - @./gradlew assemble - -register-contracts: assemble - @echo "Registering contracts ..." - @client/bin/scalardl register-contract --properties client.properties --contract-id AddAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.AddAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/AddAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id AddItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.AddItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/AddItem.class - @client/bin/scalardl register-contract --properties client.properties --contract-id AddOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.AddOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/AddOrder.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CancelOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.CancelOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/CancelOrder.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ChargeAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ChargeAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ChargeAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id SetOrderToReceivedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.class - @client/bin/scalardl register-contract --properties client.properties --contract-id SetOrderToShippedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ViewAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.ViewItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/ViewItem.class - @client/bin/scalardl register-contract --properties client.properties --contract-id DebitEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CreditEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id CreditAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id DebitAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitAccount.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewOrderHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.ViewOrderHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.class - @client/bin/scalardl register-contract --properties client.properties --contract-id ViewEscrowAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.class - -clear: - @rm -rf build - - -#### Scenario test -.PHONY: run-complete-order-scenario run-cancel-order-scenario all -run-complete-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 6000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="order shipped -id order_1 -s seller_1" - @./gradlew run --args="order received -id order_1 -b buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="account view -id seller_1" - @./gradlew run --args="escrow view -b buyer_1 -s seller_1" - -run-cancel-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 50000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 10000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="order cancel -id order_1 -a buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - - - - - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/README.mdx b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/README.mdx deleted file mode 100644 index 2e544692..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/README.mdx +++ /dev/null @@ -1,229 +0,0 @@ -# ScalarDL エスクロー支払い CLI - -import TranslationBanner from '/src/components/_translation-ja-jp.mdx'; - - - -以下は、[ScalarDL](https://github.com/scalar-labs/scalardl) を試してテストするための簡単な Java CLI アプリケーションです。 CLI フレームワークとして PicoCLI が使用されます。 - -ScalarDL には複数の言語のサポートと SDK があります。 この例ではJAVAが使用されています。 - -これは単なるサンプル プロジェクトであるため、すべてのコマンドは Gradle 経由で実行できます。 これは本番環境に対応した例ではなく、学習資料としてのみ提供されています。 - -どのコマンドが実行されているかを確認するには、前述の Makefile コマンドと ScalarDL の公式ドキュメントを確認してください。 - -## 導入 - -### 預託 - -口座 A から口座 B に資金を直接送金する代わりに、仲介口座が導入されます。 両当事者が取引の完了に同意するまで、資金はこの仲介口座にロックされます。 何か問題が発生した場合、問題が解決されるまで買い手と売り手の両方が資金にアクセスできなくなります。 - -以下は典型的なエスクロー支払いフローです。 - -- アカウント A を持つ登録購入者は、アカウント B を持つ登録販売者から商品を購入します。 -- 注文エントリが作成され、注文は `open` ステータスに設定されます。 -- 両当事者間でエスクローアカウントが作成されます。 -- アカウント A に入金され、資金がエスクロー口座に移動されます。 -- 販売者は注文を更新し、パッケージの発送を通知します。 -- 注文が更新され、 `shipped` ステータスに設定されます。 -- パッケージを受け取った後、購入者は注文を更新し、受信済みとしてマークします。 -- エスクロー口座に入金され、資金が口座 B に移動されます。 -- 注文はクローズされ、ステータスが `complete` とマークされます。 - -注文のキャンセルは可能ですが、注文がまだ `open` ステータスにある場合に限ります。 後に -商品が発送された後、現在の実装では注文をキャンセルすることはできません。 - -## 特徴 - -この CLI アプリケーションは、エスクロー支払いフローをシミュレートするための最も重要なアクションを提供します。 データの検索と監視のために追加のアクションがサポートされています。 - -次のアクションがサポートされています。 - -**アカウント** - -- 新しいアカウントを登録する -- 資金の追加、チャージ、アカウント -- アカウント履歴の表示 - -**アイテム** - -- 新しいアイテムを登録する -- アイテムの詳細を表示 - -**注文** - -- 新しい注文を作成する -- 注文を発送済みとしてマークする -- 受領済みとしてマークして注文する (注文を完了する) -- 注文をキャンセルする -- 注文履歴の表示 - -**エスクローアカウント** - -- エスクローアカウント履歴の表示 - -## 前提条件 - -- Docker -- Makefile -- Java - -## 設定 - -### ScalarDL - -ScalarDL サーバーを起動するコードは、このリポジトリには含まれていません。 ScalarDL をすぐに起動して実行するには、[次のリポジトリ](https://github.com/scalar-labs/scalardl-samples) のクローンを作成し、ScalarDL の使用を開始するためのコマンドに従ってください。 - -### 証明書 - -証明書の例が使用されていますが、例としては十分です。 証明書は `make register-certificate` 経由でロードできます。 - -### コントラクト - -すべてのコントラクト名には接尾辞が追加されます。 これは証明書所有者の名前で、この場合は `foo` です。 これは必須ではなく、コントラクト名が一意であることを確認するためにのみ行われます。 - -コントラクトは `make register-contracts` を通じてロードできます。 - -### クライアント SDK - -Java クライアント SDK が動作するには、 `client.properties` ファイルが必要です。 現在、ScalarDL サンプル プロジェクトと同じ設定が使用されています。 - -### テストシナリオ - -実際の支払いと注文キャンセルのフローを確認するために、2 つのテスト シナリオの例が提供されています。 - -シナリオは、`make run-complete-order-scenario` および `make run-cancel-order-scenario` によって実行できます。 - -## 使用法 - -### 建てる - -アプリケーションは、`./gradlew build` を介して、または `make build` Makefile コマンドを実行することによってビルドできます。 - -### CLI コマンド - -#### アカウント - -CLI を介したアカウントの管理。 - -##### アカウントを作成する - -文字列で何でもよい `id` を指定して、新しいアカウントを作成します。 アカウントの `balance` は 0 に設定され、`created_at` は現在のタイムスタンプに自動的に設定されます。 - -*コマンド* - -``` -./gradlew run --args="account add -id -n " -``` - -##### アカウント履歴の表示 - -アカウント履歴を取得します。 - -*コマンド* - -``` -./gradlew run --args="account view -id " -``` - -##### チャージアカウント - -アカウントの残高に資金を追加します。 - -*コマンド* - -``` -./gradlew run --args="account charge -id -a " -``` - -#### アイテム - -CLI を介したアイテムの管理。 - -##### アイテムの作成 - -`id`、`price`、`seller` (アカウント ID)、およびアイテムの `name` を指定して、新しいアイテムを作成します。 - -*コマンド* - -``` -./gradlew run --args="item add -id -p -s " -``` - -##### アイテムの表示 - -アイテムの詳細を見る - -*コマンド* - -``` -./gradlew run --args="item view -id " -``` - -#### 注文 - -CLI を介した注文の管理。 - -##### 注文の作成 - -`id`、`item id`、およびアカウント ID である `buyer` を指定して、新しい注文を作成します。 - -*コマンド* - -``` -./gradlew run --args="order add -id -b -i " -``` - -##### 注文をキャンセルする - -現在 `open` ステータスにある注文をキャンセルします。 他の州では注文をキャンセルできなくなります。 `account id` は必須であり、検証されます。 注文が指定されたアカウントに属していない場合、注文をキャンセルすることはできません。 - -*コマンド* - -``` -./gradlew run --args="order cancel -id -a " -``` - -##### 注文アイテムを発送済みとしてマークする - -販売者として注文を更新し、商品が発送されたことを購入者に通知します。 - -*コマンド* - -``` -./gradlew run --args="order shipped -id -s " -``` - -##### 注文アイテムを受領済みとしてマークする - -購入者として注文を更新し、商品が受け取られたことを販売者に通知します。 ご注文が完了となります。 - -*コマンド* - -``` -./gradlew run --args="order received -id -b " -``` - -##### 注文履歴の表示 - -1 つの注文の履歴を表示します。 - -*コマンド* - -``` -./gradlew run --args="order view -id " -``` - -#### エスクローアカウント - -CLI を介したエスクロー アカウントの管理。 - -##### エスクローアカウント履歴の表示 - -買い手と売り手の間の特定のエスクロー口座のアクティビティと更新履歴を表示します - -*コマンド* - -``` -./gradlew run --args="escrow view -b -s " -``` diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/build.gradle b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/build.gradle deleted file mode 100644 index 283ad318..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.1/userguide/building_java_projects.html - */ - -plugins { - // Apply the application plugin to add support for building a CLI application in Java. - id 'application' -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -dependencies { - // Use JUnit test framework. - testImplementation 'junit:junit:4.13.2' - - // This dependency is used by the application. - implementation 'com.google.guava:guava:30.1-jre' - implementation group: 'info.picocli', name: 'picocli', version: '4.6.1' - implementation group: 'com.scalar-labs', name: 'scalardl-java-client-sdk', version: '3.0.1' - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2' - - testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.14.0' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.2.0' - testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0' - testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.3.1' - testImplementation 'org.hashids:hashids:1.0.3' -} - -application { - // Define the main class for the application. - mainClass = 'com.ypeckstadt.escrow.Main' -} - -test { - useJUnitPlatform() -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/client.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/client.properties deleted file mode 100644 index 2794d227..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/client.properties +++ /dev/null @@ -1,29 +0,0 @@ -# Optional. A hostname or an IP address of the server. Use localhost by default if not specified. -# It assuems that there is a single endpoint that is given by DNS or a load balancer. -#scalar.dl.client.server.host=localhost -# Optional. A port number of the server. Use 50051 by default if not specified. -#scalar.dl.client.server.port=50051 -# Optional. A port number of the server for privileged services. Use 50052 by default if not specified. -#scalar.dl.client.server.privileged_port=50052 -# Required. The holder ID of a certificate. -# It must be configured for each private key and unique in the system. -scalar.dl.client.cert_holder_id=foo -# Optional. The version of the certificate. Use 1 by default if not specified. -# Use another bigger integer if you need to change your private key. -#scalar.dl.client.cert_version=1 -# Required. The path of the certificate file. -scalar.dl.client.cert_path=./fixture/client.pem -# Required. The path of a corresponding private key file to the certificate. -# Exceptionally it can be empty in some requests to privileged services -# such as registerCertificate and registerFunction since they don't need a signature. -scalar.dl.client.private_key_path=./fixture/client-key.pem -# Optional. A flag to enable TLS communication. False by default. -#scalar.dl.client.tls.enabled=false -# Optional. A custom CA root certificate for TLS communication. -# If the issuing certificate authority is known to the client, it can be empty. -#scalar.dl.client.tls.ca_root_cert_path=/path/to/ca-root-cert -# Optional. An authorization credential. (e.g. authorization: Bearer token) -# If this is given, clients will add "authorization: " http/2 header. -#scalar.dl.client.authorization.credential=credential -# Experimental. Proxy server -#scalar.dl.client.proxy.server=localhost:10051 diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client-key.pem b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client-key.pem deleted file mode 100644 index ed5fbd4a..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client-key.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIJHySQ7Dsapydvq06ismdaD38kqZXDe7TQq/0/nokUwHoAoGCCqGSM49 -AwEHoUQDQgAEUjQhpkHcHYagBompS7Lxfx9QdIwW1WWxBtZ+z6KEEh8xrQInJIaM -FOPtIskQ6oPdKnuxMf3T1h3sVjW6pIwi3w== ------END EC PRIVATE KEY----- diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client.pem b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client.pem deleted file mode 100644 index 7aacf6a7..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/fixture/client.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICjTCCAjKgAwIBAgIUacmufnXYLxwZkSssxVjBePp4zoUwCgYIKoZIzj0EAwIw -bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf -MB0GA1UEChMWU2NhbGFyIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2NhbGFy -IEludGVybWVkaWF0ZSBDQTAeFw0yMTA2MzAwMzA4MDBaFw0yNDA2MjkwMzA4MDBa -MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ -bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC -AARSNCGmQdwdhqAGialLsvF/H1B0jBbVZbEG1n7PooQSHzGtAickhowU4+0iyRDq -g90qe7Ex/dPWHexWNbqkjCLfo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE -DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTRioMqi4AZX+dU -Y1+YAVtyWMtMszAfBgNVHSMEGDAWgBQgvyjyoVxJUr2q5UpJng2NUCjgAjAxBggr -BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq -BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG -SM49BAMCA0kAMEYCIQCYTdQjk6kNJxOWoGUAsXMGhiTWtrPKrZxxvJjkD87/4QIh -APfY/gpIqfSu71YWIdRDbk2McECIRgHkXTd8ArIKUz8C ------END CERTIFICATE----- diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a97150..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew deleted file mode 100755 index 744e882e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew.bat b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew.bat deleted file mode 100644 index 107acd32..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/settings.gradle b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/settings.gradle deleted file mode 100644 index 6a00f360..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/7.1/userguide/multi_project_builds.html - */ - -rootProject.name = 'scalardl-escrow-demo-java' -include('app') diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java deleted file mode 100644 index ff93a903..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ypeckstadt.escrow; - -import com.ypeckstadt.escrow.command.account.AccountCommand; -import com.ypeckstadt.escrow.command.escrowAccount.EscrowAccountCommand; -import com.ypeckstadt.escrow.command.item.ItemCommand; -import com.ypeckstadt.escrow.command.order.OrderCommand; -import java.io.IOException; -import picocli.CommandLine; - -@CommandLine.Command( - name = "app", - description = "ScalarDL escrow demo CLI", - mixinStandardHelpOptions = true, - version = "1.0", - subcommands = { - AccountCommand.class, - ItemCommand.class, - OrderCommand.class, - EscrowAccountCommand.class - }) -public class Main { - public static void main(String[] args) throws IOException { - // Display the help if no arguments are passed - String[] commandArgs = args.length != 0 ? args : new String[] {"--help"}; - int exitCode = new CommandLine(new Main()).execute(commandArgs); - System.exit(exitCode); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java deleted file mode 100644 index 7b337e0b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "account", - description = "manage accounts", - subcommands = { - AddAccountCommand.class, - ViewAccountHistoryCommand.class, - ChargeAccountCommand.class - }) -public class AccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java deleted file mode 100644 index 9eb6fc52..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.ypeckstadt.escrow.contract.account.AddAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ACCOUNT ID", - description = "the account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "the account owner's name", - required = true) - String name; - - @Override - public Integer call() throws Exception { - - // Add account - JsonObject argument = - Json.createObjectBuilder() - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(AddAccount.class.getSimpleName(), argument, true); - LOG.info("The account has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java deleted file mode 100644 index 67ef333e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; - -import com.ypeckstadt.escrow.contract.account.ChargeAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "charge") -public class ChargeAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ChargeAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-a", "--amount"}, - paramLabel = "AMOUNT", - description = "amount to charge", - required = true) - int amount; - - @Override - public Integer call() throws Exception { - // Charge account - JsonObject argument = - Json.createObjectBuilder() - .add(ChargeAccount.AMOUNT, amount) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(ChargeAccount.class.getSimpleName(), argument, true); - LOG.info("Funds have been added to the account successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java deleted file mode 100644 index 74b71e96..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.account.ViewAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "the account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ACCOUNT_ID, accountId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java deleted file mode 100644 index ddb34d84..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "escrow", - description = "view escrow accounts history", - subcommands = { - ViewEscrowAccountHistoryCommand.class, - }) -public class EscrowAccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java deleted file mode 100644 index 9ddf9215..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewEscrowAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewEscrowAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "ID", - description = "buyer account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "ID", - description = "seller account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(ViewEscrowAccountHistory.BUYER_ACCOUNT_ID, buyerAccountId) - .add(ViewEscrowAccountHistory.SELLER_ACCOUNT_ID, sellerAccountId) - .build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewEscrowAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java deleted file mode 100644 index 9d7c0c1e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.ypeckstadt.escrow.contract.item.AddItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "item id", - required = true) - String itemId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "item name", - required = true) - String name; - - @CommandLine.Option( - names = {"-p", "--price"}, - paramLabel = "PRICE", - description = "item price", - required = true) - int price; - - @CommandLine.Option( - names = {"-s", "--seller"}, - paramLabel = "SELLER", - description = "seller's account id", - required = true) - String seller; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(AddItem.NAME, name) - .add(AddItem.SELLER_ACCOUNT_ID, seller) - .add(AddItem.PRICE, price) - .add(AddItem.TIMESTAMP, new Date().getTime()) - .add(AddItem.ID, itemId) - .build(); - - try { - executeContract(AddItem.class.getSimpleName(), argument, true); - LOG.info("The item has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java deleted file mode 100644 index 7b74e24a..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "item", - description = "manage items", - subcommands = { - AddItemCommand.class, - ViewItemCommand.class, - }) -public class ItemCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java deleted file mode 100644 index d6a5b9df..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.item.ViewItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--itemId"}, - paramLabel = "ITEM", - description = "the item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ViewItem.ID, itemId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewItem.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java deleted file mode 100644 index 4e2caa0f..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.AddOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyer"}, - paramLabel = "BUYER", - description = "buyer's account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-i", "--item"}, - paramLabel = "ITEM", - description = "item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - // Add order - JsonObject argument = - Json.createObjectBuilder() - .add(AddOrder.ID, orderId) - .add(AddOrder.BUYER_ACCOUNT_ID, buyerAccountId) - .add(AddOrder.ITEM_ID, itemId) - .add(AddOrder.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(AddOrder.class.getSimpleName(), argument, true); - LOG.info( - "The order has been added successfully. Waiting for the seller to mark the item as" - + " shipped."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java deleted file mode 100644 index 3e147c2b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.CancelOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "cancel") -public class CancelOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(CancelOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-a", "--accountId"}, - paramLabel = "ACCOUNT", - description = "buyer or seller account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(CancelOrder.ACCOUNT_ID, accountId) - .add(CancelOrder.TIMESTAMP, new Date().getTime()) - .add(CancelOrder.ID, orderId) - .build(); - - try { - executeContract(CancelOrder.class.getSimpleName(), argument, true); - LOG.info("The order has been cancelled successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java deleted file mode 100644 index dcec55ff..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "order", - description = "manage orders", - subcommands = { - ViewOrderHistoryCommand.class, - AddOrderCommand.class, - ShippedItemsOrderCommand.class, - ReceivedItemsOrderCommand.class, - CancelOrderCommand.class, - }) -public class OrderCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java deleted file mode 100644 index 60028162..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "received") -public class ReceivedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ReceivedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "BUYER ID", - description = "the buyer's account id", - required = true) - String buyerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToReceivedStatus.ID, orderId) - .add(SetOrderToReceivedStatus.BUYER_ACCOUNT_ID, buyerAccountId) - .add(SetOrderToReceivedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToReceivedStatus.class.getSimpleName(), argument, true); - LOG.info("The order has completed."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java deleted file mode 100644 index 3bbbbbd8..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "shipped") -public class ShippedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ShippedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "SELLER ID", - description = "the seller's account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToShippedStatus.ID, orderId) - .add(SetOrderToShippedStatus.SELLER_ACCOUNT_ID, sellerAccountId) - .add(SetOrderToShippedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToShippedStatus.class.getSimpleName(), argument, true); - LOG.info( - "The order has been updated successfully. Waiting for the buyer to mark the item as" - + " received."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java deleted file mode 100644 index 981d6e48..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.order.ViewOrderHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewOrderHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewOrderHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ID", - description = "the order id", - required = true) - String orderId; - - @Override - public Integer call() throws Exception { - - // prepare contract arguments - JsonObject argument = Json.createObjectBuilder().add(ViewOrderHistory.ID, orderId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewOrderHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java deleted file mode 100644 index d8d504be..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ypeckstadt.escrow.common; - -public class Constants { - // Account related json names - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ACCOUNT_ID = "id"; - public static final String ACCOUNT_NAME = "name"; - public static final String ACCOUNT_TIMESTAMP = "timestamp"; - public static final String ACCOUNT_BALANCE = "balance"; - public static final String ACCOUNT_BALANCE_CHANGE = "balance_change"; - - // Contract error messages - public static final String CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR = - "wrong or missing arguments to create an account"; - public static final String CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR = - "an account with this id already exists"; -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java deleted file mode 100644 index 9d9fe551..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddAccount extends Contract { - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(ACCOUNT_NAME) - || !argument.containsKey(ACCOUNT_TIMESTAMP)) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - // Get field data - String name = argument.getString(ACCOUNT_NAME); - long timestamp = argument.getJsonNumber(ACCOUNT_TIMESTAMP).longValue(); - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ACCOUNT_ID, accountId) - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_BALANCE, 0) - .add(ACCOUNT_BALANCE_CHANGE, 0) - .add(ACCOUNT_TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java deleted file mode 100644 index 9e81ee00..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class ChargeAccount extends Contract { - - public static final String ID = "id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - public static final String NAME = "name"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to charge an account"); - } - - // get input data - String accountId = argument.getString(ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if account exists - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - Optional optionalAsset = ledger.get(assetId); - if (!optionalAsset.isPresent()) { - throw new ContractContextException("the provided account does not exist"); - } - - // calculate new balance - JsonObject assetData = optionalAsset.get().data(); - int newBalance = assetData.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, assetData.get(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java deleted file mode 100644 index d8da2b17..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditAccount extends Contract { - - public static final String ACCOUNT_ID = "account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to credit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // check balance - JsonObject account = asset.get().data(); - int balance = account.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the account has insufficient funds"); - } - - // credit account - int newBalance = balance - amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java deleted file mode 100644 index dbbae076..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditEscrowAccount extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - public static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to credit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - if (!optionalEscrowAccount.isPresent()) { - throw new ContractContextException("no escrow account was found"); - } - - // calculate new balance - int newBalance = optionalEscrowAccount.get().data().getInt(BALANCE) - amount; - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java deleted file mode 100644 index 1dccc696..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitAccount extends Contract { - - private static final String ACCOUNT_ID = "account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ID = "id"; - private static final String NAME = "name"; - private static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to debit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // debit balance - JsonObject account = asset.get().data(); - int newBalance = account.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java deleted file mode 100644 index 8a720dc0..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitEscrowAccount extends Contract { - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to debit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check buyer's account sufficient funds - JsonObject buyerAccount = optionalBuyerAsset.get().data(); - int balance = buyerAccount.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the buyer's account has insufficient funds"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - - // calculate new balance - int newBalance = amount; - if (optionalEscrowAccount.isPresent()) { - newBalance += optionalEscrowAccount.get().data().getInt(BALANCE); - } - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java deleted file mode 100644 index 9cd00cc6..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewAccountHistory extends Contract { - - public static final String ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - private static final String HISTORY = "account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for account lookup"); - } - - // Determine asset id - String accountId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + accountId; - - // Retrieve account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no account with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String name = data.getString(NAME); - int balance = data.getInt(BALANCE); - int balanceChange = data.getInt(BALANCE_CHANGE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(NAME, name) - .add(BALANCE, balance) - .add(BALANCE_CHANGE, balanceChange) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java deleted file mode 100644 index 0014d639..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.ypeckstadt.escrow.contract.escrowAccount; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.*; - -public class ViewEscrowAccountHistory extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String HISTORY = "escrow_account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) || !argument.containsKey(SELLER_ACCOUNT_ID)) { - throw new ContractContextException("missing ID argument for escrow account lookup"); - } - - // Determine asset id - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String assetId = ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - - // Retrieve escrow account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException( - "no escrow account between this seller and buyer was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String orderId = data.getString(ORDER_ID); - int balance = data.getInt(BALANCE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(BALANCE, balance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java deleted file mode 100644 index baba5a59..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddItem extends Contract { - - public static final String ITEM_ASSET_TYPE = "item"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(NAME) - || !argument.containsKey(PRICE) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an item"); - } - - // get field data from arguments - String itemId = argument.getString(ID); - String name = argument.getString(NAME); - int price = argument.getInt(PRICE); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - - // determine asset id - String assetId = ITEM_ASSET_TYPE + "_" + itemId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException("an item with this id already exists"); - } - - // validate the seller has an account - String accountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - asset = ledger.get(accountAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("the provided seller does not have an account"); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, itemId) - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(TIMESTAMP, timestamp); - - // add item - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java deleted file mode 100644 index 1638aa58..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; - -public class ViewItem extends Contract { - - public static final String ASSET_TYPE = "item"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for item lookup"); - } - - // Determine asset id - String itemId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + itemId; - - // Retrieve item - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("no item with this id was found"); - } - - // get field data - JsonObject data = asset.get().data(); - String id = data.getString(ID); - String name = data.getString(NAME); - String seller = data.getString(SELLER_ACCOUNT_ID); - int price = data.getInt(PRICE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // asset json object builder - return Json.createObjectBuilder() - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, seller) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java deleted file mode 100644 index 8cb9385c..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddOrder extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String ITEM_ID = "item_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String ID = "id"; - - private static final String ITEM_ASSET_TYPE = "item"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ID = "account_id"; - private static final String ITEM_PRICE = "price"; - private static final String TOTAL = "total"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ORDER_ID = "order_id"; - private static final String STATUS = "status"; - private static final String DEBIT_ESCROW_ACCOUNT_CONTRACT = "DebitEscrowAccount_foo"; - private static final String CREDIT_ACCOUNT_CONTRACT = "CreditAccount_foo"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ITEM_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an order"); - } - - // get field data from arguments - String itemId = argument.getString(ITEM_ID); - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String orderId = argument.getString(ID); - - // determine asset ids - String itemAssetId = ITEM_ASSET_TYPE + "_" + itemId; - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - - // check if the item exists - Optional optionalItemAsset = ledger.get(itemAssetId); - if (!optionalItemAsset.isPresent()) { - throw new ContractContextException("the item does not exist"); - } - - // check if the buyer's account exists - Optional optionalBuyerAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAccountAsset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // get json object data - JsonObject item = optionalItemAsset.get().data(); - int itemPrice = item.getInt(ITEM_PRICE); - String sellerAccountId = item.getString(SELLER_ACCOUNT_ID); - - // Debit escrow and credit are split into 2 separate contracts to not make the contract to heavy - // and test calling external contracts. - // In a normal situation both actions will always follow each other so it makes more sense to - // put it into one contract - - // Debit escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, itemPrice) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Credit buyer's account - JsonObject creditArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, itemPrice) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ACCOUNT_CONTRACT, ledger, creditArguments); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_OPEN) - .add(TOTAL, itemPrice) - .add(TIMESTAMP, timestamp); - - // add order record - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java deleted file mode 100644 index 2c8b0e57..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CancelOrder extends Contract { - - public static final String ID = "id"; - public static final String ACCOUNT_ID = "account_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String STATUS = "status"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String ORDER_STATUS_CANCELLED = "cancelled"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String TOTAL = "total"; - private static final String AMOUNT = "amount"; - private static final String ORDER_ID = "order_id"; - private static final String ITEM_ID = "item_id"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to cancel an order"); - } - - // Get input data - String orderId = argument.getString(ID); - - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - - // check if order exists - Optional asset = ledger.get(orderAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("no order with this id was found"); - } - - // Get order data - JsonObject order = asset.get().data(); - String orderStatus = order.getString(STATUS); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - long timestamp = order.getJsonNumber(TIMESTAMP).longValue(); - String itemId = order.getString(ITEM_ID); - - // check order status ,if still in open mode, cant be cancelled after - if (!orderStatus.equals(ORDER_STATUS_OPEN)) { - throw new ContractContextException("the order cannot be cancelled anymore"); - } - - // make sure the account id is a seller or buyer - if (!accountId.equals(buyerAccountId) && !accountId.equals(sellerAccountId)) { - throw new ContractContextException("the order does not belong to the account"); - } - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit buyer account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - // update order, set to cancelled status - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_CANCELLED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java deleted file mode 100644 index 76fbec83..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToReceivedStatus extends Contract { - - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_COMPLETE = "complete"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - private static final String ACCOUNT_ID = "account_id"; - private static final String TOTAL = "total"; - private static final String ORDER_ID = "order_id"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as received"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if buyer's account exists - Optional optionalAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if the order belongs to the buyer - JsonObject order = optionalOrderAsset.get().data(); - String orderBuyerAccountId = order.getString(BUYER_ACCOUNT_ID); - if (!buyerAccountId.equals(orderBuyerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the buyer"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_COMPLETE) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit Seller account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java deleted file mode 100644 index 410aac54..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToShippedStatus extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_SHIPPED = "shipped"; - private static final String TOTAL = "total"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as shipped"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if seller's account exists - Optional optionalAccountAsset = ledger.get(sellerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check if the order belongs to the seller - JsonObject order = optionalOrderAsset.get().data(); - String orderSellerAccountId = order.getString(SELLER_ACCOUNT_ID); - if (!sellerAccountId.equals(orderSellerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the seller"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_SHIPPED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java deleted file mode 100644 index 344fe68b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewOrderHistory extends Contract { - - public static final String ID = "id"; - - private static final String ASSET_TYPE = "order"; - private static final String TIMESTAMP = "timestamp"; - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String TOTAL = "total"; - - private static final String HISTORY = "order_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for order lookup"); - } - - // Determine asset id - String orderId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + orderId; - - // Retrieve order history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no order with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String itemId = data.getString(ITEM_ID); - String buyerAccountId = data.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = data.getString(SELLER_ACCOUNT_ID); - String status = data.getString(STATUS); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - int total = data.getInt(TOTAL); - - // build json object result - JsonObject order = - Json.createObjectBuilder() - .add(ID, id) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, status) - .add(TOTAL, total) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(order); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java deleted file mode 100644 index 61d3de7f..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.ypeckstadt.escrow.dl; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.scalar.dl.client.config.ClientConfig; -import com.scalar.dl.client.service.ClientModule; -import com.scalar.dl.client.service.ClientService; -import com.scalar.dl.ledger.model.ContractExecutionResult; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public abstract class LedgerClientExecutor { - - private static final Logger LOG = LogManager.getLogger(LedgerClientExecutor.class); - private static final String CLIENT_PROPERTIES = "client.properties"; - - private ClientConfig loadClientConfig() throws Exception { - File file = new File(System.getProperty("user.dir") + File.separator + CLIENT_PROPERTIES); - return new ClientConfig(file); - } - - protected ContractExecutionResult executeContract( - String contractName, JsonObject contractParameter, boolean useCertHolderIdSuffix) - throws Exception { - ClientConfig config = loadClientConfig(); - - // Custom naming convention to make sure the contract Id is unique, not required and contractId - // can be anything - // just make sure the contractId is set to the same value as specified when registering the - // contract on the ledger - String contractId = - useCertHolderIdSuffix ? contractName + "_" + config.getCertHolderId() : contractName; - - Injector injector = Guice.createInjector(new ClientModule(config)); - ClientService service = injector.getInstance(ClientService.class); - JsonObject object = - (contractParameter != null) ? contractParameter : Json.createObjectBuilder().build(); - return service.executeContract(contractId, object); - } - - /** - * Pretty print the json to the standard output - * - * @param json the json to print - */ - protected void prettyPrintJson(JsonObject jsonObject) { - if (jsonObject != null) { - System.out.println("[Return]"); - Map config = new HashMap<>(1); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonWriterFactory factory = Json.createWriterFactory(config); - JsonWriter writer = factory.createWriter(System.out); - writer.writeObject(jsonObject); - System.out.println(""); - writer.close(); - } - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/resources/log4j2.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/resources/log4j2.properties deleted file mode 100644 index a3f65c97..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/main/resources/log4j2.properties +++ /dev/null @@ -1,18 +0,0 @@ -name=PropertiesConfig -property.filename = logs -appenders = console, file - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -appender.file.type = File -appender.file.name = LOGFILE -appender.file.fileName=${filename}/propertieslogs.log -appender.file.layout.type=PatternLayout -appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -rootLogger.level = info -rootLogger.appenderRefs = stdout -rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java deleted file mode 100644 index ad63ded5..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/current/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ASSET_TYPE; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_NAME; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.crypto.CertificateEntry.Key; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -public class AddAccountTest { - - private static final String MOCKED_HOLDER_ID = "mockedHolderId"; - - @Mock private Ledger ledger; - @Mock private Key mockedKey; - @Spy private AddAccount addAccount; - - @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); - when(addAccount.getCertificateKey()).thenReturn(mockedKey); - when(mockedKey.getHolderId()).thenReturn(MOCKED_HOLDER_ID); - } - - @Test - public void invoke_InsertNonexistentAccount_ShouldInsertAccount() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, null); - - // Act - JsonObject invokeResult = addAccount.invoke(ledger, argument, Optional.of(properties)); - assertEquals(invokeResult, null); - } - - @Test - public void invoke_ArgumentsMissing_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = Json.createObjectBuilder().build(); - JsonObject properties = prepareProperties(); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - @Test - public void invoke_InsertExistentAccount_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, mock(Asset.class)); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - private JsonObject prepareArgument() { - return Json.createObjectBuilder() - .add(ACCOUNT_ID, "1") - .add(ACCOUNT_NAME, "name") - .add(ACCOUNT_TIMESTAMP, System.currentTimeMillis()) - .build(); - } - - private JsonObject prepareProperties() { - return Json.createObjectBuilder().build(); - } - - private void mockLedgerGetCall(JsonObject argument, Asset result) { - when(ledger.get(getAssetId(argument))).thenReturn(Optional.ofNullable(result)); - } - - private String getAssetId(JsonObject argument) { - return ACCOUNT_ASSET_TYPE + "_" + argument.getString(ACCOUNT_ID); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitattributes b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitattributes deleted file mode 100644 index 00a51aff..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# These are explicitly windows files and should use crlf -*.bat text eol=crlf - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitignore b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitignore deleted file mode 100644 index be8ace73..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# custom -cfssl -build -.idea - - -# Ignore Gradle project-specific cache directory -.gradle - -.settings/ -bin/ - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/Makefile b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/Makefile deleted file mode 100644 index 54e2c3ca..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -SHELL := /bin/bash - -##### BUILD -.PHONY: build -build: - @echo "Building ScalarDL escrow demo CLI" - @./gradlew build - -#### ScalarDL -.PHONY: register-cert assemble register-contracts clear register-all - -register-all: register-cert register-contracts - -register-cert: - @echo "Registering certificate ..." - @client/bin/register-cert --properties client.properties - -assemble: clear - @echo "Building contracts ..." - @./gradlew assemble - -register-contracts: assemble - @echo "Registering contracts ..." - @client/bin/register-contract --properties client.properties --contract-id AddAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.AddAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/AddAccount.class - @client/bin/register-contract --properties client.properties --contract-id AddItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.AddItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/AddItem.class - @client/bin/register-contract --properties client.properties --contract-id AddOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.AddOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/AddOrder.class - @client/bin/register-contract --properties client.properties --contract-id CancelOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.CancelOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/CancelOrder.class - @client/bin/register-contract --properties client.properties --contract-id ChargeAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ChargeAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ChargeAccount.class - @client/bin/register-contract --properties client.properties --contract-id SetOrderToReceivedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.class - @client/bin/register-contract --properties client.properties --contract-id SetOrderToShippedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.class - @client/bin/register-contract --properties client.properties --contract-id ViewAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ViewAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.class - @client/bin/register-contract --properties client.properties --contract-id ViewItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.ViewItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/ViewItem.class - @client/bin/register-contract --properties client.properties --contract-id DebitEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.class - @client/bin/register-contract --properties client.properties --contract-id CreditEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.class - @client/bin/register-contract --properties client.properties --contract-id CreditAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditAccount.class - @client/bin/register-contract --properties client.properties --contract-id DebitAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitAccount.class - @client/bin/register-contract --properties client.properties --contract-id ViewOrderHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.ViewOrderHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.class - @client/bin/register-contract --properties client.properties --contract-id ViewEscrowAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.class - -clear: - @rm -rf build - - -#### Scenario test -.PHONY: run-complete-order-scenario run-cancel-order-scenario all -run-complete-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 6000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="order shipped -id order_1 -s seller_1" - @./gradlew run --args="order received -id order_1 -b buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="account view -id seller_1" - @./gradlew run --args="escrow view -b buyer_1 -s seller_1" - -run-cancel-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 50000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 10000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="order cancel -id order_1 -a buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - - - - - diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/README.mdx b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/README.mdx deleted file mode 100644 index 2e544692..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/README.mdx +++ /dev/null @@ -1,229 +0,0 @@ -# ScalarDL エスクロー支払い CLI - -import TranslationBanner from '/src/components/_translation-ja-jp.mdx'; - - - -以下は、[ScalarDL](https://github.com/scalar-labs/scalardl) を試してテストするための簡単な Java CLI アプリケーションです。 CLI フレームワークとして PicoCLI が使用されます。 - -ScalarDL には複数の言語のサポートと SDK があります。 この例ではJAVAが使用されています。 - -これは単なるサンプル プロジェクトであるため、すべてのコマンドは Gradle 経由で実行できます。 これは本番環境に対応した例ではなく、学習資料としてのみ提供されています。 - -どのコマンドが実行されているかを確認するには、前述の Makefile コマンドと ScalarDL の公式ドキュメントを確認してください。 - -## 導入 - -### 預託 - -口座 A から口座 B に資金を直接送金する代わりに、仲介口座が導入されます。 両当事者が取引の完了に同意するまで、資金はこの仲介口座にロックされます。 何か問題が発生した場合、問題が解決されるまで買い手と売り手の両方が資金にアクセスできなくなります。 - -以下は典型的なエスクロー支払いフローです。 - -- アカウント A を持つ登録購入者は、アカウント B を持つ登録販売者から商品を購入します。 -- 注文エントリが作成され、注文は `open` ステータスに設定されます。 -- 両当事者間でエスクローアカウントが作成されます。 -- アカウント A に入金され、資金がエスクロー口座に移動されます。 -- 販売者は注文を更新し、パッケージの発送を通知します。 -- 注文が更新され、 `shipped` ステータスに設定されます。 -- パッケージを受け取った後、購入者は注文を更新し、受信済みとしてマークします。 -- エスクロー口座に入金され、資金が口座 B に移動されます。 -- 注文はクローズされ、ステータスが `complete` とマークされます。 - -注文のキャンセルは可能ですが、注文がまだ `open` ステータスにある場合に限ります。 後に -商品が発送された後、現在の実装では注文をキャンセルすることはできません。 - -## 特徴 - -この CLI アプリケーションは、エスクロー支払いフローをシミュレートするための最も重要なアクションを提供します。 データの検索と監視のために追加のアクションがサポートされています。 - -次のアクションがサポートされています。 - -**アカウント** - -- 新しいアカウントを登録する -- 資金の追加、チャージ、アカウント -- アカウント履歴の表示 - -**アイテム** - -- 新しいアイテムを登録する -- アイテムの詳細を表示 - -**注文** - -- 新しい注文を作成する -- 注文を発送済みとしてマークする -- 受領済みとしてマークして注文する (注文を完了する) -- 注文をキャンセルする -- 注文履歴の表示 - -**エスクローアカウント** - -- エスクローアカウント履歴の表示 - -## 前提条件 - -- Docker -- Makefile -- Java - -## 設定 - -### ScalarDL - -ScalarDL サーバーを起動するコードは、このリポジトリには含まれていません。 ScalarDL をすぐに起動して実行するには、[次のリポジトリ](https://github.com/scalar-labs/scalardl-samples) のクローンを作成し、ScalarDL の使用を開始するためのコマンドに従ってください。 - -### 証明書 - -証明書の例が使用されていますが、例としては十分です。 証明書は `make register-certificate` 経由でロードできます。 - -### コントラクト - -すべてのコントラクト名には接尾辞が追加されます。 これは証明書所有者の名前で、この場合は `foo` です。 これは必須ではなく、コントラクト名が一意であることを確認するためにのみ行われます。 - -コントラクトは `make register-contracts` を通じてロードできます。 - -### クライアント SDK - -Java クライアント SDK が動作するには、 `client.properties` ファイルが必要です。 現在、ScalarDL サンプル プロジェクトと同じ設定が使用されています。 - -### テストシナリオ - -実際の支払いと注文キャンセルのフローを確認するために、2 つのテスト シナリオの例が提供されています。 - -シナリオは、`make run-complete-order-scenario` および `make run-cancel-order-scenario` によって実行できます。 - -## 使用法 - -### 建てる - -アプリケーションは、`./gradlew build` を介して、または `make build` Makefile コマンドを実行することによってビルドできます。 - -### CLI コマンド - -#### アカウント - -CLI を介したアカウントの管理。 - -##### アカウントを作成する - -文字列で何でもよい `id` を指定して、新しいアカウントを作成します。 アカウントの `balance` は 0 に設定され、`created_at` は現在のタイムスタンプに自動的に設定されます。 - -*コマンド* - -``` -./gradlew run --args="account add -id -n " -``` - -##### アカウント履歴の表示 - -アカウント履歴を取得します。 - -*コマンド* - -``` -./gradlew run --args="account view -id " -``` - -##### チャージアカウント - -アカウントの残高に資金を追加します。 - -*コマンド* - -``` -./gradlew run --args="account charge -id -a " -``` - -#### アイテム - -CLI を介したアイテムの管理。 - -##### アイテムの作成 - -`id`、`price`、`seller` (アカウント ID)、およびアイテムの `name` を指定して、新しいアイテムを作成します。 - -*コマンド* - -``` -./gradlew run --args="item add -id -p -s " -``` - -##### アイテムの表示 - -アイテムの詳細を見る - -*コマンド* - -``` -./gradlew run --args="item view -id " -``` - -#### 注文 - -CLI を介した注文の管理。 - -##### 注文の作成 - -`id`、`item id`、およびアカウント ID である `buyer` を指定して、新しい注文を作成します。 - -*コマンド* - -``` -./gradlew run --args="order add -id -b -i " -``` - -##### 注文をキャンセルする - -現在 `open` ステータスにある注文をキャンセルします。 他の州では注文をキャンセルできなくなります。 `account id` は必須であり、検証されます。 注文が指定されたアカウントに属していない場合、注文をキャンセルすることはできません。 - -*コマンド* - -``` -./gradlew run --args="order cancel -id -a " -``` - -##### 注文アイテムを発送済みとしてマークする - -販売者として注文を更新し、商品が発送されたことを購入者に通知します。 - -*コマンド* - -``` -./gradlew run --args="order shipped -id -s " -``` - -##### 注文アイテムを受領済みとしてマークする - -購入者として注文を更新し、商品が受け取られたことを販売者に通知します。 ご注文が完了となります。 - -*コマンド* - -``` -./gradlew run --args="order received -id -b " -``` - -##### 注文履歴の表示 - -1 つの注文の履歴を表示します。 - -*コマンド* - -``` -./gradlew run --args="order view -id " -``` - -#### エスクローアカウント - -CLI を介したエスクロー アカウントの管理。 - -##### エスクローアカウント履歴の表示 - -買い手と売り手の間の特定のエスクロー口座のアクティビティと更新履歴を表示します - -*コマンド* - -``` -./gradlew run --args="escrow view -b -s " -``` diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/build.gradle b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/build.gradle deleted file mode 100644 index 283ad318..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.1/userguide/building_java_projects.html - */ - -plugins { - // Apply the application plugin to add support for building a CLI application in Java. - id 'application' -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -dependencies { - // Use JUnit test framework. - testImplementation 'junit:junit:4.13.2' - - // This dependency is used by the application. - implementation 'com.google.guava:guava:30.1-jre' - implementation group: 'info.picocli', name: 'picocli', version: '4.6.1' - implementation group: 'com.scalar-labs', name: 'scalardl-java-client-sdk', version: '3.0.1' - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2' - - testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.14.0' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.2.0' - testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0' - testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.3.1' - testImplementation 'org.hashids:hashids:1.0.3' -} - -application { - // Define the main class for the application. - mainClass = 'com.ypeckstadt.escrow.Main' -} - -test { - useJUnitPlatform() -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/client.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/client.properties deleted file mode 100644 index 2794d227..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/client.properties +++ /dev/null @@ -1,29 +0,0 @@ -# Optional. A hostname or an IP address of the server. Use localhost by default if not specified. -# It assuems that there is a single endpoint that is given by DNS or a load balancer. -#scalar.dl.client.server.host=localhost -# Optional. A port number of the server. Use 50051 by default if not specified. -#scalar.dl.client.server.port=50051 -# Optional. A port number of the server for privileged services. Use 50052 by default if not specified. -#scalar.dl.client.server.privileged_port=50052 -# Required. The holder ID of a certificate. -# It must be configured for each private key and unique in the system. -scalar.dl.client.cert_holder_id=foo -# Optional. The version of the certificate. Use 1 by default if not specified. -# Use another bigger integer if you need to change your private key. -#scalar.dl.client.cert_version=1 -# Required. The path of the certificate file. -scalar.dl.client.cert_path=./fixture/client.pem -# Required. The path of a corresponding private key file to the certificate. -# Exceptionally it can be empty in some requests to privileged services -# such as registerCertificate and registerFunction since they don't need a signature. -scalar.dl.client.private_key_path=./fixture/client-key.pem -# Optional. A flag to enable TLS communication. False by default. -#scalar.dl.client.tls.enabled=false -# Optional. A custom CA root certificate for TLS communication. -# If the issuing certificate authority is known to the client, it can be empty. -#scalar.dl.client.tls.ca_root_cert_path=/path/to/ca-root-cert -# Optional. An authorization credential. (e.g. authorization: Bearer token) -# If this is given, clients will add "authorization: " http/2 header. -#scalar.dl.client.authorization.credential=credential -# Experimental. Proxy server -#scalar.dl.client.proxy.server=localhost:10051 diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client-key.pem b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client-key.pem deleted file mode 100644 index ed5fbd4a..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client-key.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIJHySQ7Dsapydvq06ismdaD38kqZXDe7TQq/0/nokUwHoAoGCCqGSM49 -AwEHoUQDQgAEUjQhpkHcHYagBompS7Lxfx9QdIwW1WWxBtZ+z6KEEh8xrQInJIaM -FOPtIskQ6oPdKnuxMf3T1h3sVjW6pIwi3w== ------END EC PRIVATE KEY----- diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client.pem b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client.pem deleted file mode 100644 index 7aacf6a7..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/fixture/client.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICjTCCAjKgAwIBAgIUacmufnXYLxwZkSssxVjBePp4zoUwCgYIKoZIzj0EAwIw -bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf -MB0GA1UEChMWU2NhbGFyIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2NhbGFy -IEludGVybWVkaWF0ZSBDQTAeFw0yMTA2MzAwMzA4MDBaFw0yNDA2MjkwMzA4MDBa -MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ -bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC -AARSNCGmQdwdhqAGialLsvF/H1B0jBbVZbEG1n7PooQSHzGtAickhowU4+0iyRDq -g90qe7Ex/dPWHexWNbqkjCLfo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE -DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTRioMqi4AZX+dU -Y1+YAVtyWMtMszAfBgNVHSMEGDAWgBQgvyjyoVxJUr2q5UpJng2NUCjgAjAxBggr -BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq -BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG -SM49BAMCA0kAMEYCIQCYTdQjk6kNJxOWoGUAsXMGhiTWtrPKrZxxvJjkD87/4QIh -APfY/gpIqfSu71YWIdRDbk2McECIRgHkXTd8ArIKUz8C ------END CERTIFICATE----- diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a97150..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew deleted file mode 100755 index 744e882e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew.bat b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew.bat deleted file mode 100644 index 107acd32..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/settings.gradle b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/settings.gradle deleted file mode 100644 index 6a00f360..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/7.1/userguide/multi_project_builds.html - */ - -rootProject.name = 'scalardl-escrow-demo-java' -include('app') diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java deleted file mode 100644 index ff93a903..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ypeckstadt.escrow; - -import com.ypeckstadt.escrow.command.account.AccountCommand; -import com.ypeckstadt.escrow.command.escrowAccount.EscrowAccountCommand; -import com.ypeckstadt.escrow.command.item.ItemCommand; -import com.ypeckstadt.escrow.command.order.OrderCommand; -import java.io.IOException; -import picocli.CommandLine; - -@CommandLine.Command( - name = "app", - description = "ScalarDL escrow demo CLI", - mixinStandardHelpOptions = true, - version = "1.0", - subcommands = { - AccountCommand.class, - ItemCommand.class, - OrderCommand.class, - EscrowAccountCommand.class - }) -public class Main { - public static void main(String[] args) throws IOException { - // Display the help if no arguments are passed - String[] commandArgs = args.length != 0 ? args : new String[] {"--help"}; - int exitCode = new CommandLine(new Main()).execute(commandArgs); - System.exit(exitCode); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java deleted file mode 100644 index 7b337e0b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "account", - description = "manage accounts", - subcommands = { - AddAccountCommand.class, - ViewAccountHistoryCommand.class, - ChargeAccountCommand.class - }) -public class AccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java deleted file mode 100644 index 9eb6fc52..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.ypeckstadt.escrow.contract.account.AddAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ACCOUNT ID", - description = "the account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "the account owner's name", - required = true) - String name; - - @Override - public Integer call() throws Exception { - - // Add account - JsonObject argument = - Json.createObjectBuilder() - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(AddAccount.class.getSimpleName(), argument, true); - LOG.info("The account has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java deleted file mode 100644 index 67ef333e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; - -import com.ypeckstadt.escrow.contract.account.ChargeAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "charge") -public class ChargeAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ChargeAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-a", "--amount"}, - paramLabel = "AMOUNT", - description = "amount to charge", - required = true) - int amount; - - @Override - public Integer call() throws Exception { - // Charge account - JsonObject argument = - Json.createObjectBuilder() - .add(ChargeAccount.AMOUNT, amount) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(ChargeAccount.class.getSimpleName(), argument, true); - LOG.info("Funds have been added to the account successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java deleted file mode 100644 index 74b71e96..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.account.ViewAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "the account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ACCOUNT_ID, accountId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java deleted file mode 100644 index ddb34d84..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "escrow", - description = "view escrow accounts history", - subcommands = { - ViewEscrowAccountHistoryCommand.class, - }) -public class EscrowAccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java deleted file mode 100644 index 9ddf9215..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewEscrowAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewEscrowAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "ID", - description = "buyer account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "ID", - description = "seller account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(ViewEscrowAccountHistory.BUYER_ACCOUNT_ID, buyerAccountId) - .add(ViewEscrowAccountHistory.SELLER_ACCOUNT_ID, sellerAccountId) - .build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewEscrowAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java deleted file mode 100644 index 9d7c0c1e..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.ypeckstadt.escrow.contract.item.AddItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "item id", - required = true) - String itemId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "item name", - required = true) - String name; - - @CommandLine.Option( - names = {"-p", "--price"}, - paramLabel = "PRICE", - description = "item price", - required = true) - int price; - - @CommandLine.Option( - names = {"-s", "--seller"}, - paramLabel = "SELLER", - description = "seller's account id", - required = true) - String seller; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(AddItem.NAME, name) - .add(AddItem.SELLER_ACCOUNT_ID, seller) - .add(AddItem.PRICE, price) - .add(AddItem.TIMESTAMP, new Date().getTime()) - .add(AddItem.ID, itemId) - .build(); - - try { - executeContract(AddItem.class.getSimpleName(), argument, true); - LOG.info("The item has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java deleted file mode 100644 index 7b74e24a..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "item", - description = "manage items", - subcommands = { - AddItemCommand.class, - ViewItemCommand.class, - }) -public class ItemCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java deleted file mode 100644 index d6a5b9df..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.item.ViewItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--itemId"}, - paramLabel = "ITEM", - description = "the item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ViewItem.ID, itemId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewItem.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java deleted file mode 100644 index 4e2caa0f..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.AddOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyer"}, - paramLabel = "BUYER", - description = "buyer's account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-i", "--item"}, - paramLabel = "ITEM", - description = "item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - // Add order - JsonObject argument = - Json.createObjectBuilder() - .add(AddOrder.ID, orderId) - .add(AddOrder.BUYER_ACCOUNT_ID, buyerAccountId) - .add(AddOrder.ITEM_ID, itemId) - .add(AddOrder.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(AddOrder.class.getSimpleName(), argument, true); - LOG.info( - "The order has been added successfully. Waiting for the seller to mark the item as" - + " shipped."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java deleted file mode 100644 index 3e147c2b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.CancelOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "cancel") -public class CancelOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(CancelOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-a", "--accountId"}, - paramLabel = "ACCOUNT", - description = "buyer or seller account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(CancelOrder.ACCOUNT_ID, accountId) - .add(CancelOrder.TIMESTAMP, new Date().getTime()) - .add(CancelOrder.ID, orderId) - .build(); - - try { - executeContract(CancelOrder.class.getSimpleName(), argument, true); - LOG.info("The order has been cancelled successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java deleted file mode 100644 index dcec55ff..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "order", - description = "manage orders", - subcommands = { - ViewOrderHistoryCommand.class, - AddOrderCommand.class, - ShippedItemsOrderCommand.class, - ReceivedItemsOrderCommand.class, - CancelOrderCommand.class, - }) -public class OrderCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java deleted file mode 100644 index 60028162..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "received") -public class ReceivedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ReceivedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "BUYER ID", - description = "the buyer's account id", - required = true) - String buyerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToReceivedStatus.ID, orderId) - .add(SetOrderToReceivedStatus.BUYER_ACCOUNT_ID, buyerAccountId) - .add(SetOrderToReceivedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToReceivedStatus.class.getSimpleName(), argument, true); - LOG.info("The order has completed."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java deleted file mode 100644 index 3bbbbbd8..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "shipped") -public class ShippedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ShippedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "SELLER ID", - description = "the seller's account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToShippedStatus.ID, orderId) - .add(SetOrderToShippedStatus.SELLER_ACCOUNT_ID, sellerAccountId) - .add(SetOrderToShippedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToShippedStatus.class.getSimpleName(), argument, true); - LOG.info( - "The order has been updated successfully. Waiting for the buyer to mark the item as" - + " received."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java deleted file mode 100644 index 981d6e48..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.order.ViewOrderHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewOrderHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewOrderHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ID", - description = "the order id", - required = true) - String orderId; - - @Override - public Integer call() throws Exception { - - // prepare contract arguments - JsonObject argument = Json.createObjectBuilder().add(ViewOrderHistory.ID, orderId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewOrderHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java deleted file mode 100644 index d8d504be..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ypeckstadt.escrow.common; - -public class Constants { - // Account related json names - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ACCOUNT_ID = "id"; - public static final String ACCOUNT_NAME = "name"; - public static final String ACCOUNT_TIMESTAMP = "timestamp"; - public static final String ACCOUNT_BALANCE = "balance"; - public static final String ACCOUNT_BALANCE_CHANGE = "balance_change"; - - // Contract error messages - public static final String CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR = - "wrong or missing arguments to create an account"; - public static final String CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR = - "an account with this id already exists"; -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java deleted file mode 100644 index 9d9fe551..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddAccount extends Contract { - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(ACCOUNT_NAME) - || !argument.containsKey(ACCOUNT_TIMESTAMP)) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - // Get field data - String name = argument.getString(ACCOUNT_NAME); - long timestamp = argument.getJsonNumber(ACCOUNT_TIMESTAMP).longValue(); - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ACCOUNT_ID, accountId) - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_BALANCE, 0) - .add(ACCOUNT_BALANCE_CHANGE, 0) - .add(ACCOUNT_TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java deleted file mode 100644 index 9e81ee00..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class ChargeAccount extends Contract { - - public static final String ID = "id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - public static final String NAME = "name"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to charge an account"); - } - - // get input data - String accountId = argument.getString(ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if account exists - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - Optional optionalAsset = ledger.get(assetId); - if (!optionalAsset.isPresent()) { - throw new ContractContextException("the provided account does not exist"); - } - - // calculate new balance - JsonObject assetData = optionalAsset.get().data(); - int newBalance = assetData.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, assetData.get(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java deleted file mode 100644 index d8da2b17..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditAccount extends Contract { - - public static final String ACCOUNT_ID = "account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to credit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // check balance - JsonObject account = asset.get().data(); - int balance = account.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the account has insufficient funds"); - } - - // credit account - int newBalance = balance - amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java deleted file mode 100644 index dbbae076..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditEscrowAccount extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - public static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to credit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - if (!optionalEscrowAccount.isPresent()) { - throw new ContractContextException("no escrow account was found"); - } - - // calculate new balance - int newBalance = optionalEscrowAccount.get().data().getInt(BALANCE) - amount; - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java deleted file mode 100644 index 1dccc696..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitAccount extends Contract { - - private static final String ACCOUNT_ID = "account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ID = "id"; - private static final String NAME = "name"; - private static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to debit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // debit balance - JsonObject account = asset.get().data(); - int newBalance = account.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java deleted file mode 100644 index 8a720dc0..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitEscrowAccount extends Contract { - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to debit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check buyer's account sufficient funds - JsonObject buyerAccount = optionalBuyerAsset.get().data(); - int balance = buyerAccount.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the buyer's account has insufficient funds"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - - // calculate new balance - int newBalance = amount; - if (optionalEscrowAccount.isPresent()) { - newBalance += optionalEscrowAccount.get().data().getInt(BALANCE); - } - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java deleted file mode 100644 index 9cd00cc6..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewAccountHistory extends Contract { - - public static final String ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - private static final String HISTORY = "account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for account lookup"); - } - - // Determine asset id - String accountId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + accountId; - - // Retrieve account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no account with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String name = data.getString(NAME); - int balance = data.getInt(BALANCE); - int balanceChange = data.getInt(BALANCE_CHANGE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(NAME, name) - .add(BALANCE, balance) - .add(BALANCE_CHANGE, balanceChange) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java deleted file mode 100644 index 0014d639..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.ypeckstadt.escrow.contract.escrowAccount; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.*; - -public class ViewEscrowAccountHistory extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String HISTORY = "escrow_account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) || !argument.containsKey(SELLER_ACCOUNT_ID)) { - throw new ContractContextException("missing ID argument for escrow account lookup"); - } - - // Determine asset id - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String assetId = ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - - // Retrieve escrow account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException( - "no escrow account between this seller and buyer was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String orderId = data.getString(ORDER_ID); - int balance = data.getInt(BALANCE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(BALANCE, balance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java deleted file mode 100644 index baba5a59..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddItem extends Contract { - - public static final String ITEM_ASSET_TYPE = "item"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(NAME) - || !argument.containsKey(PRICE) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an item"); - } - - // get field data from arguments - String itemId = argument.getString(ID); - String name = argument.getString(NAME); - int price = argument.getInt(PRICE); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - - // determine asset id - String assetId = ITEM_ASSET_TYPE + "_" + itemId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException("an item with this id already exists"); - } - - // validate the seller has an account - String accountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - asset = ledger.get(accountAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("the provided seller does not have an account"); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, itemId) - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(TIMESTAMP, timestamp); - - // add item - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java deleted file mode 100644 index 1638aa58..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; - -public class ViewItem extends Contract { - - public static final String ASSET_TYPE = "item"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for item lookup"); - } - - // Determine asset id - String itemId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + itemId; - - // Retrieve item - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("no item with this id was found"); - } - - // get field data - JsonObject data = asset.get().data(); - String id = data.getString(ID); - String name = data.getString(NAME); - String seller = data.getString(SELLER_ACCOUNT_ID); - int price = data.getInt(PRICE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // asset json object builder - return Json.createObjectBuilder() - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, seller) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java deleted file mode 100644 index 8cb9385c..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddOrder extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String ITEM_ID = "item_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String ID = "id"; - - private static final String ITEM_ASSET_TYPE = "item"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ID = "account_id"; - private static final String ITEM_PRICE = "price"; - private static final String TOTAL = "total"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ORDER_ID = "order_id"; - private static final String STATUS = "status"; - private static final String DEBIT_ESCROW_ACCOUNT_CONTRACT = "DebitEscrowAccount_foo"; - private static final String CREDIT_ACCOUNT_CONTRACT = "CreditAccount_foo"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ITEM_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an order"); - } - - // get field data from arguments - String itemId = argument.getString(ITEM_ID); - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String orderId = argument.getString(ID); - - // determine asset ids - String itemAssetId = ITEM_ASSET_TYPE + "_" + itemId; - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - - // check if the item exists - Optional optionalItemAsset = ledger.get(itemAssetId); - if (!optionalItemAsset.isPresent()) { - throw new ContractContextException("the item does not exist"); - } - - // check if the buyer's account exists - Optional optionalBuyerAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAccountAsset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // get json object data - JsonObject item = optionalItemAsset.get().data(); - int itemPrice = item.getInt(ITEM_PRICE); - String sellerAccountId = item.getString(SELLER_ACCOUNT_ID); - - // Debit escrow and credit are split into 2 separate contracts to not make the contract to heavy - // and test calling external contracts. - // In a normal situation both actions will always follow each other so it makes more sense to - // put it into one contract - - // Debit escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, itemPrice) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Credit buyer's account - JsonObject creditArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, itemPrice) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ACCOUNT_CONTRACT, ledger, creditArguments); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_OPEN) - .add(TOTAL, itemPrice) - .add(TIMESTAMP, timestamp); - - // add order record - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java deleted file mode 100644 index 2c8b0e57..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CancelOrder extends Contract { - - public static final String ID = "id"; - public static final String ACCOUNT_ID = "account_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String STATUS = "status"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String ORDER_STATUS_CANCELLED = "cancelled"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String TOTAL = "total"; - private static final String AMOUNT = "amount"; - private static final String ORDER_ID = "order_id"; - private static final String ITEM_ID = "item_id"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to cancel an order"); - } - - // Get input data - String orderId = argument.getString(ID); - - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - - // check if order exists - Optional asset = ledger.get(orderAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("no order with this id was found"); - } - - // Get order data - JsonObject order = asset.get().data(); - String orderStatus = order.getString(STATUS); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - long timestamp = order.getJsonNumber(TIMESTAMP).longValue(); - String itemId = order.getString(ITEM_ID); - - // check order status ,if still in open mode, cant be cancelled after - if (!orderStatus.equals(ORDER_STATUS_OPEN)) { - throw new ContractContextException("the order cannot be cancelled anymore"); - } - - // make sure the account id is a seller or buyer - if (!accountId.equals(buyerAccountId) && !accountId.equals(sellerAccountId)) { - throw new ContractContextException("the order does not belong to the account"); - } - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit buyer account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - // update order, set to cancelled status - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_CANCELLED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java deleted file mode 100644 index 76fbec83..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToReceivedStatus extends Contract { - - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_COMPLETE = "complete"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - private static final String ACCOUNT_ID = "account_id"; - private static final String TOTAL = "total"; - private static final String ORDER_ID = "order_id"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as received"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if buyer's account exists - Optional optionalAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if the order belongs to the buyer - JsonObject order = optionalOrderAsset.get().data(); - String orderBuyerAccountId = order.getString(BUYER_ACCOUNT_ID); - if (!buyerAccountId.equals(orderBuyerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the buyer"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_COMPLETE) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit Seller account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java deleted file mode 100644 index 410aac54..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToShippedStatus extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_SHIPPED = "shipped"; - private static final String TOTAL = "total"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as shipped"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if seller's account exists - Optional optionalAccountAsset = ledger.get(sellerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check if the order belongs to the seller - JsonObject order = optionalOrderAsset.get().data(); - String orderSellerAccountId = order.getString(SELLER_ACCOUNT_ID); - if (!sellerAccountId.equals(orderSellerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the seller"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_SHIPPED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java deleted file mode 100644 index 344fe68b..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewOrderHistory extends Contract { - - public static final String ID = "id"; - - private static final String ASSET_TYPE = "order"; - private static final String TIMESTAMP = "timestamp"; - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String TOTAL = "total"; - - private static final String HISTORY = "order_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for order lookup"); - } - - // Determine asset id - String orderId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + orderId; - - // Retrieve order history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no order with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String itemId = data.getString(ITEM_ID); - String buyerAccountId = data.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = data.getString(SELLER_ACCOUNT_ID); - String status = data.getString(STATUS); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - int total = data.getInt(TOTAL); - - // build json object result - JsonObject order = - Json.createObjectBuilder() - .add(ID, id) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, status) - .add(TOTAL, total) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(order); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java deleted file mode 100644 index 61d3de7f..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.ypeckstadt.escrow.dl; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.scalar.dl.client.config.ClientConfig; -import com.scalar.dl.client.service.ClientModule; -import com.scalar.dl.client.service.ClientService; -import com.scalar.dl.ledger.model.ContractExecutionResult; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public abstract class LedgerClientExecutor { - - private static final Logger LOG = LogManager.getLogger(LedgerClientExecutor.class); - private static final String CLIENT_PROPERTIES = "client.properties"; - - private ClientConfig loadClientConfig() throws Exception { - File file = new File(System.getProperty("user.dir") + File.separator + CLIENT_PROPERTIES); - return new ClientConfig(file); - } - - protected ContractExecutionResult executeContract( - String contractName, JsonObject contractParameter, boolean useCertHolderIdSuffix) - throws Exception { - ClientConfig config = loadClientConfig(); - - // Custom naming convention to make sure the contract Id is unique, not required and contractId - // can be anything - // just make sure the contractId is set to the same value as specified when registering the - // contract on the ledger - String contractId = - useCertHolderIdSuffix ? contractName + "_" + config.getCertHolderId() : contractName; - - Injector injector = Guice.createInjector(new ClientModule(config)); - ClientService service = injector.getInstance(ClientService.class); - JsonObject object = - (contractParameter != null) ? contractParameter : Json.createObjectBuilder().build(); - return service.executeContract(contractId, object); - } - - /** - * Pretty print the json to the standard output - * - * @param json the json to print - */ - protected void prettyPrintJson(JsonObject jsonObject) { - if (jsonObject != null) { - System.out.println("[Return]"); - Map config = new HashMap<>(1); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonWriterFactory factory = Json.createWriterFactory(config); - JsonWriter writer = factory.createWriter(System.out); - writer.writeObject(jsonObject); - System.out.println(""); - writer.close(); - } - } -} diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties deleted file mode 100644 index a3f65c97..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties +++ /dev/null @@ -1,18 +0,0 @@ -name=PropertiesConfig -property.filename = logs -appenders = console, file - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -appender.file.type = File -appender.file.name = LOGFILE -appender.file.fileName=${filename}/propertieslogs.log -appender.file.layout.type=PatternLayout -appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -rootLogger.level = info -rootLogger.appenderRefs = stdout -rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java b/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java deleted file mode 100644 index ad63ded5..00000000 --- a/i18n/versioned_docs/ja-jp/docusaurus-plugin-content-docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ASSET_TYPE; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_NAME; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.crypto.CertificateEntry.Key; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -public class AddAccountTest { - - private static final String MOCKED_HOLDER_ID = "mockedHolderId"; - - @Mock private Ledger ledger; - @Mock private Key mockedKey; - @Spy private AddAccount addAccount; - - @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); - when(addAccount.getCertificateKey()).thenReturn(mockedKey); - when(mockedKey.getHolderId()).thenReturn(MOCKED_HOLDER_ID); - } - - @Test - public void invoke_InsertNonexistentAccount_ShouldInsertAccount() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, null); - - // Act - JsonObject invokeResult = addAccount.invoke(ledger, argument, Optional.of(properties)); - assertEquals(invokeResult, null); - } - - @Test - public void invoke_ArgumentsMissing_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = Json.createObjectBuilder().build(); - JsonObject properties = prepareProperties(); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - @Test - public void invoke_InsertExistentAccount_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, mock(Asset.class)); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - private JsonObject prepareArgument() { - return Json.createObjectBuilder() - .add(ACCOUNT_ID, "1") - .add(ACCOUNT_NAME, "name") - .add(ACCOUNT_TIMESTAMP, System.currentTimeMillis()) - .build(); - } - - private JsonObject prepareProperties() { - return Json.createObjectBuilder().build(); - } - - private void mockLedgerGetCall(JsonObject argument, Asset result) { - when(ledger.get(getAssetId(argument))).thenReturn(Optional.ofNullable(result)); - } - - private String getAssetId(JsonObject argument) { - return ACCOUNT_ASSET_TYPE + "_" + argument.getString(ACCOUNT_ID); - } -} diff --git a/sidebars.js b/sidebars.js index 3a7d8bd2..6e2df562 100644 --- a/sidebars.js +++ b/sidebars.js @@ -50,7 +50,6 @@ const sidebars = { collapsible: true, items: [ 'applications/simple-bank-account/README', - 'applications/escrow-payment/README', ], }, { diff --git a/src/components/Cards/3.4.tsx b/src/components/Cards/3.4.tsx index 596d8296..30966b6d 100644 --- a/src/components/Cards/3.4.tsx +++ b/src/components/Cards/3.4.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, diff --git a/src/components/Cards/3.5.tsx b/src/components/Cards/3.5.tsx index 596d8296..30966b6d 100644 --- a/src/components/Cards/3.5.tsx +++ b/src/components/Cards/3.5.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, diff --git a/src/components/Cards/3.6.tsx b/src/components/Cards/3.6.tsx index 596d8296..30966b6d 100644 --- a/src/components/Cards/3.6.tsx +++ b/src/components/Cards/3.6.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, diff --git a/src/components/Cards/3.7.tsx b/src/components/Cards/3.7.tsx index e39ce829..f25274b6 100644 --- a/src/components/Cards/3.7.tsx +++ b/src/components/Cards/3.7.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, diff --git a/src/components/Cards/3.8.tsx b/src/components/Cards/3.8.tsx index e39ce829..31d7d221 100644 --- a/src/components/Cards/3.8.tsx +++ b/src/components/Cards/3.8.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, @@ -71,11 +71,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/simple-bank-account', + page: 'installation-with-docker', }, description: ( - Bank account application + Set up ScalarDL locally in Docker ), }, @@ -83,11 +83,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/escrow-payment', + page: 'applications/simple-bank-account', }, description: ( - Escrow payment CLI + Create a bank account application ), }, diff --git a/src/components/Cards/3.9.tsx b/src/components/Cards/3.9.tsx index e39ce829..31d7d221 100644 --- a/src/components/Cards/3.9.tsx +++ b/src/components/Cards/3.9.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, @@ -71,11 +71,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/simple-bank-account', + page: 'installation-with-docker', }, description: ( - Bank account application + Set up ScalarDL locally in Docker ), }, @@ -83,11 +83,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/escrow-payment', + page: 'applications/simple-bank-account', }, description: ( - Escrow payment CLI + Create a bank account application ), }, diff --git a/src/components/Cards/index.tsx b/src/components/Cards/index.tsx index ee51886c..d5123967 100644 --- a/src/components/Cards/index.tsx +++ b/src/components/Cards/index.tsx @@ -48,7 +48,7 @@ const CardsGettingStarted = [ }, description: ( - Getting started with ScalarDL + Getting started with ScalarDL Ledger ), }, @@ -71,11 +71,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/simple-bank-account/', + page: 'installation-with-docker/', }, description: ( - Bank account application + Set up ScalarDL locally in Docker ), }, @@ -83,11 +83,11 @@ const CardsSamples = [ // name: '', // image: '.png', url: { - page: 'applications/escrow-payment/', + page: 'applications/simple-bank-account/', }, description: ( - Escrow payment CLI + Create a bank account application ), }, diff --git a/versioned_docs/version-3.8/applications/escrow-payment/.gitattributes b/versioned_docs/version-3.8/applications/escrow-payment/.gitattributes deleted file mode 100644 index 00a51aff..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# These are explicitly windows files and should use crlf -*.bat text eol=crlf - diff --git a/versioned_docs/version-3.8/applications/escrow-payment/.gitignore b/versioned_docs/version-3.8/applications/escrow-payment/.gitignore deleted file mode 100644 index be8ace73..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# custom -cfssl -build -.idea - - -# Ignore Gradle project-specific cache directory -.gradle - -.settings/ -bin/ - diff --git a/versioned_docs/version-3.8/applications/escrow-payment/Makefile b/versioned_docs/version-3.8/applications/escrow-payment/Makefile deleted file mode 100644 index 54e2c3ca..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -SHELL := /bin/bash - -##### BUILD -.PHONY: build -build: - @echo "Building ScalarDL escrow demo CLI" - @./gradlew build - -#### ScalarDL -.PHONY: register-cert assemble register-contracts clear register-all - -register-all: register-cert register-contracts - -register-cert: - @echo "Registering certificate ..." - @client/bin/register-cert --properties client.properties - -assemble: clear - @echo "Building contracts ..." - @./gradlew assemble - -register-contracts: assemble - @echo "Registering contracts ..." - @client/bin/register-contract --properties client.properties --contract-id AddAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.AddAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/AddAccount.class - @client/bin/register-contract --properties client.properties --contract-id AddItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.AddItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/AddItem.class - @client/bin/register-contract --properties client.properties --contract-id AddOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.AddOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/AddOrder.class - @client/bin/register-contract --properties client.properties --contract-id CancelOrder_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.CancelOrder --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/CancelOrder.class - @client/bin/register-contract --properties client.properties --contract-id ChargeAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ChargeAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ChargeAccount.class - @client/bin/register-contract --properties client.properties --contract-id SetOrderToReceivedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.class - @client/bin/register-contract --properties client.properties --contract-id SetOrderToShippedStatus_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.class - @client/bin/register-contract --properties client.properties --contract-id ViewAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.ViewAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.class - @client/bin/register-contract --properties client.properties --contract-id ViewItem_foo --contract-binary-name com.ypeckstadt.escrow.contract.item.ViewItem --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/item/ViewItem.class - @client/bin/register-contract --properties client.properties --contract-id DebitEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.class - @client/bin/register-contract --properties client.properties --contract-id CreditEscrowAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditEscrowAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.class - @client/bin/register-contract --properties client.properties --contract-id CreditAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.CreditAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/CreditAccount.class - @client/bin/register-contract --properties client.properties --contract-id DebitAccount_foo --contract-binary-name com.ypeckstadt.escrow.contract.account.DebitAccount --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/account/DebitAccount.class - @client/bin/register-contract --properties client.properties --contract-id ViewOrderHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.order.ViewOrderHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.class - @client/bin/register-contract --properties client.properties --contract-id ViewEscrowAccountHistory_foo --contract-binary-name com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory --contract-class-file build/classes/java/main/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.class - -clear: - @rm -rf build - - -#### Scenario test -.PHONY: run-complete-order-scenario run-cancel-order-scenario all -run-complete-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 6000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account charge -id buyer_1 -a 5000" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="order shipped -id order_1 -s seller_1" - @./gradlew run --args="order received -id order_1 -b buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="account view -id seller_1" - @./gradlew run --args="escrow view -b buyer_1 -s seller_1" - -run-cancel-order-scenario: - @./gradlew run --args="account add -id buyer_1 -n Alfred" - @./gradlew run --args="account add -id seller_1 -n Yves" - @./gradlew run --args="account charge -id buyer_1 -a 50000" - @./gradlew run --args="item add -id item_1 -n bicycle -p 10000 -s seller_1" - @./gradlew run --args="order add -id order_1 -b buyer_1 -i item_1" - @./gradlew run --args="account view -id buyer_1" - @./gradlew run --args="order cancel -id order_1 -a buyer_1" - @./gradlew run --args="order view -id order_1" - @./gradlew run --args="account view -id buyer_1" - - - - - diff --git a/versioned_docs/version-3.8/applications/escrow-payment/README.mdx b/versioned_docs/version-3.8/applications/escrow-payment/README.mdx deleted file mode 100644 index d6e3a4d5..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/README.mdx +++ /dev/null @@ -1,250 +0,0 @@ -# ScalarDL Escrow payment CLI - -The following is a simple Java CLI application to try out and test [ScalarDL](https://github.com/scalar-labs/scalardl). PicoCLI is used as a CLI framework. - -ScalarDL has support and SDK for multiple languages. In this example, JAVA is used. - -As this is just a sample project, all commands can be run via Gradle. This is not a production-ready example and is only provided as study material. - -Please check out the mentioned Makefile commands and the official ScalarDL documentation to see which commands are being executed. - - - -## Introduction - -### Escrow - -Instead of directly transferring the funds from account A to account B an intermediary account is -introduced. The funds are locked in this intermediary account until both parties agreed that the -transaction is completed. Should something go wrong both the buyer and the seller cannot access the -funds until the issue is resolved. - -The following is a typical Escrow payment flow: - -- Registered buyer with account A, buys an item from a registered seller with account B -- An order entry is created and the order is set to the `open` status -- An escrow account between the two parties is created -- Account A is credited and the funds are moved to the escrow account -- The seller updates the order and notifies of shipment of the package -- The order is updated and set to the `shipped` status -- After receiving the package, the buyer updates the order and marks it as received -- The Escrow account is credited and the funds are moved to account B. -- The order is closed and marked with status `complete` - -Order cancellation is possible but only while the order is still in the `open` status. After the -goods are shipped, the order cannot be cancelled in the current implementation - - - -## Features - -This CLI application provides to most important actions to simulate an escrow payment flow. Extra -actions are supported for data lookup and monitoring. - -The following actions are supported: - -**Account** - -- register a new account -- add funds, charge, an account -- view account history - -**Item** - -- register a new item -- view item details - -**Order** - -- create a new order -- Mark an order as shipped -- Mark and order as received (complete an order) -- Cancel an order -- View order history - -**Escrow Account** - -- View escrow account history - - - -## Prerequisites - -- Docker - -- Makefile - -- Java - - - -## Setup - -### ScalarDL - -The code to start up the ScalarDL server is not included in this repository. To get ScalarDL up and running quickly, please clone the [following repository](https://github.com/scalar-labs/scalardl-samples) and follow the provided instructions on how to get started with ScalarDL. - -### Certificate - -An example certificate is used but is enough for the example. The certiticate can be loaded -via `make register-certificate` - -### Contracts - -All the contract names have an added suffix. This is the name of the certificate owner which in this -case is `foo`. This is not required and only done to make sure the contract names are unique. - -The contracts can be loaded via `make register-contracts` - -### Client SDK - -The Java client SDK requires a `client.properties` file to work. Currently the same settings as the -scalar examples projects are used. - -### Test scenarios - -Two example test scenarios are provided to see the payment and order cancellation flow in practice. - -The scenarios can be run via `make run-complete-order-scenario` and `make run-cancel-order-scenario` - - - -## Usage - -### Build - -The application can be build via `./gradlew build` or by running the `make build` Makefile command. - -### CLI commands - -#### Account - -Management of the accounts via CLI. - -##### Create account - -Create a new account by supplying the `id` which is string and can be anything. The account -automatically will have it's `balance` set to 0 and `created_at` set to the current timestamp. - -*Command* - -``` -./gradlew run --args="account add -id -n " -``` - -##### View account history - -Retrieve the account history. - -*Command* - -``` -./gradlew run --args="account view -id " -``` - -##### Charge account - -Add funds to the account's balance. - -*Command* - -``` -./gradlew run --args="account charge -id -a " -``` - -#### Item - -Management of the items via CLI. - -##### Create item - -Create a new item by providing an `id`, a `price` and `seller`, which is the account Id, and an -item `name`. - -*Command* - -``` -./gradlew run --args="item add -id -p -s " -``` - -##### View item - -View item details - -*Command* - -``` -./gradlew run --args="item view -id " -``` - -#### Order - -Management of the orders via CLI. - -##### Create order - -Create a new order by providing an `id`, a `item id` and `buyer`, which is the account Id. - -*Command* - -``` -./gradlew run --args="order add -id -b -i " -``` - -##### Cancel order - -Cancel an order that is currently in `open` status. Orders cannot be cancelled anymore when in -another state. A `account id` is required and validated. If the order does not belong to the -specified account, it can not be cancelled. - -*Command* - -``` -./gradlew run --args="order cancel -id -a " -``` - -##### Mark order item as shipped - -Update the order as a seller to notify the buyer the item has been shipped. - -*Command* - -``` -./gradlew run --args="order shipped -id -s " -``` - -##### Mark order item as received - -Update the order as a buyer to notify the seller the item has been received. The order will be -completed. - -*Command* - -``` -./gradlew run --args="order received -id -b " -``` - -##### View order history - -View the history for one order. - -*Command* - -``` -./gradlew run --args="order view -id " -``` - -#### Escrow account - -Management of the escrow accounts via CLI. - -##### View escrow account history - -View the activity and update history for one specific escrow account between buyer and seller - -*Command* - -``` -./gradlew run --args="escrow view -b -s " -``` - diff --git a/versioned_docs/version-3.8/applications/escrow-payment/build.gradle b/versioned_docs/version-3.8/applications/escrow-payment/build.gradle deleted file mode 100644 index 283ad318..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.1/userguide/building_java_projects.html - */ - -plugins { - // Apply the application plugin to add support for building a CLI application in Java. - id 'application' -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -dependencies { - // Use JUnit test framework. - testImplementation 'junit:junit:4.13.2' - - // This dependency is used by the application. - implementation 'com.google.guava:guava:30.1-jre' - implementation group: 'info.picocli', name: 'picocli', version: '4.6.1' - implementation group: 'com.scalar-labs', name: 'scalardl-java-client-sdk', version: '3.0.1' - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2' - - testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.14.0' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.2.0' - testImplementation group: 'io.cucumber', name: 'cucumber-java', version: '5.6.0' - testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: '5.6.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.3.1' - testImplementation 'org.hashids:hashids:1.0.3' -} - -application { - // Define the main class for the application. - mainClass = 'com.ypeckstadt.escrow.Main' -} - -test { - useJUnitPlatform() -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/client.properties b/versioned_docs/version-3.8/applications/escrow-payment/client.properties deleted file mode 100644 index 2794d227..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/client.properties +++ /dev/null @@ -1,29 +0,0 @@ -# Optional. A hostname or an IP address of the server. Use localhost by default if not specified. -# It assuems that there is a single endpoint that is given by DNS or a load balancer. -#scalar.dl.client.server.host=localhost -# Optional. A port number of the server. Use 50051 by default if not specified. -#scalar.dl.client.server.port=50051 -# Optional. A port number of the server for privileged services. Use 50052 by default if not specified. -#scalar.dl.client.server.privileged_port=50052 -# Required. The holder ID of a certificate. -# It must be configured for each private key and unique in the system. -scalar.dl.client.cert_holder_id=foo -# Optional. The version of the certificate. Use 1 by default if not specified. -# Use another bigger integer if you need to change your private key. -#scalar.dl.client.cert_version=1 -# Required. The path of the certificate file. -scalar.dl.client.cert_path=./fixture/client.pem -# Required. The path of a corresponding private key file to the certificate. -# Exceptionally it can be empty in some requests to privileged services -# such as registerCertificate and registerFunction since they don't need a signature. -scalar.dl.client.private_key_path=./fixture/client-key.pem -# Optional. A flag to enable TLS communication. False by default. -#scalar.dl.client.tls.enabled=false -# Optional. A custom CA root certificate for TLS communication. -# If the issuing certificate authority is known to the client, it can be empty. -#scalar.dl.client.tls.ca_root_cert_path=/path/to/ca-root-cert -# Optional. An authorization credential. (e.g. authorization: Bearer token) -# If this is given, clients will add "authorization: " http/2 header. -#scalar.dl.client.authorization.credential=credential -# Experimental. Proxy server -#scalar.dl.client.proxy.server=localhost:10051 diff --git a/versioned_docs/version-3.8/applications/escrow-payment/fixture/client-key.pem b/versioned_docs/version-3.8/applications/escrow-payment/fixture/client-key.pem deleted file mode 100644 index ed5fbd4a..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/fixture/client-key.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -MHcCAQEEIJHySQ7Dsapydvq06ismdaD38kqZXDe7TQq/0/nokUwHoAoGCCqGSM49 -AwEHoUQDQgAEUjQhpkHcHYagBompS7Lxfx9QdIwW1WWxBtZ+z6KEEh8xrQInJIaM -FOPtIskQ6oPdKnuxMf3T1h3sVjW6pIwi3w== ------END EC PRIVATE KEY----- diff --git a/versioned_docs/version-3.8/applications/escrow-payment/fixture/client.pem b/versioned_docs/version-3.8/applications/escrow-payment/fixture/client.pem deleted file mode 100644 index 7aacf6a7..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/fixture/client.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICjTCCAjKgAwIBAgIUacmufnXYLxwZkSssxVjBePp4zoUwCgYIKoZIzj0EAwIw -bzELMAkGA1UEBhMCSlAxDjAMBgNVBAgTBVRva3lvMQ4wDAYDVQQHEwVUb2t5bzEf -MB0GA1UEChMWU2NhbGFyIEludGVybWVkaWF0ZSBDQTEfMB0GA1UEAxMWU2NhbGFy -IEludGVybWVkaWF0ZSBDQTAeFw0yMTA2MzAwMzA4MDBaFw0yNDA2MjkwMzA4MDBa -MEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJ -bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC -AARSNCGmQdwdhqAGialLsvF/H1B0jBbVZbEG1n7PooQSHzGtAickhowU4+0iyRDq -g90qe7Ex/dPWHexWNbqkjCLfo4HVMIHSMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUE -DDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBTRioMqi4AZX+dU -Y1+YAVtyWMtMszAfBgNVHSMEGDAWgBQgvyjyoVxJUr2q5UpJng2NUCjgAjAxBggr -BgEFBQcBAQQlMCMwIQYIKwYBBQUHMAGGFWh0dHA6Ly9sb2NhbGhvc3Q6ODg4OTAq -BgNVHR8EIzAhMB+gHaAbhhlodHRwOi8vbG9jYWxob3N0Ojg4ODgvY3JsMAoGCCqG -SM49BAMCA0kAMEYCIQCYTdQjk6kNJxOWoGUAsXMGhiTWtrPKrZxxvJjkD87/4QIh -APfY/gpIqfSu71YWIdRDbk2McECIRgHkXTd8ArIKUz8C ------END CERTIFICATE----- diff --git a/versioned_docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties b/versioned_docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a97150..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/versioned_docs/version-3.8/applications/escrow-payment/gradlew b/versioned_docs/version-3.8/applications/escrow-payment/gradlew deleted file mode 100755 index 744e882e..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/versioned_docs/version-3.8/applications/escrow-payment/gradlew.bat b/versioned_docs/version-3.8/applications/escrow-payment/gradlew.bat deleted file mode 100644 index 107acd32..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/versioned_docs/version-3.8/applications/escrow-payment/settings.gradle b/versioned_docs/version-3.8/applications/escrow-payment/settings.gradle deleted file mode 100644 index 6a00f360..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/7.1/userguide/multi_project_builds.html - */ - -rootProject.name = 'scalardl-escrow-demo-java' -include('app') diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java deleted file mode 100644 index ff93a903..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ypeckstadt.escrow; - -import com.ypeckstadt.escrow.command.account.AccountCommand; -import com.ypeckstadt.escrow.command.escrowAccount.EscrowAccountCommand; -import com.ypeckstadt.escrow.command.item.ItemCommand; -import com.ypeckstadt.escrow.command.order.OrderCommand; -import java.io.IOException; -import picocli.CommandLine; - -@CommandLine.Command( - name = "app", - description = "ScalarDL escrow demo CLI", - mixinStandardHelpOptions = true, - version = "1.0", - subcommands = { - AccountCommand.class, - ItemCommand.class, - OrderCommand.class, - EscrowAccountCommand.class - }) -public class Main { - public static void main(String[] args) throws IOException { - // Display the help if no arguments are passed - String[] commandArgs = args.length != 0 ? args : new String[] {"--help"}; - int exitCode = new CommandLine(new Main()).execute(commandArgs); - System.exit(exitCode); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java deleted file mode 100644 index 7b337e0b..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AccountCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "account", - description = "manage accounts", - subcommands = { - AddAccountCommand.class, - ViewAccountHistoryCommand.class, - ChargeAccountCommand.class - }) -public class AccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java deleted file mode 100644 index 9eb6fc52..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/AddAccountCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.ypeckstadt.escrow.contract.account.AddAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ACCOUNT ID", - description = "the account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "the account owner's name", - required = true) - String name; - - @Override - public Integer call() throws Exception { - - // Add account - JsonObject argument = - Json.createObjectBuilder() - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(AddAccount.class.getSimpleName(), argument, true); - LOG.info("The account has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java deleted file mode 100644 index 67ef333e..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ChargeAccountCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; - -import com.ypeckstadt.escrow.contract.account.ChargeAccount; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "charge") -public class ChargeAccountCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ChargeAccountCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "account id", - required = true) - String accountId; - - @CommandLine.Option( - names = {"-a", "--amount"}, - paramLabel = "AMOUNT", - description = "amount to charge", - required = true) - int amount; - - @Override - public Integer call() throws Exception { - // Charge account - JsonObject argument = - Json.createObjectBuilder() - .add(ChargeAccount.AMOUNT, amount) - .add(ACCOUNT_TIMESTAMP, new Date().getTime()) - .add(ACCOUNT_ID, accountId) - .build(); - - try { - executeContract(ChargeAccount.class.getSimpleName(), argument, true); - LOG.info("Funds have been added to the account successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java deleted file mode 100644 index 74b71e96..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/account/ViewAccountHistoryCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ypeckstadt.escrow.command.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.account.ViewAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "the account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ACCOUNT_ID, accountId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java deleted file mode 100644 index ddb34d84..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/EscrowAccountCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "escrow", - description = "view escrow accounts history", - subcommands = { - ViewEscrowAccountHistoryCommand.class, - }) -public class EscrowAccountCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java deleted file mode 100644 index 9ddf9215..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/escrowAccount/ViewEscrowAccountHistoryCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.ypeckstadt.escrow.command.escrowAccount; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.escrowAccount.ViewEscrowAccountHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewEscrowAccountHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewEscrowAccountHistoryCommand.class); - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "ID", - description = "buyer account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "ID", - description = "seller account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(ViewEscrowAccountHistory.BUYER_ACCOUNT_ID, buyerAccountId) - .add(ViewEscrowAccountHistory.SELLER_ACCOUNT_ID, sellerAccountId) - .build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewEscrowAccountHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java deleted file mode 100644 index 9d7c0c1e..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/AddItemCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.ypeckstadt.escrow.contract.item.AddItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "item id", - required = true) - String itemId; - - @CommandLine.Option( - names = {"-n", "--name"}, - paramLabel = "NAME", - description = "item name", - required = true) - String name; - - @CommandLine.Option( - names = {"-p", "--price"}, - paramLabel = "PRICE", - description = "item price", - required = true) - int price; - - @CommandLine.Option( - names = {"-s", "--seller"}, - paramLabel = "SELLER", - description = "seller's account id", - required = true) - String seller; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(AddItem.NAME, name) - .add(AddItem.SELLER_ACCOUNT_ID, seller) - .add(AddItem.PRICE, price) - .add(AddItem.TIMESTAMP, new Date().getTime()) - .add(AddItem.ID, itemId) - .build(); - - try { - executeContract(AddItem.class.getSimpleName(), argument, true); - LOG.info("The item has been added successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java deleted file mode 100644 index 7b74e24a..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ItemCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "item", - description = "manage items", - subcommands = { - AddItemCommand.class, - ViewItemCommand.class, - }) -public class ItemCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java deleted file mode 100644 index d6a5b9df..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/item/ViewItemCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ypeckstadt.escrow.command.item; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.item.ViewItem; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewItemCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewItemCommand.class); - - @CommandLine.Option( - names = {"-id", "--itemId"}, - paramLabel = "ITEM", - description = "the item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - JsonObject argument = Json.createObjectBuilder().add(ViewItem.ID, itemId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewItem.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java deleted file mode 100644 index 4e2caa0f..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/AddOrderCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.AddOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "add") -public class AddOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(AddOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--id"}, - paramLabel = "ID", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyer"}, - paramLabel = "BUYER", - description = "buyer's account id", - required = true) - String buyerAccountId; - - @CommandLine.Option( - names = {"-i", "--item"}, - paramLabel = "ITEM", - description = "item id", - required = true) - String itemId; - - @Override - public Integer call() throws Exception { - // Add order - JsonObject argument = - Json.createObjectBuilder() - .add(AddOrder.ID, orderId) - .add(AddOrder.BUYER_ACCOUNT_ID, buyerAccountId) - .add(AddOrder.ITEM_ID, itemId) - .add(AddOrder.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(AddOrder.class.getSimpleName(), argument, true); - LOG.info( - "The order has been added successfully. Waiting for the seller to mark the item as" - + " shipped."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java deleted file mode 100644 index 3e147c2b..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/CancelOrderCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.CancelOrder; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "cancel") -public class CancelOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(CancelOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER", - description = "order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-a", "--accountId"}, - paramLabel = "ACCOUNT", - description = "buyer or seller account id", - required = true) - String accountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(CancelOrder.ACCOUNT_ID, accountId) - .add(CancelOrder.TIMESTAMP, new Date().getTime()) - .add(CancelOrder.ID, orderId) - .build(); - - try { - executeContract(CancelOrder.class.getSimpleName(), argument, true); - LOG.info("The order has been cancelled successfully"); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java deleted file mode 100644 index dcec55ff..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/OrderCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import java.util.concurrent.Callable; -import picocli.CommandLine; - -@CommandLine.Command( - name = "order", - description = "manage orders", - subcommands = { - ViewOrderHistoryCommand.class, - AddOrderCommand.class, - ShippedItemsOrderCommand.class, - ReceivedItemsOrderCommand.class, - CancelOrderCommand.class, - }) -public class OrderCommand implements Callable { - - @CommandLine.Spec CommandLine.Model.CommandSpec spec; - - @Override - public Integer call() throws Exception { - throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand"); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java deleted file mode 100644 index 60028162..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ReceivedItemsOrderCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToReceivedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "received") -public class ReceivedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ReceivedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-b", "--buyerId"}, - paramLabel = "BUYER ID", - description = "the buyer's account id", - required = true) - String buyerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToReceivedStatus.ID, orderId) - .add(SetOrderToReceivedStatus.BUYER_ACCOUNT_ID, buyerAccountId) - .add(SetOrderToReceivedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToReceivedStatus.class.getSimpleName(), argument, true); - LOG.info("The order has completed."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java deleted file mode 100644 index 3bbbbbd8..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ShippedItemsOrderCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.ypeckstadt.escrow.contract.order.SetOrderToShippedStatus; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.Date; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "shipped") -public class ShippedItemsOrderCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ShippedItemsOrderCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ORDER ID", - description = "the order id", - required = true) - String orderId; - - @CommandLine.Option( - names = {"-s", "--sellerId"}, - paramLabel = "SELLER ID", - description = "the seller's account id", - required = true) - String sellerAccountId; - - @Override - public Integer call() throws Exception { - JsonObject argument = - Json.createObjectBuilder() - .add(SetOrderToShippedStatus.ID, orderId) - .add(SetOrderToShippedStatus.SELLER_ACCOUNT_ID, sellerAccountId) - .add(SetOrderToShippedStatus.TIMESTAMP, new Date().getTime()) - .build(); - - try { - executeContract(SetOrderToShippedStatus.class.getSimpleName(), argument, true); - LOG.info( - "The order has been updated successfully. Waiting for the buyer to mark the item as" - + " received."); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java deleted file mode 100644 index 981d6e48..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/command/order/ViewOrderHistoryCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ypeckstadt.escrow.command.order; - -import com.scalar.dl.ledger.model.ContractExecutionResult; -import com.ypeckstadt.escrow.contract.order.ViewOrderHistory; -import com.ypeckstadt.escrow.dl.LedgerClientExecutor; -import java.util.concurrent.Callable; -import javax.json.Json; -import javax.json.JsonObject; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import picocli.CommandLine; - -@CommandLine.Command(name = "view") -public class ViewOrderHistoryCommand extends LedgerClientExecutor implements Callable { - - private static final Logger LOG = LogManager.getLogger(ViewOrderHistoryCommand.class); - - @CommandLine.Option( - names = {"-id", "--orderId"}, - paramLabel = "ID", - description = "the order id", - required = true) - String orderId; - - @Override - public Integer call() throws Exception { - - // prepare contract arguments - JsonObject argument = Json.createObjectBuilder().add(ViewOrderHistory.ID, orderId).build(); - - try { - // Execute contract - ContractExecutionResult result = - executeContract(ViewOrderHistory.class.getSimpleName(), argument, true); - - // pretty print result - result.getResult().ifPresent(this::prettyPrintJson); - } catch (Exception e) { - LOG.error(e.getMessage()); - } - - return 0; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java deleted file mode 100644 index d8d504be..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/common/Constants.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ypeckstadt.escrow.common; - -public class Constants { - // Account related json names - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ACCOUNT_ID = "id"; - public static final String ACCOUNT_NAME = "name"; - public static final String ACCOUNT_TIMESTAMP = "timestamp"; - public static final String ACCOUNT_BALANCE = "balance"; - public static final String ACCOUNT_BALANCE_CHANGE = "balance_change"; - - // Contract error messages - public static final String CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR = - "wrong or missing arguments to create an account"; - public static final String CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR = - "an account with this id already exists"; -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java deleted file mode 100644 index 9d9fe551..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/AddAccount.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.*; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddAccount extends Contract { - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(ACCOUNT_NAME) - || !argument.containsKey(ACCOUNT_TIMESTAMP)) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - // Get field data - String name = argument.getString(ACCOUNT_NAME); - long timestamp = argument.getJsonNumber(ACCOUNT_TIMESTAMP).longValue(); - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ACCOUNT_ID, accountId) - .add(ACCOUNT_NAME, name) - .add(ACCOUNT_BALANCE, 0) - .add(ACCOUNT_BALANCE_CHANGE, 0) - .add(ACCOUNT_TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java deleted file mode 100644 index 9e81ee00..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ChargeAccount.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class ChargeAccount extends Contract { - - public static final String ID = "id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - public static final String NAME = "name"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to charge an account"); - } - - // get input data - String accountId = argument.getString(ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if account exists - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - Optional optionalAsset = ledger.get(assetId); - if (!optionalAsset.isPresent()) { - throw new ContractContextException("the provided account does not exist"); - } - - // calculate new balance - JsonObject assetData = optionalAsset.get().data(); - int newBalance = assetData.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, assetData.get(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // add account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java deleted file mode 100644 index d8da2b17..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditAccount.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditAccount extends Contract { - - public static final String ACCOUNT_ID = "account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to credit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // check balance - JsonObject account = asset.get().data(); - int balance = account.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the account has insufficient funds"); - } - - // credit account - int newBalance = balance - amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java deleted file mode 100644 index dbbae076..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/CreditEscrowAccount.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CreditEscrowAccount extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String AMOUNT = "amount"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String BALANCE = "balance"; - public static final String TIMESTAMP = "timestamp"; - public static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to credit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - if (!optionalEscrowAccount.isPresent()) { - throw new ContractContextException("no escrow account was found"); - } - - // calculate new balance - int newBalance = optionalEscrowAccount.get().data().getInt(BALANCE) - amount; - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java deleted file mode 100644 index 1dccc696..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitAccount.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitAccount extends Contract { - - private static final String ACCOUNT_ID = "account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ID = "id"; - private static final String NAME = "name"; - private static final String BALANCE_CHANGE = "balance_change"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(AMOUNT) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to debit an account"); - } - - // get input data - String accountId = argument.getString(ACCOUNT_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // Determine asset id - String assetId = ACCOUNT_ASSET_TYPE + "_" + accountId; - - // check if account exists - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // debit balance - JsonObject account = asset.get().data(); - int newBalance = account.getInt(BALANCE) + amount; - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, accountId) - .add(NAME, account.getString(NAME)) - .add(BALANCE, newBalance) - .add(BALANCE_CHANGE, amount) - .add(TIMESTAMP, timestamp); - - // update account - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java deleted file mode 100644 index 8a720dc0..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/DebitEscrowAccount.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class DebitEscrowAccount extends Contract { - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String AMOUNT = "amount"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP) - || !argument.containsKey(ORDER_ID) - || !argument.containsKey(AMOUNT)) { - throw new ContractContextException("wrong or missing arguments to debit an escrow account"); - } - - // get input data - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String orderId = argument.getString(ORDER_ID); - int amount = argument.getInt(AMOUNT); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // determine asset ids - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - - // check if buyer's account exits - Optional optionalBuyerAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if seller's account exists - Optional optionalSellerAsset = ledger.get(sellerAccountAssetId); - if (!optionalSellerAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check buyer's account sufficient funds - JsonObject buyerAccount = optionalBuyerAsset.get().data(); - int balance = buyerAccount.getInt(BALANCE); - if (balance < amount) { - throw new ContractContextException("the buyer's account has insufficient funds"); - } - - // retrieve escrow account - String escrowAccountAssetId = - ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - Optional optionalEscrowAccount = ledger.get(escrowAccountAssetId); - - // calculate new balance - int newBalance = amount; - if (optionalEscrowAccount.isPresent()) { - newBalance += optionalEscrowAccount.get().data().getInt(BALANCE); - } - - // update escrow account - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(BALANCE, newBalance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp); - ledger.put(escrowAccountAssetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java deleted file mode 100644 index 9cd00cc6..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/account/ViewAccountHistory.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewAccountHistory extends Contract { - - public static final String ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String BALANCE = "balance"; - public static final String BALANCE_CHANGE = "balance_change"; - private static final String HISTORY = "account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for account lookup"); - } - - // Determine asset id - String accountId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + accountId; - - // Retrieve account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no account with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String name = data.getString(NAME); - int balance = data.getInt(BALANCE); - int balanceChange = data.getInt(BALANCE_CHANGE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(NAME, name) - .add(BALANCE, balance) - .add(BALANCE_CHANGE, balanceChange) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java deleted file mode 100644 index 0014d639..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/escrowAccount/ViewEscrowAccountHistory.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.ypeckstadt.escrow.contract.escrowAccount; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.*; - -public class ViewEscrowAccountHistory extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String ESCROW_ACCOUNT_ASSET_TYPE = "escrow"; - private static final String BALANCE = "balance"; - private static final String TIMESTAMP = "timestamp"; - private static final String ORDER_ID = "order_id"; - private static final String HISTORY = "escrow_account_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) || !argument.containsKey(SELLER_ACCOUNT_ID)) { - throw new ContractContextException("missing ID argument for escrow account lookup"); - } - - // Determine asset id - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String assetId = ESCROW_ACCOUNT_ASSET_TYPE + buyerAccountId + "_" + sellerAccountId; - - // Retrieve escrow account history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException( - "no escrow account between this seller and buyer was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String orderId = data.getString(ORDER_ID); - int balance = data.getInt(BALANCE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // build json object result - JsonObject account = - Json.createObjectBuilder() - .add(BALANCE, balance) - .add(ORDER_ID, orderId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(account); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java deleted file mode 100644 index baba5a59..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/AddItem.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddItem extends Contract { - - public static final String ITEM_ASSET_TYPE = "item"; - public static final String ACCOUNT_ASSET_TYPE = "account"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(NAME) - || !argument.containsKey(PRICE) - || !argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an item"); - } - - // get field data from arguments - String itemId = argument.getString(ID); - String name = argument.getString(NAME); - int price = argument.getInt(PRICE); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - - // determine asset id - String assetId = ITEM_ASSET_TYPE + "_" + itemId; - - // check if asset with id already exists - Optional asset = ledger.get(assetId); - if (asset.isPresent()) { - throw new ContractContextException("an item with this id already exists"); - } - - // validate the seller has an account - String accountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - asset = ledger.get(accountAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("the provided seller does not have an account"); - } - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, itemId) - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(TIMESTAMP, timestamp); - - // add item - ledger.put(assetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java deleted file mode 100644 index 1638aa58..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/item/ViewItem.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ypeckstadt.escrow.contract.item; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; - -public class ViewItem extends Contract { - - public static final String ASSET_TYPE = "item"; - public static final String ID = "id"; - public static final String NAME = "name"; - public static final String TIMESTAMP = "timestamp"; - public static final String PRICE = "price"; - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for item lookup"); - } - - // Determine asset id - String itemId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + itemId; - - // Retrieve item - Optional asset = ledger.get(assetId); - if (!asset.isPresent()) { - throw new ContractContextException("no item with this id was found"); - } - - // get field data - JsonObject data = asset.get().data(); - String id = data.getString(ID); - String name = data.getString(NAME); - String seller = data.getString(SELLER_ACCOUNT_ID); - int price = data.getInt(PRICE); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - - // asset json object builder - return Json.createObjectBuilder() - .add(NAME, name) - .add(PRICE, price) - .add(SELLER_ACCOUNT_ID, seller) - .add(ID, id) - .add(TIMESTAMP, timestamp) - .build(); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java deleted file mode 100644 index 8cb9385c..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/AddOrder.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class AddOrder extends Contract { - - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - public static final String ITEM_ID = "item_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String ID = "id"; - - private static final String ITEM_ASSET_TYPE = "item"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ID = "account_id"; - private static final String ITEM_PRICE = "price"; - private static final String TOTAL = "total"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ORDER_ID = "order_id"; - private static final String STATUS = "status"; - private static final String DEBIT_ESCROW_ACCOUNT_CONTRACT = "DebitEscrowAccount_foo"; - private static final String CREDIT_ACCOUNT_CONTRACT = "CreditAccount_foo"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ITEM_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to create an order"); - } - - // get field data from arguments - String itemId = argument.getString(ITEM_ID); - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - String orderId = argument.getString(ID); - - // determine asset ids - String itemAssetId = ITEM_ASSET_TYPE + "_" + itemId; - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - - // check if the item exists - Optional optionalItemAsset = ledger.get(itemAssetId); - if (!optionalItemAsset.isPresent()) { - throw new ContractContextException("the item does not exist"); - } - - // check if the buyer's account exists - Optional optionalBuyerAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalBuyerAccountAsset.isPresent()) { - throw new ContractContextException("the account does not exist"); - } - - // get json object data - JsonObject item = optionalItemAsset.get().data(); - int itemPrice = item.getInt(ITEM_PRICE); - String sellerAccountId = item.getString(SELLER_ACCOUNT_ID); - - // Debit escrow and credit are split into 2 separate contracts to not make the contract to heavy - // and test calling external contracts. - // In a normal situation both actions will always follow each other so it makes more sense to - // put it into one contract - - // Debit escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, itemPrice) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Credit buyer's account - JsonObject creditArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, itemPrice) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ACCOUNT_CONTRACT, ledger, creditArguments); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_OPEN) - .add(TOTAL, itemPrice) - .add(TIMESTAMP, timestamp); - - // add order record - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java deleted file mode 100644 index 2c8b0e57..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/CancelOrder.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class CancelOrder extends Contract { - - public static final String ID = "id"; - public static final String ACCOUNT_ID = "account_id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String STATUS = "status"; - private static final String ORDER_STATUS_OPEN = "open"; - private static final String ORDER_STATUS_CANCELLED = "cancelled"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String TOTAL = "total"; - private static final String AMOUNT = "amount"; - private static final String ORDER_ID = "order_id"; - private static final String ITEM_ID = "item_id"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID) - || !argument.containsKey(ACCOUNT_ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to cancel an order"); - } - - // Get input data - String orderId = argument.getString(ID); - - String accountId = argument.getString(ACCOUNT_ID); - - // Determine asset id - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - - // check if order exists - Optional asset = ledger.get(orderAssetId); - if (!asset.isPresent()) { - throw new ContractContextException("no order with this id was found"); - } - - // Get order data - JsonObject order = asset.get().data(); - String orderStatus = order.getString(STATUS); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - long timestamp = order.getJsonNumber(TIMESTAMP).longValue(); - String itemId = order.getString(ITEM_ID); - - // check order status ,if still in open mode, cant be cancelled after - if (!orderStatus.equals(ORDER_STATUS_OPEN)) { - throw new ContractContextException("the order cannot be cancelled anymore"); - } - - // make sure the account id is a seller or buyer - if (!accountId.equals(buyerAccountId) && !accountId.equals(sellerAccountId)) { - throw new ContractContextException("the order does not belong to the account"); - } - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit buyer account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, buyerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - // update order, set to cancelled status - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_CANCELLED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java deleted file mode 100644 index 76fbec83..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToReceivedStatus.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToReceivedStatus extends Contract { - - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - public static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_COMPLETE = "complete"; - private static final String DEBIT_ACCOUNT_CONTRACT = "DebitAccount_foo"; - private static final String CREDIT_ESCROW_ACCOUNT_CONTRACT = "CreditEscrowAccount_foo"; - private static final String ACCOUNT_ID = "account_id"; - private static final String TOTAL = "total"; - private static final String ORDER_ID = "order_id"; - private static final String AMOUNT = "amount"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - // Check input arguments - if (!argument.containsKey(BUYER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as received"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String buyerAccountId = argument.getString(BUYER_ACCOUNT_ID); - String buyerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + buyerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if buyer's account exists - Optional optionalAccountAsset = ledger.get(buyerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the buyer's account does not exist"); - } - - // check if the order belongs to the buyer - JsonObject order = optionalOrderAsset.get().data(); - String orderBuyerAccountId = order.getString(BUYER_ACCOUNT_ID); - if (!buyerAccountId.equals(orderBuyerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the buyer"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String sellerAccountId = order.getString(SELLER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_COMPLETE) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - // Credit Escrow account - JsonObject escrowArguments = - Json.createObjectBuilder() - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(ORDER_ID, orderId) - .add(TIMESTAMP, timestamp) - .build(); - invoke(CREDIT_ESCROW_ACCOUNT_CONTRACT, ledger, escrowArguments); - - // Debit Seller account - JsonObject debitArguments = - Json.createObjectBuilder() - .add(ACCOUNT_ID, sellerAccountId) - .add(AMOUNT, orderTotal) - .add(TIMESTAMP, timestamp) - .build(); - invoke(DEBIT_ACCOUNT_CONTRACT, ledger, debitArguments); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java deleted file mode 100644 index 410aac54..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/SetOrderToShippedStatus.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -public class SetOrderToShippedStatus extends Contract { - - public static final String SELLER_ACCOUNT_ID = "seller_account_id"; - public static final String ID = "id"; - public static final String TIMESTAMP = "timestamp"; - - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String ORDER_ASSET_TYPE = "order"; - private static final String ACCOUNT_ASSET_TYPE = "account"; - private static final String ORDER_STATUS_SHIPPED = "shipped"; - private static final String TOTAL = "total"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(SELLER_ACCOUNT_ID) - || !argument.containsKey(ID) - || !argument.containsKey(TIMESTAMP)) { - throw new ContractContextException("wrong or missing arguments to mark order as shipped"); - } - - // get field data from arguments - String orderId = argument.getString(ID); - String orderAssetId = ORDER_ASSET_TYPE + "_" + orderId; - String sellerAccountId = argument.getString(SELLER_ACCOUNT_ID); - String sellerAccountAssetId = ACCOUNT_ASSET_TYPE + "_" + sellerAccountId; - long timestamp = argument.getJsonNumber(TIMESTAMP).longValue(); - - // check if order exists - Optional optionalOrderAsset = ledger.get(orderAssetId); - if (!optionalOrderAsset.isPresent()) { - throw new ContractContextException("the order does not exist"); - } - - // check if seller's account exists - Optional optionalAccountAsset = ledger.get(sellerAccountAssetId); - if (!optionalAccountAsset.isPresent()) { - throw new ContractContextException("the seller's account does not exist"); - } - - // check if the order belongs to the seller - JsonObject order = optionalOrderAsset.get().data(); - String orderSellerAccountId = order.getString(SELLER_ACCOUNT_ID); - if (!sellerAccountId.equals(orderSellerAccountId)) { - throw new ContractContextException("Access denied. The order does not belong to the seller"); - } - - // get data - String itemId = order.getString(ITEM_ID); - String buyerAccountId = order.getString(BUYER_ACCOUNT_ID); - int orderTotal = order.getInt(TOTAL); - - // asset json object builder - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add(ID, orderId) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, ORDER_STATUS_SHIPPED) - .add(TOTAL, orderTotal) - .add(TIMESTAMP, timestamp); - - // update order record - ledger.put(orderAssetId, builder.build()); - - return null; - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java deleted file mode 100644 index 344fe68b..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/contract/order/ViewOrderHistory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.ypeckstadt.escrow.contract.order; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.contract.Contract; -import com.scalar.dl.ledger.database.AssetFilter; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.List; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; - -public class ViewOrderHistory extends Contract { - - public static final String ID = "id"; - - private static final String ASSET_TYPE = "order"; - private static final String TIMESTAMP = "timestamp"; - private static final String BUYER_ACCOUNT_ID = "buyer_account_id"; - private static final String SELLER_ACCOUNT_ID = "seller_account_id"; - private static final String ITEM_ID = "item_id"; - private static final String STATUS = "status"; - private static final String TOTAL = "total"; - - private static final String HISTORY = "order_history"; - - @Override - public JsonObject invoke(Ledger ledger, JsonObject argument, Optional properties) { - - // Check input arguments - if (!argument.containsKey(ID)) { - throw new ContractContextException("missing ID argument for order lookup"); - } - - // Determine asset id - String orderId = argument.getString(ID); - String assetId = ASSET_TYPE + "_" + orderId; - - // Retrieve order history - AssetFilter filter = new AssetFilter(assetId); - List history = ledger.scan(filter); - if (history.isEmpty()) { - throw new ContractContextException("no order with this id was found"); - } - - // build result - JsonArrayBuilder builder = Json.createArrayBuilder(); - for (Asset h : history) { - - // read data - JsonObject data = h.data(); - String id = data.getString(ID); - String itemId = data.getString(ITEM_ID); - String buyerAccountId = data.getString(BUYER_ACCOUNT_ID); - String sellerAccountId = data.getString(SELLER_ACCOUNT_ID); - String status = data.getString(STATUS); - long timestamp = data.getJsonNumber(TIMESTAMP).longValue(); - int total = data.getInt(TOTAL); - - // build json object result - JsonObject order = - Json.createObjectBuilder() - .add(ID, id) - .add(ITEM_ID, itemId) - .add(BUYER_ACCOUNT_ID, buyerAccountId) - .add(SELLER_ACCOUNT_ID, sellerAccountId) - .add(STATUS, status) - .add(TOTAL, total) - .add(TIMESTAMP, timestamp) - .build(); - builder.add(order); - } - JsonArray orderHistory = builder.build(); - - return Json.createObjectBuilder().add(HISTORY, orderHistory).build(); - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java b/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java deleted file mode 100644 index 61d3de7f..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/java/com/ypeckstadt/escrow/dl/LedgerClientExecutor.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.ypeckstadt.escrow.dl; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.scalar.dl.client.config.ClientConfig; -import com.scalar.dl.client.service.ClientModule; -import com.scalar.dl.client.service.ClientService; -import com.scalar.dl.ledger.model.ContractExecutionResult; -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public abstract class LedgerClientExecutor { - - private static final Logger LOG = LogManager.getLogger(LedgerClientExecutor.class); - private static final String CLIENT_PROPERTIES = "client.properties"; - - private ClientConfig loadClientConfig() throws Exception { - File file = new File(System.getProperty("user.dir") + File.separator + CLIENT_PROPERTIES); - return new ClientConfig(file); - } - - protected ContractExecutionResult executeContract( - String contractName, JsonObject contractParameter, boolean useCertHolderIdSuffix) - throws Exception { - ClientConfig config = loadClientConfig(); - - // Custom naming convention to make sure the contract Id is unique, not required and contractId - // can be anything - // just make sure the contractId is set to the same value as specified when registering the - // contract on the ledger - String contractId = - useCertHolderIdSuffix ? contractName + "_" + config.getCertHolderId() : contractName; - - Injector injector = Guice.createInjector(new ClientModule(config)); - ClientService service = injector.getInstance(ClientService.class); - JsonObject object = - (contractParameter != null) ? contractParameter : Json.createObjectBuilder().build(); - return service.executeContract(contractId, object); - } - - /** - * Pretty print the json to the standard output - * - * @param json the json to print - */ - protected void prettyPrintJson(JsonObject jsonObject) { - if (jsonObject != null) { - System.out.println("[Return]"); - Map config = new HashMap<>(1); - config.put(JsonGenerator.PRETTY_PRINTING, true); - JsonWriterFactory factory = Json.createWriterFactory(config); - JsonWriter writer = factory.createWriter(System.out); - writer.writeObject(jsonObject); - System.out.println(""); - writer.close(); - } - } -} diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties b/versioned_docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties deleted file mode 100644 index a3f65c97..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/main/resources/log4j2.properties +++ /dev/null @@ -1,18 +0,0 @@ -name=PropertiesConfig -property.filename = logs -appenders = console, file - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -appender.file.type = File -appender.file.name = LOGFILE -appender.file.fileName=${filename}/propertieslogs.log -appender.file.layout.type=PatternLayout -appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n - -rootLogger.level = info -rootLogger.appenderRefs = stdout -rootLogger.appenderRef.stdout.ref = STDOUT diff --git a/versioned_docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java b/versioned_docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java deleted file mode 100644 index ad63ded5..00000000 --- a/versioned_docs/version-3.8/applications/escrow-payment/src/test/java/com/ypeckstadt/escrow/contract/account/AddAccountTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ypeckstadt.escrow.contract.account; - -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ASSET_TYPE; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_ID; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_NAME; -import static com.ypeckstadt.escrow.common.Constants.ACCOUNT_TIMESTAMP; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR; -import static com.ypeckstadt.escrow.common.Constants.CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.scalar.dl.ledger.asset.Asset; -import com.scalar.dl.ledger.crypto.CertificateEntry.Key; -import com.scalar.dl.ledger.database.Ledger; -import com.scalar.dl.ledger.exception.ContractContextException; -import java.util.Optional; -import javax.json.Json; -import javax.json.JsonObject; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -public class AddAccountTest { - - private static final String MOCKED_HOLDER_ID = "mockedHolderId"; - - @Mock private Ledger ledger; - @Mock private Key mockedKey; - @Spy private AddAccount addAccount; - - @BeforeEach - public void setUp() { - MockitoAnnotations.initMocks(this); - when(addAccount.getCertificateKey()).thenReturn(mockedKey); - when(mockedKey.getHolderId()).thenReturn(MOCKED_HOLDER_ID); - } - - @Test - public void invoke_InsertNonexistentAccount_ShouldInsertAccount() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, null); - - // Act - JsonObject invokeResult = addAccount.invoke(ledger, argument, Optional.of(properties)); - assertEquals(invokeResult, null); - } - - @Test - public void invoke_ArgumentsMissing_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = Json.createObjectBuilder().build(); - JsonObject properties = prepareProperties(); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_MISSING_ARGUMENTS_ERROR); - } - - @Test - public void invoke_InsertExistentAccount_ShouldThrowContractContextException() { - // Arrange - JsonObject argument = prepareArgument(); - JsonObject properties = prepareProperties(); - mockLedgerGetCall(argument, mock(Asset.class)); - - // Act - // Assert - assertThatThrownBy( - () -> { - addAccount.invoke(ledger, argument, Optional.of(properties)); - }) - .isExactlyInstanceOf(ContractContextException.class) - .hasMessage(CONTRACT_ADD_ACCOUNT_DUPLICATE_ERROR); - } - - private JsonObject prepareArgument() { - return Json.createObjectBuilder() - .add(ACCOUNT_ID, "1") - .add(ACCOUNT_NAME, "name") - .add(ACCOUNT_TIMESTAMP, System.currentTimeMillis()) - .build(); - } - - private JsonObject prepareProperties() { - return Json.createObjectBuilder().build(); - } - - private void mockLedgerGetCall(JsonObject argument, Asset result) { - when(ledger.get(getAssetId(argument))).thenReturn(Optional.ofNullable(result)); - } - - private String getAssetId(JsonObject argument) { - return ACCOUNT_ASSET_TYPE + "_" + argument.getString(ACCOUNT_ID); - } -} diff --git a/versioned_sidebars/version-3.8-sidebars.json b/versioned_sidebars/version-3.8-sidebars.json index c419eea2..a32d192f 100644 --- a/versioned_sidebars/version-3.8-sidebars.json +++ b/versioned_sidebars/version-3.8-sidebars.json @@ -29,8 +29,7 @@ "label": "Samples", "collapsible": true, "items": [ - "applications/simple-bank-account/README", - "applications/escrow-payment/README" + "applications/simple-bank-account/README" ] }, {