Skip to content

Commit cadd1be

Browse files
authored
Merge pull request #3 from raventrov/baley
A pure-Java implementation of the PlatON protocol
2 parents 6a11da1 + f013705 commit cadd1be

432 files changed

Lines changed: 51545 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.gradle
2+
gradle
3+
.idea
4+
*.impl
5+
*.iml
6+
*.log
7+
*.bak
8+
*.class
9+
logs/*
10+
build/*
11+
account/build/
12+
common/build/
13+
consensus/build/
14+
core/build/
15+
core/out/
16+
crypto/build/
17+
crypto/out/
18+
p2p/build/
19+
slice/build/
20+
storage/build/
21+
storage/out/
22+
out/*
23+
slice/src/main/java/
24+
slice/src/main/grpc/
25+
core/db-01/
26+
core/database/
27+
slice/src/main/java/
28+
database/
29+
testdb/
30+
31+
out
32+
core/config
33+
core/blockchain

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# PlatON-Java
2-
Java implementation of the PlatON protocol
1+
# Welcome to PlatON-Java
2+
3+
# About
4+
5+
PlatON-Java is a pure-Java implementation of the PlatON protocol.
6+
7+
# Running PlatON-Java
8+
9+
##### Importing project to IntelliJ IDEA:
10+
11+
```
12+
> git clone https://github.com/PlatONnetwork/PlatON-Java.git
13+
> cd PlatON-Java
14+
> ./gradlew.bat build
15+
```
16+
17+
IDEA:
18+
* File -> New -> Project from existing sources…
19+
* Select PlatON-Java/build.gradle
20+
* Dialog “Import Project from gradle”: press “OK”
21+
* After building run `org.platon.Start` .
22+
23+
24+
# License
25+
PlatON-Java is released under the [LGPL-V3 license](LICENSE).
26+

account/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sourceCompatibility = 1.8
2+
3+
dependencies {
4+
5+
}

build.gradle

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
subprojects {
2+
3+
group 'org.platon'
4+
version '0.1.0-SNAPSHOT'
5+
6+
/** load plugin */
7+
apply plugin: 'java'
8+
apply plugin: 'maven'
9+
10+
compileJava.options.encoding = 'UTF-8'
11+
compileJava.options.compilerArgs << '-XDignore.symbol.file'
12+
compileTestJava.options.encoding = 'UTF-8'
13+
14+
ext {
15+
iceVersion = '3.7.1'
16+
springVersion = '4.2.0.RELEASE'
17+
}
18+
19+
/** define resp */
20+
repositories {
21+
maven {
22+
url "http://maven.aliyun.com/nexus/content/groups/public/"
23+
}
24+
}
25+
26+
/** define common dependency */
27+
dependencies {
28+
compile "ch.qos.logback:logback-classic:1.1.7"
29+
compile "ch.qos.logback:logback-core:1.1.7"
30+
compile "org.slf4j:slf4j-api:1.7.7"
31+
compile "org.slf4j:slf4j-api:1.7.7"
32+
compile "org.slf4j:log4j-over-slf4j:1.7.7"
33+
compile "org.slf4j:jul-to-slf4j:1.7.7"
34+
compile "org.slf4j:jcl-over-slf4j:1.7.7"
35+
36+
// spring define
37+
compile "org.springframework:spring-context:${springVersion}"
38+
compile "org.springframework:spring-orm:${springVersion}"
39+
compile "org.springframework:spring-tx:${springVersion}"
40+
41+
// config
42+
compile "com.typesafe:config:1.2.1"
43+
compile "com.googlecode.concurrent-locks:concurrent-locks:1.0.0"
44+
45+
testCompile "org.springframework:spring-test:${springVersion}"
46+
testCompile "org.mockito:mockito-core:2.19.1"
47+
testCompile group: 'junit', name: 'junit', version: '4.11'
48+
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5'
49+
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5'
50+
}
51+
52+
task "create-dir" << {
53+
sourceSets*.java.srcDirs*.each {
54+
it.mkdirs()
55+
}
56+
sourceSets*.resources.srcDirs*.each {
57+
it.mkdirs()
58+
}
59+
}
60+
}
61+
62+
task wrapper(type: Wrapper) {
63+
gradleVersion = "4.7"
64+
}

common/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
sourceCompatibility = 1.8
2+
3+
repositories {
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
9+
compile project(':slice')
10+
compile "com.google.guava:guava:24.1-jre"
11+
12+
compile "com.madgag.spongycastle:core:1.58.0.0" // for SHA3 and SECP256K1
13+
compile "com.madgag.spongycastle:prov:1.58.0.0" // for SHA3 and SECP256K1
14+
compile "com.fasterxml.jackson.core:jackson-databind:2.5.1"
15+
compile "com.fasterxml.jackson.core:jackson-annotations:2.5.0"
16+
compile "org.apache.commons:commons-collections4:4.0"
17+
18+
compile "com.cedarsoftware:java-util:1.8.0"
19+
20+
testCompile group: 'junit', name: 'junit', version: '4.11'
21+
}
22+
23+
task createJavaProject << {
24+
sourceSets*.java.srcDirs*.each{ it.mkdirs() }
25+
sourceSets*.resources.srcDirs*.each{ it.mkdirs()}
26+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.platon.common;
2+
3+
import org.slf4j.LoggerFactory;
4+
5+
public interface AppenderName {
6+
7+
final static String APPENDER_CONSENSUS = "consensus";
8+
9+
final static String APPENDER_KEY_STORE = "keystore";
10+
11+
final static String APPENDER_PLATIN = "plain";
12+
13+
final static String APPENDER_RPC = "grpc";
14+
15+
final static String APPENDER_WALLET = "wallet";
16+
17+
final static String APPENDER_DB = "db";
18+
19+
final static String APPENDER_STATE = "state";
20+
21+
final static String APPENDER_PENDING = "pending";
22+
23+
final static String APPENDER_MINE = "mine";
24+
25+
static void showWarn(String message, String... messages) {
26+
27+
LoggerFactory.getLogger(APPENDER_PLATIN).warn(message);
28+
final String ANSI_RED = "\u001B[31m";
29+
final String ANSI_RESET = "\u001B[0m";
30+
31+
System.err.println(ANSI_RED);
32+
System.err.println("");
33+
System.err.println(" " + message);
34+
for (String msg : messages) {
35+
System.err.println(" " + msg);
36+
}
37+
System.err.println("");
38+
System.err.println(ANSI_RESET);
39+
}
40+
41+
static void showErrorAndExit(String message, String... messages) {
42+
43+
LoggerFactory.getLogger(APPENDER_PLATIN).error(message);
44+
45+
46+
final String ANSI_RED = "\u001B[31m";
47+
final String ANSI_RESET = "\u001B[0m";
48+
49+
System.err.println(ANSI_RED);
50+
System.err.println("");
51+
System.err.println(" " + message);
52+
for (String msg : messages) {
53+
System.err.println(" " + msg);
54+
}
55+
System.err.println("");
56+
System.err.println(ANSI_RESET);
57+
58+
throw new RuntimeException(message);
59+
}
60+
61+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.platon.common;
2+
3+
import com.google.protobuf.ByteString;
4+
import com.google.protobuf.InvalidProtocolBufferException;
5+
import org.platon.common.proto.BaseProto;
6+
import org.platon.common.utils.ByteArrayWrapper;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
/**
12+
* base encode and decode by protoBuf
13+
* @author yanze
14+
*/
15+
public class BasicPbCodec {
16+
17+
public static byte[] encodeBytesList(byte[]... elements){
18+
if(elements == null){
19+
return null;
20+
}
21+
BaseProto.BaseBytesList.Builder builder = BaseProto.BaseBytesList.newBuilder();
22+
for(byte[] element : elements){
23+
builder.addBytesListData(ByteString.copyFrom(element));
24+
}
25+
return builder.build().toByteArray();
26+
}
27+
28+
public static byte[] encodeBytesList(List<ByteArrayWrapper> bytesList){
29+
if(bytesList == null){
30+
return null;
31+
}
32+
BaseProto.BaseBytesList.Builder builder = BaseProto.BaseBytesList.newBuilder();
33+
for(int i = 0;i<bytesList.size();i++){
34+
builder.addBytesListData(ByteString.copyFrom(bytesList.get(i).getData()));
35+
}
36+
return builder.build().toByteArray();
37+
}
38+
39+
public static List<ByteArrayWrapper> decodeBytesList(byte[] protoBuf) throws InvalidProtocolBufferException {
40+
BaseProto.BaseBytesList baseBytesList = BaseProto.BaseBytesList.parseFrom(protoBuf);
41+
List<ByteArrayWrapper> list = new ArrayList<>();
42+
for(int i = 0;i<baseBytesList.getBytesListDataCount();i++){
43+
list.add(new ByteArrayWrapper(baseBytesList.getBytesListData(i).toByteArray()));
44+
}
45+
return list;
46+
}
47+
48+
public static byte[] encodeInt(int data){
49+
BaseProto.BaseInt.Builder builder = BaseProto.BaseInt.newBuilder();
50+
builder.setIntData(data);
51+
return builder.build().toByteArray();
52+
}
53+
54+
public static int decodeInt(byte[] protoBuf) throws InvalidProtocolBufferException{
55+
BaseProto.BaseInt baseInt = BaseProto.BaseInt.parseFrom(protoBuf);
56+
return baseInt.getIntData();
57+
}
58+
59+
public static byte[] encodeLong(long data){
60+
BaseProto.BaseLong.Builder builder = BaseProto.BaseLong.newBuilder();
61+
builder.setLongData(data);
62+
return builder.build().toByteArray();
63+
}
64+
65+
public static long decodeLong(byte[] protoBuf) throws InvalidProtocolBufferException{
66+
BaseProto.BaseLong baseLong = BaseProto.BaseLong.parseFrom(protoBuf);
67+
return baseLong.getLongData();
68+
}
69+
70+
public static byte[] encodeString(String data){
71+
if(data == null){
72+
return null;
73+
}
74+
BaseProto.BaseString.Builder builder = BaseProto.BaseString.newBuilder();
75+
builder.setStringData(data);
76+
return builder.build().toByteArray();
77+
}
78+
79+
public static String decodeString(byte[] protoBuf) throws InvalidProtocolBufferException{
80+
BaseProto.BaseString baseString = BaseProto.BaseString.parseFrom(protoBuf);
81+
return baseString.getStringData();
82+
}
83+
84+
}

0 commit comments

Comments
 (0)