-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganisation.sh
executable file
·725 lines (571 loc) · 19.4 KB
/
organisation.sh
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
#!/bin/bash
ORDERER_CLI="cli.divvy.com"
ORDERER_PEER="orderer.divvy.com:7050"
API_CONTAINER="api.divvy.com"
ORG=""
PEER_PORT=""
CA_PORT=""
CC_PORT=""
CHANNEL_OWNER=""
CHANNEL=""
MSP_NAME=""
CONFIG_DIR=""
VOLUME_DIR=""
CRYPTO_DIR=""
CLI_OUTPUT_DIR=""
ORG_CLI=""
ORG_PEER=""
CHANNEL_OWNER_CLI=""
. utils.sh
export PATH=/home/vagrant/network/bin:$PATH
# Print the usage message
function printHelp() {
echo "Usage: "
echo " organisation.sh <mode> --org <org name> [--pport <port>] [--caport <port>] [--ccport] [--channelowner <channel owner>]"
echo " <mode> - one of 'create', 'remove', or 'joinchannel'"
echo " - 'create' - bring up the network with docker-compose up"
echo " - 'remove' - clear the network with docker-compose down"
echo " - 'joinchannel' - joins an org peer to a channel"
echo " - 'showchannels' - lists all channels an org peer has joined"
echo " - 'nodestatus' - shows the status of an org peer node"
echo " - 'channelinfo' - show blockchain information of an org channel."
echo " --org <org name> - name of the org to use"
echo " --pport <port> - port the org peer listens on"
echo " --caport <port> - port the org CA listens on"
echo " --ccport <port> - port the org peer chaincode listens on"
echo " --channelowner <channel owner> - org who owns the channel being joined"
echo " organisation.sh --help (print this message)"
}
function checkPrereqs() {
for tool in cryptogen configtxgen; do
which $tool > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo "${tool} not found. Make sure the binaries have been added to your path."
exit 1
fi
done
}
function generateCryptoConfig() {
sed -e "s/\${ORG}/$1/g" /home/vagrant/network/templates/crypto-config.yaml
}
function generateNetworkConfig() {
sed -e "s/\${ORG}/$1/g" \
-e "s/\${MSP_NAME}/$2/g" \
-e "s/\${PEER_PORT}/$3/g" \
/home/vagrant/network/templates/configtx.yaml
}
function generateOrgDefinition() {
echo "Generating Org definition..."
configtxgen -configPath $1 -printOrg $2 > "$1/${ORG}.json"
if [ $? -ne 0 ]; then
exit 1
fi
echo
}
function oneLinePem {
echo "`awk 'NF {sub(/\\n/, ""); printf "%s\\\\\\\n",$0;}' $1`"
}
function generateConnectionProfile {
local PP=$(oneLinePem "crypto-config/peerOrganizations/$1.divvy.com/tlsca/tlsca.$1.divvy.com-cert.pem")
local CP=$(oneLinePem "crypto-config/peerOrganizations/$1.divvy.com/ca/ca.$1.divvy.com-cert.pem")
sed -e "s/\${ORG}/$1/" \
-e "s/\${MSP_NAME}/$2/" \
-e "s/\${PEER_PORT}/$3/" \
-e "s/\${CA_PORT}/$4/" \
-e "s#\${PEER_PEM}#$PP#" \
-e "s#\${CA_PEM}#$CP#" \
/home/vagrant/network/templates/connection-profile.json
}
function generateDockerCompose() {
local CURRENT_DIR=$PWD
cd "crypto-config/peerOrganizations/$1.divvy.com/ca/"
local PRIV_KEY=$(ls *_sk)
cd "$CURRENT_DIR"
sed -e "s/\${ORG}/$1/g" \
-e "s/\${MSP_NAME}/$2/g" \
-e "s/\${PEER_PORT}/$3/g" \
-e "s/\${CA_PORT}/$4/g" \
-e "s/\${CC_PORT}/$5/g" \
-e "s/\${PRIV_KEY}/$PRIV_KEY/g" \
/home/vagrant/network/templates/docker-compose-org.yaml
}
function cliMkdirp() {
echo
echo "Creating directory $2 on $1..."
echo
sudo docker exec $1 mkdir -p $2
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliRmrf() {
echo
echo "Removing directory $2 on $1..."
echo
sudo docker exec $1 rm -rf $2
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliFetchLatestChannelConfigBlock() {
echo
echo "Fetching latest config block for channel $2..."
echo
sudo docker exec $1 peer channel fetch config $3 --tls --cafile $4 -o $ORDERER_PEER -c $2
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliDecodeConfigBlock() {
echo
echo "Decoding config block..."
echo
local type="${4:-common.Block}"
local treePath="${5:-.data.data[0].payload.data.config}"
sudo docker exec -i $1 bash <<EOF
configtxlator proto_decode --input "$2" --type "$type" | jq "$treePath" > "$3"
EOF
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliEncodeConfigJson() {
echo
echo "Encoding config block..."
echo
local type="${4:-common.Config}"
sudo docker exec $1 configtxlator proto_encode \
--input $2 \
--output $3 \
--type $type
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliGenerateUpdateBlock() {
echo
echo "Generating config update block for channel $2..."
echo
sudo docker exec $1 configtxlator compute_update \
--channel_id $2 \
--original $3 \
--updated $4 \
--output $5
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliAddConfigUpdateHeader() {
echo
echo "Adding header to config update for channel $2..."
echo
sudo docker exec -i \
-e channel=$2 \
-e updatesFile=$3 \
-e outFile=$4 \
$1 bash -c 'updates=$(< $updatesFile); echo \''{\""payload\"":{\""header\"":{\""channel_header\"":{\""channel_id\"":\""$channel\"", \""type\"":2}},\""data\"":{\""config_update\"":$updates}}}\'' | jq . > $outFile'
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliSubmitChannelUpdate() {
echo
echo "Submitting config update for channel $3..."
echo
sudo docker exec $1 peer channel update -f $2 -c $3 -o $ORDERER_PEER --tls --cafile $4
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliFetchChannelGenesisBlock() {
echo
echo "Fetching genesis block for channel $2..."
echo
sudo docker exec $1 peer channel fetch 0 $3 -o $ORDERER_PEER -c $2 --tls --cafile $4
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliJoinPeerToChannel() {
echo
echo "Joining $ORG_PEER to channel $2..."
echo
sudo docker exec $1 peer channel join -b $3 --tls --cafile $4
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliPeerNodeStatus() {
sudo docker exec $1 peer node status
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliChannelInfo() {
sudo docker exec $1 peer channel getinfo -c $2
if [ $? -ne 0 ]; then
exit 1
fi
}
function listPeerChannels() {
echo
sudo docker exec $1 peer channel list
echo
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliInstallChaincode() {
echo
echo "Installing chaincode $2 v$3 on peer..."
echo
local path="${4:-chaincode}"
sudo docker exec $1 peer chaincode install \
-n $2 \
-v $3 \
-p $path \
-l node
if [ $? -ne 0 ]; then
exit 1
fi
}
function cliInstantiateChaincode() {
echo
echo "Instanciating chaincode $2 v$3 on channel $4..."
echo
sudo docker exec $1 peer chaincode instantiate \
-o $ORDERER_PEER \
-n $2 \
-v $3 \
-C $4 \
-c $5 \
-P $6 \
-l node \
--tls \
--cafile $7
if [ $? -ne 0 ]; then
exit 1
fi
# Wait for instantiation request to be committed.
sleep 10
}
function cliInvokeChaincode() {
echo
echo "Inkoving initial $2 ledger transaction on $3 channel..."
echo
sudo docker exec $1 peer chaincode invoke \
-o $ORDERER_PEER \
-n $2 \
-C $3 \
-c $4 \
--tls \
--cafile $5
if [ $? -ne 0 ]; then
exit 1
fi
}
function addOrgToConsortium() {
local ORG_DEF="./org-config/$1/$1.json"
local CONF_BLOCK="$CLI_OUTPUT_DIR/config-$1.pb"
local CONF_MOD_BLOCK="$CLI_OUTPUT_DIR/config-modified-$1.pb"
local CONF_DELTA_BLOCK="$CLI_OUTPUT_DIR/config-delta-$1.pb"
local CONF_JSON="$CLI_OUTPUT_DIR/config-$1.json"
local CONF_MOD_JSON="$CLI_OUTPUT_DIR/config-modified-$1.json"
local CONF_DELTA_JSON="$CLI_OUTPUT_DIR/config-delta-$1.json"
local PAYLOAD_BLOCK="$CLI_OUTPUT_DIR/payload-$1.pb"
local PAYLOAD_JSON="$CLI_OUTPUT_DIR/payload-$1.json"
local CA_PATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto-config/msp/tlscacerts/tlsca.divvy.com-cert.pem
cliMkdirp $ORDERER_CLI $CLI_OUTPUT_DIR
cliFetchLatestChannelConfigBlock $ORDERER_CLI $CHANNEL $CONF_BLOCK $CA_PATH
cliDecodeConfigBlock $ORDERER_CLI $CONF_BLOCK $CONF_JSON
# Add the Org definition to config.
sudo docker exec -i $ORDERER_CLI bash <<EOF
jq -s '.[0] * {"channel_group":{"groups":{"Consortiums":{"groups": {"Default": {"groups": {"$MSP_NAME":.[1]}, "mod_policy": "/Channel/Orderer/Admins", "policies": {}, "values": {"ChannelCreationPolicy": {"mod_policy": "/Channel/Orderer/Admins","value": {"type": 3,"value": {"rule": "ANY","sub_policy": "Admins"}},"version": "0"}},"version": "0"}}}}}}' $CONF_JSON $ORG_DEF > $CONF_MOD_JSON
EOF
if [ $? -ne 0 ]; then
exit 1
fi
# Convert the origional (extracted) config to a block, so we can diff it against the updates.
cliEncodeConfigJson $ORDERER_CLI $CONF_JSON $CONF_BLOCK
# Convert the updated config to a block, so we can diff it against the origional.
cliEncodeConfigJson $ORDERER_CLI $CONF_MOD_JSON $CONF_MOD_BLOCK
# Diff the changes to create an "update" block.
cliGenerateUpdateBlock $ORDERER_CLI $CHANNEL $CONF_BLOCK $CONF_MOD_BLOCK $CONF_DELTA_BLOCK
# Convert the update block to JSON so we can add a header.
cliDecodeConfigBlock $ORDERER_CLI $CONF_DELTA_BLOCK $CONF_DELTA_JSON common.ConfigUpdate '.'
# Add the header.
cliAddConfigUpdateHeader $ORDERER_CLI $CHANNEL $CONF_DELTA_JSON $PAYLOAD_JSON
# Convert the payload to a block.
cliEncodeConfigJson $ORDERER_CLI $PAYLOAD_JSON $PAYLOAD_BLOCK common.Envelope
# Make the update.
cliSubmitChannelUpdate $ORDERER_CLI $PAYLOAD_BLOCK $CHANNEL $CA_PATH
# Clean up.
cliRmrf $ORDERER_CLI $CLI_OUTPUT_DIR
}
function createOrgChannel() {
local orgChannelId="$2"
local ordererCaPath=/etc/hyperledger/fabric/orderer/msp/tlscacerts/tlsca.divvy.com-cert.pem
echo "Generating config transactions..."
# Generate the channel configuration transation.
configtxgen \
-configPath $1 \
-profile $orgChannelId \
-outputCreateChannelTx "$1/channel.tx" \
-channelID $orgChannelId
# Generate the anchor peer transaction.
configtxgen \
-configPath $1 \
-profile $orgChannelId \
-outputAnchorPeersUpdate "$1/$2-msp-anchor-$2.tx" \
-channelID $orgChannelId \
-asOrg "$2-msp"
echo
echo "Creating channel..."
sudo docker exec \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/users/Admin@$2.divvy.com/msp" \
$ORG_PEER peer channel create \
-o $ORDERER_PEER \
-c "$orgChannelId" \
-f ./org-config/channel.tx \
--tls \
--cafile $ordererCaPath
if [ $? -ne 0 ]; then
exit 1
fi
echo
echo "Adding peer to channel..."
sudo docker exec \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/users/Admin@$2.divvy.com/msp" \
$ORG_PEER peer channel join \
-b "$orgChannelId.block"
if [ $? -ne 0 ]; then
exit 1
fi
# Check the peer successfully joined the channel.
listPeerChannels $ORG_PEER
echo
echo "Adding anchor peer config to channel..."
sudo docker exec \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/msp/users/Admin@$2.divvy.com/msp" \
$ORG_PEER peer channel update \
-o $ORDERER_PEER \
-c "$orgChannelId" \
-f ./org-config/"$2-msp-anchor-$2.tx" \
--tls \
--cafile $ordererCaPath
if [ $? -ne 0 ]; then
exit 1
fi
}
checkPrereqs
MODE=$1
shift
if [ "$MODE" != "create" ] && [ "$MODE" != "remove" ] && [ "$MODE" != "joinchannel" ] && [ "$MODE" != "showchannels" ] && [ "$MODE" != "nodestatus" ] && [ "$MODE" != "channelinfo" ]; then
printHelp
exit 1
fi
POSITIONAL=()
while [[ $# -gt 0 ]]
do
opt="$1"
case "$opt" in
--help)
printHelp
exit 0
;;
--org)
ORG=$2
MSP_NAME="${ORG}-msp"
shift
shift
;;
--pport)
PEER_PORT=$2
shift
shift
;;
--caport)
CA_PORT=$2
shift
shift
;;
--ccport)
CC_PORT=$2
shift
shift
;;
--channelowner)
CHANNEL_OWNER=$2
CHANNEL_OWNER_CLI="cli.$2.divvy.com"
CHANNEL="$2"
shift
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ "$ORG" == "" ]; then
echo "No organisation name specified."
echo
printHelp
exit 1
fi
CONFIG_DIR="$PWD/org-config/$ORG"
VOLUME_DIR="$PWD/peer.$ORG.divvy.com"
CRYPTO_DIR="$PWD/crypto-config/peerOrganizations/$ORG.divvy.com"
CLI_OUTPUT_DIR="./org-artifacts/$ORG"
ORG_CLI="cli.$ORG.divvy.com"
ORG_PEER="peer.$ORG.divvy.com"
if [ "$MODE" == "create" ]; then
if [ "$PEER_PORT" == "" ]; then
echo "No peer port specified."
echo
printHelp
exit 1
fi
if [ "$CA_PORT" == "" ]; then
echo "No CA port specified."
echo
printHelp
exit 1
fi
if [ "$CC_PORT" == "" ]; then
echo "No chaincode port specified."
echo
printHelp
exit 1
fi
if [ -d $CONFIG_DIR ]; then
echo "There is already an organisation called ${ORG}."
exit 1
fi
# Don't clobber the client app namespace.
if [ "$ORG" == "app" ]; then
echo "There is already an organisation called ${ORG}."
exit 1
fi
CHANNEL='sys-channel'
mkdir -p $CONFIG_DIR
echo "Generating crypto config for ${ORG}..."
generateCryptoConfig $ORG > "$CONFIG_DIR/crypto-config.yaml"
echo
echo "Generating certificates for trust domain:"
generateCryptoMaterial "$CONFIG_DIR/crypto-config.yaml"
echo
echo "Generating network config..."
generateNetworkConfig $ORG $MSP_NAME $PEER_PORT > "$CONFIG_DIR/configtx.yaml"
echo
generateOrgDefinition $CONFIG_DIR $MSP_NAME
echo "Generating connection profile..."
generateConnectionProfile $ORG $MSP_NAME $PEER_PORT $CA_PORT > "$CONFIG_DIR/connection-profile.json"
echo
echo "Generating docker compose file..."
generateDockerCompose $ORG $MSP_NAME $PEER_PORT $CA_PORT $CC_PORT > "$CONFIG_DIR/docker-compose.yaml"
echo
echo "Starting Organisation containers..."
echo
sudo docker-compose -f "$CONFIG_DIR/docker-compose.yaml" up -d 2>&1
sleep 10
echo
sudo docker ps -a --filter name=".$ORG.divvy.com"
echo
echo "Generating wallet..."
sudo docker exec $API_CONTAINER node ./lib/security.js enrolladmin ${ORG}
sudo docker exec $API_CONTAINER node ./lib/security.js registeruser ${ORG} app
echo
echo "Adding $ORG to the default consortium..."
addOrgToConsortium $ORG $MSP_NAME
echo
createOrgChannel $CONFIG_DIR $ORG
echo
cliInstallChaincode $ORG_CLI share 1.0
cliInstantiateChaincode $ORG_CLI share 1.0 $ORG '{"Args":[]}' "AND('${MSP_NAME}.member')" "/opt/gopath/src/github.com/hyperledger/fabric/orderer/msp/tlscacerts/tlsca.divvy.com-cert.pem"
cliInvokeChaincode $ORG_CLI share $ORG "{\"Args\":[\"com.divvy.share:instantiate\",\"$ORG\"]}" "/opt/gopath/src/github.com/hyperledger/fabric/orderer/msp/tlscacerts/tlsca.divvy.com-cert.pem"
# Tell the application we're done.
# Run a task on the app container which adds a job (notifies the user) to the queue.
# The job will be executed by a cron job.
sudo docker exec -i web.app.divvy.com bash <<EOF
./vendor/bin/sake dev/tasks/OrganisationSetupCompleteTask "org=$ORG"
EOF
echo "Done"
elif [ "$MODE" == "remove" ]; then
# TODO: Remove from consortium
# TODO: Remove org from all channels
# TODO: Remove all other orgs from org channel
echo "Stopping $ORG containers..."
sudo docker-compose -f "$CONFIG_DIR/docker-compose.yaml" down --volumes
echo
echo "Removing files..."
for dir in "$CRYPTO_DIR" "$CONFIG_DIR" "$VOLUME_DIR" "/home/vagrant/api/wallet/${ORG}"; do
echo "Removing $dir"
rm -rf $dir
done
echo
echo "Done"
elif [ "$MODE" == "joinchannel" ]; then
if [ "$CHANNEL_OWNER" == "" ]; then
echo "No channel owner specified."
echo
printHelp
exit 1
fi
if [ ! -d "$CONFIG_DIR" ]; then
echo "Invalid org name. Did you spell the org name correctly?"
exit 1
fi
configBlock="$CLI_OUTPUT_DIR/config-$CHANNEL.pb"
configBlockUpdated="$CLI_OUTPUT_DIR/config-$CHANNEL-updated.pb"
configJson="$CLI_OUTPUT_DIR/config-$CHANNEL.json"
configJsonUpdated="$CLI_OUTPUT_DIR/config-$CHANNEL-updated.json"
payloadBlock="$CLI_OUTPUT_DIR/config-$CHANNEL-payload.pb"
payloadJson="$CLI_OUTPUT_DIR/config-$CHANNEL-payload.json"
orgDefinition="$CLI_OUTPUT_DIR/$ORG.json"
channelGenesisBlock="$CLI_OUTPUT_DIR/$CHANNEL-genesis.block"
caPath="/opt/gopath/src/github.com/hyperledger/fabric/orderer/msp/tlscacerts/tlsca.divvy.com-cert.pem"
cliMkdirp $CHANNEL_OWNER_CLI $CLI_OUTPUT_DIR
generateOrgDefinition $CONFIG_DIR $MSP_NAME
sudo docker cp "$CONFIG_DIR/$ORG.json" $CHANNEL_OWNER_CLI:"/opt/gopath/src/github.com/hyperledger/fabric/peer/$orgDefinition"
cliFetchLatestChannelConfigBlock $CHANNEL_OWNER_CLI $CHANNEL $configBlock $caPath
cliDecodeConfigBlock $CHANNEL_OWNER_CLI $configBlock $configJson
# Add Org to config.
sudo docker exec -i $CHANNEL_OWNER_CLI bash <<EOF
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"$MSP_NAME":.[1]}}}}}' $configJson $orgDefinition > $configJsonUpdated
EOF
if [ $? -ne 0 ]; then
exit 1
fi
# TODO: Update the chaincode endorsement policy so the new org can execute chaincode.
# Convert the origional (extracted) config to a block, so we can diff it against the updates.
cliEncodeConfigJson $CHANNEL_OWNER_CLI $configJson $configBlock
# Convert the updated config to a block, so we can diff it against the origional.
cliEncodeConfigJson $CHANNEL_OWNER_CLI $configJsonUpdated $configBlockUpdated
# Diff the changes to create an "update" block.
cliGenerateUpdateBlock $CHANNEL_OWNER_CLI $CHANNEL $configBlock $configBlockUpdated $payloadBlock
# Convert the update block to JSON so we can add a header.
cliDecodeConfigBlock $CHANNEL_OWNER_CLI $payloadBlock $payloadJson common.ConfigUpdate '.'
# Add the header.
cliAddConfigUpdateHeader $CHANNEL_OWNER_CLI $CHANNEL $payloadJson $payloadJson
# Convert the payload to a block.
cliEncodeConfigJson $CHANNEL_OWNER_CLI $payloadJson $payloadBlock common.Envelope
# Submit the block.
cliSubmitChannelUpdate $CHANNEL_OWNER_CLI $payloadBlock $CHANNEL $caPath
# Clean up.
cliRmrf $CHANNEL_OWNER_CLI $CLI_OUTPUT_DIR
cliMkdirp $ORG_CLI $CLI_OUTPUT_DIR
# Fetch the genesis block to start syncing the new org peer's ledger
cliFetchChannelGenesisBlock $ORG_CLI $CHANNEL $channelGenesisBlock $caPath
# Join peer to channel
cliJoinPeerToChannel $ORG_CLI $CHANNEL $channelGenesisBlock $caPath $caPath
listPeerChannels $ORG_CLI
echo "Done"
elif [ "$MODE" == "showchannels" ]; then
listPeerChannels $ORG_CLI
elif [ "$MODE" == "nodestatus" ]; then
cliPeerNodeStatus $ORG_CLI
elif [ "$MODE" == "channelinfo" ]; then
cliChannelInfo $ORG_CLI $ORG
fi