Skip to content

Commit

Permalink
Merge pull request #153 from casper-network/dev
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
meywood authored Nov 23, 2022
2 parents 7b82c78 + 5534e20 commit f0df6ab
Show file tree
Hide file tree
Showing 113 changed files with 2,958 additions and 622 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build
run: ./gradlew clean build

publish-docs-reports:
needs: build
needs: build
runs-on: ubuntu-latest

steps:
Expand All @@ -44,12 +44,12 @@ jobs:

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Export project version
run: echo "PROJECT_VERSION=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_ENV

- name: Generate Javadoc
run: ./gradlew javadoc
run: ./gradlew clean javadoc

- name: Run tests and generate reports
run: ./gradlew test
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -32,10 +32,10 @@ jobs:
- name: Publish package
uses: gradle/gradle-build-action@v2
with:
arguments: publish
arguments: publish closeAndReleaseStagingRepository
env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 52 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ plugins {
id 'jacoco'
id 'signing'
id 'maven-publish'
id('io.github.gradle-nexus.publish-plugin') version '1.1.0'
}

group = 'com.syntifi.casper'
version = '0.4.0-SNAPSHOT'
sourceCompatibility = '8'
apply plugin: 'java'

group = 'network.casper'
version='2.0.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
Expand All @@ -20,7 +24,7 @@ repositories {

dependencies {
implementation "dev.oak3:sbs4j:${sbs4jVersion}"
implementation "com.github.briandilley.jsonrpc4j:jsonrpc4j:${jsonrpc4jVersion}"
implementation "io.github.oak:jsonrpc4j:${jsonrpc4jVersion}"
implementation "com.syntifi.crypto:crypto-key-common:${cryptokeyVersion}"
implementation "com.syntifi.crypto:crypto-key-ed25519:${cryptokeyVersion}"
implementation "com.syntifi.crypto:crypto-key-secp256k1:${cryptokeyVersion}"
Expand All @@ -35,6 +39,8 @@ dependencies {
testImplementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
testImplementation "com.jayway.jsonpath:json-path-assert:${jsonPathAssertVersion}"
testImplementation "com.squareup.okhttp3:mockwebserver:${mockwebserverVersion}"

// Use JUnit Jupiter for testing.
testImplementation "org.junit.jupiter:junit-jupiter:${jupiterVersion}"
Expand All @@ -47,12 +53,30 @@ java {
withSourcesJar()
}

task casperJar(type: Jar) {
archiveBaseName = 'casper-java-sdk'
archiveVersion = "${version}"
from { configurations.compileClasspath.findAll { it.isDirectory() ? it : zipTree(it) } }
with jar
}

javadoc {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(System.getenv('MAVEN_USERNAME'))
password.set(System.getenv('MAVEN_PASSWORD'))
}
}
}

test {
finalizedBy jacocoTestReport

Expand Down Expand Up @@ -130,9 +154,9 @@ publishing {
artifactId = 'casper-java-sdk'
from components.java
pom {
name = 'Java 8+ Casper RPC Client SDK'
name = 'Casper Java SDK'
packaging = 'jar'
description = 'This project implements the SDK to interact with a Casper Node. It wraps the Json-RPC requests and maps the results to Java objects.'
description = 'SDK to streamline the 3rd party Java client integration processes. Such 3rd parties include exchanges & app developers.'
url = 'https://github.com/casper-network/casper-java-sdk'

scm {
Expand Down Expand Up @@ -169,16 +193,31 @@ publishing {
name = 'Andre Bertolace'
email = '[email protected]'
}
developer {
id = 'meywood'
name = 'Ian Mills'
email = '[email protected]'
}
developer {
id = 'stormeye'
name = 'Carl Norburn'
email = '[email protected]'
}
}
}
}
}
}

// Reference at https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
signing {
def signingKey = System.getenv('GPG_SIGNING_KEY') ?: findProperty('GPG_SIGNING_KEY')
def signingKeyPassword = System.getenv('GPG_SIGNING_KEY_PASSWORD') ?: findProperty('GPG_SIGNING_KEY_PASSWORD')
useInMemoryPgpKeys(signingKey, signingKeyPassword)
sign publishing.publications.mavenJava
jar {
archiveClassifier = ''
}

// Reference at https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
signing {
def signingKey = System.getenv('GPG_SIGNING_KEY') ?: findProperty('GPG_SIGNING_KEY')
def signingKeyPassword = System.getenv('GPG_SIGNING_KEY_PASSWORD') ?: findProperty('GPG_SIGNING_KEY_PASSWORD')

useInMemoryPgpKeys(signingKey, signingKeyPassword)
sign publishing.publications.mavenJava
}
}
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ sbs4jVersion=0.1.5
cryptokeyVersion=0.4.0
lombokPluginVersion=6.2.0
jupiterVersion=5.9.0
jsonrpc4jVersion=1.6
jacksonVersion=2.13.3
jsonrpc4jVersion=1.6.1-oak
jacksonVersion=2.13.4
jsonassertVersion=1.5.1
jsonPathAssertVersion=2.7.0
mockwebserverVersion=4.10.0
log4jVersion=2.18.0
slf4jApiVersion=1.7.36
slf4jApiVersion=2.0.0
javaTuplesVersion=1.2
jsonassertVersion=1.5.1
jodaTimeVersion=2.10.14
jodaTimeVersion=2.11.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public CasperClientException(CasperClientErrorData error) {
public CasperClientException(String message, Throwable cause) {
super(message, cause);
}

public CasperClientException(String message) {
super(message);

}
}
27 changes: 17 additions & 10 deletions src/main/java/com/casper/sdk/helper/CasperDeployHelper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.casper.sdk.helper;

import com.casper.sdk.exception.NoSuchTypeException;

import com.casper.sdk.model.clvalue.CLValueByteArray;
import com.casper.sdk.model.clvalue.CLValueU512;
import com.casper.sdk.model.clvalue.cltype.CLTypeU512;
import com.casper.sdk.model.clvalue.serde.Target;
import com.casper.sdk.model.common.Digest;
import com.casper.sdk.model.common.Ttl;
import com.casper.sdk.model.deploy.*;
import com.casper.sdk.model.deploy.Approval;
import com.casper.sdk.model.deploy.Deploy;
import com.casper.sdk.model.deploy.DeployHeader;
import com.casper.sdk.model.deploy.NamedArg;
import com.casper.sdk.model.deploy.executabledeploy.ExecutableDeployItem;
import com.casper.sdk.model.deploy.executabledeploy.ModuleBytes;
import com.casper.sdk.model.key.PublicKey;
Expand All @@ -16,11 +18,16 @@
import com.syntifi.crypto.key.hash.Blake2b;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.util.*;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
* Deploy Service class implementing the process to generate deploys
Expand Down Expand Up @@ -48,10 +55,10 @@ public static DeployHeader buildDeployHeader(PublicKey fromPublicKey, String cha
}

public static HashAndSignature signDeployHeader(AbstractPrivateKey privateKey, DeployHeader deployHeader)
throws GeneralSecurityException {
throws GeneralSecurityException, NoSuchTypeException, ValueSerializationException {
SerializerBuffer serializerBuffer = new SerializerBuffer();

deployHeader.serialize(serializerBuffer, true);
deployHeader.serialize(serializerBuffer, Target.BYTE);
byte[] headerHash = Blake2b.digest(serializerBuffer.toByteArray(), 32);
Signature signature = Signature.sign(privateKey, headerHash);
return new HashAndSignature(headerHash, signature);
Expand All @@ -60,12 +67,12 @@ public static HashAndSignature signDeployHeader(AbstractPrivateKey privateKey, D
public static byte[] getDeployItemAndModuleBytesHash(ExecutableDeployItem deployItem, ModuleBytes moduleBytes)
throws NoSuchTypeException, ValueSerializationException {
SerializerBuffer ser = new SerializerBuffer();
moduleBytes.serialize(ser, true);
deployItem.serialize(ser, true);
moduleBytes.serialize(ser, Target.BYTE);
deployItem.serialize(ser, Target.BYTE);
return Blake2b.digest(ser.toByteArray(), 32);
}

public static ModuleBytes getPaymentModuleBytes(BigInteger paymentAmount) {
public static ModuleBytes getPaymentModuleBytes(BigInteger paymentAmount) throws ValueSerializationException {
List<NamedArg<?>> paymentArgs = new LinkedList<>();
NamedArg<CLTypeU512> paymentArg = new NamedArg<>("amount",
new CLValueU512(paymentAmount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@
public abstract class AbstractSerializedKeyTaggedHexDeserializer<T extends AbstractSerializedKeyTaggedHex<S>, S extends Tag>
extends JsonDeserializer<T> {

/** Missing PublicKey in Events is shown as "00" */
private static final String NULL_PUBLIC_KEY = "00";

@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonNode node = p.getCodec().readTree(p);

if (NULL_PUBLIC_KEY.equals(node.textValue())) {
return null;
}

T object = this.getInstanceOf();

try {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/casper/sdk/model/bid/Bid.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/casper/sdk/model/block/JsonBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -28,7 +29,7 @@ public class JsonBlock {
* The block's hash.
*/
@JsonProperty("hash")
private String hash;
private Digest hash;

/**
* {@link JsonBlockHeader}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/casper/sdk/model/block/JsonBlockHeader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.casper.sdk.model.block;

import com.casper.sdk.model.common.Digest;
import com.casper.sdk.model.era.JsonEraEnd;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class JsonBlockHeader {
* Hex-encoded hash digest
*/
@JsonProperty("state_root_hash")
private String stateRootHash;
private Digest stateRootHash;

/**
* boolean
Expand All @@ -53,19 +54,19 @@ public class JsonBlockHeader {
* Hex-encoded hash digest
*/
@JsonProperty("body_hash")
private String bodyHash;
private Digest bodyHash;

/**
* Hex-encoded hash digest.
*/
@JsonProperty("parent_hash")
private String parentHash;
private Digest parentHash;

/**
* Hex-encoded hash digest
*/
@JsonProperty("accumulated_seed")
private String accumulatedSeed;
private Digest accumulatedSeed;

/**
* Timestamp formatted as per RFC 3339
Expand Down
Loading

0 comments on commit f0df6ab

Please sign in to comment.