Skip to content

Commit

Permalink
[FAB-3263] remove ChaincodeBase.getChaincodeId()
Browse files Browse the repository at this point in the history
No longer needed.

Change-Id: I991cf3d16b629030cfd92482ea1ebcdd843ff76f
Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
  • Loading branch information
Luis Sanchez committed Apr 26, 2017
1 parent b306d7b commit 6458126
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public abstract class ChaincodeBase implements Chaincode {

private static Log logger = LogFactory.getLog(ChaincodeBase.class);

public abstract String getChaincodeID();
public static final String DEFAULT_HOST = "127.0.0.1";
public static final int DEFAULT_PORT = 7051;

Expand All @@ -69,26 +68,32 @@ public abstract class ChaincodeBase implements Chaincode {
private String rootCertFile = "/etc/hyperledger/fabric/peer.crt";

private Handler handler;
private String id = getChaincodeID();
private String id;

private final static String CORE_CHAINCODE_ID_NAME = "CORE_CHAINCODE_ID_NAME";
private final static String CORE_PEER_ADDRESS = "CORE_PEER_ADDRESS";
private final static String CORE_PEER_TLS_ENABLED = "CORE_PEER_TLS_ENABLED";
private final static String CORE_PEER_TLS_SERVERHOSTOVERRIDE = "CORE_PEER_TLS_SERVERHOSTOVERRIDE";
private static final String CORE_PEER_TLS_ROOTCERT_FILE = "CORE_PEER_TLS_ROOTCERT_FILE";

// Start entry point for chaincodes bootstrap.
public void start(String[] args) {
processEnvironmentOptions();
processCommandLineOptions(args);
new Thread(() -> {
logger.trace("chaincode started");
final ManagedChannel connection = newPeerClientConnection();
logger.trace("connection created");
chatWithPeer(connection);
logger.trace("chatWithPeer DONE");
}).start();
}
/**
* Start chaincode
* @param args command line arguments
*/
public void start(String[] args) {
processEnvironmentOptions();
processCommandLineOptions(args);
if(this.id == null) {
logger.error(String.format("The chaincode id must be specified using either the -i or --i command line options or the %s environment variable.", CORE_CHAINCODE_ID_NAME));
}
new Thread(() -> {
logger.trace("chaincode started");
final ManagedChannel connection = newPeerClientConnection();
logger.trace("connection created");
chatWithPeer(connection);
logger.trace("chatWithPeer DONE");
}).start();
}

private void processCommandLineOptions(String[] args) {
Options options = new Options();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package example;

import org.hyperledger.fabric.shim.ChaincodeBase;
import org.hyperledger.fabric.shim.ChaincodeStub;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyperledger.fabric.shim.ChaincodeBase;
import org.hyperledger.fabric.shim.ChaincodeStub;


/**
Expand Down Expand Up @@ -101,11 +101,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {
}
}

@Override
public String getChaincodeID() {
return "hello";
}

public static void main(String[] args) throws Exception {
System.out.println("Hello world! starting "+args);
log.info("starting");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,4 @@ public static void main(String[] args) throws Exception {
new LinkExample().start(args);
}

@Override
public String getChaincodeID() {
return "link";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {
return stub.getState(args[0]);
}

@Override
public String getChaincodeID() {
return "map";
}

public static void main(String[] args) throws Exception {
new MapExample().start(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {

}

@java.lang.Override
public String getChaincodeID() {
return "RangeExample";
}

public static void main(String[] args) throws Exception {
log.info("starting");
new RangeExample().start(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ public Response query(ChaincodeStub stub, String function, String[] args) {

}

@Override
public String getChaincodeID() {
return "SimpleSample";
}

public static void main(String[] args) throws Exception {
new SimpleSample().start(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse;
import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse;

import java.util.List;

import javax.json.Json;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -155,11 +153,6 @@ private Response query(ChaincodeStub stub, String[] args) {

}

@Override
public String getChaincodeID() {
return "Example02";
}

public static void main(String[] args) throws Exception {
new Example02().start(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) {
return response;
}

@Override
public String getChaincodeID() {
return "Example04";
}

public static void main(String[] args) throws Exception {
new Example04().start(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) {
return newSuccessResponse(String.valueOf(sum).getBytes(UTF_8));
}

@Override
public String getChaincodeID() {
return "Example05";
}

public static void main(String[] args) throws Exception {
new Example05().start(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public Response invoke(ChaincodeStub stub) {
return newBadRequestResponse(format("Invalid arguments specified"));
}
}

@Override
public String getChaincodeID() {
return "Example06";
}

public static void main(String[] args) throws Exception {
new Example06().start(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static org.hyperledger.fabric.shim.ChaincodeHelper.newBadRequestResponse;
import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse;
import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse;
Expand Down Expand Up @@ -82,11 +81,6 @@ private Response doQuery(ChaincodeStub stub) {
return newSuccessResponse(String.format("{\"NoEvents\":%d}", Integer.parseInt(stub.getStringState(EVENT_COUNT))));
}

@Override
public String getChaincodeID() {
return "EventSender";
}

public static void main(String[] args) throws Exception {
new EventSender().start(args);
}
Expand Down

0 comments on commit 6458126

Please sign in to comment.