Skip to content

Commit 6458126

Browse files
author
Luis Sanchez
committed
[FAB-3263] remove ChaincodeBase.getChaincodeId()
No longer needed. Change-Id: I991cf3d16b629030cfd92482ea1ebcdd843ff76f Signed-off-by: Luis Sanchez <[email protected]>
1 parent b306d7b commit 6458126

File tree

11 files changed

+21
-69
lines changed

11 files changed

+21
-69
lines changed

core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeBase.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public abstract class ChaincodeBase implements Chaincode {
5858

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

61-
public abstract String getChaincodeID();
6261
public static final String DEFAULT_HOST = "127.0.0.1";
6362
public static final int DEFAULT_PORT = 7051;
6463

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

7170
private Handler handler;
72-
private String id = getChaincodeID();
71+
private String id;
7372

7473
private final static String CORE_CHAINCODE_ID_NAME = "CORE_CHAINCODE_ID_NAME";
7574
private final static String CORE_PEER_ADDRESS = "CORE_PEER_ADDRESS";
7675
private final static String CORE_PEER_TLS_ENABLED = "CORE_PEER_TLS_ENABLED";
7776
private final static String CORE_PEER_TLS_SERVERHOSTOVERRIDE = "CORE_PEER_TLS_SERVERHOSTOVERRIDE";
7877
private static final String CORE_PEER_TLS_ROOTCERT_FILE = "CORE_PEER_TLS_ROOTCERT_FILE";
7978

80-
// Start entry point for chaincodes bootstrap.
81-
public void start(String[] args) {
82-
processEnvironmentOptions();
83-
processCommandLineOptions(args);
84-
new Thread(() -> {
85-
logger.trace("chaincode started");
86-
final ManagedChannel connection = newPeerClientConnection();
87-
logger.trace("connection created");
88-
chatWithPeer(connection);
89-
logger.trace("chatWithPeer DONE");
90-
}).start();
91-
}
79+
/**
80+
* Start chaincode
81+
* @param args command line arguments
82+
*/
83+
public void start(String[] args) {
84+
processEnvironmentOptions();
85+
processCommandLineOptions(args);
86+
if(this.id == null) {
87+
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));
88+
}
89+
new Thread(() -> {
90+
logger.trace("chaincode started");
91+
final ManagedChannel connection = newPeerClientConnection();
92+
logger.trace("connection created");
93+
chatWithPeer(connection);
94+
logger.trace("chatWithPeer DONE");
95+
}).start();
96+
}
9297

9398
private void processCommandLineOptions(String[] args) {
9499
Options options = new Options();

examples/chaincode/java/Example/src/main/java/example/Example.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
package example;
1919

20-
import org.hyperledger.fabric.shim.ChaincodeBase;
21-
import org.hyperledger.fabric.shim.ChaincodeStub;
2220
import org.apache.commons.logging.Log;
2321
import org.apache.commons.logging.LogFactory;
22+
import org.hyperledger.fabric.shim.ChaincodeBase;
23+
import org.hyperledger.fabric.shim.ChaincodeStub;
2424

2525

2626
/**
@@ -101,11 +101,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {
101101
}
102102
}
103103

104-
@Override
105-
public String getChaincodeID() {
106-
return "hello";
107-
}
108-
109104
public static void main(String[] args) throws Exception {
110105
System.out.println("Hello world! starting "+args);
111106
log.info("starting");

examples/chaincode/java/LinkExample/src/main/java/example/LinkExample.java

-5
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,4 @@ public static void main(String[] args) throws Exception {
7676
new LinkExample().start(args);
7777
}
7878

79-
@Override
80-
public String getChaincodeID() {
81-
return "link";
82-
}
83-
8479
}

examples/chaincode/java/MapExample/src/main/java/example/MapExample.java

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {
4949
return stub.getState(args[0]);
5050
}
5151

52-
@Override
53-
public String getChaincodeID() {
54-
return "map";
55-
}
56-
5752
public static void main(String[] args) throws Exception {
5853
new MapExample().start(args);
5954
}

examples/chaincode/java/RangeExample/src/main/java/example/RangeExample.java

-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ public String query(ChaincodeStub stub, String function, String[] args) {
7171

7272
}
7373

74-
@java.lang.Override
75-
public String getChaincodeID() {
76-
return "RangeExample";
77-
}
78-
7974
public static void main(String[] args) throws Exception {
8075
log.info("starting");
8176
new RangeExample().start(args);

examples/chaincode/java/SimpleSample/src/main/java/example/SimpleSample.java

-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ public Response query(ChaincodeStub stub, String function, String[] args) {
142142

143143
}
144144

145-
@Override
146-
public String getChaincodeID() {
147-
return "SimpleSample";
148-
}
149-
150145
public static void main(String[] args) throws Exception {
151146
new SimpleSample().start(args);
152147
}

examples/chaincode/java/chaincode_example02/src/main/java/example/Example02.java

-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse;
2323
import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse;
2424

25-
import java.util.List;
26-
2725
import javax.json.Json;
2826

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

156154
}
157155

158-
@Override
159-
public String getChaincodeID() {
160-
return "Example02";
161-
}
162-
163156
public static void main(String[] args) throws Exception {
164157
new Example02().start(args);
165158
}

examples/chaincode/java/chaincode_example04/src/main/java/example/Example04.java

-5
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) {
150150
return response;
151151
}
152152

153-
@Override
154-
public String getChaincodeID() {
155-
return "Example04";
156-
}
157-
158153
public static void main(String[] args) throws Exception {
159154
new Example04().start(args);
160155
}

examples/chaincode/java/chaincode_example05/src/main/java/example/Example05.java

-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ private Response doInvoke(ChaincodeStub stub, String[] args) {
129129
return newSuccessResponse(String.valueOf(sum).getBytes(UTF_8));
130130
}
131131

132-
@Override
133-
public String getChaincodeID() {
134-
return "Example05";
135-
}
136-
137132
public static void main(String[] args) throws Exception {
138133
new Example05().start(args);
139134
}

examples/chaincode/java/chaincode_example06/src/main/java/example/Example06.java

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public Response invoke(ChaincodeStub stub) {
4242
return newBadRequestResponse(format("Invalid arguments specified"));
4343
}
4444
}
45-
46-
@Override
47-
public String getChaincodeID() {
48-
return "Example06";
49-
}
5045

5146
public static void main(String[] args) throws Exception {
5247
new Example06().start(args);

examples/chaincode/java/eventsender/src/main/java/example/EventSender.java

-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static java.lang.String.format;
2020
import static java.nio.charset.StandardCharsets.UTF_8;
2121
import static java.util.stream.Collectors.joining;
22-
import static java.util.stream.Collectors.toList;
2322
import static org.hyperledger.fabric.shim.ChaincodeHelper.newBadRequestResponse;
2423
import static org.hyperledger.fabric.shim.ChaincodeHelper.newInternalServerErrorResponse;
2524
import static org.hyperledger.fabric.shim.ChaincodeHelper.newSuccessResponse;
@@ -82,11 +81,6 @@ private Response doQuery(ChaincodeStub stub) {
8281
return newSuccessResponse(String.format("{\"NoEvents\":%d}", Integer.parseInt(stub.getStringState(EVENT_COUNT))));
8382
}
8483

85-
@Override
86-
public String getChaincodeID() {
87-
return "EventSender";
88-
}
89-
9084
public static void main(String[] args) throws Exception {
9185
new EventSender().start(args);
9286
}

0 commit comments

Comments
 (0)