Skip to content

Commit

Permalink
FAB-5368 No means to get channel config
Browse files Browse the repository at this point in the history
FAB-5368 No means to get channel config bytes for update.

PS 4: Fix up javadoc. Do a sanity check in End2endAndBackAgainIT
       for getChannelConfigurationBytes

Change-Id: Ia7dd6de821e507ac37db17454072d85b86cb9664
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Jul 24, 2017
1 parent 83b117c commit 946e871
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,13 @@ private Map<String, MSP> traverseConfigGroupsMSP(String name, ConfigGroup config
return msps;
}

/**
* Provide the Channel's latest raw Configuration Block.
*
* @return Channel configuration block.
* @throws TransactionException
*/

private Block getConfigurationBlock() throws TransactionException {

logger.debug(format("getConfigurationBlock for channel %s", name));
Expand Down Expand Up @@ -874,6 +881,37 @@ private Block getConfigurationBlock() throws TransactionException {

}

/**
* Channel Configuration bytes. Bytes that can be used with configtxlator tool to upgrade the channel.
* Convert to Json for editing with:
* {@code
*
* curl -v POST --data-binary @fooConfig http://host/protolator/decode/common.Config
*
* }
* See http://hyperledger-fabric.readthedocs.io/en/latest/configtxlator.html
*
* @return Channel configuration bytes.
* @throws TransactionException
*/

public byte[] getChannelConfigurationBytes() throws TransactionException {
try {
final Block configBlock = getConfigurationBlock();

Envelope envelopeRet = Envelope.parseFrom(configBlock.getData().getData(0));

Payload payload = Payload.parseFrom(envelopeRet.getPayload());

ConfigEnvelope configEnvelope = ConfigEnvelope.parseFrom(payload.getData());
return configEnvelope.getConfig().toByteArray();

} catch (Exception e) {
throw new TransactionException(e);
}

}

private Block getBlockByNumber(final long number) throws TransactionException {

logger.trace(format("getConfigurationBlock for channel %s", name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;

import org.hyperledger.fabric.protos.common.Configtx;
import org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo;
import org.hyperledger.fabric.sdk.BlockEvent;
import org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy;
Expand Down Expand Up @@ -55,6 +56,7 @@

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -515,6 +517,16 @@ private Channel reconstructChannel(String name, HFClient client, SampleOrg sampl

newChannel.initialize();

//Just see if we can get channelConfiguration. Not required for the rest of scenario but should work.
final byte[] channelConfigurationBytes = newChannel.getChannelConfigurationBytes();
Configtx.Config channelConfig = Configtx.Config.parseFrom(channelConfigurationBytes);
assertNotNull(channelConfig);
Configtx.ConfigGroup channelGroup = channelConfig.getChannelGroup();
assertNotNull(channelGroup);
Map<String, Configtx.ConfigGroup> groupsMap = channelGroup.getGroupsMap();
assertNotNull(groupsMap.get("Orderer"));
assertNotNull(groupsMap.get("Application"));

//Before return lets see if we have the chaincode on the peers that we expect from End2endIT
//And if they were instantiated too.

Expand Down

0 comments on commit 946e871

Please sign in to comment.