args){
return this;
}
- public PeerBuilder argsTx(String argsArray[]){
+ public PeerBuilder argsTx(String[] argsArray){
this.args = Arrays.asList(argsArray);
return this;
}
diff --git a/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh b/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh
index 6df1a20d4..f2cb4d8f1 100755
--- a/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh
+++ b/fabric-chaincode-integration-test/src/test/resources/scripts/mfsetup.sh
@@ -26,7 +26,7 @@ docker run --name microfab \
sleep 10
curl -sSL http://console.localho.st:8080/ak/api/v1/components > $CFG/cfg.json
-weft microfab -w $CFG/_wallets -p $CFG/_gateways -m $CFG/_msp -f --config $CFG/cfg.json
+npx @hyperledger-labs/weft microfab -w $CFG/_wallets -p $CFG/_gateways -m $CFG/_msp -f --config $CFG/cfg.json
# bring in the helper bash scripts
. $DIR/scripts/ccutils.sh
diff --git a/fabric-chaincode-shim/build.gradle b/fabric-chaincode-shim/build.gradle
index 097353485..25d3c1aaf 100644
--- a/fabric-chaincode-shim/build.gradle
+++ b/fabric-chaincode-shim/build.gradle
@@ -8,7 +8,7 @@
mavenCentral()
}
dependencies {
- classpath 'org.owasp:dependency-check-gradle:7.4.3'
+ classpath 'org.owasp:dependency-check-gradle:8.4.0'
}
}
@@ -17,12 +17,11 @@ plugins {
id 'jacoco'
id 'signing'
id 'checkstyle'
+ id 'org.cyclonedx.bom' version '1.8.1'
}
-apply plugin: 'org.owasp.dependencycheck'
-
checkstyle {
- toolVersion '8.29'
+ toolVersion '10.12.5'
configFile file("../ci/checkstyle/checkstyle.xml")
configProperties = [root_dir: file("..") ]
}
@@ -34,47 +33,51 @@ checkstyleTest {
source ='src/test/java'
}
-check.dependsOn dependencyCheckAnalyze
+cyclonedxBom {
+ includeConfigs = ["runtimeClasspath"]
+ skipConfigs = ["compileClasspath", "testCompileClasspath"]
+ projectType = "library"
+ schemaVersion = "1.5"
+ destination = file("build/reports")
+ outputName = "bom"
+ outputFormat = "json"
+ includeBomSerialNumber = false
+ includeLicenseText = false
+}
tasks.withType(org.gradle.api.tasks.testing.Test) {
systemProperty 'CORE_CHAINCODE_LOGGING_LEVEL', 'DEBUG'
}
dependencies {
- implementation group: 'org.hyperledger.fabric', name:'fabric-protos', version:'0.2.0'
- implementation 'org.bouncycastle:bcpkix-jdk15on:1.62'
- implementation 'org.bouncycastle:bcprov-jdk15on:1.62'
- implementation group: 'io.github.classgraph', name: 'classgraph', version: '4.8.146'
- implementation group: 'com.github.everit-org.json-schema', name: 'org.everit.json.schema', version: '1.14.1'
- implementation 'org.json:json:20220320'
- implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.20.1'
+ implementation 'org.hyperledger.fabric:fabric-protos:0.2.1'
+ implementation 'org.bouncycastle:bcpkix-jdk18on:1.77'
+ implementation 'org.bouncycastle:bcprov-jdk18on:1.77'
+ implementation 'io.github.classgraph:classgraph:4.8.165'
+ implementation 'com.github.everit-org.json-schema:org.everit.json.schema:1.14.2'
+ implementation 'org.json:json:20231013'
+ implementation 'com.google.protobuf:protobuf-java-util:3.24.4'
// Required if using Java 11+ as no longer bundled in the core libraries
- testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
- implementation 'io.grpc:grpc-netty-shaded:1.46.0'
- implementation 'io.grpc:grpc-protobuf:1.46.0'
- implementation 'io.grpc:grpc-stub:1.46.0'
-
- implementation platform("io.opentelemetry:opentelemetry-bom:1.6.0")
-
- implementation "io.opentelemetry:opentelemetry-api"
- implementation "io.opentelemetry:opentelemetry-proto:1.6.0-alpha"
- implementation "io.opentelemetry:opentelemetry-sdk"
- implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.6.0-alpha"
- implementation "io.opentelemetry:opentelemetry-sdk-trace"
- implementation 'io.opentelemetry:opentelemetry-exporter-otlp'
- implementation 'io.opentelemetry:opentelemetry-extension-trace-propagators:1.6.0'
- implementation "io.opentelemetry.instrumentation:opentelemetry-grpc-1.6:1.5.3-alpha"
-}
+ testImplementation 'javax.xml.bind:jaxb-api:2.3.1'
-dependencyCheck {
- format='ALL'
- analyzers {
- assemblyEnabled=false
- ossIndex {
- enabled=false
- }
- }
+ implementation platform('io.grpc:grpc-bom:1.60.0')
+ implementation 'io.grpc:grpc-netty-shaded'
+ implementation 'io.grpc:grpc-protobuf'
+ implementation 'io.grpc:grpc-stub'
+
+ testImplementation 'io.grpc:grpc-inprocess'
+
+ implementation platform("io.opentelemetry:opentelemetry-bom:1.32.0")
+
+ implementation 'io.opentelemetry:opentelemetry-api'
+ implementation 'io.opentelemetry.proto:opentelemetry-proto:1.0.0-alpha'
+ implementation 'io.opentelemetry:opentelemetry-sdk'
+ implementation 'io.opentelemetry:opentelemetry-sdk-extension-autoconfigure'
+ implementation 'io.opentelemetry:opentelemetry-sdk-trace'
+ implementation 'io.opentelemetry:opentelemetry-exporter-otlp'
+ implementation 'io.opentelemetry:opentelemetry-extension-trace-propagators'
+ implementation 'io.opentelemetry.instrumentation:opentelemetry-grpc-1.6:1.32.0-alpha'
}
sourceSets {
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java
index ba0ebb230..10ff45d65 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Serializer.java
@@ -15,7 +15,7 @@
* Class level annotation that defines the serializer that should be used to
* convert objects to and from the wire format.
*
- * This should annotate a class that implements the Serializer interface
+ * This should annotate a class that implements the Serializer interface
*/
@Retention(RUNTIME)
@Target({ElementType.TYPE, ElementType.TYPE_USE})
@@ -25,7 +25,14 @@
*
*/
enum TARGET {
- TRANSACTION, ALL
+ /**
+ * Target transaction functions.
+ */
+ TRANSACTION,
+ /**
+ * Target all elements.
+ */
+ ALL
}
/**
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java
index 5bdf8c95a..c9180ca46 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/annotation/Transaction.java
@@ -29,20 +29,27 @@
public @interface Transaction {
/**
- * SUBMIT or EVALUATE semantics.
+ * The intended invocation style for a transaction function.
*/
enum TYPE {
- SUBMIT, EVALUATE
+ /**
+ * Transaction is used to submit updates to the ledger.
+ */
+ SUBMIT,
+ /**
+ * Transaction is evaluated to query information from the ledger.
+ */
+ EVALUATE
}
/**
* Submit semantics.
*
- * TRUE indicates that this function is intended to be called with the 'submit'
- * semantics
+ * TRUE indicates that this function is intended to be called with the 'submit'
+ * semantics
*
- * FALSE indicates that this is intended to be called with the evaluate
- * semantics
+ * FALSE indicates that this is intended to be called with the evaluate
+ * semantics
*
* @return boolean, default is true
* @deprecated Please use intent
@@ -52,11 +59,12 @@ enum TYPE {
/**
* What are submit semantics for this transaction.
- *
- * SUBMIT - indicates that this function is intended to be called with the
- * 'submit' semantics EVALUATE - indicates that this is intended to be called
- * with the 'evaluate' semantics
- *
+ *
+ * - SUBMIT
- indicates that this function is intended to be called with the
+ * 'submit' semantics
+ * - EVALUATE
- indicates that this is intended to be called
+ * with the 'evaluate' semantics
+ *
* @return submit semantics
*/
TYPE intent() default Transaction.TYPE.SUBMIT;
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java
index b2df42030..860e22783 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/TxFunction.java
@@ -15,13 +15,32 @@
public interface TxFunction {
interface Routing {
-
+ /**
+ * Method to route calls to the transaction function.
+ * @return a method.
+ */
Method getMethod();
+ /**
+ * The associated contract class.
+ * @return a contract class.
+ */
Class extends ContractInterface> getContractClass();
+ /**
+ * The associated contract instance.
+ * @return a contract.
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws InvocationTargetException
+ * @throws NoSuchMethodException
+ */
ContractInterface getContractInstance() throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException;
+ /**
+ * Name of the serializer used for the transaction function.
+ * @return a serializer name.
+ */
String getSerializerName();
}
@@ -31,7 +50,7 @@ interface Routing {
boolean isUnknownTx();
/**
- * @param unknown
+ * @param unknown true if the transaction is to be called when the request fn is unknown; otherwise false.
*/
void setUnknownTx(boolean unknown);
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java
new file mode 100644
index 000000000..96b288ea9
--- /dev/null
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/ledger/impl/package-info.java
@@ -0,0 +1,6 @@
+/*
+ * Copyright 2023 IBM All Rights Reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+package org.hyperledger.fabric.ledger.impl;
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java
index 8209c6660..046595df3 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/Chaincode.java
@@ -39,23 +39,38 @@ public interface Chaincode {
* and{@link #invoke(ChaincodeStub)}
*/
class Response {
-
private final int statusCode;
private final String message;
private final byte[] payload;
+ /**
+ * Constructor.
+ * @param status a status object.
+ * @param message a response message.
+ * @param payload a response payload.
+ */
public Response(final Status status, final String message, final byte[] payload) {
this.statusCode = status.getCode();
this.message = message;
this.payload = payload;
}
+ /**
+ * Constructor.
+ * @param statusCode a status code.
+ * @param message a response message.
+ * @param payload a response payload.
+ */
public Response(final int statusCode, final String message, final byte[] payload) {
this.statusCode = statusCode;
this.message = message;
this.payload = payload;
}
+ /**
+ * Get the response status.
+ * @return status.
+ */
public Status getStatus() {
if (Status.hasStatusForCode(statusCode)) {
return Status.forCode(statusCode);
@@ -64,18 +79,34 @@ public Status getStatus() {
}
}
+ /**
+ * Get the response status code.
+ * @return status code.
+ */
public int getStatusCode() {
return statusCode;
}
+ /**
+ * Get the response message.
+ * @return a message.
+ */
public String getMessage() {
return message;
}
+ /**
+ * Get the response payload.
+ * @return payload bytes.
+ */
public byte[] getPayload() {
return payload;
}
+ /**
+ * Get the response payload as a UTF-8 string.
+ * @return a string.
+ */
public String getStringPayload() {
return (payload == null) ? null : new String(payload, UTF_8);
}
@@ -84,7 +115,18 @@ public String getStringPayload() {
* {@link Response} status enum.
*/
public enum Status {
- SUCCESS(200), ERROR_THRESHOLD(400), INTERNAL_SERVER_ERROR(500);
+ /**
+ * Successful response status.
+ */
+ SUCCESS(200),
+ /**
+ * Minimum threshold for as error status code.
+ */
+ ERROR_THRESHOLD(400),
+ /**
+ * Server-side error status.
+ */
+ INTERNAL_SERVER_ERROR(500);
private static final Map CODETOSTATUS = new HashMap<>();
private final int code;
@@ -93,10 +135,19 @@ public enum Status {
this.code = code;
}
+ /**
+ * Get the status code associated with this status object.
+ * @return a status code.
+ */
public int getCode() {
return code;
}
+ /**
+ * Get a status object for a given status code.
+ * @param code a status code.
+ * @return a status object.
+ */
public static Status forCode(final int code) {
final Status result = CODETOSTATUS.get(code);
if (result == null) {
@@ -105,6 +156,11 @@ public static Status forCode(final int code) {
return result;
}
+ /**
+ * Whether a status exists for a given status code.
+ * @param code a status code.
+ * @return True if a status for the code exists; otherwise false.
+ */
public static boolean hasStatusForCode(final int code) {
return CODETOSTATUS.containsKey(code);
}
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java
index 6e9f01922..27c842572 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeServerProperties.java
@@ -8,14 +8,13 @@
import java.net.SocketAddress;
public final class ChaincodeServerProperties {
-
private SocketAddress serverAddress;
- private int maxInboundMetadataSize = 100 * 1024 * 1024;
- private int maxInboundMessageSize = 100 * 1024 * 1024;
- private int maxConnectionAgeSeconds = 5;
- private int keepAliveTimeoutSeconds = 20;
- private int permitKeepAliveTimeMinutes = 1;
- private int keepAliveTimeMinutes = 1;
+ private int maxInboundMetadataSize = 100 * 1024 * 1024; // checkstyle:ignore-line:MagicNumber
+ private int maxInboundMessageSize = 100 * 1024 * 1024; // checkstyle:ignore-line:MagicNumber
+ private int maxConnectionAgeSeconds = 5; // checkstyle:ignore-line:MagicNumber
+ private int keepAliveTimeoutSeconds = 20; // checkstyle:ignore-line:MagicNumber
+ private int permitKeepAliveTimeMinutes = 1; // checkstyle:ignore-line:MagicNumber
+ private int keepAliveTimeMinutes = 1; // checkstyle:ignore-line:MagicNumber
private boolean permitKeepAliveWithoutCalls = true;
private String keyPassword;
private String keyCertChainFile;
@@ -23,9 +22,24 @@ public final class ChaincodeServerProperties {
private String trustCertCollectionFile;
private boolean tlsEnabled = false;
+ /**
+ * Constructor using default configuration.
+ */
public ChaincodeServerProperties() {
}
+ /**
+ * Constructor.
+ * @param portChaincodeServer ignored.
+ * @param maxInboundMetadataSize the maximum metadata size allowed to be received by the server.
+ * @param maxInboundMessageSize the maximum message size allowed to be received by the server.
+ * @param maxConnectionAgeSeconds the maximum connection age in seconds.
+ * @param keepAliveTimeoutSeconds timeout for a keep-alive ping request in seconds.
+ * @param permitKeepAliveTimeMinutes the most aggressive keep-alive time clients are permitted to configure in minutes.
+ * @param keepAliveTimeMinutes delay before server sends a keep-alive in minutes.
+ * @param permitKeepAliveWithoutCalls whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.
+ */
+ // checkstyle:ignore-next-line:ParameterNumber
public ChaincodeServerProperties(
final int portChaincodeServer, final int maxInboundMetadataSize, final int maxInboundMessageSize,
final int maxConnectionAgeSeconds, final int keepAliveTimeoutSeconds, final int permitKeepAliveTimeMinutes,
@@ -41,114 +55,226 @@ public ChaincodeServerProperties(
this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls;
}
+ /**
+ * The maximum size of metadata allowed to be received.
+ * @return The maximum metadata size allowed.
+ */
public int getMaxInboundMetadataSize() {
return maxInboundMetadataSize;
}
+ /**
+ * Sets the maximum metadata size allowed to be received by the server.
+ * @param maxInboundMetadataSize The new maximum size allowed for incoming metadata.
+ */
public void setMaxInboundMetadataSize(final int maxInboundMetadataSize) {
this.maxInboundMetadataSize = maxInboundMetadataSize;
}
+ /**
+ * The maximum message size allowed to be received by the server.
+ * @return the maximum message size allowed.
+ */
public int getMaxInboundMessageSize() {
return maxInboundMessageSize;
}
+ /**
+ * Sets the maximum message size allowed to be received by the server.
+ * @param maxInboundMessageSize The new maximum size allowed for incoming messages.
+ */
public void setMaxInboundMessageSize(final int maxInboundMessageSize) {
this.maxInboundMessageSize = maxInboundMessageSize;
}
+ /**
+ * The maximum connection age.
+ * @return The maximum connection age in seconds.
+ */
public int getMaxConnectionAgeSeconds() {
return maxConnectionAgeSeconds;
}
+ /**
+ * Specify a maximum connection age.
+ * @param maxConnectionAgeSeconds The maximum connection age in seconds.
+ */
public void setMaxConnectionAgeSeconds(final int maxConnectionAgeSeconds) {
this.maxConnectionAgeSeconds = maxConnectionAgeSeconds;
}
+ /**
+ * The timeout for a keep-alive ping requests.
+ * @return timeout in seconds.
+ */
public int getKeepAliveTimeoutSeconds() {
return keepAliveTimeoutSeconds;
}
+ /**
+ * Set the timeout for keep-alive ping requests.
+ * @param keepAliveTimeoutSeconds timeout in seconds.
+ */
public void setKeepAliveTimeoutSeconds(final int keepAliveTimeoutSeconds) {
this.keepAliveTimeoutSeconds = keepAliveTimeoutSeconds;
}
+ /**
+ * The most aggressive keep-alive time clients are permitted to configure.
+ * @return time in minutes.
+ */
public int getPermitKeepAliveTimeMinutes() {
return permitKeepAliveTimeMinutes;
}
+ /**
+ * Specify the most aggressive keep-alive time clients are permitted to configure.
+ * @param permitKeepAliveTimeMinutes time in minutes.
+ */
public void setPermitKeepAliveTimeMinutes(final int permitKeepAliveTimeMinutes) {
this.permitKeepAliveTimeMinutes = permitKeepAliveTimeMinutes;
}
+ /**
+ * The delay before the server sends a keep-alive.
+ * @return delay in minutes.
+ */
public int getKeepAliveTimeMinutes() {
return keepAliveTimeMinutes;
}
+ /**
+ * Set the delay before the server sends a keep-alive.
+ * @param keepAliveTimeMinutes delay in minutes.
+ */
public void setKeepAliveTimeMinutes(final int keepAliveTimeMinutes) {
this.keepAliveTimeMinutes = keepAliveTimeMinutes;
}
+ /**
+ * Whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.
+ * @return true if clients are allowed to send keep-alive requests without calls; otherwise false.
+ */
public boolean getPermitKeepAliveWithoutCalls() {
return permitKeepAliveWithoutCalls;
}
+ /**
+ * Get the server socket address.
+ * @return a socket address.
+ */
public SocketAddress getServerAddress() {
return serverAddress;
}
+ /**
+ * Set the server socket address.
+ * @param address a socket address.
+ */
public void setServerAddress(final SocketAddress address) {
this.serverAddress = address;
}
+ /**
+ * Whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.
+ * @return true if clients are allowed to send keep-alive requests without calls; otherwise false.
+ */
public boolean isPermitKeepAliveWithoutCalls() {
return permitKeepAliveWithoutCalls;
}
+ /**
+ * Specify whether clients are allowed to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.
+ * @param permitKeepAliveWithoutCalls Whether to allow clients to send keep-alive requests without calls.
+ */
public void setPermitKeepAliveWithoutCalls(final boolean permitKeepAliveWithoutCalls) {
this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls;
}
+ /**
+ * Password used to access the server key.
+ * @return a password.
+ */
public String getKeyPassword() {
return keyPassword;
}
+ /**
+ * Set the password used to access the server key.
+ * @param keyPassword a password.
+ */
public void setKeyPassword(final String keyPassword) {
this.keyPassword = keyPassword;
}
+ /**
+ * Server keychain file name.
+ * @return a file name.
+ */
public String getKeyCertChainFile() {
return keyCertChainFile;
}
+ /**
+ * Set the server keychain file name.
+ * @param keyCertChainFile a file name.
+ */
public void setKeyCertChainFile(final String keyCertChainFile) {
this.keyCertChainFile = keyCertChainFile;
}
+ /**
+ * Server key file name.
+ * @return a file name.
+ */
public String getKeyFile() {
return keyFile;
}
+ /**
+ * Set the server key file name.
+ * @param keyFile a file name.
+ */
public void setKeyFile(final String keyFile) {
this.keyFile = keyFile;
}
+ /**
+ * Server trust certificate collection file name.
+ * @return a file name.
+ */
public String getTrustCertCollectionFile() {
return trustCertCollectionFile;
}
+ /**
+ * Set the server trust certificate collection file name.
+ * @param trustCertCollectionFile a file name.
+ */
public void setTrustCertCollectionFile(final String trustCertCollectionFile) {
this.trustCertCollectionFile = trustCertCollectionFile;
}
+ /**
+ * Whether TLS is enabled for the server.
+ * @return true if TLS is enabled; otherwise false.
+ */
public boolean isTlsEnabled() {
return tlsEnabled;
}
+ /**
+ * Set whether TLS is enabled for the server.
+ * @param tlsEnabled true to enable TLS; otherwise false.
+ */
public void setTlsEnabled(final boolean tlsEnabled) {
this.tlsEnabled = tlsEnabled;
}
+ /**
+ * Check that all the server property values are valid.
+ * @throws IllegalArgumentException if any properties are not valid.
+ */
public void validate() {
if (this.getServerAddress() == null) {
throw new IllegalArgumentException("chaincodeServerProperties.getServerAddress() must be set");
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java
index f049dbb58..7c77f5daa 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java
@@ -572,8 +572,15 @@ public interface ChaincodeStub {
QueryResultsIterator getPrivateDataQueryResult(String collection, String query);
/**
- * Defines the CHAINCODE type event that will be posted to interested clients
- * when the chaincode's result is committed to the ledger.
+ * Allows the chaincode to propose an event on the transaction proposal response.
+ * When the transaction is included in a block and the block is successfully committed to the ledger,
+ * the block event (including transaction level chaincode events)
+ * will be delivered to the current client application event listeners that have been registered with the peer's event producer.
+ * Consult each SDK's documentation for details.
+ * Only a single chaincode event can be included in a transaction.
+ * If setEvent() is called multiple times only the last event will be included in the transaction.
+ * The event must originate from the outer-most invoked chaincode in chaincode-to-chaincode scenarios.
+ * The marshaled ChaincodeEvent will be available in the transaction's ChaincodeAction.events field.
*
* @param name Name of event. Cannot be null or empty string.
* @param payload Optional event payload.
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java
new file mode 100644
index 000000000..f4f3bb511
--- /dev/null
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ext/sbe/impl/package-info.java
@@ -0,0 +1,6 @@
+/*
+ * Copyright 2023 IBM All Rights Reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+package org.hyperledger.fabric.shim.ext.sbe.impl;
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java
index 5610985b1..696aececb 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProvider.java
@@ -11,12 +11,15 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
-import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTracing;
-import io.opentelemetry.sdk.autoconfigure.OpenTelemetrySdkAutoConfiguration;
-import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
+import io.opentelemetry.instrumentation.grpc.v1_6.GrpcTelemetry;
+import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
+import io.opentelemetry.semconv.ResourceAttributes;
+
import org.hyperledger.fabric.shim.ChaincodeStub;
import org.hyperledger.fabric.traces.TracesProvider;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
public final class OpenTelemetryTracesProvider implements TracesProvider {
@@ -26,17 +29,31 @@ public final class OpenTelemetryTracesProvider implements TracesProvider {
private static final String CORE_CHAINCODE_ID_NAME = "CORE_CHAINCODE_ID_NAME";
private Tracer tracer;
- private GrpcTracing grpcTracer;
+ private GrpcTelemetry grpcTracer;
@Override
public void initialize(final Properties props) {
String serviceName = props.getProperty(CORE_CHAINCODE_ID_NAME, "unknown");
props.setProperty(ResourceAttributes.SERVICE_NAME.getKey(), serviceName);
- OpenTelemetry openTelemetry = OpenTelemetrySdkAutoConfiguration.initialize(false,
- new OpenTelemetryProperties(System.getenv(), System.getProperties(), props));
+ OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.builder()
+ .addPropertiesSupplier(() -> getOpenTelemetryProperties(props))
+ .build()
+ .getOpenTelemetrySdk();
+
tracer = openTelemetry.getTracerProvider().get("org.hyperledger.traces");
- grpcTracer = GrpcTracing.newBuilder(openTelemetry).build();
+ grpcTracer = GrpcTelemetry.create(openTelemetry);
+ }
+
+ private Map getOpenTelemetryProperties(final Properties props) {
+ Map results = new HashMap<>(System.getenv());
+
+ Properties systemProps = System.getProperties();
+ systemProps.stringPropertyNames().forEach(key -> results.put(key, systemProps.getProperty(key)));
+
+ props.stringPropertyNames().forEach(key -> results.put(key, props.getProperty(key)));
+
+ return results;
}
@Override
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java
new file mode 100644
index 000000000..b8aef10b1
--- /dev/null
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/traces/impl/package-info.java
@@ -0,0 +1,6 @@
+/*
+ * Copyright 2023 IBM All Rights Reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+package org.hyperledger.fabric.traces.impl;
diff --git a/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java b/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java
index 3b900b360..7b03a3f2d 100644
--- a/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java
+++ b/fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/traces/impl/OpenTelemetryTracesProviderTest.java
@@ -40,7 +40,7 @@
public final class OpenTelemetryTracesProviderTest {
- private class ContextGetterChaincode extends ChaincodeBase {
+ private final class ContextGetterChaincode extends ChaincodeBase {
@Override
public Response init(final ChaincodeStub stub) {
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c02..afba10928 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 05679dc3c..b1624c473 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
+networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0c8..65dcd68d6 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
-# Copyright 2015 the original author or authors.
+# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,67 +17,101 @@
#
##############################################################################
-##
-## Gradle start up script for UN*X
-##
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
##############################################################################
# Attempt to set APP_HOME
+
# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
+MAX_FD=maximum
warn () {
echo "$*"
-}
+} >&2
die () {
echo
echo "$*"
echo
exit 1
-}
+} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- NONSTOP* )
- nonstop=true
- ;;
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACMD=$JAVA_HOME/jre/sh/java
else
- JAVACMD="$JAVA_HOME/bin/java"
+ JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
- JAVACMD="java"
+ JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
@@ -106,80 +140,105 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
fi
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
-if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
fi
- i=`expr $i + 1`
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
done
- case $i in
- 0) set -- ;;
- 1) set -- "$args0" ;;
- 2) set -- "$args0" "$args1" ;;
- 3) set -- "$args0" "$args1" "$args2" ;;
- 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
fi
-# Escape application args
-save () {
- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
- echo " "
-}
-APP_ARGS=`save "$@"`
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index ac1b06f93..6689b85be 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
-@if "%DEBUG%" == "" @echo off
+@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
+if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
+if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal