Skip to content

Commit

Permalink
supplyscraper: deployment and config parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kaythxbye committed Oct 8, 2020
1 parent ee4e30f commit 3d7d5c1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
15 changes: 15 additions & 0 deletions build/Dockerfile-supplyService
@@ -0,0 +1,15 @@
FROM golang:1.14 as build

WORKDIR $GOPATH/src/

COPY . .

WORKDIR $GOPATH/src/github.com/diadata-org/diadata/cmd/services/supplyService
RUN go install

FROM gcr.io/distroless/base

COPY --from=build /go/bin/supplyService /bin/supplyService
COPY --from=build /go/src/github.com/diadata-org/diadata/config /config/

CMD ["supplyService"]
4 changes: 2 additions & 2 deletions cmd/services/supplyService/main.go
Expand Up @@ -16,7 +16,7 @@ func main() {
if err != nil {
log.Fatal("datastore error: ", err)
}
conn, err := ethclient.Dial("https://mainnet.infura.io/v3/251a25bd10b8460fa040bb7202e22571")
conn, err := ethclient.Dial("http://159.69.120.42:8545/")
if err != nil {
log.Fatal(err)
}
Expand All @@ -29,7 +29,7 @@ func main() {
for {
timeInit := time.Now()
for _, address := range adds {
supp, err := supplyservice.GetTotalSupplyfromMainNet(address, ds, conn)
supp, err := supplyservice.GetTotalSupplyfromMainNet(address, conn)
if err != nil || len(supp.Symbol) < 2 || supp.Supply < 2 {
continue
}
Expand Down
14 changes: 14 additions & 0 deletions deployments/docker-compose.services.yml
Expand Up @@ -90,6 +90,20 @@ services:
options:
max-size: "50m"

supplyservice:
build:
context: ../../../..
dockerfile: github.com/diadata-org/diadata/build/Dockerfile-supplyService
image: ${DOCKER_HUB_LOGIN}/${STACKNAME}_supplyservice:latest
networks:
- redis-network
- influxdb-network
environment:
- EXEC_MODE=production
logging:
options:
max-size: "50m"

networks:
kafka-network:
external:
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/supplyService/supply.go
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/diadata-org/diadata/pkg/dia"
models "github.com/diadata-org/diadata/pkg/model"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -67,7 +66,7 @@ func GetWalletBalance(walletAddr string, tokenAddr string, c *ethclient.Client)
}

// GetTotalSupplyfromMainNet return total supply minus wallets' balances from config file
func GetTotalSupplyfromMainNet(tokenAddress string, datastore models.Datastore, client *ethclient.Client) (supply dia.Supply, err error) {
func GetTotalSupplyfromMainNet(tokenAddress string, client *ethclient.Client) (supply dia.Supply, err error) {

instance, err := NewERC20(common.HexToAddress(tokenAddress), client)
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion pkg/dia/helpers/ethhelper/tokenInfo.go
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"math/big"
"os"
"os/user"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -77,10 +78,24 @@ func GetDecimals(address common.Address) (int, error) {

}

func ConfigFilePath(filename string) string {
usr, _ := user.Current()
dir := usr.HomeDir
if dir == "/root" || dir == "/home" {
return "/config/token_supply/" + filename + ".json" //hack for docker...
}
if dir == "/home/travis" {
return "../config/token_supply/" + filename + ".json" //hack for travis
}
return os.Getenv("GOPATH") + "/src/github.com/diadata-org/diadata/config/token_supply/" + filename + ".json"
}


// GetAddressesFromFile fetches token addresses from a config file available here:
// https://etherscan.io/exportData?type=open-source-contract-codes
func GetAddressesFromFile() (addresses []string, err error) {
jsonFile, err := os.Open("../../../config/token_supply/tokens_list.json")
configPath := ConfigFilePath("tokens_list")
jsonFile, err := os.Open(configPath)
if err != nil {
log.Errorln("Error opening file", err)
return
Expand Down

0 comments on commit 3d7d5c1

Please sign in to comment.