README.md 6.67 KB
Newer Older
Anastasios Kalogeropoulos's avatar
Anastasios Kalogeropoulos committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Deploy chaincode on the Test Network

Before you proceed, make sure that you have installed the [prerequisites](https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html#).

Also, make sure that you have [Installed Fabric and Fabric samples](https://hyperledger-fabric.readthedocs.io/en/latest/install.html).

Download the `evidentia-chaincode` project and **copy** it under the `fabric-samples` directory. The chaincode for Evidentia is implemented in [Go](https://golang.org/), so make sure that you have configured your machine properly.


## Package chaincode with dependencies

To install the chaincode dependencies, run the following commands inside the `evidentia` directory:

*NOTE: The chaincode dependencies are already installed. Run the following two steps in case you want to re-install them.*

1. `go mod init evidentia`
2. `GO111MODULE=on go mod vendor`

The first command will create a file named `go.mod` which should look like below:

```
module evidentia

go 1.15

require github.com/hyperledger/fabric-contract-api-go v1.1.1
```

The following steps provide a summary of how to start the `test-network`, included in the `fabric-samples` directory and deploy the *evidentia* chaincode on the channel. More details can be found [here](https://hyperledger-fabric.readthedocs.io/en/latest/deploy_chaincode.html#package-the-smart-contract).

Navigate to the `test-network` directory.

Start the network using Certificate Authorities:

```
./network.sh up -ca
```

Create a channel with default name `mychannel`: 

```
./network.sh createChannel
```

Add binaries to CLI Path:

```bash
export PATH=${PWD}/../bin:$PATH
```

Configure `FABRIC_CFG_PATH`:

```bash
export FABRIC_CFG_PATH=$PWD/../config/ 
```

Create the chaincode package:

```bash
peer lifecycle chaincode package evidentia.tar.gz --path ../evidentia/ --lang golang --label evidentia_1.0
```



Install the chaincode package as **Org1**:

```bash
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051

peer lifecycle chaincode install evidentia.tar.gz
```

Install the chaincode package as **Org2**:

```bash
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051

peer lifecycle chaincode install evidentia.tar.gz
```



Approve chaincode definition for **Org2**:

```bash
peer lifecycle chaincode queryinstalled 

## DO NOT COPY - replace with package id from the previous command
export CC_PACKAGE_ID=evidentia_1.0:3e0024708a8a678f654252ee6149e860067bb8f434df9899b34778663f70bff0

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name evidentia --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
```

Approve chaincode definition for **Org1**:

```bash
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051

peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name evidentia --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
```



Commit chaincode on channel:

```bash
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name evidentia --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --output json

peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name evidentia --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"

peer lifecycle chaincode querycommitted --channelID mychannel --name evidentia --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
	
```



Invoke chaincode and test that is working:

```bash
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n evidentia --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"AddEvidentiaQuery","Args":["test", "testService", "[testParam1, testParam2, testParam3]"]}'
```



Read the previous entry and verify that you receive the correct data:

```bash
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n evidentia --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"ReadEvidentiaQuery","Args":["test_testService"]}'
```