Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: TRON-US/go-btfs-common
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.14
Choose a base ref
...
head repository: TRON-US/go-btfs-common
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 163,575 additions and 8,194 deletions.
  1. +3 −1 .gitignore
  2. +49 −0 Dockerfile
  3. +68 −13 Makefile
  4. +39 −1 README.md
  5. +14 −0 bin/test-git-diff-protos
  6. +14 −5 config/common.go
  7. +27 −0 config/common_test_vars.go
  8. +5 −0 controller/defaultController.go
  9. +200 −0 crypto/crypto.go
  10. +117 −0 crypto/crypto_test.go
  11. +192 −0 crypto/keys.go
  12. +19 −0 crypto/keys_test.go
  13. +129 −0 crypto/tron_address.go
  14. +33 −0 crypto/tron_address_test.go
  15. +32 −0 docker-compose.yml
  16. +15 −5 go.mod
  17. +777 −27 go.sum
  18. +12,631 −0 js/protos/escrow/escrow_pb.js
  19. +5,612 −0 js/protos/exchange/exchange_message_pb.js
  20. +16 −0 js/protos/exchange/exchange_pb.js
  21. +1,744 −0 js/protos/guard/guard_admin_pb.js
  22. +14,090 −0 js/protos/guard/guard_pb.js
  23. +5,633 −0 js/protos/hub/hub_pb.js
  24. +4,223 −0 js/protos/ledger/ledger_pb.js
  25. +8,094 −0 js/protos/node/node_pb.js
  26. +1,602 −0 js/protos/online/online_pb.js
  27. +7,120 −0 js/protos/protocol/api/api_pb.js
  28. +8,876 −0 js/protos/protocol/core/Contract_pb.js
  29. +1,494 −0 js/protos/protocol/core/Discover_pb.js
  30. +247 −0 js/protos/protocol/core/TronInventoryItems_pb.js
  31. +14,928 −0 js/protos/protocol/core/Tron_pb.js
  32. +1,071 −0 js/protos/shared/shared_pb.js
  33. +2,789 −0 js/protos/status/status_pb.js
  34. +99 −0 ledger/escrow.go
  35. +97 −69 ledger/ledger.go
  36. +82 −0 ledger/sample/demo.go
  37. +10,831 −2,856 protos/escrow/escrow.pb.go
  38. +293 −36 protos/escrow/escrow.proto
  39. +344 −0 protos/exchange/exchange.pb.go
  40. +15 −0 protos/exchange/exchange.proto
  41. +1,653 −0 protos/exchange/exchange_message.pb.go
  42. +220 −0 protos/exchange/exchange_message.proto
  43. +15,922 −2,758 protos/guard/guard.pb.go
  44. +550 −118 protos/guard/guard.proto
  45. +7,353 −0 protos/hub/hub.pb.go
  46. +257 −0 protos/hub/hub.proto
  47. +1,880 −441 protos/ledger/ledger.pb.go
  48. +27 −3 protos/ledger/ledger.proto
  49. +10,017 −619 protos/node/node.pb.go
  50. +305 −17 protos/node/node.proto
  51. +2,285 −0 protos/online/online.pb.go
  52. +81 −0 protos/online/online.proto
  53. +6,225 −0 protos/protocol/api/api.pb.go
  54. +860 −0 protos/protocol/api/api.proto
  55. +2,063 −0 protos/protocol/core/Contract.pb.go
  56. +237 −0 protos/protocol/core/Contract.proto
  57. +383 −0 protos/protocol/core/Discover.pb.go
  58. +41 −0 protos/protocol/core/Discover.proto
  59. +4,078 −0 protos/protocol/core/Tron.pb.go
  60. +526 −0 protos/protocol/core/Tron.proto
  61. +87 −0 protos/protocol/core/TronInventoryItems.pb.go
  62. +10 −0 protos/protocol/core/TronInventoryItems.proto
  63. +318 −246 protos/shared/shared.pb.go
  64. +24 −15 protos/shared/shared.proto
  65. +3,156 −880 protos/status/status.pb.go
  66. +91 −26 protos/status/status.proto
  67. +48 −6 prototool.yaml
  68. +37 −0 utils/convert.go
  69. +63 −0 utils/convert_test.go
  70. +164 −0 utils/grpc/client.go
  71. +78 −0 utils/grpc/client_test.go
  72. +19 −0 utils/grpc/escrow.go
  73. +19 −0 utils/grpc/exchange.go
  74. +52 −0 utils/grpc/graceful_termination.go
  75. +19 −0 utils/grpc/guard.go
  76. +19 −0 utils/grpc/health_check.go
  77. +39 −0 utils/grpc/health_check_test.go
  78. +34 −0 utils/grpc/hub.go
  79. +19 −0 utils/grpc/ledger.go
  80. +19 −0 utils/grpc/online.go
  81. +64 −0 utils/grpc/runtime.go
  82. +54 −0 utils/grpc/runtime_test.go
  83. +220 −0 utils/grpc/setup_server.go
  84. +86 −0 utils/grpc/setup_server_test.go
  85. +19 −0 utils/grpc/solidity.go
  86. +19 −0 utils/grpc/status.go
  87. +19 −0 utils/grpc/wallet.go
  88. +115 −30 utils/runtime.go
  89. +37 −22 utils/runtime_test.go
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -11,4 +11,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.DS_Store
.DS_Store

.idea/
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM golang:1.13-stretch

MAINTAINER TRON-US <support@tron.network>
# Dockerfile will build an image to run make build.

#ENV PATH="/go/bin:${PATH}"

ENV PROTOC_VERSION=3.10.0
ENV GOLANG_PROTOBUF_VERSION=1.3.2
ENV PROTOTOOL_VERSION=1.9.0

# Install patch
RUN apt-get update && apt-get install -y patch
RUN apt-get install -y unzip
RUN apt-get install -y postgresql-client redis-tools

# install standard c++ implementation of protocol buffers
RUN wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip
RUN unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d protoc3
RUN mv protoc3/bin/* /usr/local/bin/
RUN mv protoc3/include/* /usr/local/include

# install golang proto package
RUN GO111MODULE=on go get \
github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} && \
mv /go/bin/protoc-gen-go* /usr/local/bin/

# install prototool
RUN wget --quiet https://github.com/uber/prototool/releases/download/v${PROTOTOOL_VERSION}/prototool-Linux-x86_64.tar.gz
RUN tar -xf prototool-Linux-x86_64.tar.gz
RUN mv prototool/bin/prototool /usr/local/bin/prototool

ENV SRC_DIR /go/src/github.com/tron-us/go-btfs-common

# Download packages first so they can be cached.
COPY go.mod go.sum $SRC_DIR/
RUN cd $SRC_DIR \
&& go mod download

COPY . $SRC_DIR

#WORKDIR /go-btfs-common
WORKDIR $SRC_DIR

# need to run trongogo before make build
RUN make trongogo build

# by default check protos dir for diffs
CMD make test_git_diff_protos
81 changes: 68 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,89 @@
UNAME := $(shell uname)
default: lintf

TEST_DB_NAME ?= runtime
TEST_DB_STATUS ?= db_status
TEST_DB_GUARD ?= db_guard
TEST_DB_USER ?= `whoami`
TEST_DB_HOSTNAME ?= localhost
TEST_DB_URL="postgresql://$(TEST_DB_USER)@$(TEST_DB_HOSTNAME):5432/$(TEST_DB_NAME)"
TEST_RD_NAME ?= runtime
TEST_DB_PORT ?= 5432
TEST_DB_URL="postgresql://$(TEST_DB_USER)@$(TEST_DB_HOSTNAME):$(TEST_DB_PORT)/$(TEST_DB_NAME)"
TEST_DB_URL_STATUS="postgresql://$(TEST_DB_USER)@$(TEST_DB_HOSTNAME):$(TEST_DB_PORT)/$(TEST_DB_STATUS)"
TEST_DB_URL_GUARD="postgresql://$(TEST_DB_USER)@$(TEST_DB_HOSTNAME):$(TEST_DB_PORT)/$(TEST_DB_GUARD)"
TEST_RD_NAME ?= 4
TEST_RD_USER ?= `whoami`
TEST_RD_HOSTNAME ?= localhost
TEST_RD_URL="redis://$(TEST_RD_USER)@$(TEST_RD_HOSTNAME):6379/$(TEST_RD_NAME)"
TEST_RD_PORT ?= 6379
TEST_RD_URL="redis://$(TEST_RD_USER):@$(TEST_RD_HOSTNAME):$(TEST_RD_PORT)/$(TEST_RD_NAME)"
DOCKER_TEST_RD_URL="redis://$(TEST_RD_HOSTNAME):$(TEST_RD_PORT)"

install:
brew install protobuf
brew install prototool
brew install postgresql go
brew install redis go
brew services start postgresql
brew services start redis
PG_FIX_CANDIDATES=./protos/node/node.pb.go \
./protos/status/status.pb.go \
./protos/escrow/escrow.pb.go \
./protos/guard/guard.pb.go \
./protos/online/online.pb.go \

install: brew trongogo

brew:
brew install go protobuf prototool postgresql redis

trongogo:
cd ../ && git clone https://github.com/googleapis/googleapis.git && cd go-btfs-common || true
cd ../ && git clone https://github.com/TRON-US/protobuf || true
cd ../protobuf && git checkout master && git pull && make
cd ../googleapis && git checkout master && git pull

lintf:
prototool lint ./protos
prototool format -w
go fmt ./...
go mod tidy

build:
genproto:
prototool all
go mod tidy

buildgo:
go build ./...

pgfix:
ifeq ($(UNAME), Linux)
for pb in $(PG_FIX_CANDIDATES); \
do \
sed -in 's/TableName/tableName/g' $$pb; \
sed -in 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \
done
endif
ifeq ($(UNAME), Darwin)
for pb in $(PG_FIX_CANDIDATES); \
do \
sed -i '' -e 's/TableName/tableName/g' $$pb; \
sed -i '' -e 's/protobuf:"bytes,[0-9]*,opt,name=table_name,json=tableName,proto[0-9]*" json:"table_name,omitempty" pg:"table_name" //g' $$pb; \
done
endif

build: lintf genproto buildgo pgfix

test:
brew services start postgresql
brew services start redis
dropdb --if-exists $(TEST_DB_NAME)
dropdb --if-exists $(TEST_DB_GUARD)
dropdb --if-exists $(TEST_DB_STATUS)
createdb $(TEST_DB_NAME)
go test -v ./... -args -db_url=$(TEST_DB_URL) -rd_url=$(TEST_RD_URL)
createdb $(TEST_DB_GUARD)
createdb $(TEST_DB_STATUS)
TEST_DB_URL=$(TEST_DB_URL) TEST_DB_URL_STATUS=$(TEST_DB_URL_STATUS) TEST_DB_URL_GUARD=$(TEST_DB_URL_GUARD) TEST_RD_URL=$(TEST_RD_URL) go test -v ./...
dropdb $(TEST_DB_NAME)
dropdb $(TEST_DB_STATUS)
dropdb $(TEST_DB_GUARD)
brew services stop postgresql
brew services stop redis

test_docker:
sleep 10
TEST_DB_URL=$(TEST_DB_URL) TEST_DB_URL_STATUS=$(TEST_DB_URL_STATUS) TEST_DB_URL_GUARD=$(TEST_DB_URL_GUARD) TEST_RD_URL=$(TEST_RD_URL) go test -v ./...

test_git_diff_protos:
bin/test-git-diff-protos
.PHONY: test_git_dif_protos
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@ Common packages among various go-btfs projects.
├── LICENSE
├── Makefile
├── README.md
├── config
│   └── common.go
├── crypto
│   └── crypto.go
├── go.mod
├── go.sum
├── info
@@ -38,11 +42,30 @@ Common packages among various go-btfs projects.
│   └── status
│   ├── status.pb.go
│   └── status.proto
└── prototool.yaml
├── prototool.yaml
├── tree.txt
└── utils
├── grpc_health_check_provider.go
├── runtime.go
└── runtime_test.go
```

## Install Tools

#### install TRON version(pg support) protobuf

```
cd github.com/tron-us
```
```
git clone https://github.com/TRON-US/protobuf
```
```
cd protobuf && make
```

#### other tools

```
make install
```
@@ -62,3 +85,18 @@ make lintf
```
make build
```

## Use docker container to run 'git diff protos/'

```
$ docker build -f Dockerfile -t "go-btfs-common" .
$ docker run -i go-btfs-common
```

## Run interactive bash inside docker container for diagnosis

```
$ docker build -f Dockerfile -t "go-btfs-common" .
$ docker run -it go-btfs-common /bin/bash
```

14 changes: 14 additions & 0 deletions bin/test-git-diff-protos
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
git --no-pager diff protos/ >> diffs.txt
if [ -n "$(cat diffs.txt)" ]; then
echo "The following protos have changed."
echo "-----------------------------------"
cat diffs.txt
echo "-----------------------------------"
echo "Please regenerate code so protos are consistent with Master."
rm -f diffs.txt
exit 1
fi
rm -f diffs.txt

19 changes: 14 additions & 5 deletions config/common.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@ import (

var (
ConstMinQuestionsCountPerChallenge = 100
ConstMinQuestionsCountPerShard = 100

ConstRequestPayoutBatchPageSize = 100
)

func init() {
@@ -25,10 +28,16 @@ func init() {
}

func GetMinimumQuestionsCountPerShard(status *guard.FileStoreStatus) (val int) {
if status == nil || status.FileStoreMeta.CheckFrequency == 0 {
//if it is 0 or status is nil, means using default frequency, 12 per year
return ConstMinQuestionsCountPerChallenge * 12
}
//Below comment codes were reserved here
//if status == nil || status.FileStoreMeta.CheckFrequency == 0 {
// //if it is 0 or status is nil, means using default frequency
// return ConstMinQuestionsCountPerChallenge * 52
//}
//
//return int(status.FileStoreMeta.CheckFrequency) * ConstMinQuestionsCountPerChallenge
return ConstMinQuestionsCountPerShard
}

return int(status.FileStoreMeta.CheckFrequency) * ConstMinQuestionsCountPerChallenge
func GetRenewContingencyPercentage() (percent int) {
return 10
}
27 changes: 27 additions & 0 deletions config/common_test_vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package config

import (
"errors"
"fmt"
"os"
)

var (
DbStatusURL string
DbGuardURL string
RdURL string
FoundPgStatusString bool
FoundPgGuardString bool
FoundDbRdString bool
)

func InitTestDB() error {
//get db and redis connection strings
DbStatusURL, FoundPgStatusString = os.LookupEnv("TEST_DB_URL_STATUS")
DbGuardURL, FoundPgGuardString = os.LookupEnv("TEST_DB_URL_STATUS")
RdURL, FoundDbRdString = os.LookupEnv("TEST_RD_URL")
if FoundPgStatusString == false || FoundPgGuardString == false || FoundDbRdString == false {
return errors.New(fmt.Sprintf("TEST_DB_URL_STATUS or TEST_DB_URL_STATUS or TEST_RD_URL env vars need to be set before running test"))
}
return nil
}
5 changes: 5 additions & 0 deletions controller/defaultController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package controller

type DefaultController struct {
ServerName string
}
Loading