From 169058aca47849fa61ae727e176c4090c171f631 Mon Sep 17 00:00:00 2001 From: ashu Date: Thu, 12 Apr 2018 12:06:22 +0800 Subject: [PATCH 01/15] add tron grpc proxy --- api/api.proto | 15 +++++++++++---- core/Contract.proto | 2 +- core/Discover.proto | 2 +- core/Tron.proto | 3 +-- core/TronInventoryItems.proto | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/api/api.proto b/api/api.proto index 3d6c0ad0f8a..7c0474d0c8e 100644 --- a/api/api.proto +++ b/api/api.proto @@ -3,14 +3,20 @@ package protocol; import "core/Tron.proto"; import "core/Contract.proto"; +import "google/api/annotations.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 -option go_package = "github.com/tronprotocol/go-client-api/api"; +option go_package = "github.com/tronprotocol/grpc-gateway/api"; service Wallet { rpc GetAccount (Account) returns (Account) { + option (google.api.http) = { + post: "v1/account" + body: "*" + }; }; @@ -23,6 +29,10 @@ service Wallet { }; rpc ListAccounts (EmptyMessage) returns (AccountList) { + option (google.api.http) = { + post: "/v1/account/list" + body: "*" + }; }; @@ -82,9 +92,6 @@ service Wallet { } rpc TotalTransaction (EmptyMessage) returns (NumberMessage) { - } - rpc GetDynamicProperties (EmptyMessage) returns (DynamicProperties) { - } }; // the api of tron's db diff --git a/core/Contract.proto b/core/Contract.proto index a00c82eec58..37a210ecc58 100644 --- a/core/Contract.proto +++ b/core/Contract.proto @@ -19,7 +19,7 @@ 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 -option go_package = "github.com/tronprotocol/go-client-api/core"; +option go_package = "github.com/tronprotocol/grpc-gateway/core"; import "core/Tron.proto"; diff --git a/core/Discover.proto b/core/Discover.proto index ac45a30364a..cba982a18b1 100644 --- a/core/Discover.proto +++ b/core/Discover.proto @@ -5,7 +5,7 @@ package protocol; option java_package = "org.tron.protos"; //Specify the name of the package that generated the Java file option java_outer_classname = "Discover"; //Specify the class name of the generated Java file -option go_package = "github.com/tronprotocol/go-client-api/core"; +option go_package = "github.com/tronprotocol/grpc-gateway/core"; message Endpoint { bytes address = 1; diff --git a/core/Tron.proto b/core/Tron.proto index b5914a3d33f..30c16b7b568 100644 --- a/core/Tron.proto +++ b/core/Tron.proto @@ -8,8 +8,7 @@ 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 -option go_package = "github.com/tronprotocol/go-client-api/core"; - +option go_package = "github.com/tronprotocol/grpc-gateway/core"; enum AccountType { Normal = 0; diff --git a/core/TronInventoryItems.proto b/core/TronInventoryItems.proto index f630ffad598..a82d2de4552 100644 --- a/core/TronInventoryItems.proto +++ b/core/TronInventoryItems.proto @@ -4,7 +4,7 @@ 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 -option go_package = "github.com/tronprotocol/go-client-api/core"; +option go_package = "github.com/tronprotocol/grpc-gateway/core"; message InventoryItems { int32 type = 1; From 72101540437d52c1d36312cdc3e28f0ecb9030bc Mon Sep 17 00:00:00 2001 From: ashu Date: Thu, 12 Apr 2018 12:36:49 +0800 Subject: [PATCH 02/15] add swagger generate srcipt and swagger definitions --- api/api.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/api.proto b/api/api.proto index 7c0474d0c8e..5cdfa8bf3da 100644 --- a/api/api.proto +++ b/api/api.proto @@ -14,7 +14,7 @@ service Wallet { rpc GetAccount (Account) returns (Account) { option (google.api.http) = { - post: "v1/account" + post: "/v1/account" body: "*" }; From b33bfdd91c224f748148a7411b70e2f34d27c432 Mon Sep 17 00:00:00 2001 From: ashu Date: Thu, 12 Apr 2018 17:35:12 +0800 Subject: [PATCH 03/15] config http url for grpc --- api/api.proto | 98 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 76 insertions(+), 22 deletions(-) diff --git a/api/api.proto b/api/api.proto index 5cdfa8bf3da..d4650006d07 100644 --- a/api/api.proto +++ b/api/api.proto @@ -14,84 +14,138 @@ service Wallet { rpc GetAccount (Account) returns (Account) { option (google.api.http) = { - post: "/v1/account" - body: "*" - }; + post: "/wallet/getaccount" + body: "*" + }; }; rpc CreateTransaction (TransferContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/createtransaction" + body: "*" + }; }; rpc BroadcastTransaction (Transaction) returns (Return) { - + option (google.api.http) = { + post: "/wallet/broadcasttransaction" + body: "*" + }; }; rpc ListAccounts (EmptyMessage) returns (AccountList) { option (google.api.http) = { - post: "/v1/account/list" + post: "/wallet/listaccount" body: "*" }; }; rpc UpdateAccount (AccountUpdateContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/updateaccount" + body: "*" + }; }; rpc CreateAccount (AccountCreateContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/createaccount" + body: "*" + }; }; rpc VoteWitnessAccount (VoteWitnessContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/votewitnessaccount" + body: "*" + }; }; rpc CreateAssetIssue (AssetIssueContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/createassetissue" + body: "*" + }; }; rpc ListWitnesses (EmptyMessage) returns (WitnessList) { - + option (google.api.http) = { + post: "/wallet/listwitnesses" + body: "*" + }; }; rpc UpdateWitness (WitnessUpdateContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/updatewitness" + body: "*" + }; }; rpc CreateWitness (WitnessCreateContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/createwitness" + body: "*" + }; }; rpc TransferAsset (TransferAssetContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/transferasset" + body: "*" + }; } rpc ParticipateAssetIssue (ParticipateAssetIssueContract) returns (Transaction) { - + option (google.api.http) = { + post: "/wallet/participateassetissue" + body: "*" + }; } rpc ListNodes (EmptyMessage) returns (NodeList) { - + option (google.api.http) = { + post: "/wallet/listnodes" + body: "*" + }; } rpc GetAssetIssueList (EmptyMessage) returns (AssetIssueList) { - + option (google.api.http) = { + post: "/wallet/getassetissuelist" + body: "*" + }; } rpc GetAssetIssueByAccount (Account) returns (AssetIssueList) { - + option (google.api.http) = { + post: "/wallet/getassetissuebyaccount" + body: "*" + }; } rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) { - + option (google.api.http) = { + post: "/wallet/getassetissuebyname" + body: "*" + }; } rpc GetNowBlock (EmptyMessage) returns (Block) { - + option (google.api.http) = { + post: "/wallet/getnowblock" + body: "*" + }; } rpc GetBlockByNum (NumberMessage) returns (Block) { - + option (google.api.http) = { + post: "/wallet/getblockbynum" + body: "*" + }; } rpc TotalTransaction (EmptyMessage) returns (NumberMessage) { - + option (google.api.http) = { + post: "/wallet/totaltransaction" + body: "*" + }; } }; // the api of tron's db From 65314a5e769f928ff0c8e981b653ba10b3afa5c1 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 11:50:42 +0800 Subject: [PATCH 04/15] add googleapis proto file into protoc include --- .travis.yml | 1 + install-googleapis.sh | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100755 install-googleapis.sh diff --git a/.travis.yml b/.travis.yml index 3f1e4c4709b..0b642642c05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ sudo: false before_install: - bash install-protobuf.sh + - bash install-googleapis.sh # check what has been installed by listing contents of protobuf folder before_script: diff --git a/install-googleapis.sh b/install-googleapis.sh new file mode 100755 index 00000000000..5767d7ab909 --- /dev/null +++ b/install-googleapis.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +wget http://central.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar +jar xvf googleapis-common-protos-0.0.3.jar -C $HOME/protobuf/include/ +ls -l + + + From 623ceea36319abd47de35cbd7b7d9667904da978 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 12:07:37 +0800 Subject: [PATCH 05/15] fix install-googleapis --- install-googleapis.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install-googleapis.sh b/install-googleapis.sh index 5767d7ab909..284ed6e58a2 100755 --- a/install-googleapis.sh +++ b/install-googleapis.sh @@ -1,7 +1,8 @@ #!/bin/sh set -e wget http://central.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar -jar xvf googleapis-common-protos-0.0.3.jar -C $HOME/protobuf/include/ +jar xvf googleapis-common-protos-0.0.3.jar +cp -r google/ $HOME/protobuf/include/ ls -l From 8ead80e7cd24c544140b1faaf81bbc510215f586 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 12:22:12 +0800 Subject: [PATCH 06/15] add go proto ci --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0b642642c05..c7bc9964c35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,8 @@ before_script: # let's use protobuf script: - $HOME/protobuf/bin/protoc --java_out=./ ./core/*.proto ./api/*.proto + - $HOME/protobuf/bin/protoc --go_out=./ ./core/*.proto + - $HOME/protobuf/bin/protoc --go_out=./ ./api/*.proto + - $HOME/protobuf/bin/protoc --grpc-gateway_out=logtostderr=true:./ ./api/*.proto + - ls -l \ No newline at end of file From 84e3f19affe5f3f0002569d19b0a36ed9338a243 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 12:41:17 +0800 Subject: [PATCH 07/15] add protoc-gen-go plugin --- install-protobuf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-protobuf.sh b/install-protobuf.sh index 29e5536ee6d..b3a8cb5cbb2 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -2,8 +2,8 @@ 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 + wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-all-3.5.1.tar.gz + tar -xzvf protobuf-all-3.5.1.tar.gz cd protobuf-3.5.1 && ./configure --prefix=$HOME/protobuf && make && make install else echo "Using cached directory." From d536ddacc5bdc10be283e353df941d8487f708b2 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 12:55:27 +0800 Subject: [PATCH 08/15] rm cached directory --- install-protobuf.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-protobuf.sh b/install-protobuf.sh index b3a8cb5cbb2..76f02aa744c 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -1,6 +1,7 @@ #!/bin/sh set -e # check to see if protobuf folder is empty +rm -rf $HOME/protobuf/lib if [ ! -d "$HOME/protobuf/lib" ]; then wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-all-3.5.1.tar.gz tar -xzvf protobuf-all-3.5.1.tar.gz From 21fba07965e7bb5a4b46492fb13125298a07d1ba Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 13:02:43 +0800 Subject: [PATCH 09/15] add protoc-go-gen dependencies --- .travis.yml | 6 +++--- install-googleapis.sh | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7bc9964c35..71d8f70d57e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ before_script: # let's use protobuf script: - $HOME/protobuf/bin/protoc --java_out=./ ./core/*.proto ./api/*.proto - - $HOME/protobuf/bin/protoc --go_out=./ ./core/*.proto - - $HOME/protobuf/bin/protoc --go_out=./ ./api/*.proto - - $HOME/protobuf/bin/protoc --grpc-gateway_out=logtostderr=true:./ ./api/*.proto + - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./core/*.proto + - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./api/*.proto + - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:./ ./api/*.proto - ls -l \ No newline at end of file diff --git a/install-googleapis.sh b/install-googleapis.sh index 284ed6e58a2..0d44f6108d1 100755 --- a/install-googleapis.sh +++ b/install-googleapis.sh @@ -1,5 +1,10 @@ #!/bin/sh set -e + +go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway +go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger +go get -u github.com/golang/protobuf/protoc-gen-go + wget http://central.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar jar xvf googleapis-common-protos-0.0.3.jar cp -r google/ $HOME/protobuf/include/ From 48a994cd9dc2435f7243c0f671db4ec4bd77bdb3 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 13:55:22 +0800 Subject: [PATCH 10/15] fix go gen script --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71d8f70d57e..34fa71b3d15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ before_script: # let's use protobuf script: - $HOME/protobuf/bin/protoc --java_out=./ ./core/*.proto ./api/*.proto - - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./core/*.proto - - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./api/*.proto - - $HOME/protobuf/bin/protoc I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:./ ./api/*.proto + - $HOME/protobuf/bin/protoc -I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./core/*.proto + - $HOME/protobuf/bin/protoc -I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=./ ./api/*.proto + - $HOME/protobuf/bin/protoc -I. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:./ ./api/*.proto - ls -l \ No newline at end of file From 4743ea0f03cde9b880483d65c8422bcaaa562353 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 14:12:00 +0800 Subject: [PATCH 11/15] fix install-protobuf.sh --- install-protobuf.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/install-protobuf.sh b/install-protobuf.sh index 76f02aa744c..29e5536ee6d 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -1,10 +1,9 @@ #!/bin/sh set -e # check to see if protobuf folder is empty -rm -rf $HOME/protobuf/lib if [ ! -d "$HOME/protobuf/lib" ]; then - wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-all-3.5.1.tar.gz - tar -xzvf protobuf-all-3.5.1.tar.gz + 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." From 950a9b9f6fe37e65ba9a78c376ff38d2e440c9b6 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 15:01:22 +0800 Subject: [PATCH 12/15] disable travis cache --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34fa71b3d15..cc1be5a19f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,5 @@ language: ruby -cache: - directories: - - $HOME/protobuf - sudo: false before_install: From 23f0cce5cb881f0d25baf544bcdc51df42a1f20d Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 15:09:33 +0800 Subject: [PATCH 13/15] change protobuf-java to protobuf-all for protoc --- .travis.yml | 4 ++++ install-protobuf.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cc1be5a19f3..34fa71b3d15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: ruby +cache: + directories: + - $HOME/protobuf + sudo: false before_install: diff --git a/install-protobuf.sh b/install-protobuf.sh index 29e5536ee6d..6f69d20ad02 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -2,7 +2,7 @@ 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 + wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-all-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 From aeffcf9298c7b9b02ba1e68f0ea5ac1e9a079bb8 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 15:14:05 +0800 Subject: [PATCH 14/15] update readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c04fbf6968a..98c21fe1ad8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ the protocol of tron including api and message. -java-tron and wallet-cli +java-tron, wallet-cli and grpc-gateway git subtree pull --prefix src/main/protos/ protocol master From 38c1d2e8b8c26a666eb532be044e7b53bfef20c4 Mon Sep 17 00:00:00 2001 From: ashu Date: Fri, 13 Apr 2018 15:22:26 +0800 Subject: [PATCH 15/15] fix install-protobuf.sh --- install-protobuf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-protobuf.sh b/install-protobuf.sh index 6f69d20ad02..b3a8cb5cbb2 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -3,7 +3,7 @@ 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-all-3.5.1.tar.gz - tar -xzvf protobuf-java-3.5.1.tar.gz + tar -xzvf protobuf-all-3.5.1.tar.gz cd protobuf-3.5.1 && ./configure --prefix=$HOME/protobuf && make && make install else echo "Using cached directory."