From 4e34f89fe89e68016a573d6f3f2fd0a5c76af565 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 15 Dec 2017 22:43:19 +0800 Subject: [PATCH] [CE-136] Integrate blockchain-explorer 1. Remove useless private key 2. Map explorer-container 8080 to host 7060 3. Enable TLS 4. Updated channel-artifacts to v1.0.5 Change-Id: I0780dffb6d8d3533963adc8f3cba40b7e445a158 Signed-off-by: Luke --- .../chaincode_example02.go | 193 ++++++++++++++++++ .../chaincode_example02_test.go | 112 ++++++++++ .../local/channel-artifacts/Org1MSPanchors.tx | Bin 262 -> 296 bytes .../local/channel-artifacts/Org2MSPanchors.tx | Bin 262 -> 296 bytes .../local/channel-artifacts/channel.tx | Bin 381 -> 406 bytes .../channel-artifacts/orderer.genesis.block | Bin 9450 -> 9467 bytes ...d7155a4cd3879aca089823197e22edbb29fd2f0_sk | 5 - ...a9adb648ffa31f2defbe1add1247e40a1f0ed9a_sk | 5 - ...df25d278a23024dea2b36dd7e6667c75bdc54ac_sk | 5 - ...ff49c1b87a44b497373d2a3e657c07dc5aba537_sk | 5 - ...efb426f_sk => ca.org1.example.com-key.pem} | 0 ...9a58761e488081e6258fd185e122ccd3dd5b6f3_sk | 5 - ...6394361167de27a998cb921ae57fabab684ed92_sk | 5 - ...622adacf5479e804a4517e8183d54ba1a2e338c_sk | 5 - ...69df903f410233455a027d9e1cc274072020da3_sk | 5 - ...4536e8a59cd298f6547c810fb8cd32ee42daf0e_sk | 5 - ...2a5a45345c9c00491ffdb99754762b0e60a116c_sk | 5 - ...3c00cf832e37d0c605e03f9cf9eb6421ba06167_sk | 5 - ...afcd49d38efee22a6b3cd72cc36636ce806fe0f_sk | 5 - ...872751c8ef661044dc27a2aa121632ba0490ce4_sk | 5 - ...deea82213f927b4789fb23285ecc2a0dcf63306_sk | 5 - ...706285ce89df19e65f534ca20c27954b890a2e7_sk | 5 - ...e0f75bd_sk => ca.org2.example.com-key.pem} | 0 ...bf194df777af9310eba3be3759d5f79662439cc_sk | 5 - ...5cf172d501e6c2e79198b00905e761a67c7adab_sk | 5 - ...7f45beff0143cc54d06ae235424998d114ea1f8_sk | 5 - ...a55944c73fb6e853b601bc96288c755bd55ffef_sk | 5 - ...c1cb07c4b49a9423e1d52f5557d93951d5ada34_sk | 5 - .../local/explorer-artifacts/config.json | 73 +++++++ .../explorer-artifacts/fabricexplorer.sql | 115 +++++++++++ .../fabric-1.0/local/fabric-solo-4.yaml | 91 +++++++-- src/common/__init__.py | 2 +- src/common/utils.py | 4 + src/modules/cluster.py | 16 +- 34 files changed, 580 insertions(+), 126 deletions(-) create mode 100644 src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02.go create mode 100644 src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02_test.go delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/1c86c76138d7a9a4f8d6a1294d7155a4cd3879aca089823197e22edbb29fd2f0_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/1ec03575460ffdccc72b24760a9adb648ffa31f2defbe1add1247e40a1f0ed9a_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/68f1b96d880a2af547b56a66fdf25d278a23024dea2b36dd7e6667c75bdc54ac_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/a4e04ea76079fb2fe66772cd4ff49c1b87a44b497373d2a3e657c07dc5aba537_sk rename src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/{f2f5a08d5969b4a21f99b5667a426564a3e640a268d2f6bfe77a0e066efb426f_sk => ca.org1.example.com-key.pem} (100%) mode change 100755 => 100644 delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/ca/ca9761a3c400ae5a177f2ad779a58761e488081e6258fd185e122ccd3dd5b6f3_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/075a7ab3249cc1eb2600e7fd86394361167de27a998cb921ae57fabab684ed92_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/2ed8c268496d280f2d78405a0622adacf5479e804a4517e8183d54ba1a2e338c_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/3491bd151d319a877d3af82d569df903f410233455a027d9e1cc274072020da3_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/5129797a6cc9a70b053cd58084536e8a59cd298f6547c810fb8cd32ee42daf0e_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/ee91a7d537643618442fb6d5a2a5a45345c9c00491ffdb99754762b0e60a116c_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/28471379ce9a39c17bf7845683c00cf832e37d0c605e03f9cf9eb6421ba06167_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/306a41dec85c62d50544dae8cafcd49d38efee22a6b3cd72cc36636ce806fe0f_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/81ead898dad315b2ee4b8e3ac872751c8ef661044dc27a2aa121632ba0490ce4_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/936212003ec5235a561d7e061deea82213f927b4789fb23285ecc2a0dcf63306_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/965b9c231a24b99f17f0c565a706285ce89df19e65f534ca20c27954b890a2e7_sk rename src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/ca/{4a56bcf64913e49a5d6a05de9a71f3fa1c39ff1c4371fbb3d923cd8e3e0f75bd_sk => ca.org2.example.com-key.pem} (100%) mode change 100755 => 100644 delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/16f87d326e82d3dd544974427bf194df777af9310eba3be3759d5f79662439cc_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/4a8bd1cf7be5f9a28c3f205245cf172d501e6c2e79198b00905e761a67c7adab_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/5d487d06bfadcf73bb485e2017f45beff0143cc54d06ae235424998d114ea1f8_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/86e85d41bdb3aab49e29ad4c7a55944c73fb6e853b601bc96288c755bd55ffef_sk delete mode 100755 src/agent/docker/_compose_files/fabric-1.0/local/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/faf0ad85d33f6b9459c1b180bc1cb07c4b49a9423e1d52f5557d93951d5ada34_sk create mode 100644 src/agent/docker/_compose_files/fabric-1.0/local/explorer-artifacts/config.json create mode 100644 src/agent/docker/_compose_files/fabric-1.0/local/explorer-artifacts/fabricexplorer.sql diff --git a/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02.go b/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02.go new file mode 100644 index 000000000..eb6f430b7 --- /dev/null +++ b/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02.go @@ -0,0 +1,193 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +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 + + http://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. +*/ + +package main + +import ( + "fmt" + "strconv" + + "github.com/hyperledger/fabric/core/chaincode/shim" + pb "github.com/hyperledger/fabric/protos/peer" +) + +// SimpleChaincode example simple Chaincode implementation +type SimpleChaincode struct { +} + +func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { + fmt.Println("ex02 Init") + _, args := stub.GetFunctionAndParameters() + var A, B string // Entities + var Aval, Bval int // Asset holdings + var err error + + if len(args) != 4 { + return shim.Error("Incorrect number of arguments. Expecting 4") + } + + // Initialize the chaincode + A = args[0] + Aval, err = strconv.Atoi(args[1]) + if err != nil { + return shim.Error("Expecting integer value for asset holding") + } + B = args[2] + Bval, err = strconv.Atoi(args[3]) + if err != nil { + return shim.Error("Expecting integer value for asset holding") + } + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) + + // Write the state to the ledger + err = stub.PutState(A, []byte(strconv.Itoa(Aval))) + if err != nil { + return shim.Error(err.Error()) + } + + err = stub.PutState(B, []byte(strconv.Itoa(Bval))) + if err != nil { + return shim.Error(err.Error()) + } + + return shim.Success(nil) +} + +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { + fmt.Println("ex02 Invoke") + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + // Make payment of X units from A to B + return t.invoke(stub, args) + } else if function == "delete" { + // Deletes an entity from its state + return t.delete(stub, args) + } else if function == "query" { + // the old "Query" is now implemtned in invoke + return t.query(stub, args) + } + + return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"") +} + +// Transaction makes payment of X units from A to B +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response { + var A, B string // Entities + var Aval, Bval int // Asset holdings + var X int // Transaction value + var err error + + if len(args) != 3 { + return shim.Error("Incorrect number of arguments. Expecting 3") + } + + A = args[0] + B = args[1] + + // Get the state from the ledger + // TODO: will be nice to have a GetAllState call to ledger + Avalbytes, err := stub.GetState(A) + if err != nil { + return shim.Error("Failed to get state") + } + if Avalbytes == nil { + return shim.Error("Entity not found") + } + Aval, _ = strconv.Atoi(string(Avalbytes)) + + Bvalbytes, err := stub.GetState(B) + if err != nil { + return shim.Error("Failed to get state") + } + if Bvalbytes == nil { + return shim.Error("Entity not found") + } + Bval, _ = strconv.Atoi(string(Bvalbytes)) + + // Perform the execution + X, err = strconv.Atoi(args[2]) + if err != nil { + return shim.Error("Invalid transaction amount, expecting a integer value") + } + Aval = Aval - X + Bval = Bval + X + fmt.Printf("Aval = %d, Bval = %d\n", Aval, Bval) + + // Write the state back to the ledger + err = stub.PutState(A, []byte(strconv.Itoa(Aval))) + if err != nil { + return shim.Error(err.Error()) + } + + err = stub.PutState(B, []byte(strconv.Itoa(Bval))) + if err != nil { + return shim.Error(err.Error()) + } + + return shim.Success(nil) +} + +// Deletes an entity from state +func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string) pb.Response { + if len(args) != 1 { + return shim.Error("Incorrect number of arguments. Expecting 1") + } + + A := args[0] + + // Delete the key from the state in ledger + err := stub.DelState(A) + if err != nil { + return shim.Error("Failed to delete state") + } + + return shim.Success(nil) +} + +// query callback representing the query of a chaincode +func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) pb.Response { + var A string // Entities + var err error + + if len(args) != 1 { + return shim.Error("Incorrect number of arguments. Expecting name of the person to query") + } + + A = args[0] + + // Get the state from the ledger + Avalbytes, err := stub.GetState(A) + if err != nil { + jsonResp := "{\"Error\":\"Failed to get state for " + A + "\"}" + return shim.Error(jsonResp) + } + + if Avalbytes == nil { + jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}" + return shim.Error(jsonResp) + } + + jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" + fmt.Printf("Query Response:%s\n", jsonResp) + return shim.Success(Avalbytes) +} + +func main() { + err := shim.Start(new(SimpleChaincode)) + if err != nil { + fmt.Printf("Error starting Simple chaincode: %s", err) + } +} diff --git a/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02_test.go b/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02_test.go new file mode 100644 index 000000000..c6c8ed7f3 --- /dev/null +++ b/src/agent/docker/_compose_files/fabric-1.0/local/chaincode/go/chaincode_example02/chaincode_example02_test.go @@ -0,0 +1,112 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +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 + + http://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. +*/ +package main + +import ( + "fmt" + "testing" + + "github.com/hyperledger/fabric/core/chaincode/shim" +) + +func checkInit(t *testing.T, stub *shim.MockStub, args [][]byte) { + res := stub.MockInit("1", args) + if res.Status != shim.OK { + fmt.Println("Init failed", string(res.Message)) + t.FailNow() + } +} + +func checkState(t *testing.T, stub *shim.MockStub, name string, value string) { + bytes := stub.State[name] + if bytes == nil { + fmt.Println("State", name, "failed to get value") + t.FailNow() + } + if string(bytes) != value { + fmt.Println("State value", name, "was not", value, "as expected") + t.FailNow() + } +} + +func checkQuery(t *testing.T, stub *shim.MockStub, name string, value string) { + res := stub.MockInvoke("1", [][]byte{[]byte("query"), []byte(name)}) + if res.Status != shim.OK { + fmt.Println("Query", name, "failed", string(res.Message)) + t.FailNow() + } + if res.Payload == nil { + fmt.Println("Query", name, "failed to get value") + t.FailNow() + } + if string(res.Payload) != value { + fmt.Println("Query value", name, "was not", value, "as expected") + t.FailNow() + } +} + +func checkInvoke(t *testing.T, stub *shim.MockStub, args [][]byte) { + res := stub.MockInvoke("1", args) + if res.Status != shim.OK { + fmt.Println("Invoke", args, "failed", string(res.Message)) + t.FailNow() + } +} + +func TestExample02_Init(t *testing.T) { + scc := new(SimpleChaincode) + stub := shim.NewMockStub("ex02", scc) + + // Init A=123 B=234 + checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("123"), []byte("B"), []byte("234")}) + + checkState(t, stub, "A", "123") + checkState(t, stub, "B", "234") +} + +func TestExample02_Query(t *testing.T) { + scc := new(SimpleChaincode) + stub := shim.NewMockStub("ex02", scc) + + // Init A=345 B=456 + checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("345"), []byte("B"), []byte("456")}) + + // Query A + checkQuery(t, stub, "A", "345") + + // Query B + checkQuery(t, stub, "B", "456") +} + +func TestExample02_Invoke(t *testing.T) { + scc := new(SimpleChaincode) + stub := shim.NewMockStub("ex02", scc) + + // Init A=567 B=678 + checkInit(t, stub, [][]byte{[]byte("init"), []byte("A"), []byte("567"), []byte("B"), []byte("678")}) + + // Invoke A->B for 123 + checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("123")}) + checkQuery(t, stub, "A", "444") + checkQuery(t, stub, "B", "801") + + // Invoke B->A for 234 + checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte("B"), []byte("A"), []byte("234")}) + checkQuery(t, stub, "A", "678") + checkQuery(t, stub, "B", "567") + checkQuery(t, stub, "A", "678") + checkQuery(t, stub, "B", "567") +} diff --git a/src/agent/docker/_compose_files/fabric-1.0/local/channel-artifacts/Org1MSPanchors.tx b/src/agent/docker/_compose_files/fabric-1.0/local/channel-artifacts/Org1MSPanchors.tx index 981999f9fac3c6a2285d7f20a7ac898d93f80de7..651795d0d59a8e2af9493e58e081f7a627391e00 100644 GIT binary patch literal 296 zcmd;D%ETqgCCtI3#Gh1JoSBzeT%4Sdn3tEDBh<~r)xpGtAsj9g%Ej$iP>_?EoLG{X zpC{zT!6;=1sS9+B+DhuB~}3B80h5# d9ix|8k(gVMld6}TpDWO9E(NuRG*`h~2LL%iPHF%E literal 262 zcmd;TX5td%66Ro1;!i3q&df_KE>6x!%*#v75qinU^^B1VL)c%)my6r6pdcqRIk6-& zKTpVxgHgzei`~B{-Ox8UKuBMTor@X7U{K=bVh>79Oi3*&hH%1*GD{#FE-p65l-$fb zpoCN-qfkAni3LCta}XvbaxhBi0afHBXXF!M*!_#rjeLUxgbFzrrObdz f@{%+1ivm(pi;9KRC+<*ShZ-^Qy1oF+I2a886bCbr literal 262 zcmd;TX5td%66Ro1;!i3q&df_KE>6x!%*#v75qinU^^B1VL)c%)my6r6pdcqRIk6-& zKTpVxgHgzei`~B{-N-jMKuBMTor@X7U{K=bVh>79Oi3*&hH%1*GD{#FE-p65l-$fb zpoCN-qfkAni3LCta}XvbaxhBi0afHBXXFut+YcexeJXb6SlN1|A!=m#SCklkJtY_j{Gci*~*vL0HK!`zzn~UAQDBTdu znHlYJOJXb6SlN1}rx?`J9O%w=ana0F5d19sxpP_GXfDnTaHy68qQM%E@ z#ai|27=_vyxwst*3UV@&6H7Al^Moom7@;aqm4o#vNpZ0`rsQVk6$=Rn@o_KQn0ZRAIKIOn8oeaGUXeZ-hccq(yYveeY63R&m z$4LsrNeX!iTL=LV0U8DfUQq zWjQi3GBsf_V=-noWMgJHH)dfqVq`ctG+{L|V_{=tH8C_qHfA|xWjA7FH85m2H4+*U z7<;ld=dF=RwzsLDTJjf2#iec}qh5lNcoN1)3d2Yez(^8}E(!}nZ*FsMa&&2RZF3U+ zv)v566_ex_B?K}}Q&5wUB5ji}BV-jV3I;)BZE0?E5+f1_2mulV5&{wclVKw=v9U`E ilV%Gwlluy40V|3L+XH^4hxQ%f&&(86!(NihS{Vh+4=!S{Q(Oz0%G@6?64G61hnV zwn+-JNeX!iTL=LV0U8DfuEw*<1tJS{Wpi|6Xklq?X=ExuH!xvjWHwW3IWajjW)d0_ z7|)<&zP>7iYmbSf{DRsqWh %{level:.4s}%{color:reset} %{message} + - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # default: 127.0.0.1 + - ORDERER_GENERAL_GENESISMETHOD=file # default: provisional + - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block + - ORDERER_GENERAL_LOCALMSPID=OrdererMSP # default: DEFAULT + - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp + - ORDERER_GENERAL_LEDGERTYPE=file + #- ORDERER_GENERAL_LEDGERTYPE=json # default: file + - ORDERER_GENERAL_BATCHTIMEOUT=1s + - ORDERER_GENERAL_MAXMESSAGECOUNT=10 + - ORDERER_GENERAL_MAXWINDOWSIZE=1000 + - ORDERER_GENERAL_LISTENPORT=7050 + #- ORDERER_RAMLEDGER_HISTORY_SIZE=100 #only useful when use ram ledger + # enabled TLS + - ORDERER_GENERAL_TLS_ENABLED=true # default: false + - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] expose: - "7050" volumes: # docker.sock is mapped as the default CORE_VM_ENDPOINT @@ -54,7 +59,7 @@ services: driver: json-file options: max-size: 100m - command: peer node start + command: orderer start peer0.org1.example.com: image: "hyperledger/fabric-peer:${HLF_VERSION-1.0.0}" @@ -74,7 +79,7 @@ services: - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # this node is the group leader, default to false - CORE_PEER_PROFILE_ENABLED=false - - CORE_PEER_TLS_ENABLED=false + - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt @@ -119,7 +124,7 @@ services: - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # this node is the group leader, default to false - CORE_PEER_PROFILE_ENABLED=false - - CORE_PEER_TLS_ENABLED=false + - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt @@ -165,7 +170,7 @@ services: - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # this node is the group leader, default to false - CORE_PEER_PROFILE_ENABLED=false - - CORE_PEER_TLS_ENABLED=false + - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt @@ -211,7 +216,7 @@ services: - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false # this node is the group leader, default to false - CORE_PEER_PROFILE_ENABLED=false - - CORE_PEER_TLS_ENABLED=false + - CORE_PEER_TLS_ENABLED=true - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt @@ -249,13 +254,13 @@ services: - CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # default to operate on peer0.org1 - CORE_PEER_LOCALMSPID=Org1MSP - - CORE_PEER_TLS_ENABLED=false # to enable TLS, change to true + - CORE_PEER_TLS_ENABLED=true # to disable TLS, change to false - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp volumes: - #- ${COMPOSE_PROJECT_PATH}/e2e_cli/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples + - ${COMPOSE_PROJECT_PATH}/chaincode:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode - ${COMPOSE_PROJECT_PATH}/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ${COMPOSE_PROJECT_PATH}/scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ - ${COMPOSE_PROJECT_PATH}/channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts @@ -274,6 +279,48 @@ services: working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer command: bash -c 'sleep 2; bash ./scripts/initialize.sh; while true; do sleep 20170504; done' + + explorer: + image: yeasy/blockchain-explorer:latest + container_name: ${COMPOSE_PROJECT_NAME}_explorer + hostname: explorer + volumes: + - ${COMPOSE_PROJECT_PATH}/explorer-artifacts/config.json:/blockchain-explorer/config.json + - ${COMPOSE_PROJECT_PATH}/crypto-config:/blockchain-explorer/first-network/crypto-config + ports: + - "${DASHBOARD_PORT}:8080" + depends_on: + - mysql + - orderer.example.com + - peer0.org1.example.com + - peer1.org1.example.com + - peer0.org2.example.com + - peer1.org2.example.com + links: + - orderer.example.com + - peer0.org1.example.com + - peer1.org1.example.com + - peer0.org2.example.com + - peer1.org2.example.com + command: bash -c 'sleep 10; node main.js' + + mysql: # mysql service + image: mysql:5.7 + container_name: ${COMPOSE_PROJECT_NAME}_mysql + hostname: mysql + restart: always + environment: + - MYSQL_ROOT_PASSWORD=root + - MYSQL_DATABASE=fabricexplorer + - STARTUP_SQL=/fabricexplorer.sql + volumes: + - ${COMPOSE_PROJECT_PATH}/explorer-artifacts/fabricexplorer.sql:/docker-entrypoint-initdb.d/fabricexplorer.sql + expose: + - "3306" + command: mysqld + + + networks: default: external: diff --git a/src/common/__init__.py b/src/common/__init__.py index 5c5c080e1..f0fd37bc4 100644 --- a/src/common/__init__.py +++ b/src/common/__init__.py @@ -17,7 +17,7 @@ WORKER_TYPE_VSPHERE, \ CLUSTER_PORT_START, CLUSTER_PORT_STEP, \ NETWORK_SIZE_FABRIC_PRE_V1, NETWORK_SIZE_FABRIC_V1, \ - CLUSTER_NETWORK, \ + CLUSTER_NETWORK, EXPLORER_PORT,\ CLUSTER_LOG_TYPES, CLUSTER_LOG_LEVEL, \ SYS_CREATOR, SYS_DELETER, SYS_RESETTING, SYS_USER, \ request_debug, request_get, request_json_body, VIRTUAL_MACHINE, \ diff --git a/src/common/utils.py b/src/common/utils.py index d3f50cec0..9b5f0c412 100644 --- a/src/common/utils.py +++ b/src/common/utils.py @@ -51,6 +51,10 @@ 'tlscaa': 7059, } +EXPLORER_PORT = { + 'dashboard': 7060 +} + SERVICE_PORTS = dict(list(PEER_SERVICE_PORTS.items()) + list(CA_SERVICE_PORTS.items())) diff --git a/src/modules/cluster.py b/src/modules/cluster.py index cb736dae7..d9f565003 100644 --- a/src/modules/cluster.py +++ b/src/modules/cluster.py @@ -26,7 +26,7 @@ WORKER_TYPE_VSPHERE, SYS_CREATOR, SYS_DELETER, SYS_USER, \ SYS_RESETTING, VMIP, \ NETWORK_SIZE_FABRIC_PRE_V1, \ - PEER_SERVICE_PORTS, CA_SERVICE_PORTS + PEER_SERVICE_PORTS, CA_SERVICE_PORTS, EXPLORER_PORT from common import FabricPreNetworkConfig, FabricV1NetworkConfig from common.fabric_network import FabricV1Network @@ -137,14 +137,19 @@ def create(self, name, host_id, config, start_port=0, return None start_port = ports[0] - peer_mapped_ports, ca_mapped_ports, mapped_ports = {}, {}, {} + peer_mapped_ports, ca_mapped_ports, explorer_mapped_port, \ + mapped_ports = {}, {}, {}, {} for k, v in PEER_SERVICE_PORTS.items(): peer_mapped_ports[k] = v - PEER_SERVICE_PORTS['rest'] + start_port for k, v in CA_SERVICE_PORTS.items(): ca_mapped_ports[k] = v - PEER_SERVICE_PORTS['rest'] + start_port + for k, v in EXPLORER_PORT.items(): + explorer_mapped_port[k] = \ + v - PEER_SERVICE_PORTS['rest'] + start_port mapped_ports.update(peer_mapped_ports) mapped_ports.update(ca_mapped_ports) + mapped_ports.update(explorer_mapped_port) logger.debug("mapped_ports={}".format(mapped_ports)) network_type = config['network_type'] @@ -204,16 +209,18 @@ def create(self, name, host_id, config, start_port=0, self.delete(id=cid, record=False, forced=True) return None - access_peer, access_ca = '', '' + access_peer, access_ca, access_explorer = '', '', '' if network_type == NETWORK_TYPE_FABRIC_V1: # fabric v1.0 access_peer = 'peer0.org1.example.com' access_ca = 'ca.example.com' + access_explorer = 'explorer' elif network_type == NETWORK_TYPE_FABRIC_PRE_V1: # fabric v0.6 access_peer = 'vp0' access_ca = 'membersrvc' peer_host_ip = self._get_service_ip(cid, access_peer) ca_host_ip = self._get_service_ip(cid, access_ca) + explorer_host_ip = self._get_service_ip(cid, access_explorer) # no api_url, then clean and return if not peer_host_ip: # not valid api_url logger.error("Error to find peer host url, cleanup") @@ -227,6 +234,9 @@ def create(self, name, host_id, config, start_port=0, for k, v in ca_mapped_ports.items(): service_urls[k] = "{}:{}".format(ca_host_ip, v) + for k, v in explorer_mapped_port.items(): + service_urls[k] = "{}:{}".format(explorer_host_ip, v) + # update api_url, container, and user_id field self.db_update_one( {"id": cid},