Skip to content

Commit

Permalink
Reorganized all requests
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Jan 20, 2024
1 parent a0c2a89 commit 87952f8
Show file tree
Hide file tree
Showing 61 changed files with 643 additions and 366 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2021 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.requests;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.values.StorageReference;

/**
* A request for calling an instance method of a storage object in a node.
*/
@Immutable
public interface AbstractInstanceMethodCallTransactionRequest extends MethodCallTransactionRequest {

/**
* Yields the receiver of the call.
*
* @return the receiver of the call
*/
StorageReference getReceiver();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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.requests;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.responses.MethodCallTransactionResponse;

/**
* A request for calling an instance method of a storage object in a node.
*/
@Immutable
public interface InstanceMethodCallTransactionRequest extends AbstractInstanceMethodCallTransactionRequest, SignedTransactionRequest<MethodCallTransactionResponse> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
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.requests;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.responses.MethodCallTransactionResponse;

/**
* A request for calling an instance method of a storage object in a node.
* This request is not signed, hence it is only used for calls started by the same
* node. Users cannot run a transaction from this request.
*/
@Immutable
public interface InstanceSystemMethodCallTransactionRequest extends AbstractInstanceMethodCallTransactionRequest, SystemTransactionRequest<MethodCallTransactionResponse> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
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.requests;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.responses.MethodCallTransactionResponse;
import io.hotmoka.beans.api.signatures.MethodSignature;

/**
* A request for calling a method in a node.
*/
@Immutable
public interface MethodCallTransactionRequest extends CodeExecutionTransactionRequest<MethodCallTransactionResponse> {

@Override
MethodSignature getStaticTarget();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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.requests;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.responses.MethodCallTransactionResponse;

/**
* A request for calling a static method of a storage class in a node.
*/
@Immutable
public interface StaticMethodCallTransactionRequest extends MethodCallTransactionRequest, SignedTransactionRequest<MethodCallTransactionResponse> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
import io.hotmoka.beans.api.requests.ConstructorCallTransactionRequest;
import io.hotmoka.beans.api.requests.GameteCreationTransactionRequest;
import io.hotmoka.beans.api.requests.InitializationTransactionRequest;
import io.hotmoka.beans.api.requests.InstanceMethodCallTransactionRequest;
import io.hotmoka.beans.api.requests.InstanceSystemMethodCallTransactionRequest;
import io.hotmoka.beans.api.requests.JarStoreInitialTransactionRequest;
import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.beans.api.requests.StaticMethodCallTransactionRequest;
import io.hotmoka.beans.api.requests.TransactionRequest;
import io.hotmoka.beans.api.signatures.ConstructorSignature;
import io.hotmoka.beans.api.signatures.MethodSignature;
import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.beans.api.values.StorageValue;
Expand All @@ -37,8 +41,11 @@
import io.hotmoka.beans.internal.requests.ConstructorCallTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.GameteCreationTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.InitializationTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.InstanceMethodCallTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.InstanceSystemMethodCallTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.JarStoreInitialTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.JarStoreTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.StaticMethodCallTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.TransactionRequestImpl;
import io.hotmoka.crypto.api.Signer;
import io.hotmoka.marshalling.api.UnmarshallingContext;
Expand Down Expand Up @@ -164,6 +171,135 @@ public static ConstructorCallTransactionRequest constructorCall(Signer<? super C
return new ConstructorCallTransactionRequestImpl(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, constructor, actuals);
}

/**
* Yields a transaction request to call an instance method in a node.
*
* @param signer the signer of the request
* @param caller the externally owned caller contract that pays for the transaction
* @param nonce the nonce used for transaction ordering and to forbid transaction replay; it is relative to the {@code caller}
* @param chainId the chain identifier where this request can be executed, to forbid transaction replay across chains
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param gasPrice the coins payed for each unit of gas consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param receiver the receiver of the call
* @param actuals the actual arguments passed to the method
* @throws SignatureException if the signer cannot sign the request
* @throws InvalidKeyException if the signer uses an invalid private key
* @return the request
*/
public static InstanceMethodCallTransactionRequest instanceMethodCall(Signer<? super InstanceMethodCallTransactionRequest> signer, StorageReference caller, BigInteger nonce, String chainId, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) throws InvalidKeyException, SignatureException {
return new InstanceMethodCallTransactionRequestImpl(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, receiver, actuals);
}

/**
* Yields a transaction request to call an instance method in a node.
*
* @param signature the signature of the request
* @param caller the externally owned caller contract that pays for the transaction
* @param nonce the nonce used for transaction ordering and to forbid transaction replay; it is relative to the {@code caller}
* @param chainId the chain identifier where this request can be executed, to forbid transaction replay across chains; this can be {@code null}
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param gasPrice the coins payed for each unit of gas consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param receiver the receiver of the call
* @param actuals the actual arguments passed to the method
* @return the request
*/
public static InstanceMethodCallTransactionRequest instanceMethodCall(byte[] signature, StorageReference caller, BigInteger nonce, String chainId, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) {
return new InstanceMethodCallTransactionRequestImpl(signature, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, receiver, actuals);
}

/**
* Yields a transaction request to call an instance method in a node, that is expected to be annotated as {@code @@View}.
* It fixes the signature to a missing signature, the nonce to zero, the chain identifier
* to the empty string and the gas price to zero. None of them is used for a view transaction.
*
* @param caller the externally owned caller contract that pays for the transaction
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param receiver the receiver of the call
* @param actuals the actual arguments passed to the method
* @return the request
*/
public static InstanceMethodCallTransactionRequest instanceViewMethodCall(StorageReference caller, BigInteger gasLimit, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) {
return new InstanceMethodCallTransactionRequestImpl(caller, gasLimit, classpath, method, receiver, actuals);
}

/**
* Yields a transaction request to call an instance method. It is not signed,
* hence it is only used for calls started by the same node.
* Users cannot run a transaction from this request.
*
* @param caller the externally owned caller contract that pays for the transaction
* @param nonce the nonce used for transaction ordering and to forbid transaction replay; it is relative to the {@code caller}
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param receiver the receiver of the call
* @param actuals the actual arguments passed to the method
* @return the request
*/
public static InstanceSystemMethodCallTransactionRequest instanceSystemMethodCall(StorageReference caller, BigInteger nonce, BigInteger gasLimit, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) {
return new InstanceSystemMethodCallTransactionRequestImpl(caller, nonce, gasLimit, classpath, method, receiver, actuals);
}

/**
* Yields a transaction request to call a static method in a node.
*
* @param signature the signature of the request
* @param caller the externally owned caller contract that pays for the transaction
* @param nonce the nonce used for transaction ordering and to forbid transaction replay; it is relative to the {@code caller}
* @param chainId the chain identifier where this request can be executed, to forbid transaction replay across chains; this can be {@code null}
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param gasPrice the coins payed for each unit of gas consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param actuals the actual arguments passed to the method
* @return the request
*/
public static StaticMethodCallTransactionRequest staticMethodCall(byte[] signature, StorageReference caller, BigInteger nonce, String chainId, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageValue... actuals) {
return new StaticMethodCallTransactionRequestImpl(signature, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, actuals);
}

/**
* Yields a transaction request to call a static method in a node.
*
* @param signer the signer of the request
* @param caller the externally owned caller contract that pays for the transaction
* @param nonce the nonce used for transaction ordering and to forbid transaction replay; it is relative to the {@code caller}
* @param chainId the chain identifier where this request can be executed, to forbid transaction replay across chains
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param gasPrice the coins payed for each unit of gas consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param actuals the actual arguments passed to the method
* @return the request
* @throws SignatureException if the signer cannot sign the request
* @throws InvalidKeyException if the signer uses an invalid private key
*/
public static StaticMethodCallTransactionRequest staticMethodCall(Signer<? super StaticMethodCallTransactionRequest> signer, StorageReference caller, BigInteger nonce, String chainId, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageValue... actuals) throws InvalidKeyException, SignatureException {
return new StaticMethodCallTransactionRequestImpl(signer, caller, nonce, chainId, gasLimit, gasPrice, classpath, method, actuals);
}

/**
* Yields a transaction request to call a static method in a node, that is expected to be annotated as {@code @@View}.
* It fixes the signature to a missing signature, the nonce to zero, the chain identifier
* to the empty string and the gas price to zero. None of them is used for a view transaction.
*
* @param caller the externally owned caller contract that pays for the transaction
* @param gasLimit the maximal amount of gas that can be consumed by the transaction
* @param classpath the class path where the {@code caller} can be interpreted and the code must be executed
* @param method the method that must be called
* @param actuals the actual arguments passed to the method
* @return the request
*/
public static StaticMethodCallTransactionRequest staticViewMethodCall(StorageReference caller, BigInteger gasLimit, TransactionReference classpath, MethodSignature method, StorageValue... actuals) {
return new StaticMethodCallTransactionRequestImpl(caller, gasLimit, classpath, method, actuals);
}

/**
* Yields a transaction request unmarshalled from the given context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
limitations under the License.
*/

package io.hotmoka.beans.requests;
package io.hotmoka.beans.internal.requests;

import java.io.IOException;
import java.math.BigInteger;
import java.util.Objects;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.requests.AbstractInstanceMethodCallTransactionRequest;
import io.hotmoka.beans.api.signatures.MethodSignature;
import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.beans.api.values.StorageReference;
Expand All @@ -31,12 +32,12 @@
* A request for calling an instance method of a storage object in a node.
*/
@Immutable
public abstract class AbstractInstanceMethodCallTransactionRequest extends MethodCallTransactionRequest {
public abstract class AbstractInstanceMethodCallTransactionRequestImpl extends MethodCallTransactionRequestImpl implements AbstractInstanceMethodCallTransactionRequest {

/**
* The receiver of the call.
*/
public final StorageReference receiver;
private final StorageReference receiver;

/**
* Builds the transaction request.
Expand All @@ -50,12 +51,21 @@ public abstract class AbstractInstanceMethodCallTransactionRequest extends Metho
* @param receiver the receiver of the call
* @param actuals the actual arguments passed to the method
*/
protected AbstractInstanceMethodCallTransactionRequest(StorageReference caller, BigInteger nonce, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) {
protected AbstractInstanceMethodCallTransactionRequestImpl(StorageReference caller, BigInteger nonce, BigInteger gasLimit, BigInteger gasPrice, TransactionReference classpath, MethodSignature method, StorageReference receiver, StorageValue... actuals) {
super(caller, nonce, gasLimit, gasPrice, classpath, method, actuals);

this.receiver = Objects.requireNonNull(receiver, "receiver cannot be null");
}

/**
* Yields the receiver of the call.
*
* @return the receiver of the call
*/
public StorageReference getReceiver() {
return receiver;
}

@Override
public String toString() {
return super.toString()
Expand All @@ -64,7 +74,7 @@ public String toString() {

@Override
public boolean equals(Object other) {
return other instanceof AbstractInstanceMethodCallTransactionRequest aimctr && super.equals(other) && receiver.equals(aimctr.receiver);
return other instanceof AbstractInstanceMethodCallTransactionRequestImpl aimctr && super.equals(other) && receiver.equals(aimctr.receiver);
}

@Override
Expand Down
Loading

0 comments on commit 87952f8

Please sign in to comment.