matiru

Blockchain-Based Supply Chain Transparency for Agricultural Produce

fabric/network/scripts/configUpdate.sh (1844B)


 1#!/usr/bin/env bash
 2
 3. scripts/envVar.sh
 4
 5# Writes the current channel config for a given channel to a JSON file
 6fetchChannelConfig() {
 7  ORG=$1
 8  CHANNEL=$2
 9  OUTPUT=$3
10
11  setGlobals $ORG
12
13  infoln "Fetching the most recent configuration block for the channel"
14  set -x
15  peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile "$ORDERER_CA"
16  { set +x; } 2>/dev/null
17
18  infoln "Decoding config block to JSON and isolating config to ${OUTPUT}"
19  set -x
20  configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
21  { set +x; } 2>/dev/null
22}
23
24# Takes an original and modified config, and produces the config update tx which transitions between the two
25createConfigUpdate() {
26  CHANNEL=$1
27  ORIGINAL=$2
28  MODIFIED=$3
29  OUTPUT=$4
30
31  set -x
32  configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
33  configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
34  configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
35  configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
36  echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
37  configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
38  { set +x; } 2>/dev/null
39}
40
41# Set the peerOrg admin of an org and sign the config update
42signConfigtxAsPeerOrg() {
43  ORG=$1
44  CONFIGTXFILE=$2
45  setGlobals $ORG
46  set -x
47  peer channel signconfigtx -f "${CONFIGTXFILE}"
48  { set +x; } 2>/dev/null
49}