Skip to content

Commit

Permalink
Finished the reorganization of the requests and responses for jar ins…
Browse files Browse the repository at this point in the history
…tallation
  • Loading branch information
spoto committed Jan 19, 2024
1 parent f1712ed commit 4bc5cd2
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Update> 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<TransactionReference> dependencies, long verificationToolVersion, Stream<Update> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<Update> updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage, BigInteger gasConsumedForPenalty) {
public JarStoreTransactionFailedResponseImpl(String classNameOfCause, String messageOfCause, Stream<Update> updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage, BigInteger gasConsumedForPenalty) {
super(updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage);

this.classNameOfCause = Objects.requireNonNull(classNameOfCause, "classNameOfCause cannot be null");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -126,14 +124,14 @@ 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<Update> updates = Stream.of(context.readLengthAndArray(Updates::from, Update[]::new));
var gasConsumedForCPU = context.readBigInteger();
var gasConsumedForRAM = context.readBigInteger();
var gasConsumedForStorage = context.readBigInteger();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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<TransactionReference> dependencies, long verificationToolVersion, Stream<Update> updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage) {
public JarStoreTransactionSuccessfulResponseImpl(byte[] instrumentedJar, Stream<TransactionReference> dependencies, long verificationToolVersion, Stream<Update> updates, BigInteger gasConsumedForCPU, BigInteger gasConsumedForRAM, BigInteger gasConsumedForStorage) {
super(updates, gasConsumedForCPU, gasConsumedForRAM, gasConsumedForStorage);

this.instrumentedJar = instrumentedJar.clone();
Expand All @@ -93,7 +92,7 @@ public Stream<TransactionReference> 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);
}

Expand Down Expand Up @@ -128,15 +127,15 @@ 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<Update> updates = Stream.of(context.readLengthAndArray(Updates::from, Update[]::new));
var gasConsumedForCPU = context.readBigInteger();
var gasConsumedForRAM = context.readBigInteger();
var gasConsumedForStorage = context.readBigInteger();
var verificationToolVersion = context.readLong();
byte[] instrumentedJar = context.readLengthAndBytes("Jar length mismatch in response");
Stream<TransactionReference> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 4bc5cd2

Please sign in to comment.