From 6abbeb988ffa211a073d06db68d686ea5872391a Mon Sep 17 00:00:00 2001 From: Fausto Spoto Date: Fri, 29 Dec 2023 20:08:40 +0100 Subject: [PATCH] Reorganized and refactored the io-hotmoka-node-remote module --- .../local/internal/LocalNodeConfigImpl.java | 11 +- .../pom.xml | 9 +- .../java/io/hotmoka/remote/RemoteNode.java | 27 +++ .../io/hotmoka/remote/RemoteNodeConfig.java | 61 ++++++ .../remote/RemoteNodeConfigBuilder.java | 48 +++++ .../remote/RemoteNodeConfigBuilders.java | 65 ++++++ .../java/io/hotmoka/remote/RemoteNodes.java | 15 +- .../remote/internal/AbstractRemoteNode.java | 2 +- .../remote/internal/RemoteNodeConfigImpl.java | 194 ++++++++++++++++++ .../internal/http/HTTPRemoteNodeImpl.java | 2 +- .../http/client/RestClientService.java | 0 .../websockets/WebSocketsRemoteNodeImpl.java | 0 .../internal/websockets/client/Message.java | 0 .../websockets/client/ResultHandler.java | 0 .../websockets/client/Subscription.java | 0 .../websockets/client/WebSocketClient.java | 0 .../websockets/client/stomp/StompCommand.java | 0 .../websockets/client/stomp/StompHeaders.java | 0 .../client/stomp/StompMessageHelper.java | 2 +- .../src/main/java/module-info.java | 1 + .../io/hotmoka/remote/RemoteNodeConfig.java | 87 -------- io-hotmoka-tests/pom.xml | 2 +- .../java/io/hotmoka/tests/HotmokaTest.java | 14 +- .../io/hotmoka/tests/NodeFromNetwork.java | 101 +++++---- .../io/hotmoka/tests/NodeFromNetworkWS.java | 99 +++++---- io-hotmoka-tools/pom.xml | 2 +- .../tools/internal/moka/AbstractCommand.java | 3 +- .../hotmoka/tools/internal/moka/BindKey.java | 4 +- .../tools/internal/moka/BuyValidation.java | 4 +- .../io/hotmoka/tools/internal/moka/Call.java | 4 +- .../hotmoka/tools/internal/moka/Create.java | 4 +- .../tools/internal/moka/CreateAccount.java | 4 +- .../hotmoka/tools/internal/moka/Faucet.java | 4 +- .../io/hotmoka/tools/internal/moka/Info.java | 4 +- .../hotmoka/tools/internal/moka/Install.java | 5 +- .../tools/internal/moka/RotateKey.java | 4 +- .../tools/internal/moka/SellValidation.java | 4 +- .../io/hotmoka/tools/internal/moka/Send.java | 4 +- .../tools/internal/moka/ShowAccount.java | 4 +- .../io/hotmoka/tools/internal/moka/State.java | 4 +- pom.xml | 7 +- 41 files changed, 556 insertions(+), 249 deletions(-) rename {io-hotmoka-remote => io-hotmoka-node-remote}/pom.xml (88%) create mode 100644 io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNode.java create mode 100644 io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java create mode 100644 io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilder.java create mode 100644 io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilders.java rename io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNode.java => io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodes.java (73%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java (99%) create mode 100644 io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/RemoteNodeConfigImpl.java rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java (99%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/http/client/RestClientService.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/WebSocketsRemoteNodeImpl.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/Message.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/ResultHandler.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/Subscription.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/WebSocketClient.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompCommand.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompHeaders.java (100%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java (97%) rename {io-hotmoka-remote => io-hotmoka-node-remote}/src/main/java/module-info.java (96%) delete mode 100644 io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/LocalNodeConfigImpl.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/LocalNodeConfigImpl.java index 750490db3..b3f19be05 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/LocalNodeConfigImpl.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/LocalNodeConfigImpl.java @@ -30,7 +30,7 @@ import io.hotmoka.node.local.api.LocalNodeConfigBuilder; /** - * The configuration of a node. + * The configuration of a local node. * * @param the concrete type of the configuration * @param the concrete type of the builder @@ -153,19 +153,22 @@ public String toToml() { @Override public boolean equals(Object other) { - if (other != null && getClass() == other.getClass()) { - var otherConfig = (LocalNodeConfigImpl) other; + if (other instanceof LocalNodeConfigImpl otherConfig && getClass() == other.getClass()) return dir.equals(otherConfig.dir) && maxPollingAttempts == otherConfig.maxPollingAttempts && pollingDelay == otherConfig.pollingDelay && requestCacheSize == otherConfig.requestCacheSize && responseCacheSize == otherConfig.responseCacheSize && maxGasPerViewTransaction.equals(otherConfig.maxGasPerViewTransaction); - } else return false; } + @Override + public int hashCode() { + return dir.hashCode() ^ Long.hashCode(maxPollingAttempts) ^ maxGasPerViewTransaction.hashCode(); + } + @Override public String toString() { return toToml(); diff --git a/io-hotmoka-remote/pom.xml b/io-hotmoka-node-remote/pom.xml similarity index 88% rename from io-hotmoka-remote/pom.xml rename to io-hotmoka-node-remote/pom.xml index c6bd6e02c..f00b8d8df 100644 --- a/io-hotmoka-remote/pom.xml +++ b/io-hotmoka-node-remote/pom.xml @@ -10,9 +10,9 @@ 4.0.0 - io-hotmoka-remote + io-hotmoka-node-remote jar - io-hotmoka-remote + io-hotmoka-node-remote ${hotmoka.version} @@ -36,6 +36,11 @@ io-hotmoka-ws-client ${hotmoka.version} + + io.hotmoka + toml4j + 0.7.3 + com.google.code.gson gson diff --git a/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNode.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNode.java new file mode 100644 index 000000000..719aacf10 --- /dev/null +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNode.java @@ -0,0 +1,27 @@ +/* +Copyright 2021 Dinu Berinde and 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.remote; + +import io.hotmoka.annotations.ThreadSafe; +import io.hotmoka.node.api.Node; + +/** + * A node that forwards its calls to a remote network service. + */ +@ThreadSafe +public interface RemoteNode extends Node { +} \ No newline at end of file diff --git a/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java new file mode 100644 index 000000000..8a9b75a75 --- /dev/null +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java @@ -0,0 +1,61 @@ +/* +Copyright 2023 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.remote; + +import io.hotmoka.annotations.Immutable; + +/** + * The configuration of a node that forwards all its calls to a remote network service. + */ +@Immutable +public interface RemoteNodeConfig { + + /** + * Yields the URL of the remote service, without the protocol. This defaults + * to {@code localhost:8080}. + * + * @return the URL + */ + String getURL(); + + /** + * Determines if web sockets should be used for the connection. This defaults to false. + * + * @return true if and only if web sockets should be used for the connection + */ + boolean usesWebSockets(); + + /** + * Yields a TOML representation of this configuration. + * + * @return the TOML representation, as a string + */ + String toToml(); + + @Override + boolean equals(Object other); + + @Override + String toString(); + + /** + * Yields a builder initialized with the information in this object. + * + * @return the builder + */ + RemoteNodeConfigBuilder toBuilder(); +} \ No newline at end of file diff --git a/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilder.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilder.java new file mode 100644 index 000000000..473c2828e --- /dev/null +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilder.java @@ -0,0 +1,48 @@ +/* +Copyright 2023 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.remote; + +/** + * The builder of a configuration object. + */ +public interface RemoteNodeConfigBuilder { + + /** + * Specifies the URL of the remote service, without the protocol. + * The default is {@code localhost:8080}. + * + * @param url the url + * @return this same builder + */ + RemoteNodeConfigBuilder setURL(String url); + + /** + * Sets the use of websockets. + * + * @param usesWebSockets true if and only if websockets should be used + * instead of http connections. This defaults to false + * @return this same builder + */ + RemoteNodeConfigBuilder usesWebSockets(boolean usesWebSockets); + + /** + * Builds the configuration from this builder. + * + * @return the configuration + */ + RemoteNodeConfig build(); +} \ No newline at end of file diff --git a/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilders.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilders.java new file mode 100644 index 000000000..b18d14e8f --- /dev/null +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfigBuilders.java @@ -0,0 +1,65 @@ +/* +Copyright 2023 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.remote; + +import java.io.FileNotFoundException; +import java.nio.file.Path; + +import com.moandjiezana.toml.Toml; + +import io.hotmoka.remote.internal.RemoteNodeConfigImpl.RemoteNodeConfigBuilderImpl; + +/** + * Providers of configuration object builders for a remote node. + */ +public abstract class RemoteNodeConfigBuilders { + + private RemoteNodeConfigBuilders() {} + + /** + * Creates a builder containing default data. + * + * @return the builder + */ + public static RemoteNodeConfigBuilder defaults() { + return new RemoteNodeConfigBuilderImpl(); + } + + /** + * Creates a builder from the given TOML configuration file. + * The resulting builder will contain the information in the file, + * and use defaults for the data not contained in the file. + * + * @param path the path to the TOML file + * @return the builder + * @throws FileNotFoundException if {@code path} cannot be found + */ + public static RemoteNodeConfigBuilder load(Path path) throws FileNotFoundException { + return new RemoteNodeConfigBuilderImpl(path); + } + + /** + * Creates a builder by reading the properties of the given TOML file and + * setting them for the corresponding fields of the builder. + * + * @param toml the file + * @return the builder + */ + public static RemoteNodeConfigBuilder from(Toml toml) { + return new RemoteNodeConfigBuilderImpl(toml); + } +} \ No newline at end of file diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNode.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodes.java similarity index 73% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNode.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodes.java index c1d4c575a..2a92cf7a6 100644 --- a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNode.java +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/RemoteNodes.java @@ -1,5 +1,5 @@ /* -Copyright 2021 Dinu Berinde and Fausto Spoto +Copyright 2023 Fausto Spoto Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,25 +19,26 @@ import java.io.IOException; import io.hotmoka.annotations.ThreadSafe; -import io.hotmoka.node.api.Node; import io.hotmoka.remote.internal.http.HTTPRemoteNodeImpl; import io.hotmoka.remote.internal.websockets.WebSocketsRemoteNodeImpl; /** - * A node that forwards its calls to a remote network service. + * Providers of nodes that forward their calls to a remote network service. */ @ThreadSafe -public interface RemoteNode extends Node { +public abstract class RemoteNodes { - /** + private RemoteNodes() {} + + /** * Yields a remote node with the given configuration. * * @param config the configuration * @return the remote node * @throws IOException */ - static RemoteNode of(RemoteNodeConfig config) throws IOException { + public static RemoteNode of(RemoteNodeConfig config) throws IOException { // there are two implementations: for websockets or for http connections - return config.webSockets ? new WebSocketsRemoteNodeImpl(config) : new HTTPRemoteNodeImpl(config); + return config.usesWebSockets() ? new WebSocketsRemoteNodeImpl(config) : new HTTPRemoteNodeImpl(config); } } \ No newline at end of file diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java similarity index 99% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java index 11fd19d57..950d9646c 100644 --- a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/AbstractRemoteNode.java @@ -89,7 +89,7 @@ public abstract class AbstractRemoteNode extends AbstractNode implements RemoteN protected AbstractRemoteNode(RemoteNodeConfig config) throws IOException { this.config = config; try { - this.webSocketClient = new WebSocketClient("ws://" + config.url + "/node"); + this.webSocketClient = new WebSocketClient("ws://" + config.getURL() + "/node"); } catch (WebSocketException e) { throw new IOException(e); diff --git a/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/RemoteNodeConfigImpl.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/RemoteNodeConfigImpl.java new file mode 100644 index 000000000..0592e74a2 --- /dev/null +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/RemoteNodeConfigImpl.java @@ -0,0 +1,194 @@ +/* +Copyright 2023 Dinu Berinde and 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.remote.internal; + +import java.io.FileNotFoundException; +import java.nio.file.Path; +import java.util.Objects; + +import com.moandjiezana.toml.Toml; + +import io.hotmoka.remote.RemoteNodeConfig; +import io.hotmoka.remote.RemoteNodeConfigBuilder; + +/** + * The configuration of a node that forwards all its calls to a remote network service. + */ +public class RemoteNodeConfigImpl implements RemoteNodeConfig { + + /** + * The URL of the remote service, without the protocol. This defaults + * to {@code localhost:8080}. + */ + public final String url; + + /** + * True if and only if web sockets should be used for the connection. + * This defaults to false. + */ + public final boolean usesWebSockets; + + /** + * Builds the configuration from a builder. + * + * @param builder the builder + */ + private RemoteNodeConfigImpl(RemoteNodeConfigBuilderImpl builder) { + this.url = builder.url; + this.usesWebSockets = builder.usesWebSockets; + } + + @Override + public String getURL() { + return url; + } + + @Override + public boolean usesWebSockets() { + return usesWebSockets; + } + + @Override + public String toToml() { + var sb = new StringBuilder(); + + sb.append("# This is a TOML config file for a remote Hotmoka node.\n"); + sb.append("# For more information about TOML, see https://github.com/toml-lang/toml\n"); + sb.append("# For more information about Hotmoka, see https://www.hotmoka.io\n"); + sb.append("\n"); + sb.append("# the URL of the remote service, without the protocol\n"); + sb.append("url = \"" + url + "\"\n"); + sb.append("\n"); + sb.append("# true if and only if web sockets should be used for the connection\n"); + sb.append("uses_websockets = " + usesWebSockets + "\n"); + + return sb.toString(); + } + + @Override + public RemoteNodeConfigBuilderImpl toBuilder() { + return new RemoteNodeConfigBuilderImpl(this); + } + + @Override + public boolean equals(Object other) { + return other instanceof RemoteNodeConfig rnc && url.equals(rnc.getURL()) && usesWebSockets == rnc.usesWebSockets(); + } + + @Override + public int hashCode() { + return url.hashCode(); + } + + @Override + public String toString() { + return toToml(); + } + + /** + * The builder of a configuration of a remote node. + */ + public static class RemoteNodeConfigBuilderImpl implements RemoteNodeConfigBuilder { + private String url = "localhost:8080"; + + private boolean usesWebSockets; + + /** + * Creates a builder with default values for the properties. + */ + public RemoteNodeConfigBuilderImpl() {} + + /** + * Creates a builder with properties initialized to those of the given configuration object. + * + * @param config the configuration object + */ + private RemoteNodeConfigBuilderImpl(RemoteNodeConfigImpl config) { + setURL(config.url); + usesWebSockets(config.usesWebSockets); + } + + /** + * Creates a builder by reading the properties of the given TOML file and + * setting them for the corresponding fields of the builder. + * + * @param toml the file + */ + public RemoteNodeConfigBuilderImpl(Toml toml) { + var url = toml.getString("url"); + if (url != null) + setURL(url); + + var usesWebSockets = toml.getBoolean("uses_websockets"); + usesWebSockets(usesWebSockets); + } + + /** + * Creates a builder by reading the properties of the given TOML file and sets them for + * the corresponding fields of this builder. + * + * @param toml the file + * @throws FileNotFoundException if the file cannot be found + */ + public RemoteNodeConfigBuilderImpl(Path toml) throws FileNotFoundException { + this(readToml(toml)); + } + + @Override + public RemoteNodeConfigBuilderImpl setURL(String url) { + Objects.requireNonNull(url, "url cannot be null"); + this.url = url; + return this; + } + + @Override + public RemoteNodeConfigBuilderImpl usesWebSockets(boolean usesWebSockets) { + this.usesWebSockets = usesWebSockets; + return this; + } + + /** + * Builds the configuration from this builder. + * + * @return the configuration + */ + public RemoteNodeConfigImpl build() { + return new RemoteNodeConfigImpl(this); + } + + /** + * Loads the TOML file at the given path. + * + * @param path the path + * @return the file + * @throws FileNotFoundException if {@code path} cannot be found + */ + protected static Toml readToml(Path path) throws FileNotFoundException { + try { + return new Toml().read(path.toFile()); + } + catch (RuntimeException e) { + // the toml4j library wraps the FileNotFoundException inside a RuntimeException... + Throwable cause = e.getCause(); + if (cause instanceof FileNotFoundException) + throw (FileNotFoundException) cause; + else + throw e; + } + } + } +} \ No newline at end of file diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java similarity index 99% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java index 756263b1d..eff19416e 100644 --- a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/http/HTTPRemoteNodeImpl.java @@ -88,7 +88,7 @@ public class HTTPRemoteNodeImpl extends AbstractRemoteNode { public HTTPRemoteNodeImpl(RemoteNodeConfig config) throws IOException { super(config); - this.url = "http://" + config.url; + this.url = "http://" + config.getURL(); } @Override diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/http/client/RestClientService.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/http/client/RestClientService.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/http/client/RestClientService.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/http/client/RestClientService.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/WebSocketsRemoteNodeImpl.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/WebSocketsRemoteNodeImpl.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/WebSocketsRemoteNodeImpl.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/WebSocketsRemoteNodeImpl.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Message.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Message.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Message.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Message.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/ResultHandler.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/ResultHandler.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/ResultHandler.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/ResultHandler.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Subscription.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Subscription.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Subscription.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/Subscription.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/WebSocketClient.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/WebSocketClient.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/WebSocketClient.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/WebSocketClient.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompCommand.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompCommand.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompCommand.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompCommand.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompHeaders.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompHeaders.java similarity index 100% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompHeaders.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompHeaders.java diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java similarity index 97% rename from io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java rename to io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java index 5da03e2e6..469924dd7 100644 --- a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java +++ b/io-hotmoka-node-remote/src/main/java/io/hotmoka/remote/internal/websockets/client/stomp/StompMessageHelper.java @@ -21,7 +21,7 @@ import io.hotmoka.remote.internal.websockets.client.Message; /** - * Builder class which builds the STOMP messages by command. The following commands are implemented: + * RemoteNodeConfigBuilderImpl class which builds the STOMP messages by command. The following commands are implemented: *
    *
  • connect - to connect to a webSocket
  • *
  • subscribe - to subscribe to a topic
  • diff --git a/io-hotmoka-remote/src/main/java/module-info.java b/io-hotmoka-node-remote/src/main/java/module-info.java similarity index 96% rename from io-hotmoka-remote/src/main/java/module-info.java rename to io-hotmoka-node-remote/src/main/java/module-info.java index 95cb45a0d..75b3d2979 100644 --- a/io-hotmoka-remote/src/main/java/module-info.java +++ b/io-hotmoka-node-remote/src/main/java/module-info.java @@ -22,5 +22,6 @@ requires io.hotmoka.network; requires io.hotmoka.ws.client; requires com.google.gson; + requires transitive toml4j; requires java.logging; } \ No newline at end of file diff --git a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java b/io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java deleted file mode 100644 index a0147f261..000000000 --- a/io-hotmoka-remote/src/main/java/io/hotmoka/remote/RemoteNodeConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2021 Dinu Berinde and 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.remote; - -/** - * The configuration of a node that forwards all its calls to a remote network service. - */ -public class RemoteNodeConfig { - - /** - * The URL of the remote service, without the protocol. This defaults - * to {@code localhost:8080}. - */ - public final String url; - - /** - * True if and only if web sockets should be used for the connection. - * This defaults to false. - */ - public final boolean webSockets; - - /** - * Builds the configuration from a builder. - * - * @param builder the builder - */ - private RemoteNodeConfig(Builder builder) { - this.url = builder.url; - this.webSockets = builder.webSockets; - } - - /** - * The builder of a configuration of a remote node. - */ - public static class Builder { - private String url = "localhost:8080"; - - private boolean webSockets; - - /** - * Specifies if the URL of the remote service, without the protocol. - * The default is {@code localhost:8080}. - * - * @param url the url - * @return this same builder - */ - public Builder setURL(String url) { - this.url = url; - return this; - } - - /** - * Sets the use of websockets. - * - * @param webSockets true if and only if websockets should be used - * instead of http connections. This defaults to false - * @return this same builder - */ - public Builder setWebSockets(boolean webSockets) { - this.webSockets = webSockets; - return this; - } - - /** - * Builds the configuration from this builder. - * - * @return the configuration - */ - public RemoteNodeConfig build() { - return new RemoteNodeConfig(this); - } - } -} \ No newline at end of file diff --git a/io-hotmoka-tests/pom.xml b/io-hotmoka-tests/pom.xml index b6d5114ca..7f940fa32 100644 --- a/io-hotmoka-tests/pom.xml +++ b/io-hotmoka-tests/pom.xml @@ -88,7 +88,7 @@ io.hotmoka - io-hotmoka-remote + io-hotmoka-node-remote ${hotmoka.version} test diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java index 59bcdb0a7..f07576e2c 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java @@ -84,8 +84,8 @@ import io.hotmoka.node.tendermint.TendermintNodeConfigBuilders; import io.hotmoka.node.tendermint.TendermintNodes; import io.hotmoka.node.tendermint.api.TendermintNode; -import io.hotmoka.remote.RemoteNode; -import io.hotmoka.remote.RemoteNodeConfig; +import io.hotmoka.remote.RemoteNodeConfigBuilders; +import io.hotmoka.remote.RemoteNodes; import io.hotmoka.service.NodeService; import io.hotmoka.service.NodeServiceConfig; import io.hotmoka.testing.AbstractLoggedTests; @@ -291,21 +291,21 @@ private static Node mkRemoteNode(Node exposed) throws IOException { NodeService.of(serviceConfig, exposed); - var remoteNodeConfig = new RemoteNodeConfig.Builder() + var remoteNodeConfig = RemoteNodeConfigBuilders.defaults() // comment for using http - .setWebSockets(true) + .usesWebSockets(true) .setURL("localhost:8080") .build(); - return RemoteNode.of(remoteNodeConfig); + return RemoteNodes.of(remoteNodeConfig); } @SuppressWarnings("unused") private static Node mkRemoteNode(String url) throws IOException { - var remoteNodeConfig = new RemoteNodeConfig.Builder() + var remoteNodeConfig = RemoteNodeConfigBuilders.defaults() //.setWebSockets(true) .setURL(url).build(); - return RemoteNode.of(remoteNodeConfig); + return RemoteNodes.of(remoteNodeConfig); } protected final void setAccounts(BigInteger... coins) throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, TransactionRejectedException, TransactionException, CodeExecutionException, NoSuchElementException, ClassNotFoundException { 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 27c146476..05dd77736 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 @@ -61,8 +61,9 @@ import io.hotmoka.crypto.internal.ED25519; import io.hotmoka.network.values.TransactionReferenceModel; import io.hotmoka.node.api.JarSupplier; -import io.hotmoka.remote.RemoteNode; import io.hotmoka.remote.RemoteNodeConfig; +import io.hotmoka.remote.RemoteNodeConfigBuilders; +import io.hotmoka.remote.RemoteNodes; import io.hotmoka.service.NodeService; import io.hotmoka.service.NodeServiceConfig; import io.hotmoka.verification.VerificationException; @@ -70,7 +71,7 @@ public class NodeFromNetwork extends HotmokaTest { private final ClassType HASH_MAP_TESTS = new ClassType("io.hotmoka.examples.javacollections.HashMapTests"); private final NodeServiceConfig serviceConfig = new NodeServiceConfig.Builder().setPort(8081).setSpringBannerModeOn(false).build(); - private final RemoteNodeConfig remoteNodeconfig = new RemoteNodeConfig.Builder().setURL("localhost:8081").build(); + private final RemoteNodeConfig remoteNodeconfig = RemoteNodeConfigBuilders.defaults().setURL("localhost:8081").build(); @BeforeEach void beforeEach() throws Exception { @@ -83,8 +84,8 @@ void testRemoteGetTakamakaCode() throws Exception { TransactionReference localTakamakaCode = node.getTakamakaCode(); TransactionReference remoteTakamakaCode; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteTakamakaCode = remoteNode.getTakamakaCode(); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remoteTakamakaCode = remote.getTakamakaCode(); } assertEquals(localTakamakaCode, remoteTakamakaCode); @@ -95,8 +96,8 @@ void testRemoteGetTakamakaCode() throws Exception { void testRemoteGetSignatureAlgorithmForRequests() throws Exception { SignatureAlgorithm algo; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - algo = SignatureAlgorithms.of(remoteNode.getNameOfSignatureAlgorithmForRequests()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + algo = SignatureAlgorithms.of(remote.getNameOfSignatureAlgorithmForRequests()); } assertNotNull(algo); @@ -109,8 +110,8 @@ void testRemoteGetClassTag() throws Exception { ClassTag localClassTag = node.getClassTag(account(0)); ClassTag remoteClassTag; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteClassTag = remoteNode.getClassTag(account(0)); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remoteClassTag = remote.getClassTag(account(0)); } assertEquals(localClassTag, remoteClassTag); @@ -119,8 +120,8 @@ void testRemoteGetClassTag() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getClassTag for a non-existing reference") void testRemoteGetClassTagNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteNode.getClassTag(getInexistentStorageReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.getClassTag(getInexistentStorageReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -134,8 +135,8 @@ void testRemoteGetState() throws Exception { Stream localState = node.getState(account(0)); Stream remoteState; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteState = remoteNode.getState(account(0)); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remoteState = remote.getState(account(0)); } assertEquals(localState.collect(Collectors.toSet()), remoteState.collect(Collectors.toSet())); @@ -144,8 +145,8 @@ void testRemoteGetState() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getState for a non-existing reference") void testRemoteGetStateNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteNode.getState(getInexistentStorageReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.getState(getInexistentStorageReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -158,8 +159,8 @@ void testRemoteGetStateNonExisting() { void testRemoteGetRequest() throws Exception { TransactionRequest request; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - request = remoteNode.getRequest(node.getTakamakaCode()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + request = remote.getRequest(node.getTakamakaCode()); } // the jar containing the base Takamaka code was installed by an initial jar store transaction request @@ -169,8 +170,8 @@ void testRemoteGetRequest() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getRequest for a non-existing reference") void testRemoteGetRequestNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteNode.getRequest(getInexistentTransactionReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.getRequest(getInexistentTransactionReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -186,8 +187,8 @@ void testRemoteGetRequestNonExisting() { void testRemoteGetResponse() throws Exception { TransactionResponse response; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - response = remoteNode.getResponse(node.getTakamakaCode()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + response = remote.getResponse(node.getTakamakaCode()); } // the jar containing the base Takamaka code was installed by an initial jar store transaction @@ -197,8 +198,8 @@ void testRemoteGetResponse() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getResponse for a non-existing reference") void testRemoteGetResponseNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteNode.getResponse(getInexistentTransactionReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.getResponse(getInexistentTransactionReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -212,7 +213,7 @@ void testRemoteGetResponseNonExisting() { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getResponse for the reference of a failed request") void testRemoteGetResponseFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything @@ -230,7 +231,7 @@ void testRemoteGetResponseFailed() throws Exception { } // if we ask for the outcome of the request, we will get the TransactionRejectedException as answer - remoteNode.getResponse(future.getReferenceOfRequest()); + remote.getResponse(future.getReferenceOfRequest()); } catch (TransactionRejectedException e) { assertTrue(e.getMessage().contains(ClassNotFoundException.class.getName())); @@ -245,15 +246,13 @@ void testRemoteGetResponseFailed() throws Exception { void testRemoteGetPolledResponse() throws Exception { TransactionResponse response; - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeconfig)) { - + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we install a jar in blockchain JarSupplier future = postJarStoreTransaction(privateKey(0), account(0), _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode()); // we poll for its result - response = remoteNode.getPolledResponse(future.getReferenceOfRequest()); + response = remote.getPolledResponse(future.getReferenceOfRequest()); } // lambdas.jar has been correctly installed in the node, hence the response is successful @@ -263,10 +262,8 @@ void testRemoteGetPolledResponse() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getPolledResponse for a non-existing reference") void testRemoteGetPolledResponseNonExisting() { - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeconfig)) { - - remoteNode.getPolledResponse(getInexistentTransactionReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.getPolledResponse(getInexistentTransactionReference()); } catch (Exception e) { assertTrue(e instanceof TimeoutException); @@ -280,9 +277,7 @@ void testRemoteGetPolledResponseNonExisting() { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getPolledResponse for the reference of a failed request") void testRemoteGetPolledResponseFailed() throws Exception { - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeconfig)) { - + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything @@ -300,7 +295,7 @@ void testRemoteGetPolledResponseFailed() throws Exception { } // if we ask for the outcome of the request to the remote node, we will get the TransactionRejectedException as answer - remoteNode.getPolledResponse(future.getReferenceOfRequest()); + remote.getPolledResponse(future.getReferenceOfRequest()); } catch (TransactionRejectedException e) { assertTrue(e.getMessage().contains(ClassNotFoundException.class.getName())); @@ -315,8 +310,8 @@ void testRemoteGetPolledResponseFailed() throws Exception { void testRemoteAddJarStoreTransaction() throws Exception { TransactionReference transaction; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - transaction = remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + transaction = remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode())); } @@ -327,11 +322,11 @@ void testRemoteAddJarStoreTransaction() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to addJarStoreTransactionRequest for a request that gets rejected") void testRemoteAddJarStoreTransactionRejected() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar") // , takamakaCode() // <-- forgot that @@ -348,8 +343,8 @@ ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar") @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to addJarStoreTransactionRequest for a request that fails") void testRemoteAddJarStoreTransactionFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _100_000, ONE, takamakaCode(), bytesOf("callernotonthis.jar"), takamakaCode())); } @@ -367,8 +362,8 @@ void testRemoteAddJarStoreTransactionFailed() throws Exception { void testRemotePostJarStoreTransaction() throws Exception { TransactionReference transaction; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode())); @@ -382,11 +377,11 @@ void testRemotePostJarStoreTransaction() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to postJarStoreTransactionRequest for a request that gets rejected") void testRemotePostJarStoreTransactionRejected() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar") // , takamakaCode() // <-- forgot that @@ -407,11 +402,11 @@ ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar") @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to postJarStoreTransactionRequest for a request that fails") void testRemotePostJarStoreTransactionFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("callernotonthis.jar"), takamakaCode())); @@ -431,13 +426,11 @@ void testRemotePostJarStoreTransactionFailed() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to runStaticMethodCallTransaction") void testRemoteRunStaticMethodCallTransaction() throws Exception { - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeconfig)) { - + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { TransactionReference jar = addJarStoreTransaction(privateKey(0), account(0), _500_000, ONE, takamakaCode(), bytesOf("javacollections.jar"), takamakaCode()); - var toString = (StringValue) remoteNode.runStaticMethodCallTransaction + var toString = (StringValue) remote.runStaticMethodCallTransaction (new StaticMethodCallTransactionRequest(account(0), _100_000, jar, new NonVoidMethodSignature(HASH_MAP_TESTS, "testToString1", ClassType.STRING))); assertEquals("[how, are, hello, you, ?]", toString.value); @@ -449,11 +442,11 @@ void testRemoteRunStaticMethodCallTransaction() throws Exception { void testRemoteRunInstanceMethodCallTransaction() throws Exception { BigIntegerValue value; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeconfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeconfig)) { var request = new InstanceMethodCallTransactionRequest (account(0), _100_000, takamakaCode(), CodeSignature.NONCE, account(0)); - value = (BigIntegerValue) remoteNode.runInstanceMethodCallTransaction(request); + value = (BigIntegerValue) remote.runInstanceMethodCallTransaction(request); } assertEquals(ZERO, value.value); 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 a1e6403ed..1e6daf7e5 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 @@ -61,8 +61,9 @@ import io.hotmoka.crypto.api.SignatureAlgorithm; import io.hotmoka.network.values.TransactionReferenceModel; import io.hotmoka.node.api.JarSupplier; -import io.hotmoka.remote.RemoteNode; import io.hotmoka.remote.RemoteNodeConfig; +import io.hotmoka.remote.RemoteNodeConfigBuilders; +import io.hotmoka.remote.RemoteNodes; import io.hotmoka.service.NodeService; import io.hotmoka.service.NodeServiceConfig; import io.hotmoka.verification.VerificationException; @@ -70,8 +71,8 @@ public class NodeFromNetworkWS extends HotmokaTest { private final ClassType HASH_MAP_TESTS = new ClassType("io.hotmoka.examples.javacollections.HashMapTests"); private final NodeServiceConfig serviceConfig = new NodeServiceConfig.Builder().setPort(8081).setSpringBannerModeOn(false).build(); - private final RemoteNodeConfig remoteNodeConfig = new RemoteNodeConfig.Builder() - .setWebSockets(true) + private final RemoteNodeConfig remoteNodeConfig = RemoteNodeConfigBuilders.defaults() + .usesWebSockets(true) .setURL("localhost:8081").build(); @BeforeEach @@ -85,10 +86,8 @@ void testRemoteGetTakamakaCode() throws Exception { TransactionReference localTakamakaCode = node.getTakamakaCode(); TransactionReference remoteTakamakaCode; - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeConfig)) { - - remoteTakamakaCode = remoteNode.getTakamakaCode(); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remoteTakamakaCode = remote.getTakamakaCode(); } assertEquals(localTakamakaCode, remoteTakamakaCode); @@ -99,8 +98,8 @@ void testRemoteGetTakamakaCode() throws Exception { void testRemoteGetSignatureAlgorithmForRequests() throws Exception { SignatureAlgorithm algo; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - algo = SignatureAlgorithms.of(remoteNode.getNameOfSignatureAlgorithmForRequests()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + algo = SignatureAlgorithms.of(remote.getNameOfSignatureAlgorithmForRequests()); } assertNotNull(algo); @@ -116,8 +115,8 @@ void testRemoteGetClassTag() throws Exception { ClassTag localClassTag = node.getClassTag(account(0)); ClassTag remoteClassTag; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteClassTag = remoteNode.getClassTag(account(0)); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remoteClassTag = remote.getClassTag(account(0)); } assertEquals(localClassTag, remoteClassTag); @@ -126,8 +125,8 @@ void testRemoteGetClassTag() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getClassTag for a non-existing reference") void testRemoteGetClassTagNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteNode.getClassTag(getInexistentStorageReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remote.getClassTag(getInexistentStorageReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -141,8 +140,8 @@ void testRemoteGetState() throws Exception { Stream localState = node.getState(account(0)); Stream remoteState; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteState = remoteNode.getState(account(0)); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remoteState = remote.getState(account(0)); } assertEquals(localState.collect(Collectors.toSet()), remoteState.collect(Collectors.toSet())); @@ -151,8 +150,8 @@ void testRemoteGetState() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getState for a non-existing reference") void testRemoteGetStateNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteNode.getState(getInexistentStorageReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remote.getState(getInexistentStorageReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -165,10 +164,8 @@ void testRemoteGetStateNonExisting() { void testRemoteGetRequest() throws Exception { TransactionRequest request; - try (NodeService nodeRestService = NodeService.of(serviceConfig, node); - RemoteNode remoteNode = RemoteNode.of(remoteNodeConfig)) { - - request = remoteNode.getRequest(node.getTakamakaCode()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + request = remote.getRequest(node.getTakamakaCode()); } // the jar containing the base Takamaka code was installed by an initial jar store transaction request @@ -178,8 +175,8 @@ void testRemoteGetRequest() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getRequest for a non-existing reference") void testRemoteGetRequestNonExisting() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - var e = assertThrows(NoSuchElementException.class, () -> remoteNode.getRequest(getInexistentTransactionReference())); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + var e = assertThrows(NoSuchElementException.class, () -> remote.getRequest(getInexistentTransactionReference())); assertEquals("unknown transaction reference 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", e.getMessage()); } } @@ -188,8 +185,8 @@ void testRemoteGetRequestNonExisting() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getResponse") void testRemoteGetResponse() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - TransactionResponse response = remoteNode.getResponse(node.getTakamakaCode()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + TransactionResponse response = remote.getResponse(node.getTakamakaCode()); // the jar containing the base Takamaka code was installed by an initial jar store transaction assertTrue(response instanceof JarStoreInitialTransactionResponse); } @@ -198,8 +195,8 @@ void testRemoteGetResponse() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getResponse for a non-existing reference") void testRemoteGetResponseNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteNode.getResponse(getInexistentTransactionReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remote.getResponse(getInexistentTransactionReference()); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); @@ -213,7 +210,7 @@ void testRemoteGetResponseNonExisting() { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getResponse for the reference of a failed request") void testRemoteGetResponseFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything @@ -231,7 +228,7 @@ void testRemoteGetResponseFailed() throws Exception { } // if we ask for the outcome of the request, we will get the TransactionRejectedException as answer - remoteNode.getResponse(future.getReferenceOfRequest()); + remote.getResponse(future.getReferenceOfRequest()); } catch (TransactionRejectedException e) { assertTrue(e.getMessage().contains(ClassNotFoundException.class.getName())); @@ -246,13 +243,13 @@ void testRemoteGetResponseFailed() throws Exception { void testRemoteGetPolledResponse() throws Exception { TransactionResponse response; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we install a jar in blockchain JarSupplier future = postJarStoreTransaction(privateKey(0), account(0), _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode()); // we poll for its result - response = remoteNode.getPolledResponse(future.getReferenceOfRequest()); + response = remote.getPolledResponse(future.getReferenceOfRequest()); } // lambdas.jar has been correctly installed in the node, hence the response is successful @@ -262,8 +259,8 @@ void testRemoteGetPolledResponse() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getPolledResponse for a non-existing reference") void testRemoteGetPolledResponseNonExisting() { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteNode.getPolledResponse(getInexistentTransactionReference()); + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remote.getPolledResponse(getInexistentTransactionReference()); } catch (Exception e) { assertTrue(e instanceof TimeoutException); @@ -277,7 +274,7 @@ void testRemoteGetPolledResponseNonExisting() { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to getPolledResponse for the reference of a failed request") void testRemoteGetPolledResponseFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything @@ -295,7 +292,7 @@ void testRemoteGetPolledResponseFailed() throws Exception { } // if we ask for the outcome of the request, we will get the TransactionRejectedException as answer - remoteNode.getPolledResponse(future.getReferenceOfRequest()); + remote.getPolledResponse(future.getReferenceOfRequest()); } catch (TransactionRejectedException e) { assertTrue(e.getMessage().contains(ClassNotFoundException.class.getName())); @@ -310,8 +307,8 @@ void testRemoteGetPolledResponseFailed() throws Exception { void testRemoteAddJarStoreTransaction() throws Exception { TransactionReference transaction; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - transaction = remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + transaction = remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode())); } @@ -322,11 +319,11 @@ void testRemoteAddJarStoreTransaction() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to addJarStoreTransactionRequest for a request that gets rejected") void testRemoteAddJarStoreTransactionRejected() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _50_000, ONE, takamakaCode(), bytesOf("lambdas.jar") // , takamakaCode() // <-- forgot that @@ -343,8 +340,8 @@ ZERO, chainId, _50_000, ONE, takamakaCode(), bytesOf("lambdas.jar") @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to addJarStoreTransactionRequest for a request that fails") void testRemoteAddJarStoreTransactionFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - remoteNode.addJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + remote.addJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _100_000, ONE, takamakaCode(), bytesOf("callernotonthis.jar"), takamakaCode())); } @@ -362,8 +359,8 @@ void testRemoteAddJarStoreTransactionFailed() throws Exception { void testRemotePostJarStoreTransaction() throws Exception { TransactionReference transaction; - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _500_000, ONE, takamakaCode(), bytesOf("lambdas.jar"), takamakaCode())); @@ -377,11 +374,11 @@ void testRemotePostJarStoreTransaction() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to postJarStoreTransactionRequest for a request that gets rejected") void testRemotePostJarStoreTransactionRejected() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _50_000, ONE, takamakaCode(), bytesOf("lambdas.jar") // , takamakaCode() // <-- forgot that @@ -402,11 +399,11 @@ ZERO, chainId, _50_000, ONE, takamakaCode(), bytesOf("lambdas.jar") @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to postJarStoreTransactionRequest for a request that fails") void testRemotePostJarStoreTransactionFailed() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { // we try to install a jar, but we forget to add its dependency (lambdas.jar needs takamakaCode() as dependency); // this means that the request fails and the future refers to a failed request; since this is a post, // the execution does not stop, nor throws anything - JarSupplier future = remoteNode.postJarStoreTransaction(new JarStoreTransactionRequest + JarSupplier future = remote.postJarStoreTransaction(new JarStoreTransactionRequest (signature().getSigner(privateKey(0), SignedTransactionRequest::toByteArrayWithoutSignature), account(0), ZERO, chainId, _100_000, ONE, takamakaCode(), bytesOf("callernotonthis.jar"), takamakaCode())); @@ -426,11 +423,11 @@ void testRemotePostJarStoreTransactionFailed() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to runStaticMethodCallTransaction") void testRemoteRunStaticMethodCallTransaction() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { TransactionReference jar = addJarStoreTransaction(privateKey(0), account(0), _500_000, ONE, takamakaCode(), bytesOf("javacollections.jar"), takamakaCode()); - var toString = (StringValue) remoteNode.runStaticMethodCallTransaction + var toString = (StringValue) remote.runStaticMethodCallTransaction (new StaticMethodCallTransactionRequest(account(0), _50_000, jar, new NonVoidMethodSignature(HASH_MAP_TESTS, "testToString1", ClassType.STRING))); assertEquals("[how, are, hello, you, ?]", toString.value); } @@ -439,11 +436,11 @@ void testRemoteRunStaticMethodCallTransaction() throws Exception { @Test @DisplayName("starts a network server from a Hotmoka node and makes a remote call to runInstanceMethodCallTransaction") void testRemoteRunInstanceMethodCallTransaction() throws Exception { - try (var nodeRestService = NodeService.of(serviceConfig, node); var remoteNode = RemoteNode.of(remoteNodeConfig)) { + try (var service = NodeService.of(serviceConfig, node); var remote = RemoteNodes.of(remoteNodeConfig)) { var request = new InstanceMethodCallTransactionRequest (account(0), _50_000, takamakaCode(), CodeSignature.NONCE, account(0)); - BigIntegerValue value = (BigIntegerValue) remoteNode.runInstanceMethodCallTransaction(request); + BigIntegerValue value = (BigIntegerValue) remote.runInstanceMethodCallTransaction(request); assertEquals(ZERO, value.value); } } diff --git a/io-hotmoka-tools/pom.xml b/io-hotmoka-tools/pom.xml index 1e40a11df..53d271c2f 100644 --- a/io-hotmoka-tools/pom.xml +++ b/io-hotmoka-tools/pom.xml @@ -46,7 +46,7 @@ io.hotmoka - io-hotmoka-remote + io-hotmoka-node-remote ${hotmoka.version} diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/AbstractCommand.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/AbstractCommand.java index b44e636b5..66000401a 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/AbstractCommand.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/AbstractCommand.java @@ -42,6 +42,7 @@ import io.hotmoka.node.api.Account; import io.hotmoka.node.api.Node; import io.hotmoka.remote.RemoteNodeConfig; +import io.hotmoka.remote.RemoteNodeConfigBuilders; public abstract class AbstractCommand implements Runnable { protected static final BigInteger _100_000 = BigInteger.valueOf(100_000L); @@ -72,7 +73,7 @@ public final void run() { protected abstract void execute() throws Exception; protected final static RemoteNodeConfig remoteNodeConfig(String url) { - return new RemoteNodeConfig.Builder().setURL(url).build(); + return RemoteNodeConfigBuilders.defaults().setURL(url).build(); } /** diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BindKey.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BindKey.java index 8b308308f..2ff9179e3 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BindKey.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BindKey.java @@ -28,7 +28,7 @@ import io.hotmoka.crypto.Base58; import io.hotmoka.crypto.Entropies; import io.hotmoka.node.Accounts; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -66,7 +66,7 @@ protected void execute() throws Exception { } private StorageReference getReferenceFromAccountLedger() throws Exception { - try (var node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = RemoteNodes.of(remoteNodeConfig(url))) { var manifest = node.getManifest(); var takamakaCode = node.getTakamakaCode(); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BuyValidation.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BuyValidation.java index 10dcc061c..365b8a6e6 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BuyValidation.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/BuyValidation.java @@ -37,7 +37,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -82,7 +82,7 @@ private Run() throws Exception { passwordOfBuyer = ensurePassword(passwordOfBuyer, "the buyer validator", interactive, false); - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (Node node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { var gasHelper = GasHelpers.of(node); var nonceHelper = NonceHelpers.of(node); TransactionReference takamakaCode = node.getTakamakaCode(); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Call.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Call.java index b7dcb8cd2..4850ae41d 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Call.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Call.java @@ -48,7 +48,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import io.hotmoka.verification.api.TakamakaClassLoader; import io.hotmoka.whitelisting.api.WhiteListingWizard; import picocli.CommandLine.Command; @@ -118,7 +118,7 @@ private class Run { private final TakamakaClassLoader classloader; private Run() throws Exception { - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (Node node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { if ("the classpath of the receiver".equals(Call.this.classpath)) this.classpath = node.getClassTag(new StorageReference(Call.this.receiver)).jar; else diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Create.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Create.java index 27e2198e4..246e2817e 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Create.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Create.java @@ -44,7 +44,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import io.hotmoka.verification.api.TakamakaClassLoader; import io.hotmoka.whitelisting.api.WhiteListingWizard; import picocli.CommandLine.Command; @@ -96,7 +96,7 @@ private class Run { private Run() throws Exception { passwordOfPayer = ensurePassword(passwordOfPayer, "the payer account", interactive, false); - try (Node node = RemoteNode.of(remoteNodeConfig(url))) { + try (Node node = RemoteNodes.of(remoteNodeConfig(url))) { TransactionReference takamakaCode = node.getTakamakaCode(); StorageReference manifest = node.getManifest(); var payer = new StorageReference(Create.this.payer); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/CreateAccount.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/CreateAccount.java index 849e54eb2..24fd1a082 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/CreateAccount.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/CreateAccount.java @@ -34,7 +34,7 @@ import io.hotmoka.helpers.api.AccountCreationHelper; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -98,7 +98,7 @@ private Run() throws Exception { if (createTendermintValidator) signature = "ed25519"; - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { String nameOfSignatureAlgorithmOfNewAccount = "default".equals(signature) ? node.getNameOfSignatureAlgorithmForRequests() : signature; signatureAlgorithmOfNewAccount = SignatureAlgorithms.of(nameOfSignatureAlgorithmOfNewAccount); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Faucet.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Faucet.java index 3b35dbb96..8191a89f8 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Faucet.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Faucet.java @@ -34,7 +34,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -70,7 +70,7 @@ private class Run { private Run() throws Exception { passwordOfGamete = ensurePassword(passwordOfGamete, "the gamete account", interactive, false); - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { openFaucet(); } } diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Info.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Info.java index 16fc6d427..49ebba57f 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Info.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Info.java @@ -17,7 +17,7 @@ package io.hotmoka.tools.internal.moka; import io.hotmoka.helpers.ManifestHelpers; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; @@ -31,7 +31,7 @@ public class Info extends AbstractCommand { @Override protected void execute() throws Exception { - try (var node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = RemoteNodes.of(remoteNodeConfig(url))) { System.out.println("\nInfo about the node:\n" + ManifestHelpers.of(node)); } } diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Install.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Install.java index 57767ffa2..b2872572c 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Install.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Install.java @@ -34,8 +34,7 @@ import io.hotmoka.helpers.NonceHelpers; import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; -import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -79,7 +78,7 @@ private class Run { private Run() throws Exception { passwordOfPayer = ensurePassword(passwordOfPayer, "the payer account", interactive, false); - try (Node node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = RemoteNodes.of(remoteNodeConfig(url))) { TransactionReference takamakaCode = node.getTakamakaCode(); StorageReference manifest = node.getManifest(); checkStorageReference(payer); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/RotateKey.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/RotateKey.java index f509ff6a0..cdcf44f83 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/RotateKey.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/RotateKey.java @@ -38,7 +38,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -88,7 +88,7 @@ private class Run { private final Entropy entropy; private Run() throws Exception { - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { if ("the classpath of the account".equals(RotateKey.this.classpath)) this.classpath = node.getClassTag(new StorageReference(RotateKey.this.account)).jar; else diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/SellValidation.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/SellValidation.java index 5c1604fdc..358089549 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/SellValidation.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/SellValidation.java @@ -38,7 +38,7 @@ import io.hotmoka.helpers.SignatureHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -106,7 +106,7 @@ private Run() throws Exception { passwordOfSeller = ensurePassword(passwordOfSeller, "the seller validator", interactive, false); - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { var gasHelper = GasHelpers.of(node); var nonceHelper = NonceHelpers.of(node); TransactionReference takamakaCode = node.getTakamakaCode(); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Send.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Send.java index 5c6b30a30..019d7c086 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Send.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/Send.java @@ -28,7 +28,7 @@ import io.hotmoka.helpers.SendCoinsHelpers; import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -88,7 +88,7 @@ private Run() throws Exception { passwordOfPayer = ensurePassword(passwordOfPayer, "the payer account", interactive, "faucet".equals(payer)); - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { if ("faucet".equals(payer)) sendCoinsFromFaucet(); else if (looksLikePublicKey(destination)) { diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/ShowAccount.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/ShowAccount.java index e9a908d9f..28eb0ad33 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/ShowAccount.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/ShowAccount.java @@ -33,7 +33,7 @@ import io.hotmoka.node.Accounts; import io.hotmoka.node.api.Account; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -71,7 +71,7 @@ protected void execute() throws Exception { System.out.println("entropy: " + Base64.getEncoder().encodeToString(account.getEntropy())); if (balances || keys) { - try (Node node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = RemoteNodes.of(remoteNodeConfig(url))) { if (balances) showBalances(account, node); diff --git a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/State.java b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/State.java index e81f0de6e..42a7f1ae4 100644 --- a/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/State.java +++ b/io-hotmoka-tools/src/main/java/io/hotmoka/tools/internal/moka/State.java @@ -28,7 +28,7 @@ import io.hotmoka.beans.updates.UpdateOfString; import io.hotmoka.beans.values.StorageReference; import io.hotmoka.node.api.Node; -import io.hotmoka.remote.RemoteNode; +import io.hotmoka.remote.RemoteNodes; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -61,7 +61,7 @@ private Run() throws Exception { checkStorageReference(object); StorageReference reference = new StorageReference(object); - try (Node node = this.node = RemoteNode.of(remoteNodeConfig(url))) { + try (var node = this.node = RemoteNodes.of(remoteNodeConfig(url))) { this.updates = node.getState(reference).sorted().toArray(Update[]::new); this.tag = getClassTag(); diff --git a/pom.xml b/pom.xml index 2d5fa9215..8986da5c6 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ Note: submodules whose artifact must be deployed on Maven Central must activate UTF-8 17 - 1.3.3 + 1.4.0 1.0.14 @@ -103,7 +103,7 @@ Note: submodules whose artifact must be deployed on Maven Central must activate io-hotmoka-network io-hotmoka-service io-hotmoka-ws-client - io-hotmoka-remote + io-hotmoka-node-remote io-hotmoka-crypto-api io-hotmoka-crypto io-hotmoka-patricia-api @@ -290,7 +290,7 @@ Note: submodules whose artifact must be deployed on Maven Central must activate io-hotmoka-crypto-api, io-hotmoka-network, io-hotmoka-service, - io-hotmoka-remote, + io-hotmoka-node-remote, io-hotmoka-node-api, io-hotmoka-node, io-hotmoka-node-disk-api, @@ -300,7 +300,6 @@ Note: submodules whose artifact must be deployed on Maven Central must activate io-hotmoka-patricia-api, io-hotmoka-patricia, io-hotmoka-service, - io-hotmoka-remote, io-hotmoka-node-tendermint-abci, io-hotmoka-node-tendermint-api, io-hotmoka-node-tendermint,