Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into develop #647

Merged
merged 18 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ hs_err_pid*
/build
/out
*/build/
*/bin/
*/out/
*/build**/

Expand Down
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 39 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ buildscript {

ext.bouncycastleVersion = '1.65'
ext.rxjavaVersion = '2.2.21'
ext.gsonVersion = '2.10.1'
ext.okhttpVersion = '4.11.0'
ext.loggingOkhttpVersion = '4.11.0'
ext.slf4jVersion = '2.0.7'
ext.gsonVersion = '2.9.1'
ext.okhttpVersion = '4.10.0'
ext.loggingOkhttpVersion = '4.10.0'
ext.slf4jVersion = '2.0.0'
ext.guavaVersion = '32.1.1-jre'
ext.junitVersion = '5.9.3'
ext.junitVersion = '5.9.0'
ext.kotestVersion = '5.6.1'
ext.kotlinVersion = "1.8.21"
ext.mockkVersion = "1.13.5"

repositories {
jcenter()
mavenCentral()
}

Expand All @@ -23,7 +25,6 @@ buildscript {
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'java'
id 'com.jfrog.bintray' version '1.8.5'
}

apply plugin: 'com.github.johnrengelman.shadow'
Expand Down Expand Up @@ -62,24 +63,22 @@ allprojects {

configure(subprojects.findAll { it.name != 'tests' }) {
// Required for Maven Nexus repository
apply plugin: 'maven'
apply plugin: 'signing'

// Required for JFrog Artifactory repository
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

task javadocJar(type: Jar) {
tasks.register('javadocJar', Jar) {
archiveClassifier.set('javadoc')
from javadoc
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

task testJar(type: Jar) {
tasks.register('testJar', Jar) {
archiveClassifier.set('test-sources')
from sourceSets.test.output
}
Expand All @@ -94,68 +93,65 @@ configure(subprojects.findAll { it.name != 'tests' }) {
}

publishing {
repositories {
maven {
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username=ossrhUsername
password=ossrhPassword
}
}
}
publications {
mavenJava(MavenPublication) {
groupId 'org.nervos.ckb'
version '2.1.1'
from components.java
}
}
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
authentication(
userName: ossrhUsername,
password: ossrhPassword
)
}

pom.project {
name 'ckb-sdk-java'
packaging 'jar'
description project.description
url 'https://github.com/nervosnetwork/ckb-sdk-java.git'

pom {
name = 'ckb-sdk-java'
description = project.description
url = 'https://github.com/nervosnetwork/ckb-sdk-java.git'
scm {
connection 'scm:git@github.com:nervosnetwork/ckb-sdk-java.git'
url 'https://github.com/nervosnetwork/ckb-sdk-java.git'
connection = 'scm:git@github.com:nervosnetwork/ckb-sdk-java.git'
url = 'https://github.com/nervosnetwork/ckb-sdk-java.git'
}

licenses {
license {
name 'The MIT License'
url 'https://opensource.org/licenses/MIT'
name = 'The MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}

developers {
developer {
id 'nervos'
name 'nervos developer'
email 'op@nervos.org'
id = 'nervos'
name = 'nervos developer'
email = 'op@nervos.org'
}
}
}
}
}
}


tasks.register('uploadArchives') {
println "start publish ${project.name} ${it.name}"
dependsOn publish
}

signing {
required { gradle.taskGraph.hasTask('uploadArchives') }
// only execute as part of this task
sign configurations.archives
}

task release {
tasks.register('release') {
println("release ${it.name}")
dependsOn 'build'
dependsOn 'uploadArchives'
dependsOn 'bintrayUpload'

tasks.findByName('uploadArchives').mustRunAfter 'build'
tasks.findByName('bintrayUpload').mustRunAfter 'build'
}
}
6 changes: 5 additions & 1 deletion ckb-indexer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
description 'SDK for CKB indexer'

dependencies {
compile project(":core")
implementation(project(":utils"))
implementation(project(":serialization"))
implementation project(":core")

implementation "com.google.code.gson:gson:$gsonVersion"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
Expand Down
9 changes: 7 additions & 2 deletions ckb-mercury-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
description 'SDK for CKB mercury'

dependencies {
compile project(":core")
compile project(":ckb-indexer")
implementation project(":core")
implementation project(":ckb-indexer")
implementation project(":utils")

implementation("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
implementation "com.google.code.gson:gson:$gsonVersion"

testImplementation project(":ckb")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
Expand Down
13 changes: 8 additions & 5 deletions ckb/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
description 'ckb-sdk-java is a lightweight Java library for integration with nervos CKB.'

dependencies {
compile project(":core")
compile project(":ckb-indexer")
compile project(":light-client")
compile project(":utils")
compile project(":serialization")
implementation project(":core")
implementation project(":ckb-indexer")
implementation project(":light-client")
implementation project(":utils")
implementation project(":serialization")

implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.google.guava:guava:$guavaVersion"
}

apply plugin: 'com.github.johnrengelman.shadow'
3 changes: 2 additions & 1 deletion ckb/src/main/java/org/nervos/ckb/CkbRpcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public interface CkbRpcApi {
TransactionProof getTransactionProof(List<byte[]> txHashes, byte[] blockHash) throws IOException;

List<byte[]> verifyTransactionProof(TransactionProof transactionProof) throws IOException;

TransactionAndWitnessProof getTransactionAndWitnessProof(List<byte[]> txHashes, byte[] blockHash) throws IOException;
List<byte[]> verifyTransactionAndWitnessProof(TransactionAndWitnessProof proof) throws IOException;
Block getForkBlock(byte[] blockHash) throws IOException;
PackedBlockWithCycles getPackedForkBlock(byte[] blockHash) throws IOException;

Expand Down
16 changes: 16 additions & 0 deletions ckb/src/main/java/org/nervos/ckb/service/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ public List<byte[]> verifyTransactionProof(TransactionProof transactionProof) th
new TypeToken<List<byte[]>>() {}.getType());
}

@Override
public TransactionAndWitnessProof getTransactionAndWitnessProof(List<byte[]> txHashes, byte[] blockHash) throws IOException {
return rpcService.post(
"get_transaction_and_witness_proof",
blockHash == null ? Collections.singletonList(txHashes): Arrays.asList(txHashes, blockHash),
TransactionAndWitnessProof.class);
}

@Override
public List<byte[]> verifyTransactionAndWitnessProof(TransactionAndWitnessProof proof) throws IOException {
return rpcService.post(
"verify_transaction_and_witness_proof",
Collections.singletonList(proof),
new TypeToken<List<byte[]>>() {}.getType());
}

@Override
public Block getForkBlock(byte[] blockHash) throws IOException {
return rpcService.post("get_fork_block", Collections.singletonList(blockHash), Block.class);
Expand Down
44 changes: 32 additions & 12 deletions ckb/src/test/java/service/ApiTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package service;

import com.google.common.collect.Streams;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.function.Executable;
import org.nervos.ckb.service.Api;
Expand All @@ -13,10 +14,8 @@
import org.nervos.indexer.model.resp.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Stream;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class ApiTest {
Expand Down Expand Up @@ -326,6 +325,31 @@ public void testGetTransactionProof() throws IOException {
Assertions.assertEquals(1, result.size());
}

@Test
public void testGetTransactionAndWitnessProof() throws IOException {
List<byte[]> txHashes = Collections.singletonList(
Numeric.hexStringToByteArray("0x8277d74d33850581f8d843613ded0c2a1722dec0e87e748f45c115dfb14210f1"));
TransactionAndWitnessProof proof = api.getTransactionAndWitnessProof(txHashes, null);
Assertions.assertNotNull(proof);
Assertions.assertNotNull(proof.blockHash);
Assertions.assertEquals(1, proof.transactionsProof.indices.size());
Assertions.assertEquals(proof.witnessesProof.indices.size(), proof.transactionsProof.indices.size());

TransactionAndWitnessProof proof2 = api.getTransactionAndWitnessProof(txHashes, proof.blockHash);
Assertions.assertEquals(proof, proof2);

List<byte[]> result = api.verifyTransactionAndWitnessProof(proof);

Assertions.assertNotNull(result);
Iterator<byte[]> l_it = txHashes.iterator();
Iterator<byte[]> r_it = result.iterator();
while (l_it.hasNext() && r_it.hasNext()) {
Assertions.assertArrayEquals(l_it.next(), r_it.next());
}
Assertions.assertFalse(l_it.hasNext());
Assertions.assertFalse(r_it.hasNext());
}

@Test
public void testGetForkBlock() throws IOException {
byte[] block_hash = Numeric.hexStringToByteArray(
Expand Down Expand Up @@ -740,19 +764,15 @@ public void testGetFeeRateStatics() throws IOException {
Assertions.assertTrue(statics.mean > 0 && statics.median > 0);

statics = api.getFeeRateStatics(1);
Assertions.assertNotNull(statics);
Assertions.assertTrue(statics.mean > 0 && statics.median > 0);
Assertions.assertTrue(statics == null || statics.mean > 0 && statics.median > 0);

statics = api.getFeeRateStatics(101);
Assertions.assertNotNull(statics);
Assertions.assertTrue(statics.mean > 0 && statics.median > 0);
Assertions.assertTrue(statics == null || statics.mean > 0 && statics.median > 0);

statics = api.getFeeRateStatics(0);
Assertions.assertNotNull(statics);
Assertions.assertTrue(statics.mean > 0 && statics.median > 0);
Assertions.assertTrue(statics == null || statics.mean > 0 && statics.median > 0);

statics = api.getFeeRateStatics(102);
Assertions.assertNotNull(statics);
Assertions.assertTrue(statics.mean > 0 && statics.median > 0);
Assertions.assertTrue(statics == null || statics.mean > 0 && statics.median > 0);
}
}
16 changes: 10 additions & 6 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
description 'CKB core'

dependencies {
compile project(":serialization")
compile "org.slf4j:slf4j-api:$slf4jVersion"
compile "io.reactivex.rxjava2:rxjava:$rxjavaVersion"
compile "com.google.code.gson:gson:$gsonVersion"
compile "com.squareup.okhttp3:okhttp:$okhttpVersion"
compile "com.squareup.okhttp3:logging-interceptor:$loggingOkhttpVersion"
implementation(project(":utils"))
implementation project(":serialization")

implementation "org.slf4j:slf4j-api:$slf4jVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxjavaVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("com.google.guava:guava:$guavaVersion")
implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$loggingOkhttpVersion"
}
Loading