-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(validator): validators including execSyncFunctions
Signed-off-by: Takuma TAKEUCHI <[email protected]>
- Loading branch information
Showing
150 changed files
with
3,504 additions
and
4,244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,64 @@ | ||
# example-cartrade | ||
|
||
## Prerequisites | ||
|
||
Before you begin, you need to check that you have all the prerequisites installed as follows: | ||
- Docker (recommend: v17.06.2-ce or greater) | ||
- Docker-compose (recommend: v1.14.0 or greater) | ||
- node.js (recommend: v10.23.0 or greater) | ||
- The ports 5034, 5040, 5050 are available (If they are already used, the following processes can be done by changing the port number setting) | ||
|
||
## Boot method | ||
|
||
1. Before booting, please modify the following information for your environment | ||
- applicationHostInfo.hostName (URL of the host on the Location header) on `/packages/config/default.json` | ||
- applicationHostInfo.hostPort (The port number of Routing-interface http server) on `/packages/config/default.json` | ||
- `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. Start ledgers: | ||
- `./script-start-ledgers.sh` | ||
1. Build validators, packages, and the cartrade app: | ||
- `./script-build-all.sh` | ||
1. Start validators and the cartrade app | ||
- Please open three consoles and execute the following:. | ||
- Start the validator for Fabric: | ||
- Start the validator for Fabric on the first console: | ||
`./script-start-validator-fabric.sh` | ||
- Start the validator for Ethereum: | ||
- Start the validator for Ethereum on the second console: | ||
`./script-start-validator-ethereum.sh` | ||
- Start the cartrade app: | ||
- Start the cartrade app on the third console: | ||
`./script-start-cartrade.sh` | ||
|
||
## How to use this application | ||
- Run with curl, etc. Currently only POST is available. | ||
- Examples of curl POSTs:. | ||
- **transaction execution** | ||
- `curl localhost:5034/api/v1/bl/trades/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"guks32pf","tradeParams":["0xec709e1774f0ce4aba47b52a499f9abaaa159f71", "0x9d624f7995e8bd70251f8265f2f9f2b49f169c55", "user01", "user02", 50, "CAR1"],"authParams":["none"]}'` | ||
- **Transaction Reference** | ||
- `curl localhost:5034/api/v1/bl/trades/XXXXXXXXXXXXXX-XXX -XGET` | ||
- **Login** | ||
- `curl localhost:5034/api/v1/bl/login/ -XPOST -H "Content-Type: application/json" -d '{"userid":"user01","pwd":"hoge"}'` | ||
|
||
- In the case of the above "transaction execution", the console log is the following: | ||
``` | ||
[2020-08-21T19:55:24.207] [INFO] TransactionManagement - tradeID: 20200821195524-001 | ||
[2020-08-21T19:55:24.282] [INFO] BusinessLogicCartrade - firstTransaction txId : 0xafe7c812ab55c02feb691d2133bbba2c38abaf7f221794c3ca833a29708f4653 | ||
[2020-08-21T19:56:20.005] [INFO] BusinessLogicCartrade - ##INFO: underEscrow -> underTransfer, businessLogicID: guks32pf, tradeID: 20200821195524-001 | ||
[2020-08-21T19:56:20.608] [INFO] BusinessLogicCartrade - secondTransaction txId : 17c7577f73560ea5955f3151ed678833aa45d1252b34c6f933a7123757e82969 | ||
[2020-08-21T19:56:23.691] [INFO] BusinessLogicCartrade - ##INFO: underTransfer -> underSettlement, businessLogicID: guks32pf, tradeID: 20200821195524-001 | ||
[2020-08-21T19:56:23.703] [INFO] BusinessLogicCartrade - thirdTransaction txId : 0x61acb066349e24319afdf272b35429d198046e10f8fca3972f17a9e9a4dca75d | ||
[2020-08-21T19:56:31.518] [INFO] BusinessLogicCartrade - ##INFO: completed cartrade, businessLogicID: guks32pf, tradeID: 20200821195524-001 | ||
``` | ||
- When the message `"##INFO: completed cartrade"` happens, the transaction is completed. | ||
|
||
## How to confirm operation results | ||
- How to check your account balance | ||
- `/packages/ledger-plugin/go-ethereum/validator/unit-test/validatorDriver_getNumericBalance.js` | ||
- Example: `node validatorDriver_getNumericBalance.js` | ||
- The balance of the account is displayed on the Validator's console. | ||
- Example output | ||
``` | ||
[2020-08-18T17:06:15.795] [INFO] connector_main[6710] - Response :{"status":200,"amount":1900} | ||
``` | ||
- How to identify the owner of the car | ||
- `/packages/ledger-plugin/fabric/validator/unit-test/queryCar.js` | ||
- Example: `node queryCar.js CAR1` | ||
- The owner of the car is displayed on the console. | ||
- Example output | ||
1. (Optional) Check the balance on Ethereum and the fabcar ownership on Fabric using the following script | ||
- `./script-build-get-app.sh` (only the first time) | ||
- `./script-get-app.sh` | ||
- The result is as the following: | ||
``` | ||
[process] Execute an app for getting Balance on Ethereum | ||
The balance of fromAccount: | ||
BigNumber { s: 1, e: 4, c: [ 100000 ] } | ||
The balance of toAccount: | ||
BigNumber { s: 1, e: 1, c: [ 0 ] } | ||
[process] Execute an app for getting ownership on Fabcar | ||
##queryCar Params: CAR1 | ||
Transaction has been evaluated, result is: {"colour":"red","make":"Ford","model":"Mustang","owner":"user02"} | ||
Transaction has been evaluated, result is: {"colour":"red","make":"Ford","model":"Mustang","owner":"Brad"} | ||
``` | ||
1. Run the transaction execution using the following script | ||
- `./script-post-cartrade-sample.sh` | ||
- After this, the transactions are executed by order. When the following log appears on the above third console (the console of `./script-start-cartrade.sh`), the transactions are completed. | ||
``` | ||
- How to change the ownership of the car by hand | ||
- ``/packages/ledger-plugin/fabric/validator/unit-test/validatorDriver_signTransactionOffline.js`` | ||
[INFO] BusinessLogicCartrade - ##INFO: completed cartrade, businessLogicID: guks32pf, tradeID: *******-001 | ||
``` | ||
1. (Optional) Check the balance on Ethereum and the fabcar ownership on Fabric using the following script | ||
- `./script-get-app.sh` | ||
- The result is as the following. In the following case, 50 coins from fromAccount was transferred to toAccount, and the car ownership ("owner") was transferred. | ||
``` | ||
[process] Execute an app for getting Balance on Ethereum | ||
The balance of fromAccount: | ||
BigNumber { s: 1, e: 4, c: [ 99950 ] } | ||
The balance of toAccount: | ||
BigNumber { s: 1, e: 1, c: [ 50 ] } | ||
[process] Execute an app for getting ownership on Fabcar | ||
##queryCar Params: CAR1 | ||
Transaction has been evaluated, result is: {"colour":"red","make":"Ford","model":"Mustang","owner":"Cathy"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## Build a cartrade app | ||
echo "[process] Build a cartrade app" | ||
npm install | ||
npm run build | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Build a getting app | ||
echo "[process] Build an app for getting Balance on Ethereum" | ||
cd script-test-getFunctions/go-ethereum | ||
npm install | ||
echo "[process] Build an app for getting ownership on Fabcar" | ||
cd ../fabric | ||
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Execute a getting app | ||
echo "[process] Execute an app for getting Balance on Ethereum" | ||
cd script-test-getFunctions/go-ethereum | ||
node getBalance.js | ||
echo "[process] Execute an app for getting ownership on Fabcar" | ||
cd ../fabric | ||
node queryCar.js CAR1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
curl localhost:5034/api/v1/bl/trades/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"guks32pf","tradeParams":["0xec709e1774f0ce4aba47b52a499f9abaaa159f71", "0x9d624f7995e8bd70251f8265f2f9f2b49f169c55", "user01", "user02", 50, "CAR1"],"authParams":["param"]}' | ||
curl localhost:5034/api/v1/bl/trades/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"guks32pf","tradeParams":["0x06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97", "0x9d624f7995e8bd70251f8265f2f9f2b49f169c55", "Brad", "Cathy", 50, "CAR1"],"authParams":["none"]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
cd ../../ | ||
cd ../.. | ||
|
||
## Start cartrade app | ||
echo "[process] Start the routing interface and the cartrade app" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
## Start docker environment for Fabric testnet | ||
cd ../../tools/docker/fabric14-fabcar-testnet | ||
cd ../.. | ||
|
||
## Start docker environment for Go-Ethereum testnet | ||
cd ./tools/docker/geth-testnet | ||
./script-start-docker.sh | ||
cd ../../.. | ||
|
||
## Start docker environment for Go-Ethereum testnet | ||
cd ../../tools/docker/geth-testnet | ||
## Start docker environment for Fabric testnet | ||
cd ./tools/docker/fabric14-fabcar-testnet | ||
./script-start-docker.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
cd .. | ||
cd ../.. | ||
|
||
echo "[process] Start the validator for Fabric" | ||
cd ./packages/ledger-plugin/fabric/validator/src | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
echo "[process] Stop the validators and the cartrade app" | ||
# stop the validator for Ethereum | ||
kill -9 $(lsof -t -i:5050) | ||
# stop the validator for Fabric | ||
kill -9 $(lsof -t -i:5040) | ||
# stop the cartrade app | ||
kill -9 $(lsof -t -i:5034) |
52 changes: 52 additions & 0 deletions
52
examples/cartrade/script-test-getFunctions/fabric/config/connection.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "basic-network", | ||
"version": "1.0.0", | ||
"client": { | ||
"organization": "Org1", | ||
"connection": { | ||
"timeout": { | ||
"peer": { | ||
"endorser": "300" | ||
}, | ||
"orderer": "300" | ||
} | ||
} | ||
}, | ||
"channels": { | ||
"mychannel": { | ||
"orderers": [ | ||
"orderer.example.com" | ||
], | ||
"peers": { | ||
"peer0.org1.example.com": {} | ||
} | ||
} | ||
}, | ||
"organizations": { | ||
"Org1": { | ||
"mspid": "Org1MSP", | ||
"peers": [ | ||
"peer0.org1.example.com" | ||
], | ||
"certificateAuthorities": [ | ||
"ca.example.com" | ||
] | ||
} | ||
}, | ||
"orderers": { | ||
"orderer.example.com": { | ||
"url": "grpc://localhost:7050" | ||
} | ||
}, | ||
"peers": { | ||
"peer0.org1.example.com": { | ||
"url": "grpc://localhost:7051" | ||
} | ||
}, | ||
"certificateAuthorities": { | ||
"ca.example.com": { | ||
"url": "http://localhost:7054", | ||
"caName": "ca.example.com" | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/cartrade/script-test-getFunctions/fabric/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "validatorDriver", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"config": "^1.26.1", | ||
"socket.io": "^2.0.4", | ||
"fabric-ca-client": "~1.4.0", | ||
"fabric-network": "~1.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/cartrade/script-test-getFunctions/go-ethereum/getBalance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const Web3 = require('web3'); | ||
const web3 = new Web3(); | ||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); | ||
const fromAccount = "0x06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97" | ||
const toAccount = "0x9d624f7995e8bd70251f8265f2f9f2b49f169c55" | ||
console.log("The balance of fromAccount:"); | ||
var res = web3.eth.getBalance(fromAccount); | ||
console.log(res); | ||
console.log("The balance of toAccount:"); | ||
var res = web3.eth.getBalance(toAccount); | ||
console.log(res); |
12 changes: 12 additions & 0 deletions
12
examples/cartrade/script-test-getFunctions/go-ethereum/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"dependencies": { | ||
"fs": "^0.0.1-security", | ||
"jsonfile": "^5.0.0", | ||
"web3": "^0.20.7" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"license": "ISC" | ||
} |
Oops, something went wrong.