forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
140 changed files
with
15,997 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# IDEA | ||
.idea | ||
*iml | ||
.DS_Store | ||
|
||
# gradle | ||
.gradle | ||
build | ||
gradle | ||
gradlew | ||
gradlew.bat | ||
|
||
|
||
# log | ||
logs | ||
|
||
# lombok | ||
out | ||
|
||
# levelDB | ||
tron-data | ||
database* | ||
|
||
# database | ||
database | ||
|
||
# doc | ||
doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
# java-tron | ||
Java implementation of the Tron whitepaper | ||
# What’s TRON? | ||
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. | ||
|
||
TRON is a product of Web 4.0 and the decentralized internet of next generation. | ||
|
||
# Quick Start | ||
|
||
**Download and build** | ||
|
||
```shell | ||
> git clone https://github.com/tron-network/java-tron.git | ||
> cd java-tron | ||
> gradle build | ||
``` | ||
|
||
**Import project to IDEA** | ||
|
||
1. [File] -> [New] -> [Project from Existing Sources...] | ||
2. Select java-tron/build.gradle | ||
3. Dialog [Import Project from Gradle], confirm [Use auto-import] and [Use gradle wrapper task configuration] have been | ||
selected,then select Gradle JVM(JDK 1.8)and click [OK] | ||
|
||
# Testing | ||
|
||
- Install Kafka, create two topics (block and transaction) | ||
- Adjust constant **DEFAULT_BOOTSTRAP_SERVERS** in ConsumerProperty.java file and ProducerProperty.java file to your Kafka's host(like:192.168.1.199:9092) | ||
- IDEA: [Edit Configurations...] -> [Program arguments]: **--type server** | ||
- Run Tron (server) | ||
- IDEA: [Edit Configurations...] -> [Program arguments]: **--type normal** | ||
- Run Tron (client) | ||
- Execute `help` command on the client | ||
|
||
# License | ||
|
||
java-tron is released under the [LGPL-V3 license](LICENSE). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
group 'org.tron' | ||
version '1.0.0' | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'com.google.protobuf' | ||
apply plugin: 'application' | ||
|
||
sourceCompatibility = 1.8 | ||
mainClassName = 'org.tron.example.Tron' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3' | ||
} | ||
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
|
||
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' | ||
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25' | ||
compile group: 'log4j', name: 'log4j', version: '1.2.17' | ||
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' | ||
|
||
compile "org.projectlombok:lombok:1.16.18" | ||
|
||
compile group: 'commons-codec', name: 'commons-codec', version: '1.11' | ||
|
||
compile "com.madgag.spongycastle:core:1.53.0.0" | ||
compile "com.madgag.spongycastle:prov:1.53.0.0" | ||
|
||
compile group: 'com.google.guava', name: 'guava', version: '18.0' | ||
|
||
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0' | ||
|
||
compile "org.iq80.leveldb:leveldb:0.7" | ||
|
||
compile group: 'org.fusesource.leveldbjni', name: 'leveldbjni-all', | ||
version: '1.8' | ||
|
||
compile "org.apache.commons:commons-collections4:4.0" | ||
|
||
compile group: 'com.typesafe', name: 'config', version: '1.3.2' | ||
|
||
compile "com.google.code.findbugs:jsr305:3.0.0" | ||
|
||
compile "com.cedarsoftware:java-util:1.8.0" | ||
|
||
compile "org.apache.commons:commons-lang3:3.4" | ||
|
||
compile(group: 'org.apache.kafka', name: 'kafka_2.12', version: '0.11.0.2') { | ||
exclude module: 'slf4j-log4j12' | ||
} | ||
compile group: 'org.springframework', name: 'spring-context', version: '4.2.0.RELEASE' | ||
|
||
compile(group: 'org.apache.kafka', name: 'kafka_2.12', version: '0.11.0.2') { | ||
exclude module: 'slf4j-log4j12' | ||
} | ||
|
||
compile "org.apache.commons:commons-collections4:4.0" | ||
|
||
compile group: 'com.beust', name: 'jcommander', version: '1.72' | ||
|
||
compile group: 'junit', name: 'junit', version: '4.8.1' | ||
|
||
compile group: 'io.atomix.copycat', name: 'copycat-server', version: '1.1.4' | ||
compile group: 'io.atomix.copycat', name: 'copycat-client', version: '1.1.4' | ||
compile group: 'io.atomix.catalyst', name: 'catalyst-netty', version: '1.1.1' | ||
} | ||
|
||
tasks.matching { it instanceof Test }.all { | ||
testLogging.events = ["failed", "passed", "skipped"] | ||
} | ||
|
||
if (project.hasProperty("mainClass")) { | ||
mainClassName = mainClass | ||
} | ||
|
||
sourceSets { | ||
src { | ||
main { | ||
proto { | ||
srcDir 'src/main/proto' | ||
} | ||
} | ||
} | ||
} | ||
|
||
protobuf.protoc { | ||
artifact = 'com.google.protobuf:protoc:3.4.0' | ||
} | ||
|
||
protobuf { | ||
generatedFilesBaseDir = "$projectDir/src" | ||
|
||
generateProtoTasks { | ||
all().each { task -> | ||
task.builtins { | ||
java {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rootProject.name = 'java-tron' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
import org.tron.utils.ByteArray; | ||
|
||
public class AccountCommand extends Command { | ||
public AccountCommand() { | ||
} | ||
|
||
@Override | ||
public void execute(Peer peer, String[] parameters) { | ||
System.out.println(ByteArray.toHexString(peer.getMyKey().getAddress())); | ||
} | ||
|
||
@Override | ||
public void usage() { | ||
System.out.println(""); | ||
System.out.println("USAGE [account]:"); | ||
System.out.println("Command: account"); | ||
System.out.println("Description: Get your account."); | ||
System.out.println(""); | ||
} | ||
|
||
@Override | ||
public boolean check(String[] parameters) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
|
||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
public class Cli { | ||
public Cli() { | ||
} | ||
|
||
public void run(Peer peer) { | ||
Scanner in = new Scanner(System.in); | ||
|
||
while (true) { | ||
String cmd = in.nextLine(); | ||
cmd = cmd.trim(); | ||
|
||
String[] cmdArray = cmd.split("\\s+"); | ||
|
||
if (cmdArray.length == 0) { | ||
continue; | ||
} | ||
|
||
String[] cmdParameters = Arrays.copyOfRange(cmdArray, 1, cmdArray.length); | ||
|
||
switch (cmdArray[0]) { | ||
case "exit": | ||
case "quit": | ||
case "bye": | ||
new ExitCommand().execute(peer, cmdParameters); | ||
break; | ||
case "send": | ||
new SendCommand().execute(peer, cmdParameters); | ||
break; | ||
case "getbalance": | ||
new GetBalanceCommand().execute(peer, cmdParameters); | ||
break; | ||
case "account": | ||
new AccountCommand().execute(peer, cmdParameters); | ||
break; | ||
case "printblockchain": | ||
new PrintBlockchainCommand().execute(peer, cmdParameters); | ||
break; | ||
case "help": | ||
default: | ||
new HelpCommand().execute(peer, cmdParameters); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
|
||
public abstract class Command { | ||
public abstract void execute(Peer peer, String[] parameters); | ||
|
||
public abstract void usage(); | ||
|
||
public abstract boolean check(String[] parameters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
|
||
public class ExitCommand extends Command { | ||
public ExitCommand() { | ||
} | ||
|
||
@Override | ||
public void execute(Peer peer, String[] parameters) { | ||
System.exit(0); | ||
} | ||
|
||
@Override | ||
public void usage() { | ||
System.out.println(""); | ||
System.out.println("USAGE [exit]:"); | ||
System.out.println("Command: exit | quit | bye"); | ||
System.out.println("Description: Exit the program."); | ||
System.out.println(""); | ||
} | ||
|
||
@Override | ||
public boolean check(String[] parameters) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
import org.tron.protos.core.TronTXOutput; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class GetBalanceCommand extends Command { | ||
public GetBalanceCommand() { | ||
} | ||
|
||
@Override | ||
public void execute(Peer peer, String[] parameters) { | ||
byte[] pubKeyHash = peer.getWallet().getEcKey().getPubKey(); | ||
ArrayList<TronTXOutput.TXOutput> utxos = peer.getUTXOSet().findUTXO(pubKeyHash); | ||
|
||
long balance = 0; | ||
|
||
for (TronTXOutput.TXOutput txOutput : utxos) { | ||
balance += txOutput.getValue(); | ||
} | ||
|
||
System.out.println(balance); | ||
} | ||
|
||
@Override | ||
public void usage() { | ||
System.out.println(""); | ||
System.out.println("USAGE [getbalance]:"); | ||
System.out.println("Command: getbalance"); | ||
System.out.println("Description: Get your balance."); | ||
System.out.println(""); | ||
} | ||
|
||
@Override | ||
public boolean check(String[] parameters) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.tron.command; | ||
|
||
import org.tron.peer.Peer; | ||
|
||
public class HelpCommand extends Command { | ||
public HelpCommand() { | ||
} | ||
|
||
@Override | ||
public void execute(Peer peer, String[] parameters) { | ||
new ExitCommand().usage(); | ||
new SendCommand().usage(); | ||
new GetBalanceCommand().usage(); | ||
new AccountCommand().usage(); | ||
new PrintBlockchainCommand().usage(); | ||
} | ||
|
||
@Override | ||
public void usage() { | ||
System.out.printf("USAGE [help]"); | ||
System.out.println("help"); | ||
} | ||
|
||
@Override | ||
public boolean check(String[] parameters) { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.