Skip to content

Commit

Permalink
hold connection to node
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-ota committed Oct 14, 2020
1 parent 2e861b3 commit fd9ca62
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/de/nutrisafe/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.commons.io.IOUtils;
import org.hyperledger.fabric.gateway.*;

import org.hyperledger.fabric.sdk.BlockEvent;
import org.hyperledger.fabric.sdk.BlockInfo;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.util.FileCopyUtils;
Expand All @@ -21,12 +23,15 @@
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;

import static java.nio.charset.StandardCharsets.UTF_8;

public class Utils {

private Config config;
private Network network = null;
private Gateway gateway = null;

public Utils(Config config) {
this.config = config;
Expand Down Expand Up @@ -88,17 +93,17 @@ private Contract prepareTransaction() {
* Preparing a builder for our Gateway.
* .discovery(): Service discovery for all transaction submissions is enabled.
*/

FileInputStream fileInputStream = new FileInputStream(config.getNetworkConfigPath());
//ClassPathResource classPathResource = new ClassPathResource(config.getNetworkConfigPath());
Gateway.Builder builder = Gateway.createBuilder()
.identity(loadWallet(), config.getCompany())
.networkConfig(fileInputStream);
//.discovery(true);
final Gateway gateway = builder.connect();

final Network network = gateway.getNetwork(config.getChannelName());

if(network == null) {
FileInputStream fileInputStream = new FileInputStream(config.getNetworkConfigPath());
//ClassPathResource classPathResource = new ClassPathResource(config.getNetworkConfigPath());
Gateway.Builder builder = Gateway.createBuilder()
.identity(loadWallet(), config.getCompany())
.networkConfig(fileInputStream);
//.discovery(true);
gateway = builder.connect();

network = gateway.getNetwork(config.getChannelName());
}
contract = network.getContract(config.getChaincodeName());

} catch (IOException e) {
Expand All @@ -112,6 +117,7 @@ public String submitTransaction(final String function, String[] args, HashMap<St
String ret = "";
try {
Contract contract = prepareTransaction();

if(contract == null) throw new IOException();
final byte[] result;
if (pArgs.size() == 0){
Expand Down

0 comments on commit fd9ca62

Please sign in to comment.