From c9410d823e77b729eb106aaca7d91e35ffc7747d Mon Sep 17 00:00:00 2001 From: Sheip Date: Fri, 16 Mar 2018 18:51:10 +0100 Subject: [PATCH] refactoring --- .gitignore | 4 + .travis.yml | 19 ++++ LICENSE | 165 +++++++++++++++++++++++++++++++++ README.md | 8 ++ api/api.proto | 81 +++++++++++++++++ core/Contract.proto | 85 +++++++++++++++++ core/Tron.proto | 166 ++++++++++++++++++++++++++++++++++ core/TronInventoryItems.proto | 11 +++ install-protobuf.sh | 10 ++ 9 files changed, 549 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 api/api.proto create mode 100644 core/Contract.proto create mode 100644 core/Tron.proto create mode 100644 core/TronInventoryItems.proto create mode 100755 install-protobuf.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..1554c5edd92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# IDEA +.idea +*iml +.DS_Store diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..3f1e4c4709b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: ruby + +cache: + directories: + - $HOME/protobuf + +sudo: false + +before_install: + - bash install-protobuf.sh + +# check what has been installed by listing contents of protobuf folder +before_script: + - ls -R $HOME/protobuf + +# let's use protobuf +script: + - $HOME/protobuf/bin/protoc --java_out=./ ./core/*.proto ./api/*.proto + - ls -l \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000000..65c5ca88a67 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md new file mode 100644 index 00000000000..c04fbf6968a --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# protocol [![Build Status](https://travis-ci.org/tronprotocol/protocol.svg?branch=master)](https://travis-ci.org/tronprotocol/protocol) + + +the protocol of tron including api and message. + +java-tron and wallet-cli + +git subtree pull --prefix src/main/protos/ protocol master diff --git a/api/api.proto b/api/api.proto new file mode 100644 index 00000000000..77e4be1938c --- /dev/null +++ b/api/api.proto @@ -0,0 +1,81 @@ +syntax = "proto3"; +package protocol; + +import "core/Tron.proto"; +import "core/Contract.proto"; + +option java_package = "org.tron.api"; //Specify the name of the package that generated the Java file +option java_outer_classname = "GrpcAPI"; //Specify the class name of the generated Java file + +service Wallet { + + rpc GetBalance (Account) returns (Account) { + + }; + rpc CreateTransaction (TransferContract) returns (Transaction) { + + }; + + rpc BroadcastTransaction (Transaction) returns (Return) { + + }; + + rpc ListAccounts (EmptyMessage) returns (AccountList) { + + }; + + rpc CreateAccount (AccountCreateContract) returns (Transaction) { + + }; + + rpc VoteWitnessAccount (VoteWitnessContract) returns (Transaction) { + + }; + + rpc CreateAssetIssue (AssetIssueContract) returns (Transaction) { + + }; + + rpc ListWitnesses (EmptyMessage) returns (WitnessList) { + + }; + + rpc CreateWitness (WitnessCreateContract) returns (Transaction) { + + }; + + rpc ListNodes (EmptyMessage) returns (NodeList) { + + } +}; + +message Return { + bool result = 1; +} + +message AccountList { + repeated Account accounts = 1; +} + +message WitnessList { + repeated Witness witnesses = 1; +} + +// Gossip node list +message NodeList { + repeated Node nodes = 1; +} + +// Gossip node +message Node { + Address address = 1; +} + +// Gossip node address +message Address { + bytes host = 1; + int32 port = 2; +} + +message EmptyMessage { +} diff --git a/core/Contract.proto b/core/Contract.proto new file mode 100644 index 00000000000..8b3fff1167f --- /dev/null +++ b/core/Contract.proto @@ -0,0 +1,85 @@ +/* + * java-tron is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * java-tron is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +syntax = "proto3"; + +package protocol; + +option java_package = "org.tron.protos"; //Specify the name of the package that generated the Java file +option java_outer_classname = "Contract"; //Specify the class name of the generated Java file + +import "core/Tron.proto"; + +message AccountCreateContract { + AccountType type = 1; + bytes account_name = 2; + bytes owner_address = 3; +} + +message TransferContract { + bytes owner_address = 1; + bytes to_address = 2; + int64 amount = 3; +} + +message TransferAssertContract { + bytes assert_name = 1; + bytes owner_address = 2; + bytes to_address = 3; + int64 amount = 4; +} + + +message VoteAssetContract { + bytes owner_address = 1; + repeated bytes vote_address = 2; + bool support = 3; + int32 count = 5; +} + +message VoteWitnessContract { + message Vote { + bytes vote_address = 1; + int64 vote_count = 2; + } + bytes owner_address = 1; + repeated Vote votes = 2; + bool support = 3; +} + +message WitnessCreateContract { + bytes owner_address = 1; + bytes url = 12; +} + +message AssetIssueContract { + bytes owner_address = 1; + bytes name = 2; + int64 total_supply = 4; + int32 trx_num = 6; + int32 num = 8; + int64 start_time = 9; + int64 end_time = 10; + int32 decay_ratio = 15; + int32 vote_score = 16; + bytes description = 20; + bytes url = 21; +} + +message DeployContract { + bytes owner_address = 1; + bytes script = 2; +} + diff --git a/core/Tron.proto b/core/Tron.proto new file mode 100644 index 00000000000..4b5d5446c7e --- /dev/null +++ b/core/Tron.proto @@ -0,0 +1,166 @@ +syntax = "proto3"; + +import "google/protobuf/any.proto"; + +package protocol; + + +option java_package = "org.tron.protos"; //Specify the name of the package that generated the Java file +option java_outer_classname = "Protocol"; //Specify the class name of the generated Java file + + +enum AccountType { + Normal = 0; + AssetIssue = 1; + Contract = 2; +} + +// Account +message Account { + message Vote { + bytes vote_address = 1; + int64 vote_count = 2; + } + bytes account_name = 1; + AccountType type = 2; + bytes address = 3; + int64 balance = 4; + repeated Vote votes = 5; + map asset = 6; + +} + +// Witness +message Witness { + bytes address = 1; + int64 voteCount = 2; + bytes pubKey = 3; + string url = 4; + int64 totalProduced = 5; + int64 totalMissed = 6; + int64 latestBlockNum = 7; + int64 latestSlotNum = 8; + bool isJobs = 9; +} + +// Transcation + +message TXOutput { + int64 value = 1; + bytes pubKeyHash = 2; +} + +message TXInput { + message raw { + bytes txID = 1; + int64 vout = 2; + bytes pubKey = 3; + } + raw raw_data = 1; + bytes signature = 4; +} + +message TXOutputs { + repeated TXOutput outputs = 1; +} + +message Transaction { + enum TransactionType { + UtxoType = 0; + ContractType = 1; + } + message Contract { + enum ContractType { + AccountCreateContract = 0; + TransferContract = 1; + TransferAssertContract = 2; + VoteAssetContract = 3; + VoteWitnessContract = 4; + WitnessCreateContract = 5; + AssetIssueContract = 6; + DeployContract = 7; + } + ContractType type = 1; + google.protobuf.Any parameter = 2; + } + message raw { + TransactionType type = 2; + repeated TXInput vin = 5; + repeated TXOutput vout = 7; + int64 expiration = 8; + bytes data = 10; + repeated Contract contract = 11; + bytes scripts = 16; + } + raw raw_data = 1; + repeated bytes signature = 5; +} + +message BlockHeader { + message raw { + int64 timestamp = 1; + bytes txTrieRoot = 2; + bytes parentHash = 3; + //bytes nonce = 5; + //bytes difficulty = 6; + int64 number = 7; + int64 witness_id = 8; + bytes witness_address = 9; + } + raw raw_data = 1; + bytes witness_signature = 2; +} + +// block +message Block { + repeated Transaction transactions = 1; + BlockHeader block_header = 2; +} + +message ChainInventory { + message BlockId { + bytes hash = 1; + int64 number = 2; + } + repeated BlockId ids = 1; + int64 remain_num = 2; +} + +// Inventory +message BlockInventory { + enum Type { + SYNC = 0; + ADVTISE = 1; + FETCH = 2; + } + + message BlockId { + bytes hash = 1; + int64 number = 2; + } + repeated BlockId ids = 1; + Type type = 2; +} + +message Inventory { + enum InventoryType { + TRX = 0; + BLOCK = 1; + } + InventoryType type = 1; + repeated bytes ids = 2; +} + +message Items { + enum ItemType { + ERR = 0; + TRX = 1; + BLOCK = 2; + BLOCKHEADER = 3; + } + + ItemType type = 1; + repeated Block blocks = 2; + repeated BlockHeader block_headers = 3; + repeated Transaction transactions = 4; +} diff --git a/core/TronInventoryItems.proto b/core/TronInventoryItems.proto new file mode 100644 index 00000000000..fb16f1d5431 --- /dev/null +++ b/core/TronInventoryItems.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package protocol; + +option java_package = "org.tron.protos"; //Specify the name of the package that generated the Java file +option java_outer_classname = "TronInventoryItems"; //Specify the class name of the generated Java file + +message InventoryItems { + int32 type = 1; + repeated bytes items = 2; +} \ No newline at end of file diff --git a/install-protobuf.sh b/install-protobuf.sh new file mode 100755 index 00000000000..29e5536ee6d --- /dev/null +++ b/install-protobuf.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +# check to see if protobuf folder is empty +if [ ! -d "$HOME/protobuf/lib" ]; then + wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-java-3.5.1.tar.gz + tar -xzvf protobuf-java-3.5.1.tar.gz + cd protobuf-3.5.1 && ./configure --prefix=$HOME/protobuf && make && make install +else + echo "Using cached directory." +fi