Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector-fabric-socketio): migrate to fabric-all-in-one from fabric14-fabcar-testnet #1754

Merged
merged 3 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/cartrade/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Fabric TLSCA local dir
crypto-config/

# BLP artifacts
TransactionInfo.json
wallet/

# don't commit package-lock
package-lock.json
11 changes: 0 additions & 11 deletions examples/cartrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ Cactus **car-trade** is a sample application where users can exchange car owners
./script-start-ledgers.sh
```
- (NOTICE: Before executing the above, your account needs to be added to the docker group (`usermod -a -G docker YourAccount` from root user))
- If the following containers are started when displaying the container list with the docker ps command, it will be fine.
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
14b98ba40b66 dev-peer0.org1.example.com-fabcar-1.0-5c906e402ed29f20260ae42283216aa75549c571e2e380f3615826365d8269ba "chaincode -peer.add…" 42 seconds ago Up 40 seconds dev-peer0.org1.example.com-fabcar-1.0
d0efd7479bdd hyperledger/fabric-tools "/bin/bash" About a minute ago Up 56 seconds cli
c9bd7ddfde7e hyperledger/fabric-peer "peer node start" About a minute ago Up About a minute 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
d4f2b1a76626 hyperledger/fabric-couchdb "tini -- /docker-ent…" About a minute ago Up About a minute 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb
53a79780f564 hyperledger/fabric-ca "sh -c 'fabric-ca-se…" About a minute ago Up About a minute 0.0.0.0:7054->7054/tcp ca.example.com
aceb0e52e9c7 hyperledger/fabric-orderer "orderer" About a minute ago Up About a minute 0.0.0.0:7050->7050/tcp orderer.example.com
ec57c9f78d0d ethereum/client-go:v1.8.27 "geth --rpc --networ…" 2 minutes ago Up 2 minutes 8546/tcp, 0.0.0.0:8545->8545/tcp, 30303/tcp, 30303/udp geth1
```

1. Please prepare the three consoles on your machine as the following:
- **console 1**: console for launching `cactus-plugin-ledger-connector-go-ethereum-socketio`
Expand Down
20 changes: 16 additions & 4 deletions examples/cartrade/TransactionFabric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import { Verifier } from "../../packages/cactus-cmd-socketio-server/src/main/typ
const fs = require("fs");
const path = require("path");
const yaml = require("js-yaml");
import { FileSystemWallet } from "fabric-network";

//const config: any = JSON.parse(fs.readFileSync("/etc/cactus/default.json", 'utf8'));
const config: any = yaml.safeLoad(
fs.readFileSync("/etc/cactus/default.yaml", "utf8")
fs.readFileSync("/etc/cactus/default.yaml", "utf8"),
);
import { getLogger } from "log4js";
const moduleName = "TransactionFabric";
Expand All @@ -33,7 +35,7 @@ logger.level = config.logLevel;
export function makeSignedProposal(
ccFncName: string,
ccArgs: string[],
verifierFabric: Verifier
verifierFabric: Verifier,
): Promise<{ data: {}; txId: string }> {
// exports.Invoke = async function(reqBody, isWait){
// let eventhubs = []; // For the time being, give up the eventhub connection of multiple peers.
Expand All @@ -54,8 +56,18 @@ export function makeSignedProposal(
logger.debug(transactionProposalReq);

// Get certificate and key acquisition
const certPem = config.cartradeInfo.fabric.submitter.certificate;
const privateKeyPem = config.cartradeInfo.fabric.submitter.pkey;
let certPem = undefined;
let privateKeyPem = undefined;
const submitter = config.cartradeInfo.fabric.submitter.name;
const wallet = new FileSystemWallet(config.cartradeInfo.fabric.keystore);
logger.debug(`Wallet path: ${config.cartradeInfo.fabric.keystore}`);

const submitterExists = await wallet.exists(submitter);
if (submitterExists) {
const submitterIdentity = await wallet.export(submitter);
certPem = (submitterIdentity as any).certificate;
privateKeyPem = (submitterIdentity as any).privateKey;
}

// const signedTx = await TransactionSigner.signTxFabric(transactionProposalReq, certPem, privateKeyPem);
const contract = { channelName: config.cartradeInfo.fabric.channelName };
Expand Down
7 changes: 2 additions & 5 deletions examples/cartrade/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ cartradeInfo:
fabric:
validatorID: r9IS4dDf
mspID: Org1MSP
keystore: "./wallet/admin"
keystore: "./wallet"
connUserName: user1
contractName: fabcar
peers:
-
-
name: peer0.org1.example.com
requests: grpc://localhost:7051
orderer:
Expand All @@ -19,9 +19,6 @@ cartradeInfo:

submitter:
name: admin
secret: adminpw
certificate: "-----BEGIN CERTIFICATE-----\nMIICATCCAaigAwIBAgIUPku4qKIQbtGFDlnZnOT4wuprCrowCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMjEwNzMwMDUwMjAwWhcNMjIwNzMwMDUw\nNzAwWjAhMQ8wDQYDVQQLEwZjbGllbnQxDjAMBgNVBAMTBWFkbWluMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAEcsvU2r+Td7dtCuZbzW5i6g9YZ5I99/PsbhBajl81\nP6Q7LUp0yG4KPP+RM1QP7Vq17rxTT/8jfdQGHBmyjNCGZKNsMGowDgYDVR0PAQH/\nBAQDAgeAMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFBgBGL/ubLTHr5xcQNQtQ2X/\nrxEeMCsGA1UdIwQkMCKAIEI5qg3NdtruuLoM2nAYUdFFBNMarRst3dusalc2Xkl8\nMAoGCCqGSM49BAMCA0cAMEQCIC2DR+8I1YzjtpVZartsZIvzkcUBTEkWPHu8lPoS\nXlOMAiBawCF3lIBzs/mi9kCL58M6SkddfKievhfi0/obf0sGEw==\n-----END CERTIFICATE-----\n"
pkey: "-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgMNMJbHDw6+FcclPa\nzGWYItb0g+VnXAAVMCv1RFILciOhRANCAARyy9Tav5N3t20K5lvNbmLqD1hnkj33\n8+xuEFqOXzU/pDstSnTIbgo8/5EzVA/tWrXuvFNP/yN91AYcGbKM0IZk\n-----END PRIVATE KEY-----\n"

channelName: mychannel
chaincodeID: fabcar
Expand Down
4 changes: 2 additions & 2 deletions examples/cartrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"ethereumjs-common": "^1.5.1",
"ethereumjs-tx": "^2.1.2",
"express": "~4.16.1",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10",
"fabric-ca-client": "~1.4.0",
"fabric-network": "~1.4.0",
"http-errors": "~1.6.3",
"jsonwebtoken": "^8.5.1",
"log4js": "^3.0.6",
Expand Down
13 changes: 6 additions & 7 deletions examples/cartrade/script-build-all.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0

cd ../..

## Build validator for Fabric
cd ./packages/cactus-plugin-ledger-connector-fabric-socketio
./script-build-validator.sh
cp -a ../../examples/cartrade/build/wallet ./dist/connector
cd ../..

## build validator for Ethereum
cd ./packages/cactus-plugin-ledger-connector-go-ethereum-socketio
./script-build-validator.sh
cd ../..

## build packages
cd ./packages/cactus-plugin-ledger-connector-fabric-socketio
./script-build-packages.sh
cd ../..

## build cartrade apps
cd ./examples/cartrade
./script-build-cartrade.sh
./script-build-cartrade.sh

## build getter apps
./script-build-get-app.sh
7 changes: 6 additions & 1 deletion examples/cartrade/script-build-cartrade.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0

## Build a cartrade app
echo "[process] Build a cartrade app"
rm -fr ./crypto-config
rm -fr ./wallet
rm -fr ../../dist/node_modules
npm install
npm run build
npm run build
14 changes: 10 additions & 4 deletions examples/cartrade/script-build-get-app.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0
## Build a getting app

## Build ethereum app
echo "[process] Build an app for getting Balance on Ethereum"
cd script-test-getFunctions/go-ethereum
pushd script-test-getFunctions/go-ethereum
npm install
popd

## Build fabric app
echo "[process] Build an app for getting ownership on Fabcar"
cd ../fabric
npm install
pushd ../../tools/docker/fabric-all-in-one/fabcar-cli-1.4
npm install
popd
12 changes: 9 additions & 3 deletions examples/cartrade/script-get-app.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0

## Execute a getting app
echo "[process] Execute an app for getting Balance on Ethereum"
cd script-test-getFunctions/go-ethereum
pushd script-test-getFunctions/go-ethereum
node getBalance.js
popd

echo "[process] Execute an app for getting ownership on Fabcar"
cd ../fabric
node queryCar.js CAR1
pushd ../../tools/docker/fabric-all-in-one/fabcar-cli-1.4
./setup.sh >/dev/null
node query.js
popd
4 changes: 3 additions & 1 deletion examples/cartrade/script-post-cartrade-sample.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0
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"]}'

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"]}'
9 changes: 0 additions & 9 deletions examples/cartrade/script-start-cartrade.sh

This file was deleted.

38 changes: 31 additions & 7 deletions examples/cartrade/script-start-ledgers.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
#!/usr/bin/env bash
# Copyright 2020-2021 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0
cd ../..

## Start docker environment for Go-Ethereum testnet
cd ./tools/docker/geth-testnet
# Exit on error
set -e

FABRIC_CONTAINER_NAME=fabcar14_sample_setup

pushd ../..

## Run Go-Ethereum Ledger
pushd ./tools/docker/geth-testnet
./script-start-docker.sh
cd ../../..
popd

## RunFabric Ledger
pushd ./tools/docker/fabric-all-in-one
./script-run-docker-1.4.sh
popd

popd

# Copy TLSCAs to connect peer and orderer
mkdir -p ./crypto-config/
rm -fr ./crypto-config/*
docker cp ${FABRIC_CONTAINER_NAME}:/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem ./crypto-config/
docker cp ${FABRIC_CONTAINER_NAME}:/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem ./crypto-config/

# Enroll users and copy wallet
pushd ../../tools/docker/fabric-all-in-one/fabcar-cli-1.4
./setup.sh
popd
cp -ar ../../tools/docker/fabric-all-in-one/fabcar-cli-1.4/wallet .

## Start docker environment for Fabric testnet
cd ./tools/docker/fabric14-fabcar-testnet
./script-start-docker.sh
echo "All Done."
7 changes: 0 additions & 7 deletions examples/cartrade/script-start-validator-ethereum.sh

This file was deleted.

7 changes: 0 additions & 7 deletions examples/cartrade/script-start-validator-fabric.sh

This file was deleted.

9 changes: 0 additions & 9 deletions examples/cartrade/script-stop-cartrade.sh

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions examples/cartrade/script-test-getFunctions/fabric/package.json

This file was deleted.

Loading