Skip to content

Commit

Permalink
Introduced the NodeException for the Hotmoka nodes methods
Browse files Browse the repository at this point in the history
To be extended to most of its methods
  • Loading branch information
spoto committed Mar 31, 2024
1 parent 46b5440 commit 7bba9e7
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand Down Expand Up @@ -58,10 +59,11 @@ public interface AccountCreationHelper {
* @throws CodeExecutionException if some transaction generated an exception
* @throws InvalidKeyException if the key is invalid
* @throws SignatureException if some signature failed
* @throws NodeException if the node is not able to perform the operation
*/
StorageReference paidByFaucet(SignatureAlgorithm signatureAlgorithm, PublicKey publicKey,
BigInteger balance, BigInteger balanceRed, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NodeException;

/**
* Creates a new account by letting another account pay.
Expand All @@ -84,13 +86,14 @@ StorageReference paidByFaucet(SignatureAlgorithm signatureAlgorithm, PublicKey p
* @throws SignatureException if some signature failed
* @throws NoSuchAlgorithmException if the payer uses an unknown signature algorithm
* @throws ClassNotFoundException if the class of the payer is unknown
* @throws NodeException if the node is not able to perform the operation
*/
StorageReference paidBy(StorageReference payer, KeyPair keysOfPayer,
SignatureAlgorithm signatureAlgorithm, PublicKey publicKey, BigInteger balance, BigInteger balanceRed,
boolean addToLedger,
Consumer<BigInteger> gasHandler,
Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException;

/**
* Creates a new Tendermint validator by letting the faucet pay.
Expand All @@ -106,10 +109,11 @@ StorageReference paidBy(StorageReference payer, KeyPair keysOfPayer,
* @throws InvalidKeyException if the key is invalid
* @throws SignatureException if some signature failed
* @throws NoSuchAlgorithmException if the faucet uses an unknown signature algorithm
* @throws NodeException if the node is not able to perform the operation
*/
StorageReference tendermintValidatorPaidByFaucet(PublicKey publicKey,
BigInteger balance, BigInteger balanceRed, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NodeException;

/**
* Creates a new Tendermint validator by letting another account pay.
Expand All @@ -129,9 +133,10 @@ StorageReference tendermintValidatorPaidByFaucet(PublicKey publicKey,
* @throws SignatureException if some signature failed
* @throws NoSuchAlgorithmException if the payer uses an unknown signature algorithm
* @throws ClassNotFoundException if the class of the payer is unknown
* @throws NodeException if the node is not able to perform the operation
*/
StorageReference tendermintValidatorPaidBy(StorageReference payer, KeyPair keysOfPayer, PublicKey publicKey, BigInteger balance, BigInteger balanceRed,
Consumer<BigInteger> gasHandler,
Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.hotmoka.annotations.ThreadSafe;
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand All @@ -39,7 +40,8 @@ public interface NonceHelper {
* @throws TransactionRejectedException if some transaction was rejected
* @throws TransactionException if some transaction failed
* @throws CodeExecutionException if some transaction generated an exception
* @throws NoSuchElementException if the class of the account cannot be determined
* @throws NoSuchElementException if the {@code account} cannot be found
* @throws NodeException if the node is not able to perform the operation
*/
BigInteger getNonceOf(StorageReference account) throws TransactionRejectedException, NoSuchElementException, TransactionException, CodeExecutionException;
BigInteger getNonceOf(StorageReference account) throws TransactionRejectedException, NoSuchElementException, TransactionException, CodeExecutionException, NodeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.hotmoka.beans.api.requests.TransactionRequest;
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand All @@ -53,11 +54,12 @@ public interface SendCoinsHelper {
* @throws InvalidKeyException if the key is invalid
* @throws SignatureException if some signature failed
* @throws NoSuchAlgorithmException if the sender uses an unknown signature algorithm
* @throws NodeException if the node is not able to perform the operation
*/
void sendFromPayer(StorageReference payer, KeyPair keysOfPayer,
StorageReference destination, BigInteger amount, BigInteger amountRed,
Consumer<BigInteger> gasHandler, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException;

/**
* Sends coins to an account, by letting the faucet of the node pay.
Expand All @@ -74,8 +76,9 @@ void sendFromPayer(StorageReference payer, KeyPair keysOfPayer,
* @throws InvalidKeyException if the key is invalid
* @throws SignatureException if some signature failed
* @throws NoSuchAlgorithmException if the faucet uses an unknown signature algorithm
* @throws NodeException if the node is not able to perform the operation
*/
void sendFromFaucet(StorageReference destination, BigInteger amount, BigInteger amountRed,
Consumer<BigInteger> gasHandler, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException;
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand All @@ -41,6 +42,7 @@ public interface SignatureHelper {
* @throws CodeExecutionException if some transaction generated an exception
* @throws ClassNotFoundException if some class of the Takamaka runtime cannot be loaded
* @throws NoSuchAlgorithmException if the sender uses an unknown signature algorithm
* @throws NodeException if the node is not able to perform the operation
*/
SignatureAlgorithm signatureAlgorithmFor(StorageReference account) throws NoSuchAlgorithmException, TransactionRejectedException, TransactionException, CodeExecutionException, ClassNotFoundException;
SignatureAlgorithm signatureAlgorithmFor(StorageReference account) throws NoSuchAlgorithmException, TransactionRejectedException, TransactionException, CodeExecutionException, ClassNotFoundException, NodeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.hotmoka.helpers.internal.AccountsNodeImpl;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.takamaka.code.constants.Constants;
Expand Down Expand Up @@ -60,8 +61,9 @@ private AccountsNodes() {}
* @throws InvalidKeyException if some key used for signing transactions is invalid
* @throws NoSuchAlgorithmException if the payer uses an unknown signature algorithm
* @throws ClassNotFoundException if the class of the payer cannot be determined
* @throws NodeException if the node is not able to perform the operation
*/
public static AccountsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchElementException, ClassNotFoundException {
public static AccountsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchElementException, ClassNotFoundException, NodeException {
return new AccountsNodeImpl(parent, payer, privateKeyOfPayer, Constants.EXTERNALLY_OWNED_ACCOUNTS_NAME, parent.getTakamakaCode(), false, funds);
}

Expand All @@ -86,8 +88,9 @@ public static AccountsNode of(Node parent, StorageReference payer, PrivateKey pr
* @throws InvalidKeyException if some key used for signing transactions is invalid
* @throws NoSuchAlgorithmException if the signature algorithm of {@code parent} is not available
* @throws ClassNotFoundException if the class of the payer cannot be determined
* @throws NodeException if the node is not able to perform the operation
*/
public static AccountsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, String containerClassName, TransactionReference classpath, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException {
public static AccountsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, String containerClassName, TransactionReference classpath, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException {
return new AccountsNodeImpl(parent, payer, privateKeyOfPayer, containerClassName, classpath, false, funds);
}

Expand All @@ -109,8 +112,9 @@ public static AccountsNode of(Node parent, StorageReference payer, PrivateKey pr
* @throws InvalidKeyException if some key used for signing transactions is invalid
* @throws NoSuchAlgorithmException if the signature algorithm of {@code parent} is not available
* @throws ClassNotFoundException if the class of the payer cannot be determined
* @throws NodeException if the node is not able to perform the operation
*/
public static AccountsNode ofGreenRed(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchElementException, ClassNotFoundException {
public static AccountsNode ofGreenRed(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchElementException, ClassNotFoundException, NodeException {
return new AccountsNodeImpl(parent, payer, privateKeyOfPayer, Constants.EXTERNALLY_OWNED_ACCOUNTS_NAME, parent.getTakamakaCode(), true, funds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.hotmoka.helpers.internal.JarsNodeImpl;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand Down Expand Up @@ -60,8 +61,9 @@ private JarsNodes() {}
* @throws InvalidKeyException if some key used for signing transactions is invalid
* @throws NoSuchAlgorithmException if the signature algorithm of {@code parent} is not available
* @throws ClassNotFoundException if the class of the payer cannot be determined
* @throws NodeException if the node is not able to perform the operation
*/
public static JarsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, Path... jars) throws TransactionRejectedException, TransactionException, CodeExecutionException, IOException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException {
public static JarsNode of(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, Path... jars) throws TransactionRejectedException, TransactionException, CodeExecutionException, IOException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException {
return new JarsNodeImpl(parent, payer, privateKeyOfPayer, jars);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.SignatureException;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

import io.hotmoka.beans.ConstructorSignatures;
Expand Down Expand Up @@ -49,6 +50,7 @@
import io.hotmoka.helpers.api.NonceHelper;
import io.hotmoka.node.api.CodeExecutionException;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;

Expand Down Expand Up @@ -85,7 +87,7 @@ public AccountCreationHelperImpl(Node node) throws TransactionRejectedException,
@Override
public StorageReference paidByFaucet(SignatureAlgorithm signatureAlgorithm, PublicKey publicKey,
BigInteger balance, BigInteger balanceRed, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException {
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchElementException, NodeException {

var gamete = (StorageReference) node.runInstanceMethodCallTransaction(TransactionRequests.instanceViewMethodCall
(manifest, _100_000, takamakaCode, MethodSignatures.GET_GAMETE, manifest));
Expand Down Expand Up @@ -128,7 +130,7 @@ public StorageReference paidBy(StorageReference payer, KeyPair keysOfPayer,
boolean addToLedger,
Consumer<BigInteger> gasHandler,
Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException {
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NoSuchElementException, NodeException {

ClassType eoaType;
String signature = signatureAlgorithm.getName();
Expand Down Expand Up @@ -202,7 +204,7 @@ public StorageReference paidBy(StorageReference payer, KeyPair keysOfPayer,
@Override
public StorageReference tendermintValidatorPaidByFaucet(PublicKey publicKey,
BigInteger balance, BigInteger balanceRed, Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException {
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, NoSuchElementException, NodeException {

var gamete = (StorageReference) node.runInstanceMethodCallTransaction(TransactionRequests.instanceViewMethodCall
(manifest, _100_000, takamakaCode, MethodSignatures.GET_GAMETE, manifest));
Expand All @@ -229,7 +231,7 @@ public StorageReference tendermintValidatorPaidByFaucet(PublicKey publicKey,
public StorageReference tendermintValidatorPaidBy(StorageReference payer, KeyPair keysOfPayer, PublicKey publicKey, BigInteger balance, BigInteger balanceRed,
Consumer<BigInteger> gasHandler,
Consumer<TransactionRequest<?>[]> requestsHandler)
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException {
throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NoSuchElementException, NodeException {

var signatureForPayer = SignatureHelpers.of(node).signatureAlgorithmFor(payer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import io.hotmoka.node.api.CodeSupplier;
import io.hotmoka.node.api.JarSupplier;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.Subscription;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
Expand Down Expand Up @@ -113,8 +114,9 @@ public class AccountsNodeImpl implements AccountsNode {
* @throws InvalidKeyException if some key used for signing transactions is invalid
* @throws NoSuchAlgorithmException if the payer uses an unknown signature algorithm
* @throws ClassNotFoundException if the class of the payer cannot be determined
* @throws NodeException if the node is not able to perform the operation
*/
public AccountsNodeImpl(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, String containerClassName, TransactionReference classpath, boolean greenRed, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException {
public AccountsNodeImpl(Node parent, StorageReference payer, PrivateKey privateKeyOfPayer, String containerClassName, TransactionReference classpath, boolean greenRed, BigInteger... funds) throws TransactionRejectedException, TransactionException, CodeExecutionException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, ClassNotFoundException, NodeException {
this.parent = parent;
this.accounts = new StorageReference[greenRed ? funds.length / 2 : funds.length];
this.privateKeys = new PrivateKey[accounts.length];
Expand Down Expand Up @@ -230,12 +232,12 @@ public TransactionReference getTakamakaCode() {
}

@Override
public NodeInfo getNodeInfo() {
public NodeInfo getNodeInfo() throws NodeException {
return parent.getNodeInfo();
}

@Override
public ClassTag getClassTag(StorageReference reference) throws NoSuchElementException {
public ClassTag getClassTag(StorageReference reference) throws NoSuchElementException, NodeException {
return parent.getClassTag(reference);
}

Expand Down
Loading

0 comments on commit 7bba9e7

Please sign in to comment.