Skip to content

Commit

Permalink
The postJarStoreTransaction() method has been moved from Spring to Ho…
Browse files Browse the repository at this point in the history
…tmoka's websockets
  • Loading branch information
spoto committed Apr 10, 2024
1 parent 286ec6c commit 80f8285
Show file tree
Hide file tree
Showing 23 changed files with 686 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages.api;

import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.node.api.Node;
import io.hotmoka.websockets.beans.api.RpcMessage;

/**
* The network message corresponding to {@link Node#postJarStoreTransaction(JarStoreTransactionRequest)}.
*/
@Immutable
public interface PostJarStoreTransactionMessage extends RpcMessage {

/**
* Yields the request of the required transaction.
*
* @return the request of the required transaction
*/
JarStoreTransactionRequest getRequest();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Dinu Berinde and Fausto Spoto
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,16 @@
limitations under the License.
*/

package io.hotmoka.node.service.internal.http;
package io.hotmoka.node.messages.api;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.hotmoka.annotations.Immutable;
import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.node.api.Node;

@RestController
@RequestMapping("run")
public class HTTP_RunController {
/**
* The network message corresponding to the result of the {@link Node#postJarStoreTransaction(JarStoreTransactionRequest)} method.
*/
@Immutable
public interface PostJarStoreTransactionResultMessage extends ResultMessage<TransactionReference> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages;

import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.node.messages.api.PostJarStoreTransactionMessage;
import io.hotmoka.node.messages.internal.PostJarStoreTransactionMessageImpl;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionMessageDecoder;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionMessageEncoder;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionMessageJson;

/**
* A provider of {@link PostJarStoreTransactionMessage}.
*/
public final class PostJarStoreTransactionMessages {

private PostJarStoreTransactionMessages() {}

/**
* Yields a {@link PostJarStoreTransactionMessage}.
*
* @param id the identifier of the message
* @param request the request of the transaction required to post
* @return the message
*/
public static PostJarStoreTransactionMessage of(JarStoreTransactionRequest request, String id) {
return new PostJarStoreTransactionMessageImpl(request, id);
}

/**
* Gson encoder.
*/
public static class Encoder extends PostJarStoreTransactionMessageEncoder {

/**
* Creates a new encoder.
*/
public Encoder() {}
}

/**
* Gson decoder.
*/
public static class Decoder extends PostJarStoreTransactionMessageDecoder {

/**
* Creates a new decoder.
*/
public Decoder() {}
}

/**
* Json representation.
*/
public static class Json extends PostJarStoreTransactionMessageJson {

/**
* Creates the Json representation for the given message.
*
* @param message the message
*/
public Json(PostJarStoreTransactionMessage message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages;

import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.node.messages.api.PostJarStoreTransactionResultMessage;
import io.hotmoka.node.messages.internal.PostJarStoreTransactionResultMessageImpl;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionResultMessageDecoder;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionResultMessageEncoder;
import io.hotmoka.node.messages.internal.gson.PostJarStoreTransactionResultMessageJson;

/**
* A provider of {@link PostJarStoreTransactionResultMessage}.
*/
public final class PostJarStoreTransactionResultMessages {

private PostJarStoreTransactionResultMessages() {}

/**
* Yields a {@link PostJarStoreTransactionResultMessage}.
*
* @param result the result of the call; this is the reference of the transaction that has been posted
* @param id the identifier of the message
* @return the message
*/
public static PostJarStoreTransactionResultMessage of(TransactionReference result, String id) {
return new PostJarStoreTransactionResultMessageImpl(result, id);
}

/**
* Gson encoder.
*/
public static class Encoder extends PostJarStoreTransactionResultMessageEncoder {

/**
* Creates a new encoder.
*/
public Encoder() {}
}

/**
* Gson decoder.
*/
public static class Decoder extends PostJarStoreTransactionResultMessageDecoder {

/**
* Creates a new decoder.
*/
public Decoder() {}
}

/**
* Json representation.
*/
public static class Json extends PostJarStoreTransactionResultMessageJson {

/**
* Creates the Json representation for the given message.
*
* @param message the message
*/
public Json(PostJarStoreTransactionResultMessage message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages.internal;

import java.util.Objects;

import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.messages.api.PostJarStoreTransactionMessage;
import io.hotmoka.websockets.beans.AbstractRpcMessage;

/**
* Implementation of the network message corresponding to {@link Node#postJarStoreTransaction(JarStoreTransactionRequest)}.
*/
public class PostJarStoreTransactionMessageImpl extends AbstractRpcMessage implements PostJarStoreTransactionMessage {

private final JarStoreTransactionRequest request;

/**
* Creates the message.
*
* @param request the request of the transaction required to post
* @param id the identifier of the message
*/
public PostJarStoreTransactionMessageImpl(JarStoreTransactionRequest request, String id) {
super(id);

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

@Override
public boolean equals(Object other) {
return other instanceof PostJarStoreTransactionMessage pjstm && super.equals(other) && request.equals(pjstm.getRequest());
}

@Override
protected String getExpectedType() {
return PostJarStoreTransactionMessage.class.getName();
}

@Override
public JarStoreTransactionRequest getRequest() {
return request;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages.internal;

import java.util.Objects;

import io.hotmoka.beans.api.requests.JarStoreTransactionRequest;
import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.node.api.Node;
import io.hotmoka.node.messages.api.PostJarStoreTransactionResultMessage;
import io.hotmoka.websockets.beans.AbstractRpcMessage;

/**
* Implementation of the network message corresponding to the result of the {@link Node#postJarStoreTransaction(JarStoreTransactionRequest)} method.
*/
public class PostJarStoreTransactionResultMessageImpl extends AbstractRpcMessage implements PostJarStoreTransactionResultMessage {

/**
* The result of the call; this is the reference to the transaction that has been posted.
*/
private final TransactionReference result;

/**
* Creates the message.
*
* @param result the result of the call; this is the reference to the transaction that has been posted
* @param id the identifier of the message
*/
public PostJarStoreTransactionResultMessageImpl(TransactionReference result, String id) {
super(id);

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

@Override
public boolean equals(Object other) {
return other instanceof PostJarStoreTransactionResultMessage pjstrm && super.equals(other) && result.equals(pjstrm.get());
}

@Override
protected String getExpectedType() {
return PostJarStoreTransactionResultMessage.class.getName();
}

@Override
public TransactionReference get() {
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2024 Fausto Spoto
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.hotmoka.node.messages.internal.gson;

import io.hotmoka.node.messages.PostJarStoreTransactionMessages;
import io.hotmoka.node.messages.api.PostJarStoreTransactionMessage;
import io.hotmoka.websockets.beans.MappedDecoder;

/**
* A decoder for a {@link PostJarStoreTransactionMessage}.
*/
public class PostJarStoreTransactionMessageDecoder extends MappedDecoder<PostJarStoreTransactionMessage, PostJarStoreTransactionMessages.Json> {

public PostJarStoreTransactionMessageDecoder() {
super(PostJarStoreTransactionMessages.Json.class);
}
}
Loading

0 comments on commit 80f8285

Please sign in to comment.