Skip to content

Commit

Permalink
Add command for adding asset template (trustwallet#17338)
Browse files Browse the repository at this point in the history
* Add command for adding asset template

* Fix explorer links for terra
  • Loading branch information
unanoc authored Jan 14, 2022
1 parent 0cfb242 commit 2794a27
Show file tree
Hide file tree
Showing 18 changed files with 970 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v2

- name: Run check
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=checker
run: make check

- name: Unit Test
run: make test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fix-dryrun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v2

- name: Run fix
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=fixer
run: make fix

- name: Show fix result (diff)
run: |
Expand All @@ -26,4 +26,4 @@ jobs:
git diff
- name: Run check
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=checker
run: make check
6 changes: 3 additions & 3 deletions .github/workflows/fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ jobs:
go-version: 1.17
id: go

- name: Run fix script (trustwallet repo, sanity and consistency)
- name: Run fix
if: github.repository_owner == 'trustwallet'
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=fixer
run: make fix

- name: Show fix result (diff)
run: |
git status
git diff
- name: Run check
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=checker
run: make check

- name: Commit changes
if: success()
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/periodic-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
id: go

- name: Run update auto
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=updater-auto
run: make update-auto

- name: Show update result (diff)
if: success()
Expand All @@ -29,7 +29,7 @@ jobs:
git diff
- name: Run check
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=checker
run: make check

- name: Commit changes
if: success()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v2

- name: Run check
run: go run ./cmd/main.go --config=./.github/assets.config.yaml --script=checker
run: make check

- name: Unit Test
run: make test
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#! /usr/bin/make -f


# Go related variables.
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/bin


# Go files.
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)


# Common commands.
all: fmt lint test

test:
Expand All @@ -27,14 +31,21 @@ lint: lint-install
@echo " > Running golint"
bin/golangci-lint run --timeout=2m


# Assets commands.
check:
go run ./cmd/main.go --script=checker
go run cmd/main.go check

fix:
go run ./cmd/main.go --script=fixer
go run cmd/main.go fix

update-auto:
go run ./cmd/main.go --script=updater-auto
go run cmd/main.go update-auto

update-manual:
go run ./cmd/main.go --script=updater-manual
go run cmd/main.go update-manual


# Helper commands.
add-token:
go run cmd/main.go add-token $(token)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ There are several scripts available for maintainers:
- `make fix` -- Perform automatic fixes where possible
- `make update-auto` -- Run automatic updates from external sources, executed regularly (GitHub action)
- `make update-manual` -- Run manual updates from external sources, for manual use.
- `make add-token token=c60_t0x4Fabb145d64652a948d72533023f6E7A623C7C53` -- Create `info.json` file as asset template.

## On Checks

Expand Down
2 changes: 1 addition & 1 deletion blockchains/terra/assets/ukrw/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TerraKRW",
"website": "https://terra.money",
"description": "TerraKRW is the first decentralized stablecoin that is scalable, yield bearing and interchain.",
"explorer": "https://finder.terra.money/columbus-4/ukrw",
"explorer": "https://finder.terra.money/mainnet/address/ukrw",
"type": "TERRA",
"symbol": "KRT",
"decimals": 6,
Expand Down
2 changes: 1 addition & 1 deletion blockchains/terra/assets/umnt/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TerraUMNT",
"website": "https://terra.money",
"description": "TerraUMNT is the first decentralized stablecoin that is scalable, yield bearing and interchain.",
"explorer": "https://finder.terra.money/columbus-4/umnt",
"explorer": "https://finder.terra.money/mainnet/address/umnt",
"type": "TERRA",
"symbol": "UMNT",
"decimals": 6,
Expand Down
2 changes: 1 addition & 1 deletion blockchains/terra/assets/usdr/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TerraSDT",
"website": "https://terra.money",
"description": "TerraSDT is the first decentralized stablecoin that is scalable, yield bearing and interchain.",
"explorer": "https://finder.terra.money/columbus-4/usdr",
"explorer": "https://finder.terra.money/mainnet/address/usdr",
"type": "TERRA",
"symbol": "SDT",
"decimals": 6,
Expand Down
2 changes: 1 addition & 1 deletion blockchains/terra/assets/uusd/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TerraUSD",
"website": "https://terra.money",
"description": "TerraUSD is the first decentralized stablecoin that is scalable, yield bearing and interchain.",
"explorer": "https://finder.terra.money/columbus-4/uusd",
"explorer": "https://finder.terra.money/mainnet/address/uusd",
"type": "TERRA",
"symbol": "UST",
"decimals": 6,
Expand Down
67 changes: 3 additions & 64 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,10 @@
package main

import (
"flag"

log "github.com/sirupsen/logrus"

"github.com/trustwallet/assets/internal/config"
"github.com/trustwallet/assets/internal/file"
"github.com/trustwallet/assets/internal/processor"
"github.com/trustwallet/assets/internal/report"
"github.com/trustwallet/assets/internal/service"
)

var (
configPath, root, script string
"github.com/trustwallet/assets/internal/manager"
)

func main() {
setup()

paths, err := file.ReadLocalFileStructure(root, config.Default.ValidatorsSettings.RootFolder.SkipFiles)
if err != nil {
log.WithError(err).Fatal("Failed to load file structure.")
}

fileService := file.NewService(paths...)
validatorsService := processor.NewService(fileService)
reportService := report.NewService()
assetfsProcessor := service.NewService(fileService, validatorsService, reportService)

switch script {
case "checker":
assetfsProcessor.RunJob(paths, assetfsProcessor.Check)
case "fixer":
assetfsProcessor.RunJob(paths, assetfsProcessor.Fix)
case "updater-auto":
assetfsProcessor.RunUpdateAuto()
case "updater-manual":
assetfsProcessor.RunUpdateManual()
default:
log.Info("Nothing to launch. Use --script flag to choose a script to run.")
}

reportMsg := reportService.GetReport()

if reportService.IsFailed() {
log.Fatal(reportMsg)
} else {
log.Info(reportMsg)
}
}

func setup() {
flag.StringVar(&configPath, "config", "./.github/assets.config.yaml", "path to config file")
flag.StringVar(&root, "root", "./", "path to the root of the dir")
flag.StringVar(&script, "script", "", "script type to run")

flag.Parse()

if err := config.SetConfig(configPath); err != nil {
log.WithError(err).Fatal("Failed to set config.")
}

logLevel, err := log.ParseLevel(config.Default.App.LogLevel)
if err != nil {
log.WithError(err).Fatal("Failed to parse log level.")
}

log.SetLevel(logLevel)
manager.InitCommands()
manager.Execute()
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ go 1.17

require (
github.com/sirupsen/logrus v1.8.1
github.com/trustwallet/assets-go-libs v0.0.24
github.com/trustwallet/go-libs v0.2.21
github.com/trustwallet/go-primitives v0.0.19
github.com/spf13/cobra v1.3.0
github.com/trustwallet/assets-go-libs v0.0.25
github.com/trustwallet/go-libs v0.2.23
github.com/trustwallet/go-primitives v0.0.20
)

require (
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
Expand Down
Loading

0 comments on commit 2794a27

Please sign in to comment.