Skip to content

Commit ad8d728

Browse files
committed
add java-tron
1 parent 49a6323 commit ad8d728

140 files changed

Lines changed: 15997 additions & 4 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# IDEA
2+
.idea
3+
*iml
4+
.DS_Store
5+
6+
# gradle
7+
.gradle
8+
build
9+
gradle
10+
gradlew
11+
gradlew.bat
12+
13+
14+
# log
15+
logs
16+
17+
# lombok
18+
out
19+
20+
# levelDB
21+
tron-data
22+
database*
23+
24+
# database
25+
database
26+
27+
# doc
28+
doc

‎LICENSE‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GNU LESSER GENERAL PUBLIC LICENSE
22
Version 3, 29 June 2007
33

4-
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
4+
Copyright (C) [2007] [TRON Foundation], Inc. <https://fsf.org/>
55
Everyone is permitted to copy and distribute verbatim copies
66
of this license document, but changing it is not allowed.
77

@@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation.
162162
whether future versions of the GNU Lesser General Public License shall
163163
apply, that proxy's public statement of acceptance of any version is
164164
permanent authorization for you to choose that version for the
165-
Library.
165+
Library.

‎README.md‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# java-tron
2-
Java implementation of the Tron whitepaper
1+
# What’s TRON?
2+
TRON is a block chain-based decentralized smart protocol and an application development platform. It allows each user to freely publish, store and own contents and data, and in the decentralized autonomous form, decides an incentive mechanism and enables application developers and content creators through digital asset distribution, circulation and transaction, thus forming a decentralized content entertainment ecosystem.
3+
4+
TRON is a product of Web 4.0 and the decentralized internet of next generation.
5+
6+
# Quick Start
7+
8+
**Download and build**
9+
10+
```shell
11+
> git clone https://github.com/tron-network/java-tron.git
12+
> cd java-tron
13+
> gradle build
14+
```
15+
16+
**Import project to IDEA**
17+
18+
1. [File] -> [New] -> [Project from Existing Sources...]
19+
2. Select java-tron/build.gradle
20+
3. Dialog [Import Project from Gradle], confirm [Use auto-import] and [Use gradle wrapper task configuration] have been
21+
selected,then select Gradle JVM(JDK 1.8)and click [OK]
22+
23+
# Testing
24+
25+
- Install Kafka, create two topics (block and transaction)
26+
- Adjust constant **DEFAULT_BOOTSTRAP_SERVERS** in ConsumerProperty.java file and ProducerProperty.java file to your Kafka's host(like:192.168.1.199:9092)
27+
- IDEA: [Edit Configurations...] -> [Program arguments]: **--type server**
28+
- Run Tron (server)
29+
- IDEA: [Edit Configurations...] -> [Program arguments]: **--type normal**
30+
- Run Tron (client)
31+
- Execute `help` command on the client
32+
33+
# License
34+
35+
java-tron is released under the [LGPL-V3 license](LICENSE).
36+

‎build.gradle‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
group 'org.tron'
2+
version '1.0.0'
3+
4+
apply plugin: 'java'
5+
apply plugin: 'com.google.protobuf'
6+
apply plugin: 'application'
7+
8+
sourceCompatibility = 1.8
9+
mainClassName = 'org.tron.example.Tron'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
buildscript {
16+
repositories {
17+
mavenCentral()
18+
}
19+
dependencies {
20+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
21+
}
22+
}
23+
24+
dependencies {
25+
testCompile group: 'junit', name: 'junit', version: '4.12'
26+
27+
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
28+
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
29+
compile group: 'log4j', name: 'log4j', version: '1.2.17'
30+
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
31+
32+
compile "org.projectlombok:lombok:1.16.18"
33+
34+
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
35+
36+
compile "com.madgag.spongycastle:core:1.53.0.0"
37+
compile "com.madgag.spongycastle:prov:1.53.0.0"
38+
39+
compile group: 'com.google.guava', name: 'guava', version: '18.0'
40+
41+
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0'
42+
43+
compile "org.iq80.leveldb:leveldb:0.7"
44+
45+
compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all',
46+
version: '1.8'
47+
48+
compile "org.apache.commons:commons-collections4:4.0"
49+
50+
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
51+
52+
compile "com.google.code.findbugs:jsr305:3.0.0"
53+
54+
compile "com.cedarsoftware:java-util:1.8.0"
55+
56+
compile "org.apache.commons:commons-lang3:3.4"
57+
58+
compile(group: 'org.apache.kafka', name: 'kafka_2.12', version: '0.11.0.2') {
59+
exclude module: 'slf4j-log4j12'
60+
}
61+
compile group: 'org.springframework', name: 'spring-context', version: '4.2.0.RELEASE'
62+
63+
compile(group: 'org.apache.kafka', name: 'kafka_2.12', version: '0.11.0.2') {
64+
exclude module: 'slf4j-log4j12'
65+
}
66+
67+
compile "org.apache.commons:commons-collections4:4.0"
68+
69+
compile group: 'com.beust', name: 'jcommander', version: '1.72'
70+
71+
compile group: 'junit', name: 'junit', version: '4.8.1'
72+
73+
compile group: 'io.atomix.copycat', name: 'copycat-server', version: '1.1.4'
74+
compile group: 'io.atomix.copycat', name: 'copycat-client', version: '1.1.4'
75+
compile group: 'io.atomix.catalyst', name: 'catalyst-netty', version: '1.1.1'
76+
}
77+
78+
tasks.matching { it instanceof Test }.all {
79+
testLogging.events = ["failed", "passed", "skipped"]
80+
}
81+
82+
if (project.hasProperty("mainClass")) {
83+
mainClassName = mainClass
84+
}
85+
86+
sourceSets {
87+
src {
88+
main {
89+
proto {
90+
srcDir 'src/main/proto'
91+
}
92+
}
93+
}
94+
}
95+
96+
protobuf.protoc {
97+
artifact = 'com.google.protobuf:protoc:3.4.0'
98+
}
99+
100+
protobuf {
101+
generatedFilesBaseDir = "$projectDir/src"
102+
103+
generateProtoTasks {
104+
all().each { task ->
105+
task.builtins {
106+
java {}
107+
}
108+
}
109+
}
110+
}

‎settings.gradle‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'java-tron'
2+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.tron.command;
2+
3+
import org.tron.peer.Peer;
4+
import org.tron.utils.ByteArray;
5+
6+
public class AccountCommand extends Command {
7+
public AccountCommand() {
8+
}
9+
10+
@Override
11+
public void execute(Peer peer, String[] parameters) {
12+
System.out.println(ByteArray.toHexString(peer.getMyKey().getAddress()));
13+
}
14+
15+
@Override
16+
public void usage() {
17+
System.out.println("");
18+
System.out.println("USAGE [account]:");
19+
System.out.println("Command: account");
20+
System.out.println("Description: Get your account.");
21+
System.out.println("");
22+
}
23+
24+
@Override
25+
public boolean check(String[] parameters) {
26+
return true;
27+
}
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.tron.command;
2+
3+
import org.tron.peer.Peer;
4+
5+
import java.util.Arrays;
6+
import java.util.Scanner;
7+
8+
public class Cli {
9+
public Cli() {
10+
}
11+
12+
public void run(Peer peer) {
13+
Scanner in = new Scanner(System.in);
14+
15+
while (true) {
16+
String cmd = in.nextLine();
17+
cmd = cmd.trim();
18+
19+
String[] cmdArray = cmd.split("\\s+");
20+
21+
if (cmdArray.length == 0) {
22+
continue;
23+
}
24+
25+
String[] cmdParameters = Arrays.copyOfRange(cmdArray, 1, cmdArray.length);
26+
27+
switch (cmdArray[0]) {
28+
case "exit":
29+
case "quit":
30+
case "bye":
31+
new ExitCommand().execute(peer, cmdParameters);
32+
break;
33+
case "send":
34+
new SendCommand().execute(peer, cmdParameters);
35+
break;
36+
case "getbalance":
37+
new GetBalanceCommand().execute(peer, cmdParameters);
38+
break;
39+
case "account":
40+
new AccountCommand().execute(peer, cmdParameters);
41+
break;
42+
case "printblockchain":
43+
new PrintBlockchainCommand().execute(peer, cmdParameters);
44+
break;
45+
case "help":
46+
default:
47+
new HelpCommand().execute(peer, cmdParameters);
48+
break;
49+
}
50+
}
51+
}
52+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.tron.command;
2+
3+
import org.tron.peer.Peer;
4+
5+
public abstract class Command {
6+
public abstract void execute(Peer peer, String[] parameters);
7+
8+
public abstract void usage();
9+
10+
public abstract boolean check(String[] parameters);
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.tron.command;
2+
3+
import org.tron.peer.Peer;
4+
5+
public class ExitCommand extends Command {
6+
public ExitCommand() {
7+
}
8+
9+
@Override
10+
public void execute(Peer peer, String[] parameters) {
11+
System.exit(0);
12+
}
13+
14+
@Override
15+
public void usage() {
16+
System.out.println("");
17+
System.out.println("USAGE [exit]:");
18+
System.out.println("Command: exit | quit | bye");
19+
System.out.println("Description: Exit the program.");
20+
System.out.println("");
21+
}
22+
23+
@Override
24+
public boolean check(String[] parameters) {
25+
return true;
26+
}
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.tron.command;
2+
3+
import org.tron.peer.Peer;
4+
import org.tron.protos.core.TronTXOutput;
5+
6+
import java.util.ArrayList;
7+
8+
public class GetBalanceCommand extends Command {
9+
public GetBalanceCommand() {
10+
}
11+
12+
@Override
13+
public void execute(Peer peer, String[] parameters) {
14+
byte[] pubKeyHash = peer.getWallet().getEcKey().getPubKey();
15+
ArrayList<TronTXOutput.TXOutput> utxos = peer.getUTXOSet().findUTXO(pubKeyHash);
16+
17+
long balance = 0;
18+
19+
for (TronTXOutput.TXOutput txOutput : utxos) {
20+
balance += txOutput.getValue();
21+
}
22+
23+
System.out.println(balance);
24+
}
25+
26+
@Override
27+
public void usage() {
28+
System.out.println("");
29+
System.out.println("USAGE [getbalance]:");
30+
System.out.println("Command: getbalance");
31+
System.out.println("Description: Get your balance.");
32+
System.out.println("");
33+
}
34+
35+
@Override
36+
public boolean check(String[] parameters) {
37+
return true;
38+
}
39+
}

0 commit comments

Comments
 (0)