@@ -196,10 +228,10 @@
org.apache.maven.plugins
maven-javadoc-plugin
+ ${maven-javadoc-plugin.version}
false
- ${maven-javadoc-plugin.version}
attach-javadocs
@@ -237,7 +269,6 @@
ossrh
https://s01.oss.sonatype.org/
- true
diff --git a/src/main/java/com/syntifi/near/api/exception/NoSuchTypeException.java b/src/main/java/com/syntifi/near/api/exception/NoSuchTypeException.java
index 2d56eb54..db7bd0a0 100644
--- a/src/main/java/com/syntifi/near/api/exception/NoSuchTypeException.java
+++ b/src/main/java/com/syntifi/near/api/exception/NoSuchTypeException.java
@@ -1,7 +1,7 @@
package com.syntifi.near.api.exception;
/**
- * Thrown in case of a CLType which does not exist being requested
+ * Thrown in case of a type which does not exist being requested
*
* @author Alexandre Carvalho
* @author Andre Bertolace
@@ -11,4 +11,7 @@ public class NoSuchTypeException extends RuntimeException {
public NoSuchTypeException(String message) {
super(message);
}
+ public NoSuchTypeException(String message, Throwable t) {
+ super(message, t);
+ }
}
diff --git a/src/main/java/com/syntifi/near/api/json/JsonHelper.java b/src/main/java/com/syntifi/near/api/json/JsonHelper.java
new file mode 100644
index 00000000..522eddfb
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/json/JsonHelper.java
@@ -0,0 +1,98 @@
+package com.syntifi.near.api.json;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.syntifi.near.api.service.NearObjectMapper;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Basic support functionality for test case classes
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public final class JsonHelper {
+ public static final ObjectMapper OBJECT_MAPPER = new NearObjectMapper();
+
+ /**
+ * Loads test json from resources
+ *
+ * @param file file to load from
+ * @return file content
+ * @throws IOException thrown if error reading file
+ */
+ public static String loadJsonFromFile(File file) throws IOException {
+ String fileJson;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ try (InputStream is = new FileInputStream(file)) {
+ // copy stream
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = is.read(buffer)) != -1) {
+ baos.write(buffer, 0, bytesRead);
+ }
+
+ fileJson = baos.toString();
+ }
+ return fileJson;
+ }
+
+ /**
+ * Loads test json from resources
+ *
+ * @param filename filename to load
+ * @return file content
+ * @throws IOException thrown if error reading file
+ */
+ public static String loadJsonFromResourceFile(String filename) throws IOException {
+ String fileJson;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ try (InputStream is = JsonHelper.class.getClassLoader().getResourceAsStream(filename)) {
+ // copy stream
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while (true) {
+ assert is != null;
+ if ((bytesRead = is.read(buffer)) == -1) break;
+ baos.write(buffer, 0, bytesRead);
+ }
+
+ fileJson = baos.toString();
+ }
+ return fileJson;
+ }
+
+ /**
+ * Prettifies json for assertion consistency
+ *
+ * @param json json string to prettify
+ * @return prettified json
+ * @throws JsonMappingException thrown if error mapping json
+ * @throws JsonProcessingException thrown if error processing json
+ */
+ public static String getPrettyJson(String json) throws JsonMappingException, JsonProcessingException {
+ Object jsonObject = OBJECT_MAPPER.readValue(json, Object.class);
+ return getPrettyJson(jsonObject);
+ }
+
+ /**
+ * Prettifies json for assertion consistency
+ *
+ * @param jsonObject object to serialize and prettify
+ * @return prettified json
+ * @throws JsonMappingException thrown if error mapping json
+ * @throws JsonProcessingException thrown if error processing json
+ */
+ public static String getPrettyJson(Object jsonObject) throws JsonProcessingException {
+ return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/jackson/deserializer/AbstractAnyOfDeserializer.java b/src/main/java/com/syntifi/near/api/json/deserializer/AbstractAnyOfDeserializer.java
similarity index 92%
rename from src/main/java/com/syntifi/near/api/jackson/deserializer/AbstractAnyOfDeserializer.java
rename to src/main/java/com/syntifi/near/api/json/deserializer/AbstractAnyOfDeserializer.java
index 074877ab..140f77cd 100644
--- a/src/main/java/com/syntifi/near/api/jackson/deserializer/AbstractAnyOfDeserializer.java
+++ b/src/main/java/com/syntifi/near/api/json/deserializer/AbstractAnyOfDeserializer.java
@@ -1,6 +1,4 @@
-package com.syntifi.near.api.jackson.deserializer;
-
-import java.io.IOException;
+package com.syntifi.near.api.json.deserializer;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.BeanProperty;
@@ -15,7 +13,11 @@
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.syntifi.near.api.exception.NoSuchTypeException;
+import java.io.IOException;
+
/**
+ * AbstractAnyOfDeserializer for deserializing objects with inheritance
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -23,7 +25,7 @@
public abstract class AbstractAnyOfDeserializer extends AsPropertyTypeDeserializer {
protected AbstractAnyOfDeserializer(final JavaType bt, final TypeIdResolver idRes, final String typePropertyName,
- final boolean typeIdVisible, JavaType defaultImpl) {
+ final boolean typeIdVisible, JavaType defaultImpl) {
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
@@ -55,9 +57,9 @@ public Object deserializeTypedFromObject(final JsonParser jp, final Deserializat
/**
* Returns the node which contains the type key.
- *
+ *
* Override if you have a child node which holds the type information.
- *
+ *
* @param currentNode the current deserialization node
* @return node which contains the type key.
*/
@@ -67,7 +69,7 @@ protected JsonNode getTypeNode(JsonNode currentNode) {
/**
* Method that returns the instance of the found type
- *
+ *
* @param classType the name of the class type
* @return {@link Class} of the type
* @throws NoSuchTypeException no such type found
diff --git a/src/main/java/com/syntifi/near/api/jackson/deserializer/PermissionDeserializer.java b/src/main/java/com/syntifi/near/api/json/deserializer/PermissionDeserializer.java
similarity index 84%
rename from src/main/java/com/syntifi/near/api/jackson/deserializer/PermissionDeserializer.java
rename to src/main/java/com/syntifi/near/api/json/deserializer/PermissionDeserializer.java
index 1171fd92..2fe1af7b 100644
--- a/src/main/java/com/syntifi/near/api/jackson/deserializer/PermissionDeserializer.java
+++ b/src/main/java/com/syntifi/near/api/json/deserializer/PermissionDeserializer.java
@@ -1,4 +1,4 @@
-package com.syntifi.near.api.jackson.deserializer;
+package com.syntifi.near.api.json.deserializer;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JavaType;
@@ -9,6 +9,8 @@
import com.syntifi.near.api.model.accesskey.permission.PermissionTypeData;
/**
+ * Specific implementacion of AbstractAnyOfDeserializer for Permission type objects
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -16,7 +18,7 @@
public class PermissionDeserializer extends AbstractAnyOfDeserializer {
public PermissionDeserializer(final JavaType bt, final TypeIdResolver idRes, final String typePropertyName,
- final boolean typeIdVisible, JavaType defaultImpl) {
+ final boolean typeIdVisible, JavaType defaultImpl) {
super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl);
}
diff --git a/src/main/java/com/syntifi/near/api/jackson/resolver/PermissionResolver.java b/src/main/java/com/syntifi/near/api/json/resolver/PermissionResolver.java
similarity index 74%
rename from src/main/java/com/syntifi/near/api/jackson/resolver/PermissionResolver.java
rename to src/main/java/com/syntifi/near/api/json/resolver/PermissionResolver.java
index 2734c171..ddc57151 100644
--- a/src/main/java/com/syntifi/near/api/jackson/resolver/PermissionResolver.java
+++ b/src/main/java/com/syntifi/near/api/json/resolver/PermissionResolver.java
@@ -1,15 +1,17 @@
-package com.syntifi.near.api.jackson.resolver;
-
-import java.util.Collection;
+package com.syntifi.near.api.json.resolver;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
-import com.syntifi.near.api.jackson.deserializer.PermissionDeserializer;
+import com.syntifi.near.api.json.deserializer.PermissionDeserializer;
+
+import java.util.Collection;
/**
+ * Permission type deserializer resolver
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -17,7 +19,7 @@
public class PermissionResolver extends StdTypeResolverBuilder {
@Override
public TypeDeserializer buildTypeDeserializer(final DeserializationConfig config, final JavaType baseType,
- final Collection subtypes) {
+ final Collection subtypes) {
return new PermissionDeserializer(baseType, null, _typeProperty, _typeIdVisible, baseType);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKey.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKey.java
index a0bee75c..f6be1634 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKey.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKey.java
@@ -4,17 +4,23 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.accesskey.permission.Permission;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccessKey
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
public class AccessKey {
@JsonProperty("nonce")
private long nonce;
@@ -28,5 +34,5 @@ public class AccessKey {
@JsonProperty("block_hash")
@JsonInclude(value = Include.NON_EMPTY)
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChange.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChange.java
index a068d622..05021cb6 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChange.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChange.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.common.ChangeCause;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccessKeyChange
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccessKeyChange {
@JsonProperty("cause")
private ChangeCause cause;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChangeDetails.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChangeDetails.java
index 1b92b8c1..d7856201 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChangeDetails.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChangeDetails.java
@@ -1,23 +1,31 @@
package com.syntifi.near.api.model.accesskey;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccessKeyChangeDetails
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccessKeyChangeDetails {
@JsonProperty("account_id")
private String accountId;
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
@JsonProperty("access_key")
private AccessKey accessKey;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChanges.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChanges.java
index 3dc461dd..cbf2a209 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChanges.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyChanges.java
@@ -1,22 +1,30 @@
package com.syntifi.near.api.model.accesskey;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * AccessKeyChanges
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccessKeyChanges {
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("changes")
private Collection changes;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyList.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyList.java
index c25b9aa1..e2a9232a 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyList.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyList.java
@@ -1,19 +1,27 @@
package com.syntifi.near.api.model.accesskey;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * AccessKeyList
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccessKeyList {
@JsonProperty("keys")
private Collection items;
@@ -22,5 +30,5 @@ public class AccessKeyList {
private long blockHeight;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyListItem.java b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyListItem.java
index c2fe144f..1417c8fa 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyListItem.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/AccessKeyListItem.java
@@ -1,20 +1,28 @@
package com.syntifi.near.api.model.accesskey;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccessKeyListItem
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccessKeyListItem {
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
@JsonProperty("access_key")
private AccessKey accessKey;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/Key.java b/src/main/java/com/syntifi/near/api/model/accesskey/Key.java
index ec57b1d3..268fae75 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/Key.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/Key.java
@@ -1,19 +1,21 @@
package com.syntifi.near.api.model.accesskey;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
import lombok.AllArgsConstructor;
-import lombok.Data;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
/**
- * Data structure for access key service calls
- *
+ * Key
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@Data
+@Getter
+@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Key {
@@ -22,5 +24,5 @@ public class Key {
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
}
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/permission/NoDataPermission.java b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FullAccessPermission.java
similarity index 75%
rename from src/main/java/com/syntifi/near/api/model/accesskey/permission/NoDataPermission.java
rename to src/main/java/com/syntifi/near/api/model/accesskey/permission/FullAccessPermission.java
index 398ddacb..982960bc 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/permission/NoDataPermission.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FullAccessPermission.java
@@ -1,15 +1,17 @@
-package com.syntifi.near.api.model.accesskey.permission;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
-
-/**
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @since 0.0.1
- */
-public enum NoDataPermission implements Permission {
- @JsonProperty("FullAccess")
- @JsonUnwrapped
- FULL_ACCESS;
-}
+package com.syntifi.near.api.model.accesskey.permission;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonUnwrapped;
+
+/**
+ * FullAccessPermission
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public enum FullAccessPermission implements Permission {
+ @JsonProperty("FullAccess")
+ @JsonUnwrapped
+ FULL_ACCESS
+}
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermission.java b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermission.java
index 72a67dc5..b368af1c 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermission.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermission.java
@@ -1,13 +1,15 @@
package com.syntifi.near.api.model.accesskey.permission;
import com.fasterxml.jackson.annotation.JsonProperty;
-
import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * FunctionCallPermission
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -16,6 +18,7 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
+@Builder
public class FunctionCallPermission implements Permission {
@JsonProperty("FunctionCall")
private FunctionCallPermissionData permissionData;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermissionData.java b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermissionData.java
index ab9cd264..cf85b47d 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermissionData.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/permission/FunctionCallPermissionData.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.accesskey.permission;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * FunctionCallPermissionData
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class FunctionCallPermissionData {
@JsonProperty("allowance")
private String allowance;
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/permission/Permission.java b/src/main/java/com/syntifi/near/api/model/accesskey/permission/Permission.java
index e1424f13..da68e4f5 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/permission/Permission.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/permission/Permission.java
@@ -2,14 +2,22 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeResolver;
-import com.syntifi.near.api.jackson.resolver.PermissionResolver;
+import com.syntifi.near.api.json.resolver.PermissionResolver;
+import com.syntifi.near.borshj.annotation.BorshSubTypes;
/**
+ * Permission
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
@JsonTypeResolver(PermissionResolver.class)
+@BorshSubTypes({
+ @BorshSubTypes.BorshSubType(when = Permission.FUNCTION_CALL_PERMISSION, use = FunctionCallPermission.class),
+ @BorshSubTypes.BorshSubType(when = Permission.FULL_ACCESS_PERMISSION, use = FullAccessPermission.class)})
public interface Permission {
+ int FUNCTION_CALL_PERMISSION = 0;
+ int FULL_ACCESS_PERMISSION = 1;
}
diff --git a/src/main/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeData.java b/src/main/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeData.java
index 92887773..4722aeb5 100644
--- a/src/main/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeData.java
+++ b/src/main/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeData.java
@@ -1,30 +1,31 @@
package com.syntifi.near.api.model.accesskey.permission;
import com.syntifi.near.api.exception.NoSuchTypeException;
-
import lombok.Getter;
/**
+ * PermissionTypeData
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
public enum PermissionTypeData {
- FULL_ACCESS("FullAccess", NoDataPermission.class),
+ FULL_ACCESS("FullAccess", FullAccessPermission.class),
FUNCTION_CALL("FunctionCall", FunctionCallPermission.class);
private final String name;
private final Class> clazz;
- private PermissionTypeData(String name, Class> clazz) {
+ PermissionTypeData(String name, Class> clazz) {
this.name = name;
this.clazz = clazz;
}
/**
* Retrieve Transform implementation class from Transform name
- *
+ *
* @param name the name of the permission type
* @return the class of given permission type
* @throws NoSuchTypeException no such type found
diff --git a/src/main/java/com/syntifi/near/api/model/account/Account.java b/src/main/java/com/syntifi/near/api/model/account/Account.java
index 5be0caf2..b8a43581 100644
--- a/src/main/java/com/syntifi/near/api/model/account/Account.java
+++ b/src/main/java/com/syntifi/near/api/model/account/Account.java
@@ -1,17 +1,25 @@
package com.syntifi.near.api.model.account;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Account
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Account {
@JsonProperty("amount")
private String amount;
@@ -20,7 +28,7 @@ public class Account {
private String locked;
@JsonProperty("code_hash")
- private String codeHash;
+ private EncodedHash codeHash;
@JsonProperty("storage_usage")
private long storageUsage;
@@ -32,5 +40,5 @@ public class Account {
private long blockHeight;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/account/AccountChange.java b/src/main/java/com/syntifi/near/api/model/account/AccountChange.java
index 193304a4..0aaa27c4 100644
--- a/src/main/java/com/syntifi/near/api/model/account/AccountChange.java
+++ b/src/main/java/com/syntifi/near/api/model/account/AccountChange.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.common.ChangeCause;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccountChange
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccountChange {
@JsonProperty("cause")
private ChangeCause cause;
diff --git a/src/main/java/com/syntifi/near/api/model/account/AccountChangeDetails.java b/src/main/java/com/syntifi/near/api/model/account/AccountChangeDetails.java
index acbb871e..2f32ef53 100644
--- a/src/main/java/com/syntifi/near/api/model/account/AccountChangeDetails.java
+++ b/src/main/java/com/syntifi/near/api/model/account/AccountChangeDetails.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.account;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccountChangeDetails
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccountChangeDetails {
@JsonProperty("account_id")
private String accountId;
diff --git a/src/main/java/com/syntifi/near/api/model/account/AccountChanges.java b/src/main/java/com/syntifi/near/api/model/account/AccountChanges.java
index 957d0d8a..372e3e73 100644
--- a/src/main/java/com/syntifi/near/api/model/account/AccountChanges.java
+++ b/src/main/java/com/syntifi/near/api/model/account/AccountChanges.java
@@ -1,22 +1,30 @@
package com.syntifi.near.api.model.account;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * AccountChanges
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccountChanges {
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("changes")
private Collection changes;
diff --git a/src/main/java/com/syntifi/near/api/model/block/Block.java b/src/main/java/com/syntifi/near/api/model/block/Block.java
index 9520a914..ee19229a 100644
--- a/src/main/java/com/syntifi/near/api/model/block/Block.java
+++ b/src/main/java/com/syntifi/near/api/model/block/Block.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.block;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Block
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Block {
@JsonProperty("author")
private String author;
diff --git a/src/main/java/com/syntifi/near/api/model/block/BlockChange.java b/src/main/java/com/syntifi/near/api/model/block/BlockChange.java
index 72a38e09..078e866b 100644
--- a/src/main/java/com/syntifi/near/api/model/block/BlockChange.java
+++ b/src/main/java/com/syntifi/near/api/model/block/BlockChange.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.block;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * BlockChange
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class BlockChange {
@JsonProperty("type")
private String type;
diff --git a/src/main/java/com/syntifi/near/api/model/block/BlockChanges.java b/src/main/java/com/syntifi/near/api/model/block/BlockChanges.java
index ae366fb2..ce6e6fbe 100644
--- a/src/main/java/com/syntifi/near/api/model/block/BlockChanges.java
+++ b/src/main/java/com/syntifi/near/api/model/block/BlockChanges.java
@@ -1,22 +1,30 @@
package com.syntifi.near.api.model.block;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * BlockChanges
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class BlockChanges {
@JsonProperty("block_hash")
- private String hash;
+ private EncodedHash hash;
@JsonProperty("changes")
private Collection changes;
diff --git a/src/main/java/com/syntifi/near/api/model/block/BlockHeader.java b/src/main/java/com/syntifi/near/api/model/block/BlockHeader.java
index ec653707..c1a7066b 100644
--- a/src/main/java/com/syntifi/near/api/model/block/BlockHeader.java
+++ b/src/main/java/com/syntifi/near/api/model/block/BlockHeader.java
@@ -1,21 +1,30 @@
package com.syntifi.near.api.model.block;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import com.syntifi.near.api.model.key.Signature;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * BlockHeader
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class BlockHeader {
@JsonProperty("height")
private long height;
@@ -31,13 +40,13 @@ public class BlockHeader {
private String nextEpochId;
@JsonProperty("hash")
- private String hash;
+ private EncodedHash hash;
@JsonProperty("prev_hash")
- private String previousHash;
+ private EncodedHash previousHash;
@JsonProperty("prev_state_root")
- private String previousStateRoot;
+ private EncodedHash previousStateRoot;
@JsonProperty("chunk_receipts_root")
private String chunkReceiptsRoot;
@@ -112,8 +121,8 @@ public class BlockHeader {
private Collection approvals;
@JsonProperty("signature")
- private String signature;
+ private Signature signature;
@JsonProperty("latest_protocol_version")
- private long latestrotocolVersion;
+ private long latestProtocolVersion;
}
diff --git a/src/main/java/com/syntifi/near/api/model/block/Chunk.java b/src/main/java/com/syntifi/near/api/model/block/Chunk.java
index 4f8b7cb0..004c9886 100644
--- a/src/main/java/com/syntifi/near/api/model/block/Chunk.java
+++ b/src/main/java/com/syntifi/near/api/model/block/Chunk.java
@@ -1,21 +1,28 @@
package com.syntifi.near.api.model.block;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.transaction.Receipt;
import com.syntifi.near.api.model.transaction.Transaction;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Chunk
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Chunk {
@JsonProperty("author")
private String author;
diff --git a/src/main/java/com/syntifi/near/api/model/block/ChunkHeader.java b/src/main/java/com/syntifi/near/api/model/block/ChunkHeader.java
index 9187d65f..26188c13 100644
--- a/src/main/java/com/syntifi/near/api/model/block/ChunkHeader.java
+++ b/src/main/java/com/syntifi/near/api/model/block/ChunkHeader.java
@@ -1,23 +1,32 @@
package com.syntifi.near.api.model.block;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import com.syntifi.near.api.model.key.Signature;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ChunkHeader
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ChunkHeader {
@JsonProperty("chunk_hash")
- private String hash;
+ private EncodedHash hash;
@JsonProperty("prev_block_hash")
- private String previousBlockHash;
+ private EncodedHash previousBlockHash;
@JsonProperty("outcome_root")
private String outcomeRoot;
@@ -65,5 +74,5 @@ public class ChunkHeader {
private ValidatorProposal[] validatorProposals;
@JsonProperty("signature")
- private String signature;
+ private Signature signature;
}
diff --git a/src/main/java/com/syntifi/near/api/model/block/ValidatorProposal.java b/src/main/java/com/syntifi/near/api/model/block/ValidatorProposal.java
index 155f59c6..1bf8ca1b 100644
--- a/src/main/java/com/syntifi/near/api/model/block/ValidatorProposal.java
+++ b/src/main/java/com/syntifi/near/api/model/block/ValidatorProposal.java
@@ -3,10 +3,17 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
import lombok.Getter;
import lombok.Setter;
+/**
+ * ValidatorProposal
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
@Getter
@Setter
public class ValidatorProposal {
@@ -20,7 +27,7 @@ public class ValidatorProposal {
@JsonInclude(value = Include.NON_EMPTY)
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
@JsonInclude(value = Include.NON_EMPTY)
@JsonProperty("stake")
diff --git a/src/main/java/com/syntifi/near/api/model/common/ChangeCause.java b/src/main/java/com/syntifi/near/api/model/common/ChangeCause.java
index 57e7019d..9f00256f 100644
--- a/src/main/java/com/syntifi/near/api/model/common/ChangeCause.java
+++ b/src/main/java/com/syntifi/near/api/model/common/ChangeCause.java
@@ -3,17 +3,24 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ChangeCause
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ChangeCause {
@JsonProperty("type")
private String type;
diff --git a/src/main/java/com/syntifi/near/api/model/common/EncodedHash.java b/src/main/java/com/syntifi/near/api/model/common/EncodedHash.java
new file mode 100644
index 00000000..ddfdc10e
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/common/EncodedHash.java
@@ -0,0 +1,34 @@
+package com.syntifi.near.api.model.common;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.crypto.key.encdec.Base58;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * ChangeCause
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class EncodedHash {
+ @JsonValue
+ private String encodedHash;
+
+ public byte[] getDecodedHash() {
+ return Base58.decode(this.encodedHash);
+ }
+
+ public void setEncodedHash(byte[] decodedHash) {
+ this.encodedHash = Base58.encode(decodedHash);
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractCode.java b/src/main/java/com/syntifi/near/api/model/contract/ContractCode.java
index c7ce11c0..7a2fbaae 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractCode.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractCode.java
@@ -1,27 +1,35 @@
package com.syntifi.near.api.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ContractCode
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractCode {
@JsonProperty("code_base64")
private String codeBase64;
@JsonProperty("hash")
- private String hash;
+ private EncodedHash hash;
@JsonProperty("block_height")
private long blockHeight;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChange.java b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChange.java
index ad3dd1d9..afcece15 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChange.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChange.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.common.ChangeCause;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ContractCodeChange
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractCodeChange {
@JsonProperty("cause")
private ChangeCause cause;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChangeDetails.java b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChangeDetails.java
index 85e4aee3..d953df5a 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChangeDetails.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChangeDetails.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ContractCodeChangeDetails
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractCodeChangeDetails {
@JsonProperty("account_id")
private String accountId;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChanges.java b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChanges.java
index e9f256d6..8c809d89 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChanges.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractCodeChanges.java
@@ -1,22 +1,30 @@
package com.syntifi.near.api.model.contract;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ContractCodeChanges
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractCodeChanges {
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("changes")
private Collection changes;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractFunctionCallResult.java b/src/main/java/com/syntifi/near/api/model/contract/ContractFunctionCallResult.java
index a06e8ade..6edcd563 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractFunctionCallResult.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractFunctionCallResult.java
@@ -1,19 +1,27 @@
package com.syntifi.near.api.model.contract;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ContractFunctionCallResult
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractFunctionCallResult {
@JsonProperty("result")
private int[] result;
@@ -25,5 +33,5 @@ public class ContractFunctionCallResult {
private long blockHeight;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractState.java b/src/main/java/com/syntifi/near/api/model/contract/ContractState.java
index 95cd609f..0ebf9691 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractState.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractState.java
@@ -1,20 +1,28 @@
package com.syntifi.near.api.model.contract;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.syntifi.near.api.model.common.EncodedHash;
import com.syntifi.near.api.model.transaction.Proof;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ContractState
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractState {
@JsonProperty("values")
private Collection values;
@@ -26,5 +34,5 @@ public class ContractState {
private long blockHeight;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChange.java b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChange.java
index 252bac6e..b01b4ddf 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChange.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChange.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.common.ChangeCause;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ContractStateChange
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractStateChange {
@JsonProperty("cause")
private ChangeCause cause;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChangeDetails.java b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChangeDetails.java
index e66866c8..bf2768c3 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChangeDetails.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChangeDetails.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.contract;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ContractStateChangeDetails
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractStateChangeDetails {
@JsonProperty("account_id")
private String accountId;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChanges.java b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChanges.java
index 9d7a80b8..5ff61096 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractStateChanges.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractStateChanges.java
@@ -1,22 +1,30 @@
package com.syntifi.near.api.model.contract;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ContractStateChanges
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractStateChanges {
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("changes")
private Collection changes;
diff --git a/src/main/java/com/syntifi/near/api/model/contract/ContractStateDetails.java b/src/main/java/com/syntifi/near/api/model/contract/ContractStateDetails.java
index 2d1f6ed1..7ab1f22c 100644
--- a/src/main/java/com/syntifi/near/api/model/contract/ContractStateDetails.java
+++ b/src/main/java/com/syntifi/near/api/model/contract/ContractStateDetails.java
@@ -1,20 +1,27 @@
package com.syntifi.near.api.model.contract;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.transaction.Proof;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ContractStateDetails
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ContractStateDetails {
@JsonProperty("key")
private String key;
diff --git a/src/main/java/com/syntifi/near/api/model/gas/GasPrice.java b/src/main/java/com/syntifi/near/api/model/gas/GasPrice.java
index 82290a9f..a8308016 100644
--- a/src/main/java/com/syntifi/near/api/model/gas/GasPrice.java
+++ b/src/main/java/com/syntifi/near/api/model/gas/GasPrice.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.gas;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * GasPrice
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class GasPrice {
@JsonProperty("gas_price")
private String value;
diff --git a/src/main/java/com/syntifi/near/api/model/identifier/Finality.java b/src/main/java/com/syntifi/near/api/model/identifier/Finality.java
index db36169c..70a9bc95 100644
--- a/src/main/java/com/syntifi/near/api/model/identifier/Finality.java
+++ b/src/main/java/com/syntifi/near/api/model/identifier/Finality.java
@@ -16,9 +16,9 @@
public enum Finality {
OPTIMISTIC("optimistic"), FINAL("final");
- private String type;
+ private final String type;
- private Finality(String type) {
+ Finality(String type) {
this.type = type;
}
diff --git a/src/main/java/com/syntifi/near/api/model/key/KeySig.java b/src/main/java/com/syntifi/near/api/model/key/KeySig.java
new file mode 100644
index 00000000..3b46a9be
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/KeySig.java
@@ -0,0 +1,81 @@
+package com.syntifi.near.api.model.key;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.syntifi.crypto.key.encdec.Base58;
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import com.syntifi.near.borshj.annotation.BorshField;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.regex.Pattern;
+
+/**
+ * KeySig holds information about a key or signature.
+ * Also, it handles to disassemble and assemble of key and signature structure.
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@EqualsAndHashCode
+public class KeySig {
+
+ private static final String SEPARATOR = ":";
+
+ @BorshField(order = 1)
+ @JsonIgnore
+ protected KeyType type;
+
+ @BorshField(order = 2)
+ @JsonIgnore
+ protected byte[] data;
+
+ public KeySig(KeyType keyType, byte[] data) {
+ this.type = keyType;
+ this.data = data;
+ }
+
+ /**
+ * Reads from key or signature from base-58 string
+ *
+ * @param encodedBase58String a string base-58 encoded with the key or signature
+ * @param clazz return class type
+ * @param the parameter return class
+ * @return a PublicKey, PrivateKey or Signature object with type and data
+ */
+ public static T fromEncodedBase58String(String encodedBase58String, Class clazz) {
+ KeyType keyType;
+ byte[] data;
+
+ String[] key = encodedBase58String.split(SEPARATOR, -1);
+ try {
+ keyType = KeyType.valueOf(key[0].toUpperCase());
+ } catch (Exception e) {
+ throw new NoSuchTypeException(String.format("No implementation found for key type %s", key[0]), e);
+ }
+
+ data = Base58.decode(key[1]);
+
+ try {
+ return clazz.getDeclaredConstructor(KeyType.class, byte[].class).newInstance(keyType, data);
+ } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
+ throw new NoSuchTypeException(String.format("Class %s instantiation failed for needed constructor", clazz.getSimpleName()), e);
+ }
+ }
+
+ public String toEncodedBase58String() {
+ return this.getType().toString().toLowerCase() + SEPARATOR + this;
+ }
+
+ @Override
+ public String toString() {
+ return Base58.encode(data);
+ }
+}
+
diff --git a/src/main/java/com/syntifi/near/api/model/key/KeyType.java b/src/main/java/com/syntifi/near/api/model/key/KeyType.java
new file mode 100644
index 00000000..d0e86364
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/KeyType.java
@@ -0,0 +1,12 @@
+package com.syntifi.near.api.model.key;
+
+/**
+ * The KeyType enum
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public enum KeyType {
+ ED25519
+}
diff --git a/src/main/java/com/syntifi/near/api/model/key/PrivateKey.java b/src/main/java/com/syntifi/near/api/model/key/PrivateKey.java
new file mode 100644
index 00000000..ecdb24e1
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/PrivateKey.java
@@ -0,0 +1,51 @@
+package com.syntifi.near.api.model.key;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.crypto.key.AbstractPrivateKey;
+import com.syntifi.crypto.key.Ed25519PrivateKey;
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import lombok.Builder;
+
+/**
+ * Holds a Near PrivateKey
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public class PrivateKey extends KeySig {
+
+ private static final int KEY_SIZE = 32;
+
+ public PrivateKey() {
+ // This solves the case for borsh deserialization for keys of
+ // type ED25591 because to read the 'fixed' byte array we must know
+ // its size.
+ // If any other key (and signature) is implemented, a different
+ // approach is needed (like getters and setters annotation on borsh)
+ this.data = new byte[KEY_SIZE];
+ }
+
+ @Builder
+ public PrivateKey(KeyType keyType, byte[] data) {
+ super(keyType, data);
+ }
+
+ public AbstractPrivateKey getPrivateKey() {
+ if (type == KeyType.ED25519) {
+ return new Ed25519PrivateKey(data);
+ }
+ throw new NoSuchTypeException(String.format("No implementation found for key type %s", type));
+ }
+
+ @JsonCreator
+ public static PrivateKey getPublicKeyFromJson(String base58String) {
+ return PrivateKey.fromEncodedBase58String(base58String, PrivateKey.class);
+ }
+
+ @JsonValue
+ public String getJsonPublicKey() {
+ return this.toEncodedBase58String();
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/model/key/PublicKey.java b/src/main/java/com/syntifi/near/api/model/key/PublicKey.java
new file mode 100644
index 00000000..684d4010
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/PublicKey.java
@@ -0,0 +1,60 @@
+package com.syntifi.near.api.model.key;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.crypto.key.AbstractPublicKey;
+import com.syntifi.crypto.key.Ed25519PublicKey;
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import com.syntifi.near.borshj.Borsh;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+
+/**
+ * Holds a Near PublicKey
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@EqualsAndHashCode(callSuper = true)
+public class PublicKey extends KeySig implements Borsh {
+
+ private static final int KEY_SIZE = 32;
+
+ public PublicKey() {
+ // This solves the case for borsh deserialization for keys of
+ // type ED25591 because to read the 'fixed' byte array we must know
+ // its size.
+ // If any other key (and signature) is implemented, a different
+ // approach is needed (like getters and setters annotation on borsh)
+ this.data = new byte[KEY_SIZE];
+ }
+
+ /**
+ * Instantiate a Public Key
+ *
+ * @param keyType the KeyType
+ * @param data the key bytes
+ */
+ @Builder
+ public PublicKey(KeyType keyType, byte[] data) {
+ super(keyType, data);
+ }
+
+ public AbstractPublicKey getPublicKey() {
+ if (type == KeyType.ED25519) {
+ return new Ed25519PublicKey(data);
+ }
+ throw new NoSuchTypeException(String.format("No implementation found for key type %s", type));
+ }
+
+ @JsonCreator
+ public static PublicKey getPublicKeyFromJson(String base58String) {
+ return PublicKey.fromEncodedBase58String(base58String, PublicKey.class);
+ }
+
+ @JsonValue
+ public String getJsonPublicKey() {
+ return this.toEncodedBase58String();
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/model/key/Signature.java b/src/main/java/com/syntifi/near/api/model/key/Signature.java
new file mode 100644
index 00000000..9bf38200
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/Signature.java
@@ -0,0 +1,44 @@
+package com.syntifi.near.api.model.key;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.syntifi.near.borshj.Borsh;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+
+/**
+ * Holds a Near Signature
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@EqualsAndHashCode(callSuper = true)
+public class Signature extends KeySig implements Borsh {
+
+ private static final int SIGNATURE_SIZE = 64;
+
+ public Signature() {
+ // This solves the case for borsh deserialization for signatures of
+ // type ED25591 because to read the 'fixed' byte array we must know
+ // its size.
+ // If any other signature (and key) is implemented, a different
+ // approach is needed (like getters and setters annotation on borsh)
+ this.data = new byte[SIGNATURE_SIZE];
+ }
+
+ @Builder
+ public Signature(KeyType keyType, byte[] data) {
+ super(keyType, data);
+ }
+
+ @JsonCreator
+ public static Signature getPublicKeyFromJson(String base58String) {
+ return Signature.fromEncodedBase58String(base58String, Signature.class);
+ }
+
+ @JsonValue
+ public String getJsonPublicKey() {
+ return this.toEncodedBase58String();
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/model/key/Wallet.java b/src/main/java/com/syntifi/near/api/model/key/Wallet.java
new file mode 100644
index 00000000..269f7570
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/key/Wallet.java
@@ -0,0 +1,24 @@
+package com.syntifi.near.api.model.key;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+
+/**
+ * Simple structure class mainly to hold information read from json wallets.
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+public class Wallet {
+ @JsonProperty("account_id")
+ private String account;
+ @JsonProperty("public_key")
+ private PublicKey publicKey;
+ @JsonProperty("private_key")
+ private PrivateKey privateKey;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/network/CurrentProposal.java b/src/main/java/com/syntifi/near/api/model/network/CurrentProposal.java
index df677399..ae270416 100644
--- a/src/main/java/com/syntifi/near/api/model/network/CurrentProposal.java
+++ b/src/main/java/com/syntifi/near/api/model/network/CurrentProposal.java
@@ -1,17 +1,25 @@
package com.syntifi.near.api.model.network;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * CurrentProposal
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class CurrentProposal {
@JsonProperty("validator_stake_struct_version")
private String validatorStakeStructVersion;
@@ -20,7 +28,7 @@ public class CurrentProposal {
private String accountId;
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
@JsonProperty("stake")
private String stake;
diff --git a/src/main/java/com/syntifi/near/api/model/network/Fisherman.java b/src/main/java/com/syntifi/near/api/model/network/Fisherman.java
index 9462c3b6..8fda7053 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Fisherman.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Fisherman.java
@@ -1,23 +1,31 @@
package com.syntifi.near.api.model.network;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Fisherman
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Fisherman {
@JsonProperty("account_id")
private String accountId;
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
@JsonProperty("stake")
private String stake;
diff --git a/src/main/java/com/syntifi/near/api/model/network/NetworkInfo.java b/src/main/java/com/syntifi/near/api/model/network/NetworkInfo.java
index cf8c672d..80b89b1c 100644
--- a/src/main/java/com/syntifi/near/api/model/network/NetworkInfo.java
+++ b/src/main/java/com/syntifi/near/api/model/network/NetworkInfo.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.network;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * NetworkInfo
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class NetworkInfo {
@JsonProperty("active_peers")
private Collection activePeers;
diff --git a/src/main/java/com/syntifi/near/api/model/network/NodeStatus.java b/src/main/java/com/syntifi/near/api/model/network/NodeStatus.java
index 32edc71d..4d0407df 100644
--- a/src/main/java/com/syntifi/near/api/model/network/NodeStatus.java
+++ b/src/main/java/com/syntifi/near/api/model/network/NodeStatus.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.network;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * NodeStatus
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class NodeStatus {
@JsonProperty("version")
private Version version;
diff --git a/src/main/java/com/syntifi/near/api/model/network/NotEnoughBlocksReason.java b/src/main/java/com/syntifi/near/api/model/network/NotEnoughBlocksReason.java
index 30007471..7f52e6ca 100644
--- a/src/main/java/com/syntifi/near/api/model/network/NotEnoughBlocksReason.java
+++ b/src/main/java/com/syntifi/near/api/model/network/NotEnoughBlocksReason.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * NotEnoughBlocksReason
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
@JsonTypeName("NotEnoughBlocks")
public class NotEnoughBlocksReason implements Reason {
@JsonProperty("produced")
diff --git a/src/main/java/com/syntifi/near/api/model/network/NotEnoughChunksReason.java b/src/main/java/com/syntifi/near/api/model/network/NotEnoughChunksReason.java
index 41052daa..ddf57685 100644
--- a/src/main/java/com/syntifi/near/api/model/network/NotEnoughChunksReason.java
+++ b/src/main/java/com/syntifi/near/api/model/network/NotEnoughChunksReason.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * NotEnoughChunksReason
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
@JsonTypeName("NotEnoughChunks")
public class NotEnoughChunksReason implements Reason {
@JsonProperty("produced")
diff --git a/src/main/java/com/syntifi/near/api/model/network/Peer.java b/src/main/java/com/syntifi/near/api/model/network/Peer.java
index 819fa23b..dee1a6d1 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Peer.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Peer.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.network;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Peer
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Peer {
@JsonProperty("id")
private String id;
diff --git a/src/main/java/com/syntifi/near/api/model/network/PrevEpochKickout.java b/src/main/java/com/syntifi/near/api/model/network/PrevEpochKickout.java
index 88aba570..acf78042 100644
--- a/src/main/java/com/syntifi/near/api/model/network/PrevEpochKickout.java
+++ b/src/main/java/com/syntifi/near/api/model/network/PrevEpochKickout.java
@@ -3,24 +3,31 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * PrevEpochKickout
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class PrevEpochKickout {
@Getter
@Setter
- public class Reason {
+ public static class Reason {
@Getter
@Setter
- public class NotEnough {
+ public static class NotEnough {
private long produced;
private long expected;
}
diff --git a/src/main/java/com/syntifi/near/api/model/network/Producer.java b/src/main/java/com/syntifi/near/api/model/network/Producer.java
index e692085e..25eb25f7 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Producer.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Producer.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.network;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Producer
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Producer {
@JsonProperty("account_id")
private String accountId;
diff --git a/src/main/java/com/syntifi/near/api/model/network/Reason.java b/src/main/java/com/syntifi/near/api/model/network/Reason.java
index da03460b..83d1ce0e 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Reason.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Reason.java
@@ -2,16 +2,16 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
/**
+ * Reason Interface
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT)
-@JsonSubTypes({ @JsonSubTypes.Type(value = NotEnoughBlocksReason.class, name = "NotEnoughBlocks"),
- @JsonSubTypes.Type(value = NotEnoughChunksReason.class, name = "NotEnoughChunks") })
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
+@JsonSubTypes({@JsonSubTypes.Type(value = NotEnoughBlocksReason.class, name = "NotEnoughBlocks"),
+ @JsonSubTypes.Type(value = NotEnoughChunksReason.class, name = "NotEnoughChunks")})
public interface Reason {
}
diff --git a/src/main/java/com/syntifi/near/api/model/network/SyncInfo.java b/src/main/java/com/syntifi/near/api/model/network/SyncInfo.java
index 45d193f1..96a6bc1d 100644
--- a/src/main/java/com/syntifi/near/api/model/network/SyncInfo.java
+++ b/src/main/java/com/syntifi/near/api/model/network/SyncInfo.java
@@ -3,17 +3,24 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * SyncInfo
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class SyncInfo {
@JsonProperty("latest_block_hash")
private String latestBlockHash;
diff --git a/src/main/java/com/syntifi/near/api/model/network/ValidationStatus.java b/src/main/java/com/syntifi/near/api/model/network/ValidationStatus.java
index 2f43dfa7..53effbe5 100644
--- a/src/main/java/com/syntifi/near/api/model/network/ValidationStatus.java
+++ b/src/main/java/com/syntifi/near/api/model/network/ValidationStatus.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.network;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ValidationStatus
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ValidationStatus {
@JsonProperty("current_validators")
private Collection currentValidators;
diff --git a/src/main/java/com/syntifi/near/api/model/network/Validator.java b/src/main/java/com/syntifi/near/api/model/network/Validator.java
index 8037221e..bba5a875 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Validator.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Validator.java
@@ -1,28 +1,36 @@
package com.syntifi.near.api.model.network;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Validator
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Validator {
@JsonProperty("account_id")
private String accountId;
@JsonProperty("public_key")
@JsonInclude(value = Include.NON_EMPTY)
- private String publicKey;
+ private PublicKey publicKey;
@JsonProperty("is_slashed")
@JsonInclude(value = Include.NON_EMPTY)
diff --git a/src/main/java/com/syntifi/near/api/model/network/Version.java b/src/main/java/com/syntifi/near/api/model/network/Version.java
index e066746c..3c9a277d 100644
--- a/src/main/java/com/syntifi/near/api/model/network/Version.java
+++ b/src/main/java/com/syntifi/near/api/model/network/Version.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.network;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Version
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Version {
@JsonProperty("version")
private String number;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/AccountCreationConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/AccountCreationConfig.java
index 7a03e852..8b26c93f 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/AccountCreationConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/AccountCreationConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AccountCreationConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AccountCreationConfig {
@JsonProperty("min_allowed_top_level_account_length")
private long minAllowedTopLevelAccountLength;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/ActionCreationConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/ActionCreationConfig.java
index a795094c..092f4433 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/ActionCreationConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/ActionCreationConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ActionCreationConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ActionCreationConfig {
@JsonProperty("create_account_cost")
private Cost createAccountCost;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/AddKeyCost.java b/src/main/java/com/syntifi/near/api/model/protocol/AddKeyCost.java
index 15eb912a..850dfb7b 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/AddKeyCost.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/AddKeyCost.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * AddKeyCost
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class AddKeyCost {
@JsonProperty("full_access_cost")
private Cost fullAccessCost;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/Cost.java b/src/main/java/com/syntifi/near/api/model/protocol/Cost.java
index 7597a18c..c55c423c 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/Cost.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/Cost.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Cost
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Cost {
@JsonProperty("send_sir")
private long sendSir;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/DataReceiptCreationConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/DataReceiptCreationConfig.java
index 55807364..7cadcc81 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/DataReceiptCreationConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/DataReceiptCreationConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * DataReceiptCreationConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class DataReceiptCreationConfig {
@JsonProperty("base_cost")
private Cost baseCost;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/ExtCosts.java b/src/main/java/com/syntifi/near/api/model/protocol/ExtCosts.java
index 9f324bed..cc629cb7 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/ExtCosts.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/ExtCosts.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ExtCosts
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ExtCosts {
@JsonProperty("base")
private long base;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/GenesisConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/GenesisConfig.java
index bc61feca..34f46006 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/GenesisConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/GenesisConfig.java
@@ -1,22 +1,29 @@
package com.syntifi.near.api.model.protocol;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.syntifi.near.api.model.network.Validator;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * GenesisConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class GenesisConfig {
@JsonProperty("protocol_version")
private long protocolVersion;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/LimitConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/LimitConfig.java
index 5b457562..40d7e927 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/LimitConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/LimitConfig.java
@@ -3,17 +3,24 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * LimitConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class LimitConfig {
@JsonProperty("max_gas_burnt")
private long maxGasBurnt;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/ProtocolConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/ProtocolConfig.java
index 8a0505ed..9273ad63 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/ProtocolConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/ProtocolConfig.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.protocol;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ProtocolConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ProtocolConfig {
@JsonProperty("protocol_version")
private long protocolVersion;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/RuntimeConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/RuntimeConfig.java
index bdcc5baa..0e88d265 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/RuntimeConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/RuntimeConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * RuntimeConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class RuntimeConfig {
@JsonProperty("storage_amount_per_byte")
private String storageAmountPerByte;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/ShardLayout.java b/src/main/java/com/syntifi/near/api/model/protocol/ShardLayout.java
index edcb0626..54ab1a69 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/ShardLayout.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/ShardLayout.java
@@ -1,21 +1,28 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ShardLayout
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ShardLayout {
@Getter
@Setter
- public class V0 {
+ public static class V0 {
@JsonProperty("num_shards")
private long numShards;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/SimpleNightShadeShardLayout.java b/src/main/java/com/syntifi/near/api/model/protocol/SimpleNightShadeShardLayout.java
index 6cb7c05b..15ee0fd2 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/SimpleNightShadeShardLayout.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/SimpleNightShadeShardLayout.java
@@ -1,23 +1,30 @@
package com.syntifi.near.api.model.protocol;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * SimpleNightShadeShardLayout
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class SimpleNightShadeShardLayout {
@Getter
@Setter
- public class V1 {
+ public static class V1 {
@JsonProperty("fixed_shards")
private Collection fixedShards;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/StorageUsageConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/StorageUsageConfig.java
index eb62edb7..2511e37a 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/StorageUsageConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/StorageUsageConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * StorageUsageConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class StorageUsageConfig {
@JsonProperty("num_bytes_account")
private long numBytesAccount;
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/TransactionCosts.java b/src/main/java/com/syntifi/near/api/model/protocol/TransactionCosts.java
index 98be344f..7e45fade 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/TransactionCosts.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/TransactionCosts.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.protocol;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * TransactionCosts
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class TransactionCosts {
@JsonProperty("action_receipt_creation_config")
diff --git a/src/main/java/com/syntifi/near/api/model/protocol/WasmConfig.java b/src/main/java/com/syntifi/near/api/model/protocol/WasmConfig.java
index 4506cb05..adbe1eaa 100644
--- a/src/main/java/com/syntifi/near/api/model/protocol/WasmConfig.java
+++ b/src/main/java/com/syntifi/near/api/model/protocol/WasmConfig.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * WasmConfig
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class WasmConfig {
@JsonProperty("ext_costs")
private ExtCosts extCosts;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Action.java b/src/main/java/com/syntifi/near/api/model/transaction/Action.java
index 0a6001d9..16bbfa3c 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Action.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Action.java
@@ -4,14 +4,36 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+import com.syntifi.near.borshj.Borsh;
+import com.syntifi.near.borshj.annotation.BorshSubTypes;
/**
+ * Action Interface
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT)
-@JsonSubTypes({ @JsonSubTypes.Type(value = TransferAction.class, name = "Transfer"),
- @JsonSubTypes.Type(value = FunctionCallAction.class, name = "FunctionCall") })
-public interface Action {
-}
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = TransferAction.class, name = "Transfer"),
+ @JsonSubTypes.Type(value = FunctionCallAction.class, name = "FunctionCall")})
+@BorshSubTypes({
+ @BorshSubTypes.BorshSubType(when = Action.CREATE_ACCOUNT, use = CreateAccountAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.DEPLOY_CONTRACT, use = DeployContractAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.FUNCTION_CALL, use = FunctionCallAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.STAKE, use = StakeAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.ADD_KEY, use = AddKeyAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.DELETE_KEY, use = DeleteKeyAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.DELETE_ACCOUNT, use = DeleteAccountAction.class),
+ @BorshSubTypes.BorshSubType(when = Action.TRANSFER, use = TransferAction.class)})
+public interface Action extends Borsh {
+ byte CREATE_ACCOUNT = 0;
+ byte DEPLOY_CONTRACT = 1;
+ byte FUNCTION_CALL = 2;
+ byte TRANSFER = 3;
+ byte STAKE = 4;
+ byte ADD_KEY = 5;
+ byte DELETE_KEY = 6;
+ byte DELETE_ACCOUNT = 7;
+}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/AddKeyAction.java b/src/main/java/com/syntifi/near/api/model/transaction/AddKeyAction.java
new file mode 100644
index 00000000..509ec0b4
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/AddKeyAction.java
@@ -0,0 +1,27 @@
+package com.syntifi.near.api.model.transaction;
+
+import com.syntifi.near.api.model.accesskey.AccessKey;
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * AddKeyAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class AddKeyAction implements Action {
+ private PublicKey publicKey;
+
+ private AccessKey accessKey;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/CostType.java b/src/main/java/com/syntifi/near/api/model/transaction/CostType.java
index 1e7b7bea..4ba69d94 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/CostType.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/CostType.java
@@ -1,6 +1,8 @@
package com.syntifi.near.api.model.transaction;
/**
+ * CostType
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -31,5 +33,5 @@ public enum CostType {
WRITE_MEMORY_BASE,
WRITE_MEMORY_BYTE,
WRITE_REGISTER_BASE,
- WRITE_REGISTER_BYTE;
+ WRITE_REGISTER_BYTE
}
\ No newline at end of file
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/CreateAccountAction.java b/src/main/java/com/syntifi/near/api/model/transaction/CreateAccountAction.java
new file mode 100644
index 00000000..ac92d68d
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/CreateAccountAction.java
@@ -0,0 +1,20 @@
+package com.syntifi.near.api.model.transaction;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * CreateAccountAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@Builder
+public class CreateAccountAction implements Action {
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/DeleteAccountAction.java b/src/main/java/com/syntifi/near/api/model/transaction/DeleteAccountAction.java
new file mode 100644
index 00000000..bfd13d65
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/DeleteAccountAction.java
@@ -0,0 +1,23 @@
+package com.syntifi.near.api.model.transaction;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * DeleteAccountAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class DeleteAccountAction implements Action {
+ private String beneficiaryId;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/DeleteKeyAction.java b/src/main/java/com/syntifi/near/api/model/transaction/DeleteKeyAction.java
new file mode 100644
index 00000000..b9289f33
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/DeleteKeyAction.java
@@ -0,0 +1,24 @@
+package com.syntifi.near.api.model.transaction;
+
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * DeleteKeyAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class DeleteKeyAction implements Action {
+ private PublicKey publicKey;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/DeployContractAction.java b/src/main/java/com/syntifi/near/api/model/transaction/DeployContractAction.java
new file mode 100644
index 00000000..5aa5eed4
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/DeployContractAction.java
@@ -0,0 +1,23 @@
+package com.syntifi.near.api.model.transaction;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * DeployContractAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class DeployContractAction implements Action {
+ private byte[] code;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/FunctionCallAction.java b/src/main/java/com/syntifi/near/api/model/transaction/FunctionCallAction.java
index 6b3269a1..ebf87393 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/FunctionCallAction.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/FunctionCallAction.java
@@ -2,17 +2,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * FunctionCallAction
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
@JsonTypeName("FunctionCall")
public class FunctionCallAction implements Action {
@JsonProperty("method_name")
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/GasProfile.java b/src/main/java/com/syntifi/near/api/model/transaction/GasProfile.java
index c3bfceca..745f7869 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/GasProfile.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/GasProfile.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.transaction;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * GasProfile
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class GasProfile {
@JsonProperty("cost_category")
private String costCategory;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Metadata.java b/src/main/java/com/syntifi/near/api/model/transaction/Metadata.java
index e69c45b7..130195f9 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Metadata.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Metadata.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Metadata
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Metadata {
@JsonProperty("version")
private long version;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Outcome.java b/src/main/java/com/syntifi/near/api/model/transaction/Outcome.java
index eda3a840..c040461f 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Outcome.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Outcome.java
@@ -1,21 +1,28 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Outcome
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Outcome {
@JsonProperty("logs")
private Collection logs;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Proof.java b/src/main/java/com/syntifi/near/api/model/transaction/Proof.java
index 988e2612..eeadd7a7 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Proof.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Proof.java
@@ -2,32 +2,41 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Proof
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Proof {
public enum Direction {
RIGHT("Right"),
LEFT("Left");
+ @Getter
@JsonValue
- private String name;
+ private final String name;
- private Direction(String name) {
+ Direction(String name) {
this.name = name;
}
}
@JsonProperty("hash")
- private String hash;
+ private EncodedHash hash;
@JsonProperty("direction")
private Direction direction;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Receipt.java b/src/main/java/com/syntifi/near/api/model/transaction/Receipt.java
index a4140b43..c626a9f9 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Receipt.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Receipt.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.transaction;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * Receipt
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class Receipt {
@JsonProperty("predecessor_id")
private String predecessorId;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptAction.java b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptAction.java
index 00d0fb9a..24615698 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptAction.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptAction.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ReceiptAction
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ReceiptAction {
@JsonProperty("actions")
private Collection actions;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptData.java b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptData.java
index 06eac18c..ebc987a8 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptData.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptData.java
@@ -1,17 +1,24 @@
package com.syntifi.near.api.model.transaction;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * ReceiptData
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ReceiptData {
@JsonProperty("Action")
private ReceiptAction receiptAction;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptOutcome.java b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptOutcome.java
index 6b7e3994..882c7d23 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/ReceiptOutcome.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/ReceiptOutcome.java
@@ -1,25 +1,33 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * ReceiptOutcome
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class ReceiptOutcome {
@JsonProperty("proof")
private Collection proof;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("id")
private String id;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/SignedTransaction.java b/src/main/java/com/syntifi/near/api/model/transaction/SignedTransaction.java
new file mode 100644
index 00000000..e9a3bca0
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/SignedTransaction.java
@@ -0,0 +1,31 @@
+package com.syntifi.near.api.model.transaction;
+
+import com.syntifi.near.api.model.key.Signature;
+import com.syntifi.near.borshj.Borsh;
+import com.syntifi.near.borshj.annotation.BorshField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * SignedTransaction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@EqualsAndHashCode
+public class SignedTransaction implements Borsh {
+ @BorshField(order = 1)
+ private Transaction transaction;
+ @BorshField(order = 2)
+ private Signature signature;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/StakeAction.java b/src/main/java/com/syntifi/near/api/model/transaction/StakeAction.java
new file mode 100644
index 00000000..b2697498
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/model/transaction/StakeAction.java
@@ -0,0 +1,28 @@
+package com.syntifi.near.api.model.transaction;
+
+import com.syntifi.near.api.model.key.PublicKey;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.math.BigInteger;
+
+/**
+ * StakeAction
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class StakeAction implements Action {
+ private BigInteger stake;
+
+ private PublicKey publicKey;
+}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Status.java b/src/main/java/com/syntifi/near/api/model/transaction/Status.java
index 9056081c..7c2a05fe 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Status.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Status.java
@@ -2,16 +2,16 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
-import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
/**
+ * Status
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-@JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT)
-@JsonSubTypes({ @JsonSubTypes.Type(value = SuccessReceiptIdStatus.class, name = "SuccessReceiptId"),
- @JsonSubTypes.Type(value = SuccessValueStatus.class, name = "SuccessValue") })
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
+@JsonSubTypes({@JsonSubTypes.Type(value = SuccessReceiptIdStatus.class, name = "SuccessReceiptId"),
+ @JsonSubTypes.Type(value = SuccessValueStatus.class, name = "SuccessValue")})
public interface Status {
}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/SuccessReceiptIdStatus.java b/src/main/java/com/syntifi/near/api/model/transaction/SuccessReceiptIdStatus.java
index 49e7f728..b797f421 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/SuccessReceiptIdStatus.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/SuccessReceiptIdStatus.java
@@ -2,23 +2,26 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * SuccessReceiptIdStatus
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
@JsonTypeName("SuccessReceiptId")
public class SuccessReceiptIdStatus implements Status {
@JsonValue
private String successReceiptId;
-
- public SuccessReceiptIdStatus(String successReceiptId) {
- this.successReceiptId = successReceiptId;
- }
}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/SuccessValueStatus.java b/src/main/java/com/syntifi/near/api/model/transaction/SuccessValueStatus.java
index 97dfcef6..87c20c38 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/SuccessValueStatus.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/SuccessValueStatus.java
@@ -2,23 +2,26 @@
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
/**
+ * SuccessValueStatus
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
@JsonTypeName("SuccessValue")
public class SuccessValueStatus implements Status {
@JsonValue
private String successValue;
-
- public SuccessValueStatus(String successValue) {
- this.successValue = successValue;
- }
}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/Transaction.java b/src/main/java/com/syntifi/near/api/model/transaction/Transaction.java
index 13dd51d4..6c14f716 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/Transaction.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/Transaction.java
@@ -1,38 +1,64 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import com.syntifi.near.api.model.key.PublicKey;
+import com.syntifi.near.api.model.key.Signature;
+import com.syntifi.near.borshj.Borsh;
+import com.syntifi.near.borshj.annotation.BorshField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * Transaction
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
-public class Transaction {
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@EqualsAndHashCode
+public class Transaction implements Borsh {
+ private final static int BLOCK_HASH_LENGTH = 32;
+
+ @BorshField(order = 1)
@JsonProperty("signer_id")
private String signerId;
+ @BorshField(order = 2)
@JsonProperty("public_key")
- private String publicKey;
+ private PublicKey publicKey;
+ @BorshField(order = 3)
@JsonProperty("nonce")
- private long nonce;
+ private Long nonce;
+ @BorshField(order = 4)
@JsonProperty("receiver_id")
private String receiverId;
+ @BorshField(order = 6)
@JsonProperty("actions")
private Collection actions;
@JsonProperty("signature")
- private String signature;
+ private Signature signature;
+
+ @BorshField(order = 5)
+ @JsonIgnore
+ private byte[] blockHash = new byte[BLOCK_HASH_LENGTH];
@JsonProperty("hash")
- private String hash;
+ private EncodedHash hash;
}
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/TransactionAwait.java b/src/main/java/com/syntifi/near/api/model/transaction/TransactionAwait.java
index 7c24eab2..854fb5b3 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/TransactionAwait.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/TransactionAwait.java
@@ -1,19 +1,26 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * TransactionAwait
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class TransactionAwait {
@JsonProperty("status")
private Status status;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/TransactionOutcome.java b/src/main/java/com/syntifi/near/api/model/transaction/TransactionOutcome.java
index 7b75546f..f83f78ee 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/TransactionOutcome.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/TransactionOutcome.java
@@ -1,25 +1,33 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import com.syntifi.near.api.model.common.EncodedHash;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * TransactionOutcome
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class TransactionOutcome {
@JsonProperty("proof")
private Collection proof;
@JsonProperty("block_hash")
- private String blockHash;
+ private EncodedHash blockHash;
@JsonProperty("id")
private String id;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/TransactionStatus.java b/src/main/java/com/syntifi/near/api/model/transaction/TransactionStatus.java
index 7fc5519b..9074ce17 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/TransactionStatus.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/TransactionStatus.java
@@ -1,21 +1,28 @@
package com.syntifi.near.api.model.transaction;
-import java.util.Collection;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.util.Collection;
+
/**
+ * TransactionStatus
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
public class TransactionStatus {
@JsonProperty("status")
private Status status;
diff --git a/src/main/java/com/syntifi/near/api/model/transaction/TransferAction.java b/src/main/java/com/syntifi/near/api/model/transaction/TransferAction.java
index b5e52947..8a6ce4d8 100644
--- a/src/main/java/com/syntifi/near/api/model/transaction/TransferAction.java
+++ b/src/main/java/com/syntifi/near/api/model/transaction/TransferAction.java
@@ -1,20 +1,44 @@
package com.syntifi.near.api.model.transaction;
+import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
-
+import com.syntifi.near.borshj.annotation.BorshField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import java.math.BigInteger;
+
/**
+ * TransferAction
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
@Getter
@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@EqualsAndHashCode
@JsonTypeName("Transfer")
public class TransferAction implements Action {
+ @BorshField(order = 1)
@JsonProperty("deposit")
- private String deposit;
+ private BigInteger deposit;
+
+ /**
+ * Json expects string, not number
+ *
+ * @return the deposit as string for json serialization
+ */
+ @JsonGetter("deposit")
+ private String getJsonDeposit() {
+ return deposit.toString();
+ }
}
diff --git a/src/main/java/com/syntifi/near/api/service/NearService.java b/src/main/java/com/syntifi/near/api/service/NearService.java
index 4e18fbf9..ec759c75 100644
--- a/src/main/java/com/syntifi/near/api/service/NearService.java
+++ b/src/main/java/com/syntifi/near/api/service/NearService.java
@@ -1,10 +1,5 @@
package com.syntifi.near.api.service;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-import java.util.TreeMap;
-
import com.googlecode.jsonrpc4j.JsonRpcFixedParam;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.JsonRpcMethod;
@@ -38,9 +33,14 @@
import com.syntifi.near.api.service.exception.NearServiceException;
import com.syntifi.near.api.service.exception.NearServiceExceptionResolver;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.TreeMap;
+
/**
* RPC client for the Near network
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
@@ -49,270 +49,267 @@ public interface NearService {
/**
* Queries network and returns block for given height or hash.
- *
+ *
* @param finality the finality param
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("block")
- public Block getBlock(@JsonRpcParam("finality") Finality finality) throws NearServiceException;
+ Block getBlock(@JsonRpcParam("finality") Finality finality) throws NearServiceException;
/**
* Queries network and returns block for given height or hash.
- *
+ *
* @param blockHash the block's hash
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("block")
- public Block getBlock(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
+ Block getBlock(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
/**
* Queries network and returns block for given height or hash.
- *
+ *
* @param blockHeight the block's height
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("block")
- public Block getBlock(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
+ Block getBlock(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
/**
- *
* @param finality the finality param
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_changes_in_block")
- public BlockChanges getBlockChanges(@JsonRpcParam("finality") Finality finality) throws NearServiceException;
+ BlockChanges getBlockChanges(@JsonRpcParam("finality") Finality finality) throws NearServiceException;
/**
- *
* @param blockHash the block's hash
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_changes_in_block")
- public BlockChanges getBlockChanges(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
+ BlockChanges getBlockChanges(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
/**
- *
* @param blockHeight the block's height
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_changes_in_block")
- public BlockChanges getBlockChanges(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
+ BlockChanges getBlockChanges(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
/**
* Returns details of a specific chunk. You can run a block details query to get
* a valid chunk hash.
- *
+ *
* @param chunkId the id of the chunk
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("chunk")
- public Chunk getChunkDetails(@JsonRpcParam("chunk_id") String chunkId) throws NearServiceException;
+ Chunk getChunkDetails(@JsonRpcParam("chunk_id") String chunkId) throws NearServiceException;
/**
* Returns details of a specific chunk. You can run a block details query to get
* a valid chunk hash.
- *
+ *
* @param blockId the block hash
* @param shardId the id of the shard
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("chunk")
- public Chunk getChunkDetails(@JsonRpcParam("block_id") String blockId,
- @JsonRpcParam("shard_id") long shardId) throws NearServiceException;
+ Chunk getChunkDetails(@JsonRpcParam("block_id") String blockId,
+ @JsonRpcParam("shard_id") long shardId) throws NearServiceException;
/**
* Returns details of a specific chunk. You can run a block details query to get
* a valid chunk hash.
- *
+ *
* @param blockId the block height
* @param shardId the id of the shard
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("chunk")
- public Chunk getChunkDetails(@JsonRpcParam("block_id") long blockId,
- @JsonRpcParam("shard_id") long shardId) throws NearServiceException;
+ Chunk getChunkDetails(@JsonRpcParam("block_id") long blockId,
+ @JsonRpcParam("shard_id") long shardId) throws NearServiceException;
/**
* Returns general status of a given node (sync status, nearcore node version,
* protocol version, etc), and the current set of validators.
- *
+ *
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("status")
- public NodeStatus getNodeStatus() throws NearServiceException;
+ NodeStatus getNodeStatus() throws NearServiceException;
/**
* Returns the current state of node network connections (active peers,
* transmitted data, etc.)
- *
+ *
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("network_info")
- public NetworkInfo getNetworkInfo() throws NearServiceException;
+ NetworkInfo getNetworkInfo() throws NearServiceException;
/**
* Queries active validators on the network returning details and the state of
* validation on the blockchain.
- *
+ *
* @param blockHash the block's hash
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "validators", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public ValidationStatus getNetworkValidationStatus(String blockHash) throws NearServiceException;
+ ValidationStatus getNetworkValidationStatus(String blockHash) throws NearServiceException;
/**
* Queries active validators on the network returning details and the state of
* validation on the blockchain.
- *
+ *
* @param blockHeight the block's height
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "validators", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public ValidationStatus getNetworkValidationStatus(long blockHeight) throws NearServiceException;
+ ValidationStatus getNetworkValidationStatus(long blockHeight) throws NearServiceException;
/**
* Returns gas price for a specific block_height or block_hash.
* - Using [null] will return the most recent block's gas price.
- *
+ *
* @param blockHash the block's hash
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "gas_price", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public GasPrice getGasPrice(String blockHash) throws NearServiceException;
+ GasPrice getGasPrice(String blockHash) throws NearServiceException;
/**
* Returns gas price for a specific block_height or block_hash.
- *
+ *
* @param blockHeight the block's height
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "gas_price", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public GasPrice getGasPrice(long blockHeight) throws NearServiceException;
+ GasPrice getGasPrice(long blockHeight) throws NearServiceException;
/**
* Returns current genesis configuration.
- *
+ *
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_genesis_config")
- public GenesisConfig getGenesisConfig() throws NearServiceException;
+ GenesisConfig getGenesisConfig() throws NearServiceException;
/**
* Returns most recent protocol configuration or a specific queried block.
* Useful for finding current storage and transaction costs.
- *
+ *
* @param finality the finality param
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_protocol_config")
- public ProtocolConfig getProtocolConfig(@JsonRpcParam("finality") Finality finality)
+ ProtocolConfig getProtocolConfig(@JsonRpcParam("finality") Finality finality)
throws NearServiceException;
/**
* Returns most recent protocol configuration or a specific queried block.
* Useful for finding current storage and transaction costs.
- *
+ *
* @param blockHash the block's hash
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_protocol_config")
- public ProtocolConfig getProtocolConfig(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
+ ProtocolConfig getProtocolConfig(@JsonRpcParam("block_id") String blockHash) throws NearServiceException;
/**
* Returns most recent protocol configuration or a specific queried block.
* Useful for finding current storage and transaction costs.
- *
+ *
* @param blockHeight the block's height
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_protocol_config")
- public ProtocolConfig getProtocolConfig(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
+ ProtocolConfig getProtocolConfig(@JsonRpcParam("block_id") long blockHeight) throws NearServiceException;
/**
* Sends a transaction and immediately returns transaction hash.
- *
+ *
* @param base64EncodedSignedTransaction the base64 encoded signed transaction
* string
* @return the transaction hash
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "broadcast_tx_async", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public String sendTransactionAsync(String base64EncodedSignedTransaction) throws NearServiceException;
+ String sendTransactionAsync(String base64EncodedSignedTransaction) throws NearServiceException;
/**
* Sends a transaction and waits until transaction is fully complete. (Has a 10
* second timeout)
- *
+ *
* @param base64EncodedSignedTransaction the base64 encoded signed transaction
* string
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "broadcast_tx_commit", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public TransactionAwait sendTransactionAwait(String base64EncodedSignedTransaction) throws NearServiceException;
+ TransactionAwait sendTransactionAwait(String base64EncodedSignedTransaction) throws NearServiceException;
/**
* Queries status of a transaction by hash and returns the final transaction
* result.
- *
+ *
* @param transactionHash the transaction hash
* @param senderAccountId the sender's account id
* @return the data holding object the final transaction result
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "tx", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public TransactionStatus getTransactionStatus(String transactionHash, String senderAccountId)
+ TransactionStatus getTransactionStatus(String transactionHash, String senderAccountId)
throws NearServiceException;
/**
* Queries status of a transaction by hash, returning the final transaction
* result and details of all receipts.
- *
+ *
* @param transactionHash the transaction hash
* @param senderAccountId the sender's account id
* @return the data holding object the final transaction result and details of
- * all receipts
+ * all receipts
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod(value = "EXPERIMENTAL_tx_status", paramsPassMode = JsonRpcParamsPassMode.ARRAY)
- public TransactionStatus getTransactionStatusWithReceipts(String transactionHash, String senderAccountId)
+ TransactionStatus getTransactionStatusWithReceipts(String transactionHash, String senderAccountId)
throws NearServiceException;
/**
* Fetches a receipt by it's ID (as is, without a status or execution outcome)
- *
+ *
* @param receiptId the receipt ID to query for info
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("EXPERIMENTAL_receipt")
- public Receipt getTransactionReceipt(@JsonRpcParam("receipt_id") String receiptId) throws NearServiceException;
+ Receipt getTransactionReceipt(@JsonRpcParam("receipt_id") String receiptId) throws NearServiceException;
/**
* Returns information about a single access key for given account.
- *
+ *
* If permission of the key is FunctionCall, it will return more details such as
* the allowance, receiver_id, and method_names.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @param publicKey the associated public key
@@ -321,16 +318,16 @@ public TransactionStatus getTransactionStatusWithReceipts(String transactionHash
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key")
- public AccessKey viewAccessKey(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
+ AccessKey viewAccessKey(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
throws NearServiceException;
/**
* Returns information about a single access key for given account.
- *
+ *
* If permission of the key is FunctionCall, it will return more details such as
* the allowance, receiver_id, and method_names.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @param publicKey the associated public key
@@ -339,31 +336,31 @@ public AccessKey viewAccessKey(@JsonRpcParam("finality") Finality finality,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key")
- public AccessKey viewAccessKey(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
+ AccessKey viewAccessKey(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
throws NearServiceException;
/**
* Returns information about a single access key for given account.
- *
+ *
* If permission of the key is FunctionCall, it will return more details such as
* the allowance, receiver_id, and method_names.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
- * @param publicKey the associated public key
+ * @param publicKey the associated public key
* @return the data holding object
* @throws NearServiceException rpc call error exception
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key")
- public AccessKey viewAccessKey(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
+ AccessKey viewAccessKey(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("public_key") String publicKey)
throws NearServiceException;
/**
* Returns all access keys for a given account.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @return the data holding object
@@ -371,13 +368,13 @@ public AccessKey viewAccessKey(@JsonRpcParam("block_id") long blockHeight,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key_list")
- public AccessKeyList viewAccessKeyList(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId)
+ AccessKeyList viewAccessKeyList(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns all access keys for a given account.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @return the data holding object
@@ -385,13 +382,13 @@ public AccessKeyList viewAccessKeyList(@JsonRpcParam("finality") Finality finali
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key_list")
- public AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId)
+ AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns all access keys for a given account.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
* @return the data holding object
@@ -399,15 +396,15 @@ public AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") String blockHas
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_access_key_list")
- public AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId)
+ AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns individual access key changes in a specific block. You can query
* multiple keys by passing an array of objects containing the account_id and
- * public_key.
- *
+ * key.
+ *
* @param finality the finality param
* @param keys the key data to query for changes
* @return the data holding object
@@ -415,15 +412,15 @@ public AccessKeyList viewAccessKeyList(@JsonRpcParam("block_id") long blockHeigh
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "single_access_key_changes")
- public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("keys") Key[] keys)
+ AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("keys") Key[] keys)
throws NearServiceException;
/**
* Returns individual access key changes in a specific block. You can query
* multiple keys by passing an array of objects containing the account_id and
- * public_key.
- *
+ * key.
+ *
* @param blockHash the block's hash
* @param keys the key data to query for changes
* @return the data holding object
@@ -431,15 +428,15 @@ public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("finality") Fin
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "single_access_key_changes")
- public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("keys") Key[] keys)
+ AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("keys") Key[] keys)
throws NearServiceException;
/**
* Returns individual access key changes in a specific block. You can query
* multiple keys by passing an array of objects containing the account_id and
- * public_key.
- *
+ * key.
+ *
* @param blockHeight the block's height
* @param keys the key data to query for changes
* @return the data holding object
@@ -447,14 +444,14 @@ public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") Str
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "single_access_key_changes")
- public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("keys") Key[] keys)
+ AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("keys") Key[] keys)
throws NearServiceException;
/**
* Returns changes to all access keys of a specific block. Multiple accounts can
* be quereied by passing an array of account_ids.
- *
+ *
* @param finality the finality param
* @param accountIds the account ids
* @return the data holding object
@@ -462,14 +459,14 @@ public AccessKeyChanges viewSingleAccessKeyChanges(@JsonRpcParam("block_id") lon
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "all_access_key_changes")
- public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns changes to all access keys of a specific block. Multiple accounts can
* be quereied by passing an array of account_ids.
- *
+ *
* @param blockHash the block's hash
* @param accountIds the account ids
* @return the data holding object
@@ -477,14 +474,14 @@ public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("finality") Finali
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "all_access_key_changes")
- public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns changes to all access keys of a specific block. Multiple accounts can
* be quereied by passing an array of account_ids.
- *
+ *
* @param blockHeight the block's height
* @param accountIds the account ids
* @return the data holding object
@@ -492,13 +489,13 @@ public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") String
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "all_access_key_changes")
- public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns basic account information.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @return the data holding object
@@ -506,13 +503,13 @@ public AccessKeyChanges viewAllAccessKeyChanges(@JsonRpcParam("block_id") long b
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_account")
- public Account viewAccount(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId)
+ Account viewAccount(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns basic account information.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @return the data holding object
@@ -520,13 +517,13 @@ public Account viewAccount(@JsonRpcParam("finality") Finality finality,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_account")
- public Account viewAccount(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId)
+ Account viewAccount(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns basic account information.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
* @return the data holding object
@@ -534,13 +531,13 @@ public Account viewAccount(@JsonRpcParam("block_id") String blockHash,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_account")
- public Account viewAccount(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId)
+ Account viewAccount(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns account changes from transactions in a given account.
- *
+ *
* @param finality the finality param
* @param accountIds the account ids
* @return the data holding object
@@ -548,13 +545,13 @@ public Account viewAccount(@JsonRpcParam("block_id") long blockHeight,
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "account_changes")
- public AccountChanges viewAccountChanges(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccountChanges viewAccountChanges(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns account changes from transactions in a given account.
- *
+ *
* @param blockHash the block's hash
* @param accountIds the account ids
* @return the data holding object
@@ -562,13 +559,13 @@ public AccountChanges viewAccountChanges(@JsonRpcParam("finality") Finality fina
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "account_changes")
- public AccountChanges viewAccountChanges(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccountChanges viewAccountChanges(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns account changes from transactions in a given account.
- *
+ *
* @param blockHeight the block's height
* @param accountIds the account ids
* @return the data holding object
@@ -576,14 +573,14 @@ public AccountChanges viewAccountChanges(@JsonRpcParam("block_id") String blockH
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "account_changes")
- public AccountChanges viewAccountChanges(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_ids") String[] accountIds)
+ AccountChanges viewAccountChanges(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns the contract code (Wasm binary) deployed to the account. Please note
* that the returned code will be encoded in base64.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @return the data holding object
@@ -591,14 +588,14 @@ public AccountChanges viewAccountChanges(@JsonRpcParam("block_id") long blockHei
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_code")
- public ContractCode viewContractCode(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId)
+ ContractCode viewContractCode(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns the contract code (Wasm binary) deployed to the account. Please note
* that the returned code will be encoded in base64.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @return the data holding object
@@ -606,14 +603,14 @@ public ContractCode viewContractCode(@JsonRpcParam("finality") Finality finality
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_code")
- public ContractCode viewContractCode(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId)
+ ContractCode viewContractCode(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
* Returns the contract code (Wasm binary) deployed to the account. Please note
* that the returned code will be encoded in base64.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
* @return the data holding object
@@ -621,8 +618,8 @@ public ContractCode viewContractCode(@JsonRpcParam("block_id") String blockHash,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_code")
- public ContractCode viewContractCode(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId)
+ ContractCode viewContractCode(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId)
throws NearServiceException;
/**
@@ -630,7 +627,7 @@ public ContractCode viewContractCode(@JsonRpcParam("block_id") long blockHeight,
* (base64 encoded). Pass an empty string for prefix_base64 if you would like to
* return the entire state. Please note that the returned state will be base64
* encoded as well.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @param prefixBase64 the base64 encoded prefix
@@ -639,9 +636,9 @@ public ContractCode viewContractCode(@JsonRpcParam("block_id") long blockHeight,
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_state")
- public ContractState viewContractState(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId,
- @JsonRpcParam("prefix_base64") String prefixBase64)
+ ContractState viewContractState(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId,
+ @JsonRpcParam("prefix_base64") String prefixBase64)
throws NearServiceException;
/**
@@ -649,7 +646,7 @@ public ContractState viewContractState(@JsonRpcParam("finality") Finality finali
* (base64 encoded). Pass an empty string for prefix_base64 if you would like to
* return the entire state. Please note that the returned state will be base64
* encoded as well.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @param prefixBase64 the base64 encoded prefix
@@ -658,9 +655,9 @@ public ContractState viewContractState(@JsonRpcParam("finality") Finality finali
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_state")
- public ContractState viewContractState(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId,
- @JsonRpcParam("prefix_base64") String prefixBase64)
+ ContractState viewContractState(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId,
+ @JsonRpcParam("prefix_base64") String prefixBase64)
throws NearServiceException;
/**
@@ -668,7 +665,7 @@ public ContractState viewContractState(@JsonRpcParam("block_id") String blockHas
* (base64 encoded). Pass an empty string for prefix_base64 if you would like to
* return the entire state. Please note that the returned state will be base64
* encoded as well.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
* @param prefixBase64 the base64 encoded prefix
@@ -677,16 +674,16 @@ public ContractState viewContractState(@JsonRpcParam("block_id") String blockHas
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "view_state")
- public ContractState viewContractState(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId,
- @JsonRpcParam("prefix_base64") String prefixBase64)
+ ContractState viewContractState(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId,
+ @JsonRpcParam("prefix_base64") String prefixBase64)
throws NearServiceException;
/**
* Returns the state change details of a contract based on the key prefix
* (encoded to base64). Pass an empty string for this param if you would like to
* return all state changes.
- *
+ *
* @param finality the finality param
* @param accountIds the account ids
* @param keyPrefixBase64 the base64 encoded key prefix
@@ -695,16 +692,16 @@ public ContractState viewContractState(@JsonRpcParam("block_id") long blockHeigh
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "data_changes")
- public ContractStateChanges viewContractStateChanges(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_ids") String[] accountIds,
- @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
+ ContractStateChanges viewContractStateChanges(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_ids") String[] accountIds,
+ @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
throws NearServiceException;
/**
* Returns the state change details of a contract based on the key prefix
* (encoded to base64). Pass an empty string for this param if you would like to
* return all state changes.
- *
+ *
* @param blockHash the block's hash
* @param accountIds the account ids
* @param keyPrefixBase64 the base64 encoded key prefix
@@ -713,16 +710,16 @@ public ContractStateChanges viewContractStateChanges(@JsonRpcParam("finality") F
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "data_changes")
- public ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_ids") String[] accountIds,
- @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
+ ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_ids") String[] accountIds,
+ @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
throws NearServiceException;
/**
* Returns the state change details of a contract based on the key prefix
* (encoded to base64). Pass an empty string for this param if you would like to
* return all state changes.
- *
+ *
* @param blockHeight the block's height
* @param accountIds the account ids
* @param keyPrefixBase64 the base64 encoded key prefix
@@ -731,15 +728,15 @@ public ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") S
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "data_changes")
- public ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_ids") String[] accountIds,
- @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
+ ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_ids") String[] accountIds,
+ @JsonRpcParam("key_prefix_base64") String keyPrefixBase64)
throws NearServiceException;
/**
* Returns code changes made when deploying a contract. Change is returned is a
* base64 encoded WASM file.
- *
+ *
* @param finality the finality param
* @param accountIds the account ids
* @return the data holding object
@@ -747,14 +744,14 @@ public ContractStateChanges viewContractStateChanges(@JsonRpcParam("block_id") l
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "contract_code_changes")
- public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_ids") String[] accountIds)
+ ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns code changes made when deploying a contract. Change is returned is a
* base64 encoded WASM file.
- *
+ *
* @param blockHash the block's hash
* @param accountIds the account ids
* @return the data holding object
@@ -762,14 +759,14 @@ public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("finality") Fin
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "contract_code_changes")
- public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_ids") String[] accountIds)
+ ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Returns code changes made when deploying a contract. Change is returned is a
* base64 encoded WASM file.
- *
+ *
* @param blockHeight the block's height
* @param accountIds the account ids
* @return the data holding object
@@ -777,13 +774,13 @@ public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") Str
*/
@JsonRpcMethod("EXPERIMENTAL_changes")
@JsonRpcFixedParam(name = "changes_type", value = "contract_code_changes")
- public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_ids") String[] accountIds)
+ ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_ids") String[] accountIds)
throws NearServiceException;
/**
* Allows you to call a contract method as a view function.
- *
+ *
* @param finality the finality param
* @param accountId the account id
* @param methodName the name of the method to callthe name of the method to
@@ -794,14 +791,14 @@ public ContractCodeChanges viewContractCodeChanges(@JsonRpcParam("block_id") lon
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "call_function")
- public ContractFunctionCallResult callContractFunction(@JsonRpcParam("finality") Finality finality,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
- @JsonRpcParam("args_base64") String argsBase64)
+ ContractFunctionCallResult callContractFunction(@JsonRpcParam("finality") Finality finality,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
+ @JsonRpcParam("args_base64") String argsBase64)
throws NearServiceException;
/**
* Allows you to call a contract method as a view function.
- *
+ *
* @param blockHash the block's hash
* @param accountId the account id
* @param methodName the name of the method to call
@@ -811,14 +808,14 @@ public ContractFunctionCallResult callContractFunction(@JsonRpcParam("finality")
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "call_function")
- public ContractFunctionCallResult callContractFunction(@JsonRpcParam("block_id") String blockHash,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
- @JsonRpcParam("args_base64") String argsBase64)
+ ContractFunctionCallResult callContractFunction(@JsonRpcParam("block_id") String blockHash,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
+ @JsonRpcParam("args_base64") String argsBase64)
throws NearServiceException;
/**
* Allows you to call a contract method as a view function.
- *
+ *
* @param blockHeight the block's height
* @param accountId the account id
* @param methodName the name of the method to call
@@ -828,19 +825,19 @@ public ContractFunctionCallResult callContractFunction(@JsonRpcParam("block_id")
*/
@JsonRpcMethod("query")
@JsonRpcFixedParam(name = "request_type", value = "call_function")
- public ContractFunctionCallResult callContractFunction(@JsonRpcParam("block_id") long blockHeight,
- @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
- @JsonRpcParam("args_base64") String argsBase64)
+ ContractFunctionCallResult callContractFunction(@JsonRpcParam("block_id") long blockHeight,
+ @JsonRpcParam("account_id") String accountId, @JsonRpcParam("method_name") String methodName,
+ @JsonRpcParam("args_base64") String argsBase64)
throws NearServiceException;
/**
* NearService builder
- *
+ *
* @param url the rpc peer url to connect to
* @return the data holding object
* @throws MalformedURLException thrown when url is invalid or unparseable
*/
- public static NearService usingPeer(String url) throws MalformedURLException {
+ static NearService usingPeer(String url) throws MalformedURLException {
NearObjectMapper objectMapper = new NearObjectMapper();
Map customHeaders = new TreeMap<>();
customHeaders.put("Content-Type", "application/json");
diff --git a/src/main/java/com/syntifi/near/api/service/TransactionService.java b/src/main/java/com/syntifi/near/api/service/TransactionService.java
new file mode 100644
index 00000000..1cf602a3
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/service/TransactionService.java
@@ -0,0 +1,167 @@
+package com.syntifi.near.api.service;
+
+import com.syntifi.crypto.key.hash.Sha256;
+import com.syntifi.near.api.model.accesskey.AccessKey;
+import com.syntifi.near.api.model.block.Block;
+import com.syntifi.near.api.model.common.EncodedHash;
+import com.syntifi.near.api.model.identifier.Finality;
+import com.syntifi.near.api.model.key.PrivateKey;
+import com.syntifi.near.api.model.key.PublicKey;
+import com.syntifi.near.api.model.key.Signature;
+import com.syntifi.near.api.model.transaction.Action;
+import com.syntifi.near.api.model.transaction.SignedTransaction;
+import com.syntifi.near.api.model.transaction.Transaction;
+import com.syntifi.near.api.model.transaction.TransactionAwait;
+import com.syntifi.near.api.model.transaction.TransferAction;
+import com.syntifi.near.borshj.Borsh;
+
+import java.math.BigInteger;
+import java.security.GeneralSecurityException;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.List;
+
+/**
+ * Transaction service provides methods to easily work with transactions
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public class TransactionService {
+ /**
+ * Sends a {@link TransferAction} transaction waiting for result using {@link NearService#sendTransactionAwait(String)}
+ *
+ * @param nearService the near service instance to use
+ * @param signerId the signer id
+ * @param receiverId the receiver id
+ * @param signerPublicKey signer public key
+ * @param signerPrivateKey signer private key
+ * @param amount the amount to transfer
+ * @return {@link TransactionAwait} object with the result
+ * @throws GeneralSecurityException thrown if failed to sign the transaction
+ */
+ public static TransactionAwait sendTransferActionAwait(NearService nearService, String signerId, String receiverId,
+ PublicKey signerPublicKey, PrivateKey signerPrivateKey,
+ BigInteger amount)
+ throws GeneralSecurityException {
+ return sendTransactionAwait(nearService, signerId, receiverId, signerPublicKey, signerPrivateKey,
+ Arrays.asList(
+ TransferAction.builder()
+ .deposit(amount)
+ .build()));
+ }
+
+ /**
+ * Sends a {@link TransferAction} transaction async using {@link NearService#sendTransactionAsync(String)}
+ *
+ * @param nearService the near service instance to use
+ * @param signerId the signer id
+ * @param receiverId the receiver id
+ * @param signerPublicKey signer public key
+ * @param signerPrivateKey signer private key
+ * @param amount the amount to transfer
+ * @return transaction Hash
+ * @throws GeneralSecurityException thrown if failed to sign the transaction
+ */
+ public static EncodedHash sendTransferActionAsync(NearService nearService, String signerId, String receiverId,
+ PublicKey signerPublicKey, PrivateKey signerPrivateKey,
+ BigInteger amount)
+ throws GeneralSecurityException {
+ return sendTransactionAsync(nearService, signerId, receiverId, signerPublicKey, signerPrivateKey,
+ Arrays.asList(
+ TransferAction.builder()
+ .deposit(amount)
+ .build()));
+ }
+
+ /**
+ * Sends a list of {@link Action} transaction waiting for result using {@link NearService#sendTransactionAwait(String)}
+ *
+ * @param nearService the near service instance to use
+ * @param signerId the signer id
+ * @param receiverId the receiver id
+ * @param signerPublicKey signer public key
+ * @param signerPrivateKey signer private key
+ * @param actionList list of {@link Action} to send
+ * @return {@link TransactionAwait} object with the result
+ * @throws GeneralSecurityException thrown if failed to sign the transaction
+ */
+ public static TransactionAwait sendTransactionAwait(NearService nearService, String signerId, String receiverId,
+ PublicKey signerPublicKey, PrivateKey signerPrivateKey,
+ List actionList)
+ throws GeneralSecurityException {
+ return nearService.sendTransactionAwait(prepareTransactionForActionList(nearService, signerId, receiverId, signerPublicKey, signerPrivateKey, actionList));
+ }
+
+ /**
+ * Sends a list of {@link Action} transaction waiting for result using {@link NearService#sendTransactionAsync(String)}
+ *
+ * @param nearService the near service instance to use
+ * @param signerId the signer id
+ * @param receiverId the receiver id
+ * @param signerPublicKey signer public key
+ * @param signerPrivateKey signer private key
+ * @param actionList list of {@link Action} to send
+ * @return {@link TransactionAwait} object with the result
+ * @throws GeneralSecurityException thrown if failed to sign the transaction
+ */
+ public static EncodedHash sendTransactionAsync(NearService nearService, String signerId, String receiverId,
+ PublicKey signerPublicKey, PrivateKey signerPrivateKey,
+ List actionList)
+ throws GeneralSecurityException {
+ return EncodedHash.builder()
+ .encodedHash(nearService.sendTransactionAsync(
+ prepareTransactionForActionList(nearService, signerId, receiverId, signerPublicKey, signerPrivateKey, actionList)))
+ .build();
+ }
+
+ /**
+ * Prepares the transaction to send
+ *
+ * @param nearService the near service instance to use
+ * @param signerId the signer id
+ * @param receiverId the receiver id
+ * @param signerPublicKey signer public key
+ * @param signerPrivateKey signer private key
+ * @param actionList list of {@link Action} to send
+ * @return the base64 encoded signed transaction string
+ * @throws GeneralSecurityException thrown if failed to sign the transaction
+ */
+ private static String prepareTransactionForActionList(NearService nearService, String signerId, String receiverId,
+ PublicKey signerPublicKey, PrivateKey signerPrivateKey,
+ List actionList)
+ throws GeneralSecurityException {
+ Block block = nearService.getBlock(Finality.FINAL);
+
+ AccessKey accessKey = nearService.viewAccessKey(Finality.FINAL, signerId, signerPublicKey.toEncodedBase58String());
+
+ long nextNonce = accessKey.getNonce() + 1L;
+
+ Transaction transaction = Transaction
+ .builder()
+ .signerId(signerId)
+ .publicKey(signerPublicKey)
+ .nonce(nextNonce)
+ .receiverId(receiverId)
+ .blockHash(block.getHeader().getHash().getDecodedHash())
+ .actions(actionList)
+ .build();
+
+ byte[] serializedTx = Borsh.serialize(transaction);
+ byte[] hashedTx = Sha256.digest(serializedTx);
+ byte[] signedTx = signerPrivateKey.getPrivateKey().sign(hashedTx);
+
+ SignedTransaction signedTransaction =
+ SignedTransaction.builder()
+ .transaction(transaction)
+ .signature(Signature.builder()
+ .keyType(signerPublicKey.getType())
+ .data(signedTx).build())
+ .build();
+
+ byte[] borshTx = Borsh.serialize(signedTransaction);
+
+ return Base64.getEncoder().encodeToString(borshTx);
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/service/WalletService.java b/src/main/java/com/syntifi/near/api/service/WalletService.java
new file mode 100644
index 00000000..3269123b
--- /dev/null
+++ b/src/main/java/com/syntifi/near/api/service/WalletService.java
@@ -0,0 +1,44 @@
+package com.syntifi.near.api.service;
+
+import com.syntifi.near.api.json.JsonHelper;
+import com.syntifi.near.api.model.key.Wallet;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * Service methods to manipulate wallets
+ *
+ * @author Alexandre Carvalho
+ * @author Andre Bertolace
+ * @since 0.0.1
+ */
+public class WalletService {
+ /**
+ * Loads a wallet from filesystem
+ *
+ * @param file the file to read from
+ * @return a wallet with loaded content
+ * @throws IOException thrown if file not found or not a valid wallet json
+ */
+ public static Wallet loadWalletFromFile(File file) throws IOException {
+ return JsonHelper.OBJECT_MAPPER.readValue(
+ JsonHelper.loadJsonFromFile(file),
+ Wallet.class);
+ }
+
+ /**
+ * Writes a wallet to filesystem
+ *
+ * @param file the file to write to
+ * @param wallet the wallet to persist
+ * @throws IOException thrown if file could not be written
+ */
+ public static void writeWalletToFile(File file, Wallet wallet) throws IOException {
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
+ writer.write(JsonHelper.OBJECT_MAPPER.writeValueAsString(wallet));
+ }
+ }
+}
diff --git a/src/main/java/com/syntifi/near/api/service/exception/NearServiceErrorData.java b/src/main/java/com/syntifi/near/api/service/exception/NearServiceErrorData.java
index 2286f3c2..693876a4 100644
--- a/src/main/java/com/syntifi/near/api/service/exception/NearServiceErrorData.java
+++ b/src/main/java/com/syntifi/near/api/service/exception/NearServiceErrorData.java
@@ -1,9 +1,9 @@
package com.syntifi.near.api.service.exception;
-import java.io.Serializable;
-
import lombok.Data;
+import java.io.Serializable;
+
/**
* Json RPC service error data
*
diff --git a/src/main/java/com/syntifi/near/api/service/exception/NearServiceExceptionResolver.java b/src/main/java/com/syntifi/near/api/service/exception/NearServiceExceptionResolver.java
index 6e027114..19f76911 100644
--- a/src/main/java/com/syntifi/near/api/service/exception/NearServiceExceptionResolver.java
+++ b/src/main/java/com/syntifi/near/api/service/exception/NearServiceExceptionResolver.java
@@ -15,7 +15,7 @@
* @since 0.0.1
*/
public class NearServiceExceptionResolver implements ExceptionResolver {
- private static ObjectMapper objectMapper = new NearObjectMapper();
+ private static final ObjectMapper objectMapper = new NearObjectMapper();
@Override
public Throwable resolveException(ObjectNode response) {
diff --git a/src/test/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeDataTest.java b/src/test/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeDataTest.java
index 41c41958..61e3992b 100644
--- a/src/test/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeDataTest.java
+++ b/src/test/java/com/syntifi/near/api/model/accesskey/permission/PermissionTypeDataTest.java
@@ -1,12 +1,11 @@
package com.syntifi.near.api.model.accesskey.permission;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
import com.syntifi.near.api.exception.NoSuchTypeException;
-
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
public class PermissionTypeDataTest {
@Test
void getClassByName_validName_shouldReturn_correctClass() {
diff --git a/src/test/java/com/syntifi/near/api/model/key/AbstractKeyTest.java b/src/test/java/com/syntifi/near/api/model/key/AbstractKeyTest.java
new file mode 100644
index 00000000..71602539
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/AbstractKeyTest.java
@@ -0,0 +1,41 @@
+package com.syntifi.near.api.model.key;
+
+import com.syntifi.crypto.key.AbstractPrivateKey;
+import com.syntifi.crypto.key.AbstractPublicKey;
+import org.junit.jupiter.api.BeforeAll;
+
+import java.io.IOException;
+
+import static com.syntifi.near.api.json.JsonHelper.OBJECT_MAPPER;
+import static com.syntifi.near.api.json.JsonHelper.loadJsonFromResourceFile;
+
+public abstract class AbstractKeyTest {
+ protected static Wallet aliceWallet;
+ protected static Wallet bobWallet;
+
+ protected static PrivateKey aliceNearPrivateKey;
+ protected static PublicKey aliceNearPublicKey;
+ protected static AbstractPrivateKey alicePrivateKey;
+ protected static AbstractPublicKey alicePublicKey;
+
+ protected static PrivateKey bobNearPrivateKey;
+ protected static PublicKey bobNearPublicKey;
+ protected static AbstractPrivateKey bobPrivateKey;
+ protected static AbstractPublicKey bobPublicKey;
+
+ @BeforeAll
+ static void loadKeys() throws IOException {
+ aliceWallet = OBJECT_MAPPER.readValue(loadJsonFromResourceFile("testnet-wallets/alice.json"), Wallet.class);
+ bobWallet = OBJECT_MAPPER.readValue(loadJsonFromResourceFile("testnet-wallets/bob.json"), Wallet.class);
+
+ aliceNearPrivateKey = aliceWallet.getPrivateKey();
+ aliceNearPublicKey = aliceWallet.getPublicKey();
+ alicePrivateKey = aliceNearPrivateKey.getPrivateKey();
+ alicePublicKey = aliceNearPublicKey.getPublicKey();
+
+ bobNearPrivateKey = bobWallet.getPrivateKey();
+ bobNearPublicKey = bobWallet.getPublicKey();
+ bobPrivateKey = bobNearPrivateKey.getPrivateKey();
+ bobPublicKey = bobNearPublicKey.getPublicKey();
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/model/key/KeySigTest.java b/src/test/java/com/syntifi/near/api/model/key/KeySigTest.java
new file mode 100644
index 00000000..f3a08ca9
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/KeySigTest.java
@@ -0,0 +1,18 @@
+package com.syntifi.near.api.model.key;
+
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class KeySigTest {
+ @Test
+ void fromEncodedBase58String_with_invalid_keyType_should_throw_NoSuchTypeException() {
+ assertThrows(NoSuchTypeException.class, () -> KeySig.fromEncodedBase58String("ASDF", KeySig.class));
+ }
+ @Test
+ void fromEncodedBase58String_with_invalid_class_should_throw_NoSuchTypeException() {
+ class KeySigNoConstructor extends KeySig {}
+ assertThrows(NoSuchTypeException.class, () -> KeySig.fromEncodedBase58String("ed25519:F8jARHGZdHqnwrxrnv1pFVzzirXZR2vJzeYbvwQbxZyP", KeySigNoConstructor.class));
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/model/key/PrivateKeyTest.java b/src/test/java/com/syntifi/near/api/model/key/PrivateKeyTest.java
new file mode 100644
index 00000000..ff2ff294
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/PrivateKeyTest.java
@@ -0,0 +1,24 @@
+package com.syntifi.near.api.model.key;
+
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class PrivateKeyTest extends AbstractKeyTest {
+
+ @Test
+ void getPrivateKey_with_invalidKeyType_should_throw_NoSuchTypeException() {
+ PrivateKey key = new PrivateKey();
+ assertThrows(NoSuchTypeException.class, key::getPrivateKey);
+ }
+
+ @Test
+ void loadWalletFromString_and_loadAPrivateKey() {
+ assertEquals(KeyType.ED25519, aliceNearPrivateKey.getType());
+
+ assertDoesNotThrow(aliceNearPrivateKey::getPrivateKey);
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/model/key/PublicKeyTest.java b/src/test/java/com/syntifi/near/api/model/key/PublicKeyTest.java
new file mode 100644
index 00000000..3c6c0ab4
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/PublicKeyTest.java
@@ -0,0 +1,24 @@
+package com.syntifi.near.api.model.key;
+
+import com.syntifi.near.api.exception.NoSuchTypeException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class PublicKeyTest extends AbstractKeyTest {
+
+ @Test
+ void getPublicKey_with_invalidKeyType_should_throw_NoSuchTypeException() {
+ PublicKey key = new PublicKey();
+ assertThrows(NoSuchTypeException.class, key::getPublicKey);
+ }
+
+ @Test
+ void loadWalletFromString_and_loadAPublicKey() {
+ assertEquals(KeyType.ED25519, aliceNearPublicKey.getType());
+
+ assertDoesNotThrow(aliceNearPublicKey::getPublicKey);
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/model/key/SignatureTest.java b/src/test/java/com/syntifi/near/api/model/key/SignatureTest.java
new file mode 100644
index 00000000..aad7159c
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/SignatureTest.java
@@ -0,0 +1,29 @@
+package com.syntifi.near.api.model.key;
+
+import org.junit.jupiter.api.Test;
+
+import java.security.GeneralSecurityException;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SignatureTest extends AbstractKeyTest {
+ @Test
+ void loadPrivateAndPublicKey_matchesDerivedPublicKey() {
+ assertArrayEquals(alicePublicKey.getKey(), alicePrivateKey.derivePublicKey().getKey());
+ assertArrayEquals(bobPublicKey.getKey(), bobPrivateKey.derivePublicKey().getKey());
+ }
+
+ @Test
+ void loadPrivateAndPublicKey_Sign_and_Verify_should_be_valid() throws GeneralSecurityException {
+ byte[] aliceMessage = "Hello, Bob!".getBytes();
+ byte[] aliceSignature = alicePrivateKey.sign(aliceMessage);
+
+ assertTrue(alicePublicKey.verify(aliceMessage, aliceSignature));
+
+ byte[] bobMessage = "Hello, Alice!".getBytes();
+ byte[] bobSignature = bobPrivateKey.sign(bobMessage);
+
+ assertTrue(bobPublicKey.verify(bobMessage, bobSignature));
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/model/key/WalletTest.java b/src/test/java/com/syntifi/near/api/model/key/WalletTest.java
new file mode 100644
index 00000000..8e837be0
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/model/key/WalletTest.java
@@ -0,0 +1,25 @@
+package com.syntifi.near.api.model.key;
+
+import org.json.JSONException;
+import org.junit.jupiter.api.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import java.io.IOException;
+
+import static com.syntifi.near.api.json.JsonHelper.OBJECT_MAPPER;
+import static com.syntifi.near.api.json.JsonHelper.getPrettyJson;
+import static com.syntifi.near.api.json.JsonHelper.loadJsonFromResourceFile;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+public class WalletTest {
+ @Test
+ void loadWallet_should_load_ok() throws IOException, JSONException {
+ String inputJson = loadJsonFromResourceFile("testnet-wallets/alice.json");
+
+ assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Wallet.class));
+
+ Wallet wallet = OBJECT_MAPPER.readValue(inputJson, Wallet.class);
+
+ JSONAssert.assertEquals(inputJson, getPrettyJson(wallet), false);
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/service/BaseNearServiceTest.java b/src/test/java/com/syntifi/near/api/service/BaseNearServiceTest.java
deleted file mode 100644
index 77592ee4..00000000
--- a/src/test/java/com/syntifi/near/api/service/BaseNearServiceTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.syntifi.near.api.service;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * Basic support functionality for test case classes
- *
- * @author Alexandre Carvalho
- * @author Andre Bertolace
- * @since 0.0.1
- */
-public abstract class BaseNearServiceTest {
- protected static final ObjectMapper OBJECT_MAPPER = new NearObjectMapper();
-
- /**
- * Loads test json from resources
- *
- * @param filename
- * @return
- * @throws IOException
- */
- protected String loadJsonFromFile(String filename) throws IOException {
- String fileJson;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) {
- // copy stream
- byte[] buffer = new byte[1024];
- int bytesRead;
- while ((bytesRead = is.read(buffer)) != -1) {
- baos.write(buffer, 0, bytesRead);
- }
-
- fileJson = new String(baos.toByteArray());
- }
- return fileJson;
- }
-
- /**
- * Prettifies json for assertion consistency
- *
- * @param json json string to prettify
- * @return prettified json
- * @throws JsonMappingException
- * @throws JsonProcessingException
- */
- protected String getPrettyJson(String json) throws JsonMappingException, JsonProcessingException {
- Object jsonObject = OBJECT_MAPPER.readValue(json, Object.class);
- return getPrettyJson(jsonObject);
- }
-
- /**
- * Prettifies json for assertion consistency
- *
- * @param jsonObject object to serialize and prettify
- * @return prettified json
- * @throws JsonMappingException
- * @throws JsonProcessingException
- */
- protected String getPrettyJson(Object jsonObject) throws JsonMappingException, JsonProcessingException {
- return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
- }
-}
diff --git a/src/test/java/com/syntifi/near/api/service/NearServiceHelper.java b/src/test/java/com/syntifi/near/api/service/NearServiceHelper.java
new file mode 100644
index 00000000..1cca52f6
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/service/NearServiceHelper.java
@@ -0,0 +1,27 @@
+package com.syntifi.near.api.service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.MalformedURLException;
+
+public class NearServiceHelper {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NearServiceHelper.class);
+
+ public static NearService nearService = null;
+
+ static {
+ // WARN: Using archival (archival-rpc.testnet.near.org) testnet (instead of "rpc.testnet.near.org") for stabler
+ // results
+ String peerAddress = "archival-rpc.testnet.near.org";
+
+ LOGGER.debug("======== Running tests with peer {} ========", peerAddress);
+ try {
+ nearService = NearService.usingPeer(peerAddress);
+ } catch (MalformedURLException e) {
+ LOGGER.error("Invalid URL {}", peerAddress);
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/service/NearServiceTest.java b/src/test/java/com/syntifi/near/api/service/NearServiceTest.java
index de6fd1f1..a219ad33 100644
--- a/src/test/java/com/syntifi/near/api/service/NearServiceTest.java
+++ b/src/test/java/com/syntifi/near/api/service/NearServiceTest.java
@@ -1,16 +1,5 @@
package com.syntifi.near.api.service;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Map;
-
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.syntifi.near.api.exception.NoSuchTypeException;
import com.syntifi.near.api.model.accesskey.AccessKey;
@@ -29,6 +18,7 @@
import com.syntifi.near.api.model.contract.ContractStateChanges;
import com.syntifi.near.api.model.gas.GasPrice;
import com.syntifi.near.api.model.identifier.Finality;
+import com.syntifi.near.api.model.key.PublicKey;
import com.syntifi.near.api.model.network.NetworkInfo;
import com.syntifi.near.api.model.network.NodeStatus;
import com.syntifi.near.api.model.network.ValidationStatus;
@@ -39,42 +29,43 @@
import com.syntifi.near.api.model.transaction.TransactionStatus;
import com.syntifi.near.api.service.exception.NearServiceException;
import com.syntifi.near.api.service.exception.NearServiceExceptionResolver;
-
import org.json.JSONException;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.Map;
+
+import static com.syntifi.near.api.json.JsonHelper.OBJECT_MAPPER;
+import static com.syntifi.near.api.json.JsonHelper.getPrettyJson;
+import static com.syntifi.near.api.json.JsonHelper.loadJsonFromResourceFile;
+import static com.syntifi.near.api.service.NearServiceHelper.nearService;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* Basic Service call testing
- *
+ *
* @author Alexandre Carvalho
* @author Andre Bertolace
* @since 0.0.1
*/
-public class NearServiceTest extends BaseNearServiceTest {
+public class NearServiceTest {
- private static NearService nearService;
- private static Logger LOGGER = LoggerFactory.getLogger(NearServiceTest.class);
-
- @BeforeAll
- public static void setUp() throws MalformedURLException {
- // WARN: Using archival testnet (instead of "rpc.testnet.near.org") for stabler
- // results
- String peerAddress = "archival-rpc.testnet.near.org";
-
- LOGGER.debug("======== Running tests with peer {} ========", peerAddress);
- nearService = NearService.usingPeer(peerAddress);
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(NearServiceTest.class);
// From sample response at:
// https://docs.near.org/docs/api/rpc/block-chunk#block-details
@Test
void loadedFromExample_block() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/example/block-details.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/example/block-details.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Block.class));
@@ -96,13 +87,13 @@ void getBlock_byHash_block_notNull() throws JSONException, IOException {
assertNotNull(block);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/block-details-by-hash.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/block-details-by-hash.json");
JSONAssert.assertEquals(getPrettyJson(block), inputJson, false);
}
@Test
- void getBlock_byHash_block_notNull_with_validator_proposals() throws JSONException, IOException {
+ void getBlock_byHash_block_notNull_with_validator_proposals() {
Block block = nearService.getBlock("BCEqCXnKijpvQfTMJDn6Bh2We1v1sAZoihApTnJsd32B");
assertNotNull(block);
@@ -110,7 +101,7 @@ void getBlock_byHash_block_notNull_with_validator_proposals() throws JSONExcepti
assertEquals(block.getHeader().getValidatorProposals()[0].getValidatorStakeStructVersion(), "V1");
assertEquals(block.getHeader().getValidatorProposals()[0].getAccountId(), "pontiff.pool.f863973.m0");
assertEquals(block.getHeader().getValidatorProposals()[0].getPublicKey(),
- "ed25519:4i8j7nwNyy18hfARtrVpckT8MiicdCXuWBX1TubdMb5Y");
+ PublicKey.fromEncodedBase58String("ed25519:4i8j7nwNyy18hfARtrVpckT8MiicdCXuWBX1TubdMb5Y", PublicKey.class));
assertEquals(block.getHeader().getValidatorProposals()[0].getStake(), "478888363238890192732941173068");
}
@@ -120,7 +111,7 @@ void getBlock_byHeight_block_notNull() throws JSONException, IOException {
assertNotNull(block);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/block-details-by-height.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/block-details-by-height.json");
JSONAssert.assertEquals(getPrettyJson(block), inputJson, false);
}
@@ -129,7 +120,7 @@ void getBlock_byHeight_block_notNull() throws JSONException, IOException {
// https://docs.near.org/docs/api/rpc/block-chunk#changes-in-block
@Test
void loadedFromExample_blockChanges() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/example/changes-in-block.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/example/changes-in-block.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, BlockChanges.class));
@@ -151,7 +142,7 @@ void getBlockChanges_byHash_blockChanges_notNull() throws JSONException, IOExcep
assertNotNull(blockChanges);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/changes-in-block-by-hash.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/changes-in-block-by-hash.json");
JSONAssert.assertEquals(getPrettyJson(blockChanges), inputJson, false);
}
@@ -162,7 +153,7 @@ void getBlockChanges_byHeight_blockChanges_notNull() throws JSONException, IOExc
assertNotNull(blockChanges);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/changes-in-block-by-height.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/changes-in-block-by-height.json");
JSONAssert.assertEquals(getPrettyJson(blockChanges), inputJson, false);
}
@@ -171,7 +162,7 @@ void getBlockChanges_byHeight_blockChanges_notNull() throws JSONException, IOExc
// https://docs.near.org/docs/api/rpc/block-chunk#chunk-details
@Test
void loadedFromExample_chunk() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/example/chunk-details.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/example/chunk-details.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Chunk.class));
@@ -186,7 +177,7 @@ void getChunkDetails_byChunkId_chunk_notNull() throws JSONException, IOException
assertNotNull(chunk);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/chunk-details.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/chunk-details.json");
JSONAssert.assertEquals(getPrettyJson(chunk), inputJson, false);
}
@@ -197,7 +188,7 @@ void getChunkDetails_byBlockHashAndShardId_chunk_notNull() throws JSONException,
assertNotNull(chunk);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/chunk-details.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/chunk-details.json");
JSONAssert.assertEquals(getPrettyJson(chunk), inputJson, false);
}
@@ -208,7 +199,7 @@ void getChunkDetails_byBlockHeightAndShardId_chunk_notNull() throws JSONExceptio
assertNotNull(chunk);
- String inputJson = loadJsonFromFile("json-test-samples/block-chunk/chunk-details.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/block-chunk/chunk-details.json");
JSONAssert.assertEquals(getPrettyJson(chunk), inputJson, false);
}
@@ -217,7 +208,7 @@ void getChunkDetails_byBlockHeightAndShardId_chunk_notNull() throws JSONExceptio
// https://docs.near.org/docs/api/rpc/network#network-info
@Test
void loadedFromExample_networkInfo() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/network/example/network-info.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/network/example/network-info.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, NetworkInfo.class));
@@ -237,7 +228,7 @@ void getNetworkInfo_networkInfo_notNull() {
// https://docs.near.org/docs/api/rpc/network#node-status
@Test
void loadedFromExample_nodeStatus() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/network/example/node-status.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/network/example/node-status.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, NodeStatus.class));
@@ -257,7 +248,7 @@ void getNodeStatus_nodeStatus_notNull() {
// https://docs.near.org/docs/api/rpc/network#validation-status
@Test
void loadedFromExample_validationStatus() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/network/example/validation-status.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/network/example/validation-status.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ValidationStatus.class));
@@ -280,7 +271,7 @@ void getNetworkValidationStatus_byBlockHash_validationStatus_notNull() {
Block lastBlock = nearService.getBlock(Finality.FINAL);
ValidationStatus networkValidationStatus = nearService
- .getNetworkValidationStatus(lastBlock.getHeader().getHash());
+ .getNetworkValidationStatus(lastBlock.getHeader().getHash().getEncodedHash());
assertNotNull(networkValidationStatus);
}
@@ -301,7 +292,7 @@ void getNetworkValidationStatus_byBlockNumber_validationStatus_notNull() {
// https://docs.near.org/docs/api/rpc/gas#gas-price
@Test
void loadedFromExample_gasPrice() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/gas/example/gas-price.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/gas/example/gas-price.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, GasPrice.class));
@@ -316,7 +307,7 @@ void getGasPrice_byNull_gasPrice_notNull() throws IOException, JSONException {
assertNotNull(gasPrice);
- String inputJson = loadJsonFromFile("json-test-samples/gas/gas-price-by-null.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/gas/gas-price-by-null.json");
JSONAssert.assertEquals(getPrettyJson(gasPrice), inputJson, false);
}
@@ -327,7 +318,7 @@ void getGasPrice_byBlockHash_gasPrice_notNull() throws JSONException, IOExceptio
assertNotNull(gasPrice);
- String inputJson = loadJsonFromFile("json-test-samples/gas/gas-price-by-block-hash.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/gas/gas-price-by-block-hash.json");
JSONAssert.assertEquals(getPrettyJson(gasPrice), inputJson, false);
}
@@ -338,7 +329,7 @@ void getGasPrice_byBlockNumber_gasPrice_notNull() throws IOException, JSONExcept
assertNotNull(gasPrice);
- String inputJson = loadJsonFromFile("json-test-samples/gas/gas-price-by-block-height.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/gas/gas-price-by-block-height.json");
JSONAssert.assertEquals(getPrettyJson(gasPrice), inputJson, false);
}
@@ -347,7 +338,7 @@ void getGasPrice_byBlockNumber_gasPrice_notNull() throws IOException, JSONExcept
// https://docs.near.org/docs/api/rpc/protocol#genesis-config
@Test
void loadedFromExample_genesisConfig() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/protocol/example/genesis-config.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/example/genesis-config.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, GenesisConfig.class));
@@ -362,7 +353,7 @@ void getGenesisConfig_genesisConfig_notNull() throws JSONException, IOException
assertNotNull(genesisConfig);
- String inputJson = loadJsonFromFile("json-test-samples/protocol/genesis-config.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/genesis-config.json");
JSONAssert.assertEquals(getPrettyJson(genesisConfig), inputJson, false);
}
@@ -371,7 +362,7 @@ void getGenesisConfig_genesisConfig_notNull() throws JSONException, IOException
// https://docs.near.org/docs/api/rpc/protocol#protocol-config
@Test
void loadedFromExample_protocolConfig() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/protocol/example/protocol-config.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/example/protocol-config.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ProtocolConfig.class));
@@ -386,7 +377,7 @@ void getProtocolConfig_byFinality_protocolConfig_notNull() throws IOException, J
assertNotNull(protocolConfig);
- String inputJson = loadJsonFromFile("json-test-samples/protocol/protocol-config-final.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/protocol-config-final.json");
JSONAssert.assertEquals(getPrettyJson(protocolConfig), inputJson, false);
}
@@ -397,7 +388,7 @@ void getProtocolConfig_byHash_protocolConfig_notNullProtocolVersion() throws IOE
assertNotNull(protocolConfig);
- String inputJson = loadJsonFromFile("json-test-samples/protocol/protocol-config.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/protocol-config.json");
JSONAssert.assertEquals(getPrettyJson(protocolConfig), inputJson, false);
}
@@ -408,7 +399,7 @@ void getProtocolConfig_byHeight_protocolConfig_notNullProtocolVersion() throws I
assertNotNull(protocolConfig);
- String inputJson = loadJsonFromFile("json-test-samples/protocol/protocol-config.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/protocol/protocol-config.json");
JSONAssert.assertEquals(getPrettyJson(protocolConfig), inputJson, false);
}
@@ -417,7 +408,7 @@ void getProtocolConfig_byHeight_protocolConfig_notNullProtocolVersion() throws I
// https://docs.near.org/docs/api/rpc/transactions#send-transaction-async
@Test
void loadedFromExample_transactionAsync() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/transaction/example/send-transaction-async.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/transaction/example/send-transaction-async.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Map.class));
@@ -428,7 +419,7 @@ void loadedFromExample_transactionAsync() throws IOException, JSONException {
}
@Test
- void sendTransactionAsync_transactionHash_notNull() throws IOException, JSONException {
+ void sendTransactionAsync_transactionHash_notNull() {
String signedTransaction = "DgAAAHNlbmRlci50ZXN0bmV0AOrmAai64SZOv9e/naX4W15pJx0GAap35wTT1T/DwcbbDwAAAAAAAAAQAAAAcmVjZWl2ZXIudGVzdG5ldNMnL7URB1cxPOu3G8jTqlEwlcasagIbKlAJlF5ywVFLAQAAAAMAAACh7czOG8LTAAAAAAAAAGQcOG03xVSFQFjoagOb4NBBqWhERnnz45LY4+52JgZhm1iQKz7qAdPByrGFDQhQ2Mfga8RlbysuQ8D8LlA6bQE=";
String expectedTransactionHash = "6zgh2u9DqHHiXzdy9ouTP7oGky2T4nugqzqt9wJZwNFm";
@@ -442,7 +433,7 @@ void sendTransactionAsync_transactionHash_notNull() throws IOException, JSONExce
// https://docs.near.org/docs/api/rpc/transactions#send-transaction-await
@Test
void loadedFromExample_transactionAwait() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/transaction/example/send-transaction-await.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/transaction/example/send-transaction-await.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, TransactionAwait.class));
@@ -462,7 +453,7 @@ void sendTransactionAwait_transaction_notNull() throws IOException,
assertNotNull(transaction);
- String inputJson = loadJsonFromFile("json-test-samples/transaction/send-transaction-await.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/transaction/send-transaction-await.json");
JSONAssert.assertEquals(getPrettyJson(transaction), inputJson, false);
}
@@ -473,7 +464,7 @@ void sendTransactionAwait_transaction_notNull() throws IOException,
void loadedFromExample_transactionStatus()
throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/transaction/example/transaction-status.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, TransactionStatus.class));
@@ -492,7 +483,7 @@ void getTransactionStatus_transactionStatus_notNull() throws IOException, JSONEx
assertNotNull(transactionStatus);
- String inputJson = loadJsonFromFile("json-test-samples/transaction/transaction-status-by-hash.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/transaction/transaction-status-by-hash.json");
JSONAssert.assertEquals(getPrettyJson(transactionStatus), inputJson, false);
}
@@ -503,7 +494,7 @@ void getTransactionStatus_transactionStatus_notNull() throws IOException, JSONEx
void loadedFromExample_transactionStatusWithReceipts()
throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/transaction/example/transaction-status-with-receipts.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, TransactionStatus.class));
@@ -524,7 +515,7 @@ void getTransactionStatusWithReceipts_transactionStatusWithReceipts_notNull()
assertNotNull(transactionStatusWithReceipts);
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/transaction/transaction-status-by-hash-with-receipt.json");
JSONAssert.assertEquals(getPrettyJson(transactionStatusWithReceipts), inputJson, false);
@@ -536,7 +527,7 @@ void getTransactionStatusWithReceipts_transactionStatusWithReceipts_notNull()
void loadedFromExample_transactionReceipt()
throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/transaction/example/receipt-by-id.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Receipt.class));
@@ -554,7 +545,7 @@ void getTransactionReceipt_transactionReceipt_notNull() throws JSONException, IO
assertNotNull(transactionReceipt);
- String inputJson = loadJsonFromFile("json-test-samples/transaction/receipt.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/transaction/receipt.json");
JSONAssert.assertEquals(getPrettyJson(transactionReceipt), inputJson, false);
}
@@ -564,14 +555,14 @@ void getTransactionReceipt_transactionReceipt_notNull() throws JSONException, IO
* void getTransactionReceipt_transactionReceipt_notNull_InputDataIds() throws
* JSONException, IOException {
* String receiptId = "AWbGp5rEPgcQJHfyJXhsseLGaB8nTHD6iCRnMrwiSTF4";
- *
+ *
* Receipt transactionReceipt = nearService.getTransactionReceipt(receiptId);
- *
+ *
* assertNotNull(transactionReceipt);
- *
+ *
* String inputJson =
* loadJsonFromFile("json-test-samples/transaction/receipt.json");
- *
+ *
* JSONAssert.assertEquals(getPrettyJson(transactionReceipt), inputJson, false);
* }
*/
@@ -580,7 +571,7 @@ void getTransactionReceipt_transactionReceipt_notNull() throws JSONException, IO
// https://docs.near.org/docs/api/rpc/access-keys#view-access-key
@Test
void loadedFromExample_accessKey() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/access-key/example/view-access-key.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/example/view-access-key.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, AccessKey.class));
@@ -609,7 +600,7 @@ void viewAccessKey_byHash_accessKey_notNull() throws IOException, JSONException
assertNotNull(accessKey);
- String inputJson = loadJsonFromFile("json-test-samples/access-key/view-access-key.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/view-access-key.json");
JSONAssert.assertEquals(getPrettyJson(accessKey), inputJson, false);
}
@@ -623,7 +614,7 @@ void viewAccessKey_byHeight_accessKey_notNull() throws JSONException, IOExceptio
assertNotNull(accessKey);
- String inputJson = loadJsonFromFile("json-test-samples/access-key/view-access-key.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/view-access-key.json");
JSONAssert.assertEquals(getPrettyJson(accessKey), inputJson, false);
}
@@ -632,7 +623,7 @@ void viewAccessKey_byHeight_accessKey_notNull() throws JSONException, IOExceptio
// https://docs.near.org/docs/api/rpc/access-keys#view-access-key-list
@Test
void loadedFromExample_accessKeyList() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/access-key/example/view-access-key-list.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/example/view-access-key-list.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, AccessKeyList.class));
@@ -659,7 +650,7 @@ void viewAccessKeyList_byHash_accessKey_notNull() throws IOException, JSONExcept
assertNotNull(accessKeyList);
- String inputJson = loadJsonFromFile("json-test-samples/access-key/view-access-key-list-by-hash.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/view-access-key-list-by-hash.json");
JSONAssert.assertEquals(getPrettyJson(accessKeyList), inputJson, false);
}
@@ -672,7 +663,7 @@ void viewAccessKeyList_byHeight_accessKey_notNull() throws IOException, JSONExce
assertNotNull(accessKeyList);
- String inputJson = loadJsonFromFile("json-test-samples/access-key/view-access-key-list-by-height.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/view-access-key-list-by-height.json");
JSONAssert.assertEquals(getPrettyJson(accessKeyList), inputJson, false);
}
@@ -681,7 +672,7 @@ void viewAccessKeyList_byHeight_accessKey_notNull() throws IOException, JSONExce
// https://docs.near.org/docs/api/rpc/access-keys#view-access-key-changes-single
@Test
void loadedFromExample_accessKeyChangesSingle() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/access-key/example/view-access-key-changes-single.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/example/view-access-key-changes-single.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, AccessKeyChanges.class));
@@ -696,7 +687,7 @@ void loadedFromExample_accessKeyChangesSingle() throws IOException, JSONExceptio
void viewSingleAccessKeyChanges_byFinality_accessKey_notNull() {
Key[] keys = new Key[1];
- Key key0 = new Key("example-acct.testnet", "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM");
+ Key key0 = new Key("example-acct.testnet", PublicKey.fromEncodedBase58String("ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM", PublicKey.class));
keys[0] = key0;
AccessKeyChanges accessKeyChanges = nearService.viewSingleAccessKeyChanges(Finality.FINAL, keys);
@@ -710,7 +701,7 @@ void viewSingleAccessKeyChanges_byFinality_accessKey_notNull() {
void viewSingleAccessKeyChanges_byHash_accessKey_notNull() {
Key[] keys = new Key[1];
- Key key0 = new Key("example-acct.testnet", "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM");
+ Key key0 = new Key("example-acct.testnet", PublicKey.fromEncodedBase58String("ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM", PublicKey.class));
keys[0] = key0;
AccessKeyChanges accessKeyChanges = nearService.viewSingleAccessKeyChanges(
@@ -726,7 +717,7 @@ void viewSingleAccessKeyChanges_byHash_accessKey_notNull() {
void viewSingleAccessKeyChanges_byHeight_accessKey_notNull() {
Key[] keys = new Key[1];
- Key key0 = new Key("example-acct.testnet", "ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM");
+ Key key0 = new Key("example-acct.testnet", PublicKey.fromEncodedBase58String("ed25519:25KEc7t7MQohAJ4EDThd2vkksKkwangnuJFzcoiXj9oM", PublicKey.class));
keys[0] = key0;
AccessKeyChanges accessKeyChanges = nearService.viewSingleAccessKeyChanges(78433961, keys);
@@ -738,7 +729,7 @@ void viewSingleAccessKeyChanges_byHeight_accessKey_notNull() {
// https://docs.near.org/docs/api/rpc/access-keys#view-access-key-changes-all
@Test
void loadedFromExample_accessKeyChangesAll() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/access-key/example/view-access-key-changes-all.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/access-key/example/view-access-key-changes-all.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, AccessKeyChanges.class));
@@ -749,8 +740,8 @@ void loadedFromExample_accessKeyChangesAll() throws IOException, JSONException {
@Test
void loadedJson_accessKeyChangesAll_invalidPropertyPermission_shouldThrow_NoSuchTypeException()
- throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ throws IOException {
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/access-key/view-access-key-changes-all-invalid-permission-property.json");
LOGGER.debug(
@@ -810,7 +801,7 @@ void viewAllAccessKeyChanges_byHeight_accessKey_notNull() {
// https://docs.near.org/docs/api/rpc/contracts#view-account
@Test
void loadedFromExample_account() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/example/view-account.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/example/view-account.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, Account.class));
@@ -820,7 +811,7 @@ void loadedFromExample_account() throws IOException, JSONException {
}
@Test
- void viewAccount_byFinality_account_notNull() throws IOException, JSONException {
+ void viewAccount_byFinality_account_notNull() {
Account account = nearService.viewAccount(Finality.FINAL, "nearkat.testnet");
assertNotNull(account);
@@ -832,7 +823,7 @@ void viewAccount_byHash_account_notNull() throws IOException, JSONException {
assertNotNull(account);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-account.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-account.json");
JSONAssert.assertEquals(getPrettyJson(account), inputJson, false);
}
@@ -843,7 +834,7 @@ void viewAccount_byHeight_account_notNull() throws JSONException, IOException {
assertNotNull(account);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-account.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-account.json");
JSONAssert.assertEquals(getPrettyJson(account), inputJson, false);
}
@@ -852,7 +843,7 @@ void viewAccount_byHeight_account_notNull() throws JSONException, IOException {
// https://docs.near.org/docs/api/rpc/contracts#view-account-changes
@Test
void loadedFromExample_accountChanges() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/example/view-account-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/example/view-account-changes.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, AccountChanges.class));
@@ -864,7 +855,7 @@ void loadedFromExample_accountChanges() throws IOException, JSONException {
// TODO: Empty sample account changes
// (https://docs.near.org/docs/api/rpc/contracts#view-account-changes)
@Test
- void viewAccountChanges_byFinality_account_notNull() throws IOException, JSONException {
+ void viewAccountChanges_byFinality_account_notNull() {
String[] accountIds = new String[1];
accountIds[0] = "nearkat.testnet";
@@ -887,7 +878,7 @@ void viewAccountChanges_byHash_account_notNull() throws IOException, JSONExcepti
assertNotNull(accountChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-account-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-account-changes.json");
JSONAssert.assertEquals(getPrettyJson(accountChanges), inputJson, false);
}
@@ -904,7 +895,7 @@ void viewAccountChanges_byHeight_account_notNull() throws JSONException, IOExcep
assertNotNull(accountChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-account-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-account-changes.json");
JSONAssert.assertEquals(getPrettyJson(accountChanges), inputJson, false);
}
@@ -913,7 +904,7 @@ void viewAccountChanges_byHeight_account_notNull() throws JSONException, IOExcep
// https://docs.near.org/docs/api/rpc/contracts#view-contract-code
@Test
void loadedFromExample_contractCode() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/example/view-contract-code.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/example/view-contract-code.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ContractCode.class));
@@ -923,7 +914,7 @@ void loadedFromExample_contractCode() throws IOException, JSONException {
}
@Test
- void viewContractCode_byFinality_contractCode_notNull() throws IOException, JSONException {
+ void viewContractCode_byFinality_contractCode_notNull() {
ContractCode contractCode = nearService.viewContractCode(Finality.FINAL, "guest-book.testnet");
assertNotNull(contractCode);
@@ -936,7 +927,7 @@ void viewContractCode_byHash_contractCode_notNull() throws IOException, JSONExce
assertNotNull(contractCode);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-code.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-code.json");
JSONAssert.assertEquals(getPrettyJson(contractCode), inputJson, false);
}
@@ -947,7 +938,7 @@ void viewContractCode_byHeight_contractCode_notNull() throws JSONException, IOEx
assertNotNull(contractCode);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-code.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-code.json");
JSONAssert.assertEquals(getPrettyJson(contractCode), inputJson, false);
}
@@ -956,7 +947,7 @@ void viewContractCode_byHeight_contractCode_notNull() throws JSONException, IOEx
// https://docs.near.org/docs/api/rpc/contracts#view-contract-state
@Test
void loadedFromExample_contractState() throws IOException, JSONException {
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/example/view-contract-state.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/example/view-contract-state.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ContractState.class));
@@ -968,8 +959,7 @@ void loadedFromExample_contractState() throws IOException, JSONException {
// TODO: enable this test when working test data is available
@Disabled("Too large contract state! (https://docs.near.org/docs/api/rpc/contracts#view-contract-state)")
@Test
- void viewContractState_byFinality_contractCode_notNull() throws IOException,
- JSONException {
+ void viewContractState_byFinality_contractCode_notNull() {
ContractState contractState = nearService.viewContractState(Finality.FINAL,
"guest-book.testnet", "");
@@ -986,7 +976,7 @@ void viewContractState_byHash_contractCode_notNull() throws IOException,
assertNotNull(contractState);
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/accounts-contracts/view-contract-state.json");
JSONAssert.assertEquals(getPrettyJson(contractState), inputJson, false);
@@ -1002,7 +992,7 @@ void viewContractState_byHeight_contractCode_notNull() throws JSONException,
assertNotNull(contractState);
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/accounts-contracts/view-contract-state.json");
JSONAssert.assertEquals(getPrettyJson(contractState), inputJson, false);
@@ -1012,7 +1002,7 @@ void viewContractState_byHeight_contractCode_notNull() throws JSONException,
// https://docs.near.org/docs/api/rpc/contracts#view-contract-state-changes
@Test
void loadedFromExample_contractStateChanges() throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/accounts-contracts/example/view-contract-state-changes.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ContractStateChanges.class));
@@ -1025,7 +1015,7 @@ void loadedFromExample_contractStateChanges() throws IOException, JSONException
// TODO: Empty sample contract code changes
// (https://docs.near.org/docs/api/rpc/contracts#view-contract-state-changes)
@Test
- void viewContractStateChanges_byFinality_contractStateChanges_notNull() throws IOException, JSONException {
+ void viewContractStateChanges_byFinality_contractStateChanges_notNull() {
String[] accountIds = new String[1];
accountIds[0] = "guest-book.testnet";
@@ -1050,7 +1040,7 @@ void viewContractStateChanges_byHash_contractStateChanges_notNull() throws IOExc
assertNotNull(contractStateChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-state-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-state-changes.json");
JSONAssert.assertEquals(getPrettyJson(contractStateChanges), inputJson, false);
}
@@ -1067,7 +1057,7 @@ void viewContractStateChanges_byHeight_contractStateChanges_notNull() throws JSO
assertNotNull(contractStateChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-state-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-state-changes.json");
JSONAssert.assertEquals(getPrettyJson(contractStateChanges), inputJson, false);
}
@@ -1076,7 +1066,7 @@ void viewContractStateChanges_byHeight_contractStateChanges_notNull() throws JSO
// https://docs.near.org/docs/api/rpc/contracts#view-contract-state-changes
@Test
void loadedFromExample_contractCodeChanges() throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/accounts-contracts/example/view-contract-code-changes.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ContractCodeChanges.class));
@@ -1089,7 +1079,7 @@ void loadedFromExample_contractCodeChanges() throws IOException, JSONException {
// TODO: Empty sample contract code changes
// (https://docs.near.org/docs/api/rpc/contracts#view-contract-code-changes)
@Test
- void viewContractCodeChanges_byFinality_contractCodeChanges_notNull() throws IOException, JSONException {
+ void viewContractCodeChanges_byFinality_contractCodeChanges_notNull() {
String[] accountIds = new String[1];
accountIds[0] = "dev-1602714453032-7566969";
@@ -1113,7 +1103,7 @@ void viewContractCodeChanges_byHash_contractCodeChanges_notNull() throws IOExcep
assertNotNull(contractCodeChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-code-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-code-changes.json");
JSONAssert.assertEquals(getPrettyJson(contractCodeChanges), inputJson, false);
}
@@ -1130,7 +1120,7 @@ void viewContractCodeChanges_byHeight_contractCodeChanges_notNull() throws JSONE
assertNotNull(contractCodeChanges);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/view-contract-code-changes.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/view-contract-code-changes.json");
JSONAssert.assertEquals(getPrettyJson(contractCodeChanges), inputJson, false);
}
@@ -1139,7 +1129,7 @@ void viewContractCodeChanges_byHeight_contractCodeChanges_notNull() throws JSONE
// https://docs.near.org/docs/api/rpc/contracts#view-contract-state-changes
@Test
void loadedFromExample_contractFunctionCallResult() throws IOException, JSONException {
- String inputJson = loadJsonFromFile(
+ String inputJson = loadJsonFromResourceFile(
"json-test-samples/accounts-contracts/example/call-a-contract-function.json");
assertDoesNotThrow(() -> OBJECT_MAPPER.readValue(inputJson, ContractFunctionCallResult.class));
@@ -1151,7 +1141,7 @@ void loadedFromExample_contractFunctionCallResult() throws IOException, JSONExce
}
@Test
- void callContractFunction_byFinality_contractFunctionCallResult_notNull() throws IOException, JSONException {
+ void callContractFunction_byFinality_contractFunctionCallResult_notNull() {
ContractFunctionCallResult contractFunctionCallResult = nearService
.callContractFunction(
Finality.FINAL,
@@ -1173,7 +1163,7 @@ void callContractFunction_byHash_contractFunctionCallResult_notNull() throws IOE
assertNotNull(contractFunctionCallResult);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/call-a-contract-function.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/call-a-contract-function.json");
JSONAssert.assertEquals(getPrettyJson(contractFunctionCallResult), inputJson, false);
}
@@ -1204,7 +1194,7 @@ void callContractFunction_byHeight_contractFunctionCallResult_notNull() throws J
assertNotNull(contractFunctionCallResult);
- String inputJson = loadJsonFromFile("json-test-samples/accounts-contracts/call-a-contract-function.json");
+ String inputJson = loadJsonFromResourceFile("json-test-samples/accounts-contracts/call-a-contract-function.json");
JSONAssert.assertEquals(getPrettyJson(contractFunctionCallResult), inputJson, false);
}
@@ -1224,7 +1214,7 @@ void getBlock_byHash_invalidInput_shouldThrow_NearServiceException() {
void loadError_validInput_doesHaveErrorData() throws IOException {
NearServiceExceptionResolver nearServiceExceptionResolver = new NearServiceExceptionResolver();
- String validErrorJson = loadJsonFromFile(
+ String validErrorJson = loadJsonFromResourceFile(
"json-test-samples/error/valid-error.json");
Throwable t = nearServiceExceptionResolver
@@ -1239,7 +1229,7 @@ void loadError_validInput_doesHaveErrorData() throws IOException {
void loadError_invalidInput_doesNotHaveErrorData() throws IOException {
NearServiceExceptionResolver nearServiceExceptionResolver = new NearServiceExceptionResolver();
- String invalidErrorJson = loadJsonFromFile(
+ String invalidErrorJson = loadJsonFromResourceFile(
"json-test-samples/error/invalid-error.json");
Throwable t = nearServiceExceptionResolver
diff --git a/src/test/java/com/syntifi/near/api/service/TransactionServiceTest.java b/src/test/java/com/syntifi/near/api/service/TransactionServiceTest.java
new file mode 100644
index 00000000..7c3b83e3
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/service/TransactionServiceTest.java
@@ -0,0 +1,143 @@
+package com.syntifi.near.api.service;
+
+import com.syntifi.crypto.key.hash.Sha256;
+import com.syntifi.near.api.model.accesskey.AccessKey;
+import com.syntifi.near.api.model.block.Block;
+import com.syntifi.near.api.model.common.EncodedHash;
+import com.syntifi.near.api.model.identifier.Finality;
+import com.syntifi.near.api.model.key.AbstractKeyTest;
+import com.syntifi.near.api.model.key.PrivateKey;
+import com.syntifi.near.api.model.key.PublicKey;
+import com.syntifi.near.api.model.key.Signature;
+import com.syntifi.near.api.model.transaction.SignedTransaction;
+import com.syntifi.near.api.model.transaction.SuccessValueStatus;
+import com.syntifi.near.api.model.transaction.Transaction;
+import com.syntifi.near.api.model.transaction.TransactionAwait;
+import com.syntifi.near.api.model.transaction.TransferAction;
+import com.syntifi.near.borshj.Borsh;
+import org.junit.jupiter.api.Test;
+
+import java.math.BigInteger;
+import java.security.GeneralSecurityException;
+import java.util.Arrays;
+import java.util.Base64;
+
+import static com.syntifi.near.api.service.NearServiceHelper.nearService;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TransactionServiceTest extends AbstractKeyTest {
+
+ @Test
+ void serializeSignAndDeserializeVerifyTransaction_should_match() throws GeneralSecurityException {
+ String signerId = "syntifi-alice.testnet";
+ String receiverId = "syntifi-bob.testnet";
+ String amount = "100";
+ PublicKey publicKey = aliceNearPublicKey;
+
+ Block block = nearService.getBlock(Finality.FINAL);
+
+ AccessKey accessKey = nearService.viewAccessKey(Finality.FINAL, signerId, publicKey.toEncodedBase58String());
+
+ long nextNonce = accessKey.getNonce() + 1L;
+
+ Transaction transaction = Transaction
+ .builder()
+ .signerId(signerId)
+ .publicKey(publicKey)
+ .nonce(nextNonce)
+ .receiverId(receiverId)
+ .blockHash(block.getHeader().getHash().getDecodedHash())
+ .actions(Arrays.asList(
+ TransferAction.builder()
+ .deposit(new BigInteger(amount, 10))
+ .build()))
+ .build();
+
+ byte[] serializedTx = Borsh.serialize(transaction);
+ byte[] hashedTx = Sha256.digest(serializedTx);
+ byte[] signedTx = alicePrivateKey.sign(hashedTx);
+
+ SignedTransaction signedTransaction =
+ SignedTransaction.builder()
+ .transaction(transaction)
+ .signature(Signature.builder()
+ .keyType(publicKey.getType())
+ .data(signedTx).build())
+ .build();
+
+ byte[] borshTx = Borsh.serialize(signedTransaction);
+
+ String base64Tx = Base64.getEncoder().encodeToString(borshTx);
+
+ byte[] base64TxDec = Base64.getDecoder().decode(base64Tx);
+
+ SignedTransaction signedTransactionDec = Borsh.deserialize(base64TxDec, SignedTransaction.class);
+
+ assertEquals(signedTransaction, signedTransactionDec);
+
+ Transaction transactionDec = signedTransactionDec.getTransaction();
+
+ assertEquals(transaction, transactionDec);
+
+ assertTrue(publicKey.getPublicKey().verify(hashedTx, signedTransactionDec.getSignature().getData()));
+ }
+
+ @Test
+ void sent100toBobAwait_should_getStatus_SuccessValueStatus() throws GeneralSecurityException {
+ String signerId = "syntifi-alice.testnet";
+ String receiverId = "syntifi-bob.testnet";
+ BigInteger amount = new BigInteger("100", 10);
+ PrivateKey privateKey = aliceNearPrivateKey;
+ PublicKey publicKey = aliceNearPublicKey;
+
+ TransactionAwait transactionAwait = TransactionService
+ .sendTransferActionAwait(nearService, signerId, receiverId, publicKey, privateKey, amount);
+
+ assertInstanceOf(SuccessValueStatus.class, transactionAwait.getStatus());
+ }
+
+ @Test
+ void sent100toAliceAwait_should_getStatus_SuccessValueStatus() throws GeneralSecurityException {
+ String signerId = "syntifi-bob.testnet";
+ String receiverId = "syntifi-alice.testnet";
+ BigInteger amount = new BigInteger("100", 10);
+ PrivateKey privateKey = bobNearPrivateKey;
+ PublicKey publicKey = bobNearPublicKey;
+
+ TransactionAwait transactionAwait = TransactionService
+ .sendTransferActionAwait(nearService, signerId, receiverId, publicKey, privateKey, amount);
+
+ assertInstanceOf(SuccessValueStatus.class, transactionAwait.getStatus());
+ }
+
+ @Test
+ void sent100toBobAsync_should_getStatus_SuccessValueStatus() throws GeneralSecurityException {
+ String signerId = "syntifi-alice.testnet";
+ String receiverId = "syntifi-bob.testnet";
+ BigInteger amount = new BigInteger("100", 10);
+ PrivateKey privateKey = aliceNearPrivateKey;
+ PublicKey publicKey = aliceNearPublicKey;
+
+ EncodedHash transactionAsync = TransactionService
+ .sendTransferActionAsync(nearService, signerId, receiverId, publicKey, privateKey, amount);
+
+ assertNotNull(transactionAsync.getEncodedHash());
+ }
+
+ @Test
+ void sent100toAliceAsync_should_getStatus_SuccessValueStatus() throws GeneralSecurityException {
+ String signerId = "syntifi-bob.testnet";
+ String receiverId = "syntifi-alice.testnet";
+ BigInteger amount = new BigInteger("100", 10);
+ PrivateKey privateKey = bobNearPrivateKey;
+ PublicKey publicKey = bobNearPublicKey;
+
+ EncodedHash transactionAsync = TransactionService
+ .sendTransferActionAsync(nearService, signerId, receiverId, publicKey, privateKey, amount);
+
+ assertNotNull(transactionAsync.getEncodedHash());
+ }
+}
diff --git a/src/test/java/com/syntifi/near/api/service/WalletServiceTest.java b/src/test/java/com/syntifi/near/api/service/WalletServiceTest.java
new file mode 100644
index 00000000..a06604e2
--- /dev/null
+++ b/src/test/java/com/syntifi/near/api/service/WalletServiceTest.java
@@ -0,0 +1,64 @@
+package com.syntifi.near.api.service;
+
+import com.syntifi.near.api.json.JsonHelper;
+import com.syntifi.near.api.model.key.Wallet;
+import org.junit.jupiter.api.Test;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class WalletServiceTest {
+
+ @Test
+ void loadWalletFromFile_inexist_should_throw_IOException() {
+ assertThrows(IOException.class, () -> WalletService.loadWalletFromFile(new File("")));
+ }
+
+ @Test
+ void writeWalletToFile_invalidPath_should_throw_IOException() {
+ assertThrows(IOException.class, () -> WalletService.writeWalletToFile(new File(""), new Wallet()));
+ }
+
+ @Test
+ void writeWalletToFile_should_write_wallet_to_file() throws IOException {
+ String fileName = "./wallet-d1fe5b15a491ad5bf4c1cdb290f17bee71d21449ddac80fb7b92f38fe530cf5e.json";
+
+ Wallet wallet = loadATestWallet();
+
+ assertDoesNotThrow(() -> WalletService.writeWalletToFile(new File(fileName), wallet));
+
+ assertTrue(Files.exists(Paths.get(fileName)));
+
+ assertNotNull(WalletService.loadWalletFromFile(new File(fileName)));
+
+ Files.delete(Paths.get(fileName));
+ }
+
+ @Test
+ void loadWalletFromFile_should_load_to_Wallet() throws IOException {
+ String fileName = "./wallet-d1fe5b15a491ad5bf4c1cdb290f17bee71d21449ddac80fb7b92f38fe530cf5e.json";
+
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
+ writer.write(JsonHelper.loadJsonFromResourceFile("testnet-wallets/alice.json"));
+ }
+
+ Wallet wallet = WalletService.loadWalletFromFile(new File(fileName));
+
+ Files.delete(Paths.get(fileName));
+
+ assertNotNull(wallet);
+ }
+
+ static Wallet loadATestWallet() throws IOException {
+ return JsonHelper.OBJECT_MAPPER.readValue(JsonHelper.loadJsonFromResourceFile("testnet-wallets/alice.json"), Wallet.class);
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/testnet-wallets/alice.json b/src/test/resources/testnet-wallets/alice.json
new file mode 100644
index 00000000..fd3ff519
--- /dev/null
+++ b/src/test/resources/testnet-wallets/alice.json
@@ -0,0 +1,5 @@
+{
+ "account_id": "d1fe5b15a491ad5bf4c1cdb290f17bee71d21449ddac80fb7b92f38fe530cf5e",
+ "public_key": "ed25519:F8jARHGZdHqnwrxrnv1pFVzzirXZR2vJzeYbvwQbxZyP",
+ "private_key": "ed25519:32UfEkBGTFpfu6M7RebN1JqMDrdf1YyztgYmcUG5XcRkEraJioFZLPtBvYVmAVvnjWAToSsWScJYSFViv8MaATRF"
+}
\ No newline at end of file
diff --git a/src/test/resources/testnet-wallets/bob.json b/src/test/resources/testnet-wallets/bob.json
new file mode 100644
index 00000000..82e0d221
--- /dev/null
+++ b/src/test/resources/testnet-wallets/bob.json
@@ -0,0 +1,5 @@
+{
+ "account_id": "ba56c617a2e8dd1ba484c48d40c659f088af74bd1bd8dc3c37ef1c2280547f61",
+ "public_key": "ed25519:DYPaMCfE8xQUDQ19NnGCr18WQiqYwjSoaeXpKTDFv3kt",
+ "private_key": "ed25519:59drpA65TXWoyYuQWuRgKcrxCcQaCrZB9YiUbVBjMrmch6utfoyVvDZ8Liz5mrhosr7szwrmDvVTZ7jrFbGCCaR6"
+}
\ No newline at end of file