The following is a simple Java CLI application to try out and test Scalar DL. PicoCLI is used as a CLI framework.
Scalar DL 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 Scalar DL documentation to see which commands are being executed.
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
- 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
- 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
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
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:
- register a new account
- add funds, charge, an account
- view account history
- register a new item
- view item details
- create a new order
- Mark an order as shipped
- Mark and order as received (complete an order)
- Cancel an order
- View order history
- View escrow account history
The code to start up the Scalar DL server is not included in this repository. To get Scalar DL up and running quickly, please clone the following repository and follow the provided instructions on how to get started with Scalar DL.
An example certificate is used but is enough for the example. The certiticate can be loaded
All the contract names have an added suffix. This is the name of the certificate owner which in this
foo. This is not required and only done to make sure the contract names are unique.
The contracts can be loaded via
The Java client SDK requires a
client.properties file to work. Currently the same settings as the
scalar examples projects are used.
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
The application can be build via
./gradlew build or by running the
make build Makefile command.
Management of the accounts via CLI.
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.
./gradlew run --args="account add -id <account id> -n <name>"
View account history
Retrieve the account history.
./gradlew run --args="account view -id <account id>"
Add funds to the account’s balance.
./gradlew run --args="account charge -id <account id> -a <amount>"
Management of the items via CLI.
Create a new item by providing an
seller, which is the account Id, and an
./gradlew run --args="item add -id <item id> -p <price> -s <seller account id -n <item name>"
View item details
./gradlew run --args="item view -id <item id>"
Management of the orders via CLI.
Create a new order by providing an
item id and
buyer, which is the account Id.
./gradlew run --args="order add -id <order id> -b <buyer account id> -i <item id>"
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.
./gradlew run --args="order cancel -id <order id> -a <account id>"
Mark order item as shipped
Update the order as a seller to notify the buyer the item has been shipped.
./gradlew run --args="order shipped -id <order id> -s <seller account id>"
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.
./gradlew run --args="order received -id <order id> -b <buyer account id>"
View order history
View the history for one order.
./gradlew run --args="order view -id <order id>"
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
./gradlew run --args="escrow view -b <buyer account id> -s <seller account id>"