Skip to content

Commit

Permalink
fix(example): fix README and tsconfig.json
Browse files Browse the repository at this point in the history
Signed-off-by: Takuma TAKEUCHI <takeuchi.takuma@fujitsu.com>
  • Loading branch information
takeutak committed Feb 25, 2021
1 parent a1c431e commit 79ef712
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
64 changes: 48 additions & 16 deletions examples/electricity-trade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Prerequisites

Before you begin, you need to check that you have all the prerequisites installed as follows:
- OS: Linux (recommend: Ubuntu18.04 or CentOS7)
- Docker (recommend: v17.06.2-ce or greater)
- Docker-compose (recommend: v1.14.0 or greater)
- node.js (recommend: v12)
Expand All @@ -14,19 +15,31 @@ Before you begin, you need to check that you have all the prerequisites installe
- `applicationHostInfo.hostName` (IP address of the host on the Location header) on `/packages/config/default.json`
- `applicationHostInfo.hostPort` (The port number of Routing-interface http server, the default is 5034) on `/packages/config/default.json`
1. Go to the following directory:
- `cd cactus/examples/electricity-trade/`
```
cd cactus/examples/electricity-trade/
```
1. Start ledgers:
- `./script-start-ledgers.sh`
```
./script-start-ledgers.sh
```
1. Build validators, packages, and the cartrade app:
- `./script-build-all.sh`
```
./script-build-all.sh
```
1. Start validators and the cartrade app
- Please open three consoles and execute the following:.
- Start the validator for Sawtooth on the first console:
`./script-start-validator-sawtooth.sh`
```
./script-start-validator-sawtooth.sh
```
- Start the validator for Ethereum on the second console:
`./script-start-validator-ethereum.sh`
```
./script-start-validator-ethereum.sh
```
- Start the cartrade app on the third console:
`./script-start-electricity-trade.sh`
```
./script-start-electricity-trade.sh
```

## How to use this application

Expand All @@ -41,39 +54,58 @@ Before you begin, you need to check that you have all the prerequisites installe
#### Setup the application

1. Set the intkey script on Sawtooth docker:
- `./script-set-sawtooth-intkey.sh`
```
./script-set-sawtooth-intkey.sh
```
1. Register on account information:
- `curl localhost:5034/api/v1/bl/electricity-trade/meter/register/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD","meterParams":["MI000001", "06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97", "cb5d48d371916a4ea1627189d8af4f642a5d72746a06b559780c3f5932658207", "9d624f7995e8bd70251f8265f2f9f2b49f169c55"]}'`
```
curl localhost:5034/api/v1/bl/electricity-trade/meter/register/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD","meterParams":["MI000001", "06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97", "cb5d48d371916a4ea1627189d8af4f642a5d72746a06b559780c3f5932658207", "9d624f7995e8bd70251f8265f2f9f2b49f169c55"]}'
```

#### Run the application

1. (Optional) Check the balance on Ethereum accounts using the following script
- Check the balance of the source account as the following:
- `curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97`
```
curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97
```
- The result: `{"status":200,"amount":100000}`
- Check the balance of the destination account:
- `curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55`
```
curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55
```
- The result: `{"status":200,"amount":0}`

1. Start the electricity-trade application
- `curl localhost:5034/api/v1/bl/electricity-trade/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD"}'`
```
curl localhost:5034/api/v1/bl/electricity-trade/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"h40Q9eMD"}'
```
- The example response of tradeID: `{"tradeID":"20210220075755506-001"}`
- (Then, the application starts to monitor the Sawtooth blockchain)

1. Execute the intkey transaction on Sawtooth blockchain
- Open the docker bash: `docker exec -it sawtooth-shell-default bash`
- Open the docker bash:
```
docker exec -it sawtooth-shell-default bash
```
- Execute the intkey transaction:
`intkey create_batch --key-name MI000001 --value-set 50 --value-inc 24`
`sawtooth batch submit -f batches.intkey --url http://rest-api:8008`
```
intkey create_batch --key-name MI000001 --value-set 50 --value-inc 24`
`sawtooth batch submit -f batches.intkey --url http://rest-api:8008
```
- (In the above, the value of the key `MI000001` is set as 50, and increased by 24)
- After that, exit the docker bash:
`exit`

1. (Optional) Check the balance on Ethereum accounts using the following script
- Check the balance of the source account as the following:
- `curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97`
```
curl localhost:5034/api/v1/bl/balance/06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97
```
- The result: `{"status":200,"amount":99976}`
- Check the balance of the destination account:
- `curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55`
```
curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55
```
- The result: `{"status":200,"amount":24}`
- (The result shows that the asset was transferred between Ethereum addresses depending on the value of the change in Sawtooth intkey.)
2 changes: 1 addition & 1 deletion packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"./business-logic-plugin/*.ts",
"./config/*.ts",
"./ledger-plugin/*.ts",
"./routing-interface/**/*.ts",
"./routing-interface/**/*.ts"
],
"exclude": [
"copyStaticAssets.ts",
Expand Down

0 comments on commit 79ef712

Please sign in to comment.