Skip to content

Commit

Permalink
Added JSON encoding for transaction requests
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Jan 21, 2024
1 parent 32f2b46 commit 3578868
Show file tree
Hide file tree
Showing 29 changed files with 532 additions and 41 deletions.
23 changes: 14 additions & 9 deletions io-hotmoka-beans/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-constants</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-exceptions</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-crypto</artifactId>
<version>${hotmoka.version}</version>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-crypto</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-annotations</artifactId>
<version>${hotmoka.version}</version>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-annotations</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-marshalling</artifactId>
<version>${hotmoka.version}</version>
<groupId>io.hotmoka</groupId>
<artifactId>io-hotmoka-marshalling</artifactId>
<version>${hotmoka.version}</version>
</dependency>
<dependency>
<groupId>io.hotmoka.websockets</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;
import java.io.OutputStream;

import io.hotmoka.beans.marshalling.internal.BeanMarshallingContext;
import io.hotmoka.beans.internal.marshalling.BeanMarshallingContext;
import io.hotmoka.marshalling.api.MarshallingContext;

/**
Expand All @@ -35,6 +35,7 @@ private BeanMarshallingContexts() {}
*
* @param oos the stream where bytes are marshalled.
* @throws IOException if the context cannot be created
* @return the context
*/
public static MarshallingContext of(OutputStream oos) throws IOException {
return new BeanMarshallingContext(oos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.io.InputStream;
import java.io.OutputStream;

import io.hotmoka.beans.marshalling.internal.BeanUnmarshallingContext;
import io.hotmoka.beans.internal.marshalling.BeanUnmarshallingContext;
import io.hotmoka.marshalling.api.UnmarshallingContext;

/**
Expand All @@ -37,6 +37,7 @@ private BeanUnmarshallingContexts() {}
*
* @param is the stream from which bytes get unmarshalled
* @throws IOException if the context cannot be created
* @return the context
*/
public static UnmarshallingContext of(InputStream is) throws IOException {
return new BeanUnmarshallingContext(is);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.beans.api.values.StorageReference;
import io.hotmoka.beans.api.values.StorageValue;
import io.hotmoka.beans.internal.gson.TransactionReferenceDecoder;
import io.hotmoka.beans.internal.gson.TransactionReferenceEncoder;
import io.hotmoka.beans.internal.gson.TransactionReferenceJson;
import io.hotmoka.beans.internal.gson.TransactionRequestDecoder;
import io.hotmoka.beans.internal.gson.TransactionRequestEncoder;
import io.hotmoka.beans.internal.gson.TransactionRequestJson;
import io.hotmoka.beans.internal.requests.ConstructorCallTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.GameteCreationTransactionRequestImpl;
import io.hotmoka.beans.internal.requests.InitializationTransactionRequestImpl;
Expand Down Expand Up @@ -314,7 +314,7 @@ public static TransactionRequest<?> from(UnmarshallingContext context) throws IO
/**
* Gson encoder.
*/
public static class Encoder extends TransactionReferenceEncoder {
public static class Encoder extends TransactionRequestEncoder {

/**
* Creates a new encoder.
Expand All @@ -325,7 +325,7 @@ public Encoder() {}
/**
* Gson decoder.
*/
public static class Decoder extends TransactionReferenceDecoder {
public static class Decoder extends TransactionRequestDecoder {

/**
* Creates a new decoder.
Expand All @@ -336,15 +336,15 @@ public Decoder() {}
/**
* Json representation.
*/
public static class Json extends TransactionReferenceJson {
public static class Json extends TransactionRequestJson {

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

package io.hotmoka.beans.internal.gson;

import io.hotmoka.beans.TransactionRequests;
import io.hotmoka.beans.api.requests.TransactionRequest;
import io.hotmoka.websockets.beans.MappedDecoder;

/**
* A decoder for {@link TransactionRequest}.
*/
public class TransactionRequestDecoder extends MappedDecoder<TransactionRequest<?>, TransactionRequests.Json> {

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

package io.hotmoka.beans.internal.gson;

import io.hotmoka.beans.TransactionRequests;
import io.hotmoka.beans.api.requests.TransactionRequest;
import io.hotmoka.websockets.beans.MappedEncoder;

/**
* An encoder for {@link TransactionRequest}.
*/
public class TransactionRequestEncoder extends MappedEncoder<TransactionRequest<?>, TransactionRequests.Json> {

public TransactionRequestEncoder() {
super((TransactionRequest<?> request) -> new TransactionRequests.Json(request));
}
}
Loading

0 comments on commit 3578868

Please sign in to comment.