diff --git a/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionFailedResponse.java b/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionFailedResponse.java new file mode 100644 index 000000000..803a66e62 --- /dev/null +++ b/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionFailedResponse.java @@ -0,0 +1,26 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.api.responses; + +import io.hotmoka.annotations.Immutable; + +/** + * A response for a failed transaction that should have installed a jar in the node. + */ +@Immutable +public interface JarStoreTransactionFailedResponse extends JarStoreTransactionResponse, FailedTransactionResponse { +} \ No newline at end of file diff --git a/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionSuccessfulResponse.java b/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionSuccessfulResponse.java new file mode 100644 index 000000000..3d2166f9c --- /dev/null +++ b/io-hotmoka-beans-api/src/main/java/io/hotmoka/beans/api/responses/JarStoreTransactionSuccessfulResponse.java @@ -0,0 +1,26 @@ +/* +Copyright 2024 Fausto Spoto + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.hotmoka.beans.api.responses; + +import io.hotmoka.annotations.Immutable; + +/** + * A response for a successful transaction that installs a jar in a blockchain. + */ +@Immutable +public interface JarStoreTransactionSuccessfulResponse extends JarStoreTransactionResponse, TransactionResponseWithInstrumentedJar { +} \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionResponses.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionResponses.java index 3c3326863..c5adcd6bd 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionResponses.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/TransactionResponses.java @@ -17,15 +17,21 @@ package io.hotmoka.beans; import java.io.IOException; +import java.math.BigInteger; import java.util.stream.Stream; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; +import io.hotmoka.beans.api.updates.Update; import io.hotmoka.beans.internal.gson.TransactionReferenceDecoder; import io.hotmoka.beans.internal.gson.TransactionReferenceEncoder; import io.hotmoka.beans.internal.gson.TransactionReferenceJson; import io.hotmoka.beans.internal.responses.JarStoreInitialTransactionResponseImpl; +import io.hotmoka.beans.internal.responses.JarStoreTransactionFailedResponseImpl; +import io.hotmoka.beans.internal.responses.JarStoreTransactionSuccessfulResponseImpl; import io.hotmoka.beans.internal.responses.TransactionResponseImpl; import io.hotmoka.marshalling.api.UnmarshallingContext; @@ -48,6 +54,38 @@ public static JarStoreInitialTransactionResponse jarStoreInitial(byte[] instrume return new JarStoreInitialTransactionResponseImpl(instrumentedJar, dependencies, verificationToolVersion); } + /** + * Builds the response of a failed transaction that should have installed a jar in a yet non-initialized node. + * + * @param classNameOfCause the fully-qualified class name of the cause exception + * @param messageOfCause of the message of the cause exception; this might be {@code null} + * @param updates the updates resulting from the execution of the transaction + * @param gasConsumedForCPU the amount of gas consumed by the transaction for CPU execution + * @param gasConsumedForRAM the amount of gas consumed by the transaction for RAM allocation + * @param gasConsumedForStorage the amount of gas consumed by the transaction for storage consumption + * @param gasConsumedForPenalty the amount of gas consumed by the transaction as penalty for the failure + * @return the response + */ + public static JarStoreTransactionFailedResponse jarStoreFailed(String classNameOfCause, String messageOfCause, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage, BigInteger gasConsumedForPenalty) { + return new JarStoreTransactionFailedResponseImpl(classNameOfCause, messageOfCause, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage, gasConsumedForPenalty); + } + + /** + * Builds the response of a successful transaction that installed a jar in a yet non-initialized node. + * + * @param instrumentedJar the bytes of the jar to install, instrumented + * @param dependencies the dependencies of the jar, previously installed in blockchain + * @param verificationToolVersion the version of the verification tool + * @param updates the updates resulting from the execution of the transaction + * @param gasConsumedForCPU the amount of gas consumed by the transaction for CPU execution + * @param gasConsumedForRAM the amount of gas consumed by the transaction for RAM allocation + * @param gasConsumedForStorage the amount of gas consumed by the transaction for storage consumption + * @return the response + */ + public static JarStoreTransactionSuccessfulResponse jarStoreSuccessful(byte[] instrumentedJar, Stream dependencies, long verificationToolVersion, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage) { + return new JarStoreTransactionSuccessfulResponseImpl(instrumentedJar, dependencies, verificationToolVersion, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage); + } + /** * Yields a transaction responses unmarshalled from the given context. * diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionFailedResponse.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionFailedResponseImpl.java similarity index 77% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionFailedResponse.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionFailedResponseImpl.java index 150915154..f8cf4d22d 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionFailedResponse.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionFailedResponseImpl.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.responses; +package io.hotmoka.beans.internal.responses; import java.io.IOException; import java.math.BigInteger; @@ -23,34 +23,32 @@ import io.hotmoka.annotations.Immutable; import io.hotmoka.beans.Updates; -import io.hotmoka.beans.api.responses.FailedTransactionResponse; -import io.hotmoka.beans.api.responses.JarStoreTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; import io.hotmoka.beans.api.updates.Update; -import io.hotmoka.beans.internal.responses.NonInitialTransactionResponseImpl; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; /** - * A response for a failed transaction that should have installed a jar in the node. + * Implementation of a response for a failed transaction that should have installed a jar in the node. */ @Immutable -public class JarStoreTransactionFailedResponse extends NonInitialTransactionResponseImpl implements JarStoreTransactionResponse, FailedTransactionResponse { +public class JarStoreTransactionFailedResponseImpl extends NonInitialTransactionResponseImpl implements JarStoreTransactionFailedResponse { public final static byte SELECTOR = 3; /** * The amount of gas consumed by the transaction as penalty for the failure. */ - public final BigInteger gasConsumedForPenalty; + private final BigInteger gasConsumedForPenalty; /** * The fully-qualified class name of the cause exception. */ - public final String classNameOfCause; + private final String classNameOfCause; /** * The message of the cause exception. */ - public final String messageOfCause; + private final String messageOfCause; /** * Builds the transaction response. @@ -63,7 +61,7 @@ public class JarStoreTransactionFailedResponse extends NonInitialTransactionResp * @param gasConsumedForStorage the amount of gas consumed by the transaction for storage consumption * @param gasConsumedForPenalty the amount of gas consumed by the transaction as penalty for the failure */ - public JarStoreTransactionFailedResponse(String classNameOfCause, String messageOfCause, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage, BigInteger gasConsumedForPenalty) { + public JarStoreTransactionFailedResponseImpl(String classNameOfCause, String messageOfCause, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage, BigInteger gasConsumedForPenalty) { super(updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage); this.classNameOfCause = Objects.requireNonNull(classNameOfCause, "classNameOfCause cannot be null"); @@ -93,7 +91,7 @@ public String getMessageOfCause() { @Override public boolean equals(Object other) { - return other instanceof JarStoreTransactionFailedResponse jstfr && super.equals(other) + return other instanceof JarStoreTransactionFailedResponseImpl jstfr && super.equals(other) && gasConsumedForPenalty.equals(jstfr.gasConsumedForPenalty) && classNameOfCause.equals(jstfr.classNameOfCause) && messageOfCause.equals(jstfr.messageOfCause); } @@ -126,7 +124,7 @@ public void into(MarshallingContext context) throws IOException { * @return the response * @throws IOException if the response could not be unmarshalled */ - public static JarStoreTransactionFailedResponse from(UnmarshallingContext context) throws IOException { + public static JarStoreTransactionFailedResponseImpl from(UnmarshallingContext context) throws IOException { Stream updates = Stream.of(context.readLengthAndArray(Updates::from, Update[]::new)); var gasConsumedForCPU = context.readBigInteger(); var gasConsumedForRAM = context.readBigInteger(); @@ -134,6 +132,6 @@ public static JarStoreTransactionFailedResponse from(UnmarshallingContext contex var gasConsumedForPenalty = context.readBigInteger(); var classNameOfCause = context.readStringUnshared(); var messageOfCause = context.readStringUnshared(); - return new JarStoreTransactionFailedResponse(classNameOfCause, messageOfCause, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage, gasConsumedForPenalty); + return new JarStoreTransactionFailedResponseImpl(classNameOfCause, messageOfCause, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage, gasConsumedForPenalty); } } \ No newline at end of file diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionSuccessfulResponse.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionSuccessfulResponseImpl.java similarity index 81% rename from io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionSuccessfulResponse.java rename to io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionSuccessfulResponseImpl.java index 23421c226..34ddeba7c 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/responses/JarStoreTransactionSuccessfulResponse.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/JarStoreTransactionSuccessfulResponseImpl.java @@ -14,7 +14,7 @@ limitations under the License. */ -package io.hotmoka.beans.responses; +package io.hotmoka.beans.internal.responses; import java.io.IOException; import java.math.BigInteger; @@ -25,19 +25,18 @@ import io.hotmoka.annotations.Immutable; import io.hotmoka.beans.TransactionReferences; import io.hotmoka.beans.Updates; -import io.hotmoka.beans.api.responses.JarStoreTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponseWithInstrumentedJar; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.updates.Update; -import io.hotmoka.beans.internal.responses.NonInitialTransactionResponseImpl; import io.hotmoka.marshalling.api.MarshallingContext; import io.hotmoka.marshalling.api.UnmarshallingContext; /** - * A response for a successful transaction that installs a jar in a blockchain. + * Implementation of a response for a successful transaction that installs a jar in a blockchain. */ @Immutable -public class JarStoreTransactionSuccessfulResponse extends NonInitialTransactionResponseImpl implements JarStoreTransactionResponse, TransactionResponseWithInstrumentedJar { +public class JarStoreTransactionSuccessfulResponseImpl extends NonInitialTransactionResponseImpl implements JarStoreTransactionSuccessfulResponse, TransactionResponseWithInstrumentedJar { public final static byte SELECTOR = 2; /** @@ -67,7 +66,7 @@ public class JarStoreTransactionSuccessfulResponse extends NonInitialTransaction * @param gasConsumedForRAM the amount of gas consumed by the transaction for RAM allocation * @param gasConsumedForStorage the amount of gas consumed by the transaction for storage consumption */ - public JarStoreTransactionSuccessfulResponse(byte[] instrumentedJar, Stream dependencies, long verificationToolVersion, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage) { + public JarStoreTransactionSuccessfulResponseImpl(byte[] instrumentedJar, Stream dependencies, long verificationToolVersion, Stream updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage) { super(updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage); this.instrumentedJar = instrumentedJar.clone(); @@ -93,7 +92,7 @@ public Stream getDependencies() { @Override public boolean equals(Object other) { - return other instanceof JarStoreTransactionSuccessfulResponse jstsr && super.equals(other) + return other instanceof JarStoreTransactionSuccessfulResponseImpl jstsr && super.equals(other) && Arrays.equals(instrumentedJar, jstsr.instrumentedJar) && Arrays.equals(dependencies, jstsr.dependencies); } @@ -128,7 +127,7 @@ public void into(MarshallingContext context) throws IOException { * @return the response * @throws IOException if the response could not be unmarshalled */ - public static JarStoreTransactionSuccessfulResponse from(UnmarshallingContext context) throws IOException { + public static JarStoreTransactionSuccessfulResponseImpl from(UnmarshallingContext context) throws IOException { Stream updates = Stream.of(context.readLengthAndArray(Updates::from, Update[]::new)); var gasConsumedForCPU = context.readBigInteger(); var gasConsumedForRAM = context.readBigInteger(); @@ -136,7 +135,7 @@ public static JarStoreTransactionSuccessfulResponse from(UnmarshallingContext co var verificationToolVersion = context.readLong(); byte[] instrumentedJar = context.readLengthAndBytes("Jar length mismatch in response"); Stream dependencies = Stream.of(context.readLengthAndArray(TransactionReferences::from, TransactionReference[]::new)); - return new JarStoreTransactionSuccessfulResponse(instrumentedJar, dependencies, verificationToolVersion, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage); + return new JarStoreTransactionSuccessfulResponseImpl(instrumentedJar, dependencies, verificationToolVersion, updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage); } @Override diff --git a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java index fdad9a6af..4e9de0235 100644 --- a/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java +++ b/io-hotmoka-beans/src/main/java/io/hotmoka/beans/internal/responses/TransactionResponseImpl.java @@ -26,8 +26,6 @@ import io.hotmoka.beans.responses.ConstructorCallTransactionSuccessfulResponse; import io.hotmoka.beans.responses.GameteCreationTransactionResponse; import io.hotmoka.beans.responses.InitializationTransactionResponse; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.responses.MethodCallTransactionExceptionResponse; import io.hotmoka.beans.responses.MethodCallTransactionFailedResponse; import io.hotmoka.beans.responses.MethodCallTransactionSuccessfulResponse; @@ -60,8 +58,8 @@ public static TransactionResponseImpl from(UnmarshallingContext context) throws case GameteCreationTransactionResponse.SELECTOR: return GameteCreationTransactionResponse.from(context); case JarStoreInitialTransactionResponseImpl.SELECTOR: return JarStoreInitialTransactionResponseImpl.from(context); case InitializationTransactionResponse.SELECTOR: return InitializationTransactionResponse.from(context); - case JarStoreTransactionFailedResponse.SELECTOR: return JarStoreTransactionFailedResponse.from(context); - case JarStoreTransactionSuccessfulResponse.SELECTOR: return JarStoreTransactionSuccessfulResponse.from(context); + case JarStoreTransactionFailedResponseImpl.SELECTOR: return JarStoreTransactionFailedResponseImpl.from(context); + case JarStoreTransactionSuccessfulResponseImpl.SELECTOR: return JarStoreTransactionSuccessfulResponseImpl.from(context); case ConstructorCallTransactionExceptionResponse.SELECTOR: return ConstructorCallTransactionExceptionResponse.from(context); case ConstructorCallTransactionFailedResponse.SELECTOR: return ConstructorCallTransactionFailedResponse.from(context); case ConstructorCallTransactionSuccessfulResponse.SELECTOR: diff --git a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionFailedResponseModel.java b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionFailedResponseModel.java index f66c1250f..bd028140f 100644 --- a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionFailedResponseModel.java +++ b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionFailedResponseModel.java @@ -18,7 +18,8 @@ import java.math.BigInteger; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; +import io.hotmoka.beans.TransactionResponses; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; import io.hotmoka.network.updates.UpdateModel; public class JarStoreTransactionFailedResponseModel extends JarStoreTransactionResponseModel { @@ -42,14 +43,14 @@ public JarStoreTransactionFailedResponseModel(JarStoreTransactionFailedResponse super(response); this.gasConsumedForPenalty = response.gasConsumedForPenalty().toString(); - this.classNameOfCause = response.classNameOfCause; - this.messageOfCause = response.messageOfCause; + this.classNameOfCause = response.getClassNameOfCause(); + this.messageOfCause = response.getMessageOfCause(); } public JarStoreTransactionFailedResponseModel() {} public JarStoreTransactionFailedResponse toBean() { - return new JarStoreTransactionFailedResponse( + return TransactionResponses.jarStoreFailed( classNameOfCause, messageOfCause, updates.stream().map(UpdateModel::toBean), diff --git a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionSuccessfulResponseModel.java b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionSuccessfulResponseModel.java index ab75b9ae8..9a59ba021 100644 --- a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionSuccessfulResponseModel.java +++ b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/JarStoreTransactionSuccessfulResponseModel.java @@ -21,7 +21,8 @@ import java.util.List; import java.util.stream.Collectors; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; +import io.hotmoka.beans.TransactionResponses; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.network.updates.UpdateModel; import io.hotmoka.network.values.TransactionReferenceModel; @@ -54,7 +55,7 @@ public JarStoreTransactionSuccessfulResponseModel(JarStoreTransactionSuccessfulR public JarStoreTransactionSuccessfulResponseModel() {} public JarStoreTransactionSuccessfulResponse toBean() { - return new JarStoreTransactionSuccessfulResponse( + return TransactionResponses.jarStoreSuccessful( Base64.getDecoder().decode(instrumentedJar), dependencies.stream().map(TransactionReferenceModel::toBean), verificationToolVersion, diff --git a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/TransactionRestResponseModel.java b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/TransactionRestResponseModel.java index 7e29781aa..44e055c48 100644 --- a/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/TransactionRestResponseModel.java +++ b/io-hotmoka-network/src/main/java/io/hotmoka/network/responses/TransactionRestResponseModel.java @@ -17,14 +17,14 @@ package io.hotmoka.network.responses; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.responses.ConstructorCallTransactionExceptionResponse; import io.hotmoka.beans.responses.ConstructorCallTransactionFailedResponse; import io.hotmoka.beans.responses.ConstructorCallTransactionSuccessfulResponse; import io.hotmoka.beans.responses.GameteCreationTransactionResponse; import io.hotmoka.beans.responses.InitializationTransactionResponse; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.responses.MethodCallTransactionExceptionResponse; import io.hotmoka.beans.responses.MethodCallTransactionFailedResponse; import io.hotmoka.beans.responses.MethodCallTransactionSuccessfulResponse; diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/Reverification.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/Reverification.java index 0e1e31c29..4a64421bd 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/Reverification.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/Reverification.java @@ -32,12 +32,12 @@ import io.hotmoka.beans.api.requests.InitialTransactionRequest; import io.hotmoka.beans.api.requests.GenericJarStoreTransactionRequest; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.GenericJarStoreTransactionResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.responses.TransactionResponseWithInstrumentedJar; import io.hotmoka.beans.api.transactions.TransactionReference; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.node.api.ConsensusConfig; import io.hotmoka.node.local.api.UnsupportedVerificationVersionException; import io.hotmoka.verification.TakamakaClassLoaders; @@ -204,7 +204,7 @@ private JarStoreTransactionFailedResponse transformIntoFailed(TransactionRespons // there remains only this possibility: var currentResponseAsNonInitial = (JarStoreTransactionSuccessfulResponse) response; - var replacement = new JarStoreTransactionFailedResponse( + var replacement = TransactionResponses.jarStoreFailed( VerificationException.class.getName(), error, currentResponseAsNonInitial.getUpdates(), currentResponseAsNonInitial.getGasConsumedForCPU(), currentResponseAsNonInitial.getGasConsumedForRAM(), currentResponseAsNonInitial.getGasConsumedForStorage(), @@ -224,7 +224,7 @@ private GenericJarStoreTransactionResponse updateVersion(TransactionResponseWith // there remains only this possibility var currentResponseAsNonInitial = (JarStoreTransactionSuccessfulResponse) response; - replacement = new JarStoreTransactionSuccessfulResponse( + replacement = TransactionResponses.jarStoreSuccessful( response.getInstrumentedJar(), response.getDependencies(), consensus.getVerificationVersion(), currentResponseAsNonInitial.getUpdates(), currentResponseAsNonInitial.getGasConsumedForCPU(), currentResponseAsNonInitial.getGasConsumedForRAM(), currentResponseAsNonInitial.getGasConsumedForStorage()); diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/transactions/JarStoreResponseBuilder.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/transactions/JarStoreResponseBuilder.java index df3f698f0..d31c43a33 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/transactions/JarStoreResponseBuilder.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/transactions/JarStoreResponseBuilder.java @@ -22,11 +22,10 @@ import java.util.logging.Logger; import java.util.stream.Stream; +import io.hotmoka.beans.TransactionResponses; import io.hotmoka.beans.api.requests.JarStoreTransactionRequest; import io.hotmoka.beans.api.responses.JarStoreTransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.instrumentation.InstrumentedJars; import io.hotmoka.node.api.TransactionRejectedException; import io.hotmoka.node.local.AbstractNonInitialResponseBuilder; @@ -74,7 +73,7 @@ protected BigInteger minimalGasRequiredForTransaction() { @Override protected final int gasForStoringFailedResponse() { BigInteger gas = request.getGasLimit(); - return new JarStoreTransactionFailedResponse("placeholder for the name of the exception", "placeholder for the message of the exception", Stream.empty(), gas, gas, gas, gas).size(); + return TransactionResponses.jarStoreFailed("placeholder for the name of the exception", "placeholder for the message of the exception", Stream.empty(), gas, gas, gas, gas).size(); } @Override @@ -97,15 +96,15 @@ protected JarStoreTransactionResponse body() { var verifiedJar = VerifiedJars.of(request.getJar(), classLoader, false, consensus.allowsSelfCharged(), consensus.skipsVerification()); var instrumentedJar = InstrumentedJars.of(verifiedJar, gasCostModel); var instrumentedBytes = instrumentedJar.toBytes(); - chargeGasForStorageOf(new JarStoreTransactionSuccessfulResponse(instrumentedBytes, request.getDependencies(), consensus.getVerificationVersion(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage())); + chargeGasForStorageOf(TransactionResponses.jarStoreSuccessful(instrumentedBytes, request.getDependencies(), consensus.getVerificationVersion(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage())); refundPayerForAllRemainingGas(); - return new JarStoreTransactionSuccessfulResponse(instrumentedBytes, request.getDependencies(), consensus.getVerificationVersion(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage()); + return TransactionResponses.jarStoreSuccessful(instrumentedBytes, request.getDependencies(), consensus.getVerificationVersion(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage()); } catch (Throwable t) { LOGGER.log(Level.INFO, "jar store failed", t); resetBalanceOfPayerToInitialValueMinusAllPromisedGas(); // we do not pay back the gas - return new JarStoreTransactionFailedResponse(t.getClass().getName(), t.getMessage(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage(), gasConsumedForPenalty()); + return TransactionResponses.jarStoreFailed(t.getClass().getName(), t.getMessage(), updatesToBalanceOrNonceOfCaller(), gasConsumedForCPU(), gasConsumedForRAM(), gasConsumedForStorage(), gasConsumedForPenalty()); } } diff --git a/io-hotmoka-node/src/main/java/io/hotmoka/node/internal/AbstractNodeImpl.java b/io-hotmoka-node/src/main/java/io/hotmoka/node/internal/AbstractNodeImpl.java index a65cc505d..cd3793739 100644 --- a/io-hotmoka-node/src/main/java/io/hotmoka/node/internal/AbstractNodeImpl.java +++ b/io-hotmoka-node/src/main/java/io/hotmoka/node/internal/AbstractNodeImpl.java @@ -26,6 +26,7 @@ import java.util.logging.Logger; import io.hotmoka.annotations.ThreadSafe; +import io.hotmoka.beans.api.responses.JarStoreTransactionFailedResponse; import io.hotmoka.beans.api.responses.JarStoreTransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.StorageReference; @@ -34,7 +35,6 @@ import io.hotmoka.beans.responses.ConstructorCallTransactionFailedResponse; import io.hotmoka.beans.responses.ConstructorCallTransactionResponse; import io.hotmoka.beans.responses.ConstructorCallTransactionSuccessfulResponse; -import io.hotmoka.beans.responses.JarStoreTransactionFailedResponse; import io.hotmoka.beans.responses.MethodCallTransactionExceptionResponse; import io.hotmoka.beans.responses.MethodCallTransactionFailedResponse; import io.hotmoka.beans.responses.MethodCallTransactionResponse; @@ -173,7 +173,7 @@ else if (response instanceof ConstructorCallTransactionFailedResponse cctfr) */ private TransactionReference getOutcomeAt(JarStoreTransactionResponse response, TransactionReference reference) throws TransactionException { if (response instanceof JarStoreTransactionFailedResponse jstfr) - throw new TransactionException(jstfr.classNameOfCause, jstfr.messageOfCause, ""); + throw new TransactionException(jstfr.getClassNameOfCause(), jstfr.getMessageOfCause(), ""); else return reference; } diff --git a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/internal/TrieOfResponses.java b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/internal/TrieOfResponses.java index cb18cc867..8d6fbe264 100644 --- a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/internal/TrieOfResponses.java +++ b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/internal/TrieOfResponses.java @@ -25,11 +25,11 @@ import io.hotmoka.beans.TransactionResponses; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.responses.TransactionResponseWithInstrumentedJar; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.marshalling.BeanUnmarshallingContext; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.crypto.HashingAlgorithms; import io.hotmoka.crypto.api.Hasher; import io.hotmoka.patricia.PatriciaTries; @@ -133,19 +133,15 @@ private TransactionResponse readTransformation(TransactionResponse response) { } private TransactionResponse replaceJar(TransactionResponseWithInstrumentedJar response, byte[] newJar) { - if (response instanceof JarStoreTransactionSuccessfulResponse) { - var jstsr = (JarStoreTransactionSuccessfulResponse) response; - return new JarStoreTransactionSuccessfulResponse + if (response instanceof JarStoreTransactionSuccessfulResponse jstsr) + return TransactionResponses.jarStoreSuccessful (newJar, jstsr.getDependencies(), jstsr.getVerificationVersion(), jstsr.getUpdates(), jstsr.getGasConsumedForCPU(), jstsr.getGasConsumedForRAM(), jstsr.getGasConsumedForStorage()); - } - else if (response instanceof JarStoreInitialTransactionResponse) { - var jsitr = (JarStoreInitialTransactionResponse) response; + else if (response instanceof JarStoreInitialTransactionResponse jsitr) return TransactionResponses.jarStoreInitial(newJar, jsitr.getDependencies(), jsitr.getVerificationVersion()); - } else { - logger.log(Level.SEVERE, "unexpected response containing jar, of class " + response.getClass().getName()); - return (TransactionResponse) response; + logger.log(Level.SEVERE, "Unexpected response containing jar, of class " + response.getClass().getName()); + return response; } } diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetwork.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetwork.java index 7fbff6158..0b2cfb353 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetwork.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetwork.java @@ -44,6 +44,7 @@ import io.hotmoka.beans.api.requests.SignedTransactionRequest; import io.hotmoka.beans.api.requests.TransactionRequest; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.types.ClassType; @@ -54,7 +55,6 @@ import io.hotmoka.beans.api.values.StringValue; import io.hotmoka.beans.requests.InstanceMethodCallTransactionRequest; import io.hotmoka.beans.requests.StaticMethodCallTransactionRequest; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.crypto.SignatureAlgorithms; import io.hotmoka.crypto.api.SignatureAlgorithm; import io.hotmoka.crypto.internal.ED25519; diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetworkWS.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetworkWS.java index ceb12adce..47eb85645 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetworkWS.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/NodeFromNetworkWS.java @@ -45,6 +45,7 @@ import io.hotmoka.beans.api.requests.SignedTransactionRequest; import io.hotmoka.beans.api.requests.TransactionRequest; import io.hotmoka.beans.api.responses.JarStoreInitialTransactionResponse; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.types.ClassType; @@ -55,7 +56,6 @@ import io.hotmoka.beans.api.values.StringValue; import io.hotmoka.beans.requests.InstanceMethodCallTransactionRequest; import io.hotmoka.beans.requests.StaticMethodCallTransactionRequest; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.crypto.SignatureAlgorithms; import io.hotmoka.crypto.api.SignatureAlgorithm; import io.hotmoka.network.values.TransactionReferenceModel; diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/errors/Repeated.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/errors/Repeated.java index 885bc002c..577c5abec 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/errors/Repeated.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/errors/Repeated.java @@ -33,11 +33,11 @@ import io.hotmoka.beans.MethodSignatures; import io.hotmoka.beans.TransactionRequests; import io.hotmoka.beans.api.requests.SignedTransactionRequest; +import io.hotmoka.beans.api.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.beans.api.responses.TransactionResponse; import io.hotmoka.beans.api.transactions.TransactionReference; import io.hotmoka.beans.api.values.BigIntegerValue; import io.hotmoka.beans.requests.InstanceMethodCallTransactionRequest; -import io.hotmoka.beans.responses.JarStoreTransactionSuccessfulResponse; import io.hotmoka.crypto.api.Signer; import io.hotmoka.node.api.CodeExecutionException; import io.hotmoka.node.api.TransactionException;