中的內(nèi)容??梢詤⒖糷ttp://m.tkk7.com/fool/archive/2018/02/01/433032.html.
如果知道通過命令行工具進行智能合約的安裝測試就更好了。fabric中的channel可以理解為泳道。在這個泳道中可以布署
多個智能合約。當然也可以安裝多個channel. 順便多一嘴,在智能合約可以調(diào)用另一個channel中的智能合約中的查詢方法.
通過sdk動態(tài)安裝通道的步驟:
1,通過configtxgen命令生成交易通道初始文件.
configtxgen --profile TestSoft --outputCreateChannelTx testsoft.tx --channelID testsoft
2,下載testsoft.tx到本機.
3,sdk安裝通道代碼及解釋
@Override
public boolean installChannel(String channelName) throws IOException, InvalidArgumentException, TransactionException, ProposalException {
// TODO Auto-generated method stub
String configPath = this.config.getConfigPath();
//初始化 ChannelConfiguration 對象.參數(shù)是通道初始化文件路徑
ChannelConfiguration channelConfiguration = new ChannelConfiguration(new File(configPath + "/"+channelName + ".tx"));
//構(gòu)造orderder節(jié)點信息
String ordererName = orderers.get().get(0).getOrdererName();
Properties ordererProperties = loadOrderProperty(ordererName);
Orderer anOrderer = client.newOrderer(
ordererName,
orderers.get().get(0).getOrdererLocation(), ordererProperties);
//Create channel that has only one signer that is this orgs peer admin. If channel creation policy needed more signature they would need to be added too.
Channel channel = client.newChannel(channelName, anOrderer, channelConfiguration, client.getChannelConfigurationSignature(channelConfiguration, fabricOrg.getPeerAdmin()));
//構(gòu)造peer節(jié)點信息,并且將peer節(jié)點加入到通道中。peer節(jié)點加入通道后,才能通過該peer節(jié)點中訪問通道中的智能合約
for (com.ygsoft.fabric.bean.Peers.Peer p : config.getInstallPeers().get()) {
Properties peerProperties = this.loadPeerProperties(p.getPeerName());
Peer peer = client.newPeer(p.getPeerName(),p.getPeerLocation(),peerProperties);
channel.joinPeer(peer);
}
for (int i = 0; i < orderers.get().size(); i++) {
Properties ordererProperties2 = loadOrderProperty(ordererName);
channel.addOrderer(client.newOrderer(
orderers.get().get(i).getOrdererName(),
orderers.get().get(i)
.getOrdererLocation(), ordererProperties2));
}
log.debug("channel.isInitialized() = " + channel.isInitialized());
channel.initialize();
return true;
}
知道了手工命令行安裝合約的過程,上面的理解還是比較簡單的。安裝通道后就可以調(diào)用sdk安裝合約了。