diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c903fdc5..5cf9023a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: with: # list of Docker images to use as base name for tags images: | - ghcr.io/eqlabs/flow-wallet-api + ghcr.io/flow-hydraulics/flow-wallet-api # generate Docker tags based on the following events/attributes tags: | type=ref,event=branch diff --git a/Makefile b/Makefile index 027083e3..6928004d 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,23 @@ - -current_dir = $(shell pwd) - -cli_version = 0.25.1 -cli_image=flow-cli - -.PHONY: run -up: - FLOW_CLI_VERSION=${cli_version} docker-compose up -d +.PHONY: dev +dev: + docker-compose up -d db emulator + docker-compose logs -f .PHONY: stop stop: - FLOW_CLI_VERSION=${cli_version} docker-compose stop + docker-compose stop .PHONY: down down: - FLOW_CLI_VERSION=${cli_version} docker-compose down + docker-compose down + +.PHONY: reset +reset: down dev .PHONY: test test: go test ./... -.PHONY: build-cli -build-cli: - docker build \ - --network host \ - --build-arg VERSION=${cli_version} \ - -t ${cli_image}:${cli_version} \ - ./docker/flow-cli - .PHONY: deploy deploy: - docker run --rm -it -v "${current_dir}:/app" --net host ${cli_image}:${cli_version} project deploy --update - -.PHONY: shell -shell: - docker exec -it flow-emulator ash - -.PHONY: reset -reset: - FLOW_CLI_VERSION=${cli_version} docker-compose down - FLOW_CLI_VERSION=${cli_version} docker-compose up -d + flow project deploy --update diff --git a/accounts/accounts.go b/accounts/accounts.go index d44103ab..ee1cc082 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -6,11 +6,11 @@ import ( "fmt" "time" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/templates/template_strings" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/templates/template_strings" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/onflow/cadence" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" diff --git a/accounts/service.go b/accounts/service.go index cb5af344..6df4f0fb 100644 --- a/accounts/service.go +++ b/accounts/service.go @@ -6,14 +6,14 @@ import ( "net/http" "strings" - "github.com/eqlabs/flow-wallet-api/datastore" - "github.com/eqlabs/flow-wallet-api/errors" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/jobs" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/templates/template_strings" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/templates/template_strings" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/onflow/cadence" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" diff --git a/accounts/store.go b/accounts/store.go index 9272de98..37393c57 100644 --- a/accounts/store.go +++ b/accounts/store.go @@ -1,7 +1,7 @@ package accounts import ( - "github.com/eqlabs/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/datastore" ) // Store manages data regarding accounts. diff --git a/accounts/store_gorm.go b/accounts/store_gorm.go index b0bbaf2e..f5ad59d9 100644 --- a/accounts/store_gorm.go +++ b/accounts/store_gorm.go @@ -1,7 +1,7 @@ package accounts import ( - "github.com/eqlabs/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/datastore" "gorm.io/gorm" ) diff --git a/api/openapi.yaml b/api/openapi.yaml index 7082a948..0ea266a9 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -519,7 +519,7 @@ components: Content-Type: application/json Connection: close - ver: https://github.com/eqlabs/flow-wallet-api/commit/ + ver: https://github.com/flow-hydraulics/flow-wallet-api/commit/ built on: api version called: v1 diff --git a/docker-compose.yml b/docker-compose.yml index 53f1032b..25506e18 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,8 @@ version: "3.9" services: db: image: postgres:13-alpine + ports: + - "5432:5432" environment: - POSTGRES_DB=wallet - POSTGRES_USER=wallet @@ -11,11 +13,12 @@ services: build: context: . dockerfile: ./docker/wallet/Dockerfile + network: host # docker build sometimes has problems fetching from alpine's CDN ports: - "3000:3000" env_file: - ./.env - restart: unless-stopped + restart: unless-stopped environment: DATABASE_DSN: postgresql://wallet:wallet@db:5432/wallet DATABASE_TYPE: psql diff --git a/docker/flow-cli/Dockerfile b/docker/flow-cli/Dockerfile deleted file mode 100644 index 8cf223f0..00000000 --- a/docker/flow-cli/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM alpine:latest -ARG VERSION=0.22.0 -ARG UNAME=appuser -ARG GNAME=appgroup -ARG UID=1000 -ARG GID=1000 -RUN apk add --no-cache curl -RUN curl -fsSL https://storage.googleapis.com/flow-cli/install.sh | sh -s -- v$VERSION -RUN mv /root/.local/bin/flow /usr/local/bin/flow -RUN addgroup -g $GID -S $GNAME && adduser --uid $UID -S $UNAME -G $GNAME -RUN mkdir /app && chown appuser /app && chgrp $GNAME /app -WORKDIR /app -VOLUME [ "/app" ] -USER appuser -ENTRYPOINT [ "/usr/local/bin/flow" ] diff --git a/flow_helpers/flow_helpers.go b/flow_helpers/flow_helpers.go index e25d7f1a..de502f65 100644 --- a/flow_helpers/flow_helpers.go +++ b/flow_helpers/flow_helpers.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/eqlabs/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/errors" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" ) diff --git a/go.mod b/go.mod index 2a64e6bb..3805d3e0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/eqlabs/flow-wallet-api +module github.com/flow-hydraulics/flow-wallet-api go 1.16 diff --git a/handlers/accounts.go b/handlers/accounts.go index 1d65ae3b..2caf1202 100644 --- a/handlers/accounts.go +++ b/handlers/accounts.go @@ -4,7 +4,7 @@ import ( "log" "net/http" - "github.com/eqlabs/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/accounts" ) // Accounts is a HTTP server for account management. diff --git a/handlers/handlers.go b/handlers/handlers.go index 1794c2ac..64c98f47 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - "github.com/eqlabs/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/errors" ) const SyncHeader = "Use-Sync" diff --git a/handlers/jobs.go b/handlers/jobs.go index 32d91bcb..aecd0400 100644 --- a/handlers/jobs.go +++ b/handlers/jobs.go @@ -4,7 +4,7 @@ import ( "log" "net/http" - "github.com/eqlabs/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/jobs" ) // Jobs is a HTTP server for jobs. diff --git a/handlers/templates.go b/handlers/templates.go index 867173db..29583522 100644 --- a/handlers/templates.go +++ b/handlers/templates.go @@ -4,7 +4,7 @@ import ( "log" "net/http" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/templates" ) // Templates is a HTTP server for template management. @@ -22,7 +22,7 @@ func (s *Templates) AddToken() http.Handler { return UseJson(h) } -func (s *Templates) ListTokens(tType *templates.TokenType) http.Handler { +func (s *Templates) ListTokens(tType templates.TokenType) http.Handler { return s.MakeListTokensFunc(tType) } diff --git a/handlers/templates_func.go b/handlers/templates_func.go index 69a7fe65..5c862cf7 100644 --- a/handlers/templates_func.go +++ b/handlers/templates_func.go @@ -5,7 +5,7 @@ import ( "net/http" "strconv" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/templates" "github.com/gorilla/mux" ) @@ -36,7 +36,7 @@ func (s *Templates) AddTokenFunc(rw http.ResponseWriter, r *http.Request) { handleJsonResponse(rw, http.StatusCreated, newToken) } -func (s *Templates) MakeListTokensFunc(tType *templates.TokenType) http.HandlerFunc { +func (s *Templates) MakeListTokensFunc(tType templates.TokenType) http.HandlerFunc { return func(rw http.ResponseWriter, r *http.Request) { tokens, err := s.service.ListTokens(tType) if err != nil { diff --git a/handlers/tokens.go b/handlers/tokens.go index 4e248059..9727c65f 100644 --- a/handlers/tokens.go +++ b/handlers/tokens.go @@ -4,8 +4,8 @@ import ( "log" "net/http" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/tokens" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/tokens" ) type Tokens struct { diff --git a/handlers/tokens_func.go b/handlers/tokens_func.go index 9f675182..3e6fffdd 100644 --- a/handlers/tokens_func.go +++ b/handlers/tokens_func.go @@ -5,9 +5,9 @@ import ( "fmt" "net/http" - "github.com/eqlabs/flow-wallet-api/errors" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/tokens" + "github.com/flow-hydraulics/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/tokens" "github.com/gorilla/mux" ) @@ -39,7 +39,7 @@ func (s *Tokens) MakeAccountTokensFunc(tType templates.TokenType) http.HandlerFu vars := mux.Vars(r) a := vars["address"] - res, err := s.service.AccountTokens(a, &tType) + res, err := s.service.AccountTokens(a, tType) if err != nil { handleError(rw, s.log, err) return diff --git a/handlers/transactions.go b/handlers/transactions.go index 290f8848..8287a50b 100644 --- a/handlers/transactions.go +++ b/handlers/transactions.go @@ -4,7 +4,7 @@ import ( "log" "net/http" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/transactions" ) type Transactions struct { diff --git a/handlers/transactions_func.go b/handlers/transactions_func.go index 96c2713b..602c9526 100644 --- a/handlers/transactions_func.go +++ b/handlers/transactions_func.go @@ -6,9 +6,9 @@ import ( "net/http" "strconv" - "github.com/eqlabs/flow-wallet-api/errors" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/gorilla/mux" ) diff --git a/jobs/jobs.go b/jobs/jobs.go index cb89cf97..253bf2ac 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/eqlabs/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/errors" "github.com/google/uuid" "gorm.io/gorm" ) diff --git a/jobs/service.go b/jobs/service.go index fd643b59..5e29ee44 100644 --- a/jobs/service.go +++ b/jobs/service.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/eqlabs/flow-wallet-api/datastore" - "github.com/eqlabs/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/errors" "github.com/google/uuid" ) diff --git a/jobs/store.go b/jobs/store.go index d888da66..fdd1a512 100644 --- a/jobs/store.go +++ b/jobs/store.go @@ -1,7 +1,7 @@ package jobs import ( - "github.com/eqlabs/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/datastore" "github.com/google/uuid" ) diff --git a/jobs/store_gorm.go b/jobs/store_gorm.go index 20db1974..7cc9b49e 100644 --- a/jobs/store_gorm.go +++ b/jobs/store_gorm.go @@ -1,7 +1,7 @@ package jobs import ( - "github.com/eqlabs/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/datastore" "github.com/google/uuid" "gorm.io/gorm" ) diff --git a/keys/basic/keys.go b/keys/basic/keys.go index d2fd5a3c..48e07fc4 100644 --- a/keys/basic/keys.go +++ b/keys/basic/keys.go @@ -5,11 +5,11 @@ import ( "context" "fmt" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/keys/encryption" - "github.com/eqlabs/flow-wallet-api/keys/google" - "github.com/eqlabs/flow-wallet-api/keys/local" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/keys/encryption" + "github.com/flow-hydraulics/flow-wallet-api/keys/google" + "github.com/flow-hydraulics/flow-wallet-api/keys/local" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" "github.com/onflow/flow-go-sdk/crypto" diff --git a/keys/google/google.go b/keys/google/google.go index a2a8adb7..023e979a 100644 --- a/keys/google/google.go +++ b/keys/google/google.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/caarlos0/env/v6" - "github.com/eqlabs/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/keys" "github.com/google/uuid" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/crypto" diff --git a/keys/local/local.go b/keys/local/local.go index e606c1c9..e9c8e07f 100644 --- a/keys/local/local.go +++ b/keys/local/local.go @@ -5,7 +5,7 @@ import ( "crypto/rand" "strings" - "github.com/eqlabs/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/keys" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/crypto" ) diff --git a/main.go b/main.go index 529e9455..cdb8ad8b 100644 --- a/main.go +++ b/main.go @@ -11,17 +11,17 @@ import ( "time" "github.com/caarlos0/env/v6" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/chain_events" - "github.com/eqlabs/flow-wallet-api/datastore/gorm" - "github.com/eqlabs/flow-wallet-api/debug" - "github.com/eqlabs/flow-wallet-api/handlers" - "github.com/eqlabs/flow-wallet-api/jobs" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/keys/basic" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/tokens" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/chain_events" + "github.com/flow-hydraulics/flow-wallet-api/datastore/gorm" + "github.com/flow-hydraulics/flow-wallet-api/debug" + "github.com/flow-hydraulics/flow-wallet-api/handlers" + "github.com/flow-hydraulics/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/keys/basic" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/tokens" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/gorilla/mux" "github.com/joho/godotenv" "github.com/onflow/flow-go-sdk" @@ -89,6 +89,8 @@ func runServer(disableRawTx, disableFt, disableNft, disableChainEvents bool) { ls := log.New(os.Stdout, "[SERVER] ", log.LstdFlags|log.Lshortfile) lj := log.New(os.Stdout, "[JOBS] ", log.LstdFlags|log.Lshortfile) + ls.Printf("Starting server (v%s)...\n", version) + // Flow client // TODO: WithInsecure()? fc, err := client.New(cfg.AccessAPIHost, grpc.WithInsecure()) @@ -137,7 +139,7 @@ func runServer(disableRawTx, disableFt, disableNft, disableChainEvents bool) { tokenService := tokens.NewService(tokenStore, km, fc, transactionService, templateService, accountService) debugService := debug.Service{ - RepoUrl: "https://github.com/eqlabs/flow-wallet-api", + RepoUrl: "https://github.com/flow-hydraulics/flow-wallet-api", Sha1ver: sha1ver, BuildTime: buildTime, } @@ -174,23 +176,25 @@ func runServer(disableRawTx, disableFt, disableNft, disableChainEvents bool) { rv.Handle("/jobs/{jobId}", jobsHandler.Details()).Methods(http.MethodGet) // details // Token templates - rv.Handle("/tokens", templateHandler.AddToken()).Methods(http.MethodPost) // create - rv.Handle("/tokens", templateHandler.ListTokens(nil)).Methods(http.MethodGet) // list - rv.Handle("/tokens/{id_or_name}", templateHandler.GetToken()).Methods(http.MethodGet) // details - rv.Handle("/tokens/{id}", templateHandler.RemoveToken()).Methods(http.MethodDelete) // delete + rv.Handle("/tokens", templateHandler.ListTokens(templates.NotSpecified)).Methods(http.MethodGet) // list + rv.Handle("/tokens", templateHandler.AddToken()).Methods(http.MethodPost) // create + rv.Handle("/tokens/{id_or_name}", templateHandler.GetToken()).Methods(http.MethodGet) // details + rv.Handle("/tokens/{id}", templateHandler.RemoveToken()).Methods(http.MethodDelete) // delete + + // List enabled tokens by type + rv.Handle("/fungible-tokens", templateHandler.ListTokens(templates.FT)).Methods(http.MethodGet) // list + rv.Handle("/non-fungible-tokens", templateHandler.ListTokens(templates.NFT)).Methods(http.MethodGet) // list // Account - ra := rv.PathPrefix("/accounts").Subrouter() - ra.Handle("", accountHandler.List()).Methods(http.MethodGet) // list - ra.Handle("", accountHandler.Create()).Methods(http.MethodPost) // create - ra.Handle("/{address}", accountHandler.Details()).Methods(http.MethodGet) // details + rv.Handle("/accounts", accountHandler.List()).Methods(http.MethodGet) // list + rv.Handle("/accounts", accountHandler.Create()).Methods(http.MethodPost) // create + rv.Handle("/accounts/{address}", accountHandler.Details()).Methods(http.MethodGet) // details // Account raw transactions if !disableRawTx { - rt := rv.PathPrefix("/accounts/{address}/transactions").Subrouter() - rt.Handle("", transactionHandler.List()).Methods(http.MethodGet) // list - rt.Handle("", transactionHandler.Create()).Methods(http.MethodPost) // create - rt.Handle("/{transactionId}", transactionHandler.Details()).Methods(http.MethodGet) // details + rv.Handle("/accounts/{address}/transactions", transactionHandler.List()).Methods(http.MethodGet) // list + rv.Handle("/accounts/{address}/transactions", transactionHandler.Create()).Methods(http.MethodPost) // create + rv.Handle("/accounts/{address}/transactions/{transactionId}", transactionHandler.Details()).Methods(http.MethodGet) // details } else { ls.Println("raw transactions disabled") } @@ -200,41 +204,28 @@ func runServer(disableRawTx, disableFt, disableNft, disableChainEvents bool) { // Fungible tokens if !disableFt { - tokenType := templates.FT - - // List enabled tokens - rv.Handle("/fungible-tokens", templateHandler.ListTokens(&tokenType)).Methods(http.MethodGet) - - // Handle "/accounts/{address}/fungible-tokens" - rft := ra.PathPrefix("/{address}/fungible-tokens").Subrouter() - rft.Handle("", tokenHandler.AccountTokens(tokenType)).Methods(http.MethodGet) - rft.Handle("/{tokenName}", tokenHandler.Details()).Methods(http.MethodGet) - rft.Handle("/{tokenName}", tokenHandler.Setup()).Methods(http.MethodPost) - rft.Handle("/{tokenName}/withdrawals", tokenHandler.ListWithdrawals()).Methods(http.MethodGet) - rft.Handle("/{tokenName}/withdrawals", tokenHandler.CreateWithdrawal()).Methods(http.MethodPost) - rft.Handle("/{tokenName}/withdrawals/{transactionId}", tokenHandler.GetWithdrawal()).Methods(http.MethodGet) - rft.Handle("/{tokenName}/deposits", tokenHandler.ListDeposits()).Methods(http.MethodGet) - rft.Handle("/{tokenName}/deposits/{transactionId}", tokenHandler.GetDeposit()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens", tokenHandler.AccountTokens(templates.FT)).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}", tokenHandler.Details()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}", tokenHandler.Setup()).Methods(http.MethodPost) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}/withdrawals", tokenHandler.ListWithdrawals()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}/withdrawals", tokenHandler.CreateWithdrawal()).Methods(http.MethodPost) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}/withdrawals/{transactionId}", tokenHandler.GetWithdrawal()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}/deposits", tokenHandler.ListDeposits()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/fungible-tokens/{tokenName}/deposits/{transactionId}", tokenHandler.GetDeposit()).Methods(http.MethodGet) } else { ls.Println("fungible tokens disabled") } // Non-Fungible tokens if !disableNft { - tokenType := templates.NFT - - // List enabled tokens - rv.Handle("/non-fungible-tokens", templateHandler.ListTokens(&tokenType)).Methods(http.MethodGet) - - rnft := ra.PathPrefix("/{address}/non-fungible-tokens").Subrouter() - rnft.Handle("", tokenHandler.AccountTokens(tokenType)).Methods(http.MethodGet) - rnft.Handle("/{tokenName}", tokenHandler.Details()).Methods(http.MethodGet) - rnft.Handle("/{tokenName}", tokenHandler.Setup()).Methods(http.MethodPost) - rnft.Handle("/{tokenName}/withdrawals", tokenHandler.ListWithdrawals()).Methods(http.MethodGet) - rnft.Handle("/{tokenName}/withdrawals", tokenHandler.CreateWithdrawal()).Methods(http.MethodPost) - rnft.Handle("/{tokenName}/withdrawals/{transactionId}", tokenHandler.GetWithdrawal()).Methods(http.MethodGet) - rnft.Handle("/{tokenName}/deposits", tokenHandler.ListDeposits()).Methods(http.MethodGet) - rnft.Handle("/{tokenName}/deposits/{transactionId}", tokenHandler.GetDeposit()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens", tokenHandler.AccountTokens(templates.NFT)).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}", tokenHandler.Details()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}", tokenHandler.Setup()).Methods(http.MethodPost) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}/withdrawals", tokenHandler.ListWithdrawals()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}/withdrawals", tokenHandler.CreateWithdrawal()).Methods(http.MethodPost) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}/withdrawals/{transactionId}", tokenHandler.GetWithdrawal()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}/deposits", tokenHandler.ListDeposits()).Methods(http.MethodGet) + rv.Handle("/accounts/{address}/non-fungible-tokens/{tokenName}/deposits/{transactionId}", tokenHandler.GetDeposit()).Methods(http.MethodGet) } else { ls.Println("non-fungible tokens disabled") } @@ -269,7 +260,7 @@ func runServer(disableRawTx, disableFt, disableNft, disableChainEvents bool) { interval := 10 * time.Second // TODO: make this configurable getTypes := func() []string { // Get all enabled tokens - tt, err := templateService.ListTokens(nil) + tt, err := templateService.ListTokens(templates.NotSpecified) if err != nil { panic(err) } diff --git a/main_test.go b/main_test.go index b629bcc9..382a36fb 100644 --- a/main_test.go +++ b/main_test.go @@ -18,16 +18,16 @@ import ( "time" "github.com/caarlos0/env/v6" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/datastore/gorm" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/handlers" - "github.com/eqlabs/flow-wallet-api/jobs" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/keys/basic" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/tokens" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/datastore/gorm" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/handlers" + "github.com/flow-hydraulics/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/keys/basic" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/tokens" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/gorilla/mux" "github.com/joho/godotenv" "github.com/onflow/cadence" @@ -1559,7 +1559,7 @@ func TestTemplateHandlers(t *testing.T) { router := mux.NewRouter() router.Handle("/tokens", templateHandler.AddToken()).Methods(http.MethodPost) - router.Handle("/tokens", templateHandler.ListTokens(nil)).Methods(http.MethodGet) + router.Handle("/tokens", templateHandler.ListTokens(templates.NotSpecified)).Methods(http.MethodGet) router.Handle("/tokens/{id_or_name}", templateHandler.GetToken()).Methods(http.MethodGet) router.Handle("/tokens/{id}", templateHandler.RemoveToken()).Methods(http.MethodDelete) @@ -1605,7 +1605,7 @@ func TestTemplateHandlers(t *testing.T) { body: strings.NewReader(fmt.Sprintf(`{"name":"TestToken","address":"%s"}`, cfg.AdminAddress)), contentType: "application/json", url: "/tokens", - expected: fmt.Sprintf(`{"id":\d+,"name":"TestToken","address":"%s","type":"Unknown"}`, cfg.AdminAddress), + expected: fmt.Sprintf(`{"id":\d+,"name":"TestToken","address":"%s","type":"NotSpecified"}`, cfg.AdminAddress), status: http.StatusCreated, }, { @@ -1622,7 +1622,7 @@ func TestTemplateHandlers(t *testing.T) { method: http.MethodGet, contentType: "application/json", url: "/tokens", - expected: fmt.Sprintf(`\[{"id":\d+,"name":"TestToken","address":"%s","type":"Unknown"}.*\]`, cfg.AdminAddress), + expected: fmt.Sprintf(`\[{"id":\d+,"name":"TestToken","address":"%s","type":"NotSpecified"}.*\]`, cfg.AdminAddress), status: http.StatusOK, }, } @@ -1649,7 +1649,7 @@ func TestTemplateHandlers(t *testing.T) { method: http.MethodGet, contentType: "application/json", url: "/tokens/1", - expected: `{"id":1,.*"type":"Unknown"}`, + expected: `{"id":1,.*"type":"NotSpecified"}`, status: http.StatusOK, }, } @@ -1689,7 +1689,7 @@ func TestTemplateHandlers(t *testing.T) { body: strings.NewReader(fmt.Sprintf(`{"name":"TestToken2","address":"%s","type":"not-a-valid-type"}`, cfg.AdminAddress)), contentType: "application/json", url: "/tokens", - expected: fmt.Sprintf(`{"id":\d+,"name":"TestToken2","address":"%s","type":"Unknown"}`, cfg.AdminAddress), + expected: fmt.Sprintf(`{"id":\d+,"name":"TestToken2","address":"%s","type":"NotSpecified"}`, cfg.AdminAddress), status: http.StatusCreated, }, { diff --git a/openapi.yml b/openapi.yml index 346c9008..b4d86e1b 100644 --- a/openapi.yml +++ b/openapi.yml @@ -18,7 +18,7 @@ components: Content-Type: application/json Connection: close - ver: https://github.com/eqlabs/flow-wallet-api/commit/ + ver: https://github.com/flow-hydraulics/flow-wallet-api/commit/ built on: api version called: v1 diff --git a/templates/service.go b/templates/service.go index 8be9bb87..247b1efa 100644 --- a/templates/service.go +++ b/templates/service.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/eqlabs/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" "github.com/onflow/flow-go-sdk" ) @@ -65,7 +65,7 @@ func (s *Service) AddToken(t *Token) error { return s.store.Insert(t) } -func (s *Service) ListTokens(tType *TokenType) (*[]BasicToken, error) { +func (s *Service) ListTokens(tType TokenType) (*[]BasicToken, error) { return s.store.List(tType) } diff --git a/templates/store.go b/templates/store.go index 8d009e1a..bfb6ba09 100644 --- a/templates/store.go +++ b/templates/store.go @@ -3,7 +3,7 @@ package templates // Store manages data regarding templates. type Store interface { Insert(*Token) error - List(*TokenType) (*[]BasicToken, error) + List(TokenType) (*[]BasicToken, error) GetById(id uint64) (*Token, error) GetByName(name string) (*Token, error) Remove(id uint64) error diff --git a/templates/store_gorm.go b/templates/store_gorm.go index f68351cb..c5543df7 100644 --- a/templates/store_gorm.go +++ b/templates/store_gorm.go @@ -21,12 +21,12 @@ func (s *GormStore) Insert(q *Token) error { return s.db.Omit("ID").Create(q).Error } -func (s *GormStore) List(tType *TokenType) (*[]BasicToken, error) { +func (s *GormStore) List(tType TokenType) (*[]BasicToken, error) { var err error fromTemp := make([]BasicToken, 0, len(s.tempStore)) for _, t := range s.tempStore { - if tType == nil || t.Type == *tType { + if tType == NotSpecified || t.Type == tType { fromTemp = append(fromTemp, t.BasicToken()) } } @@ -35,9 +35,9 @@ func (s *GormStore) List(tType *TokenType) (*[]BasicToken, error) { q := s.db.Model(&Token{}) - if tType != nil { + if tType != NotSpecified { // Filter by type - q = q.Where(&Token{Type: *tType}) + q = q.Where(&Token{Type: tType}) } err = q.Find(&fromDB).Error diff --git a/templates/templates.go b/templates/templates.go index c378823a..9b61c328 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -5,7 +5,7 @@ import ( "regexp" "strings" - "github.com/eqlabs/flow-wallet-api/templates/template_strings" + "github.com/flow-hydraulics/flow-wallet-api/templates/template_strings" "github.com/onflow/flow-go-sdk" ) diff --git a/templates/tokentype_string.go b/templates/tokentype_string.go index 604ca39f..1f41bf99 100644 --- a/templates/tokentype_string.go +++ b/templates/tokentype_string.go @@ -8,14 +8,14 @@ func _() { // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. var x [1]struct{} - _ = x[Unknown-0] + _ = x[NotSpecified-0] _ = x[FT-1] _ = x[NFT-2] } -const _TokenType_name = "UnknownFTNFT" +const _TokenType_name = "NotSpecifiedFTNFT" -var _TokenType_index = [...]uint8{0, 7, 9, 12} +var _TokenType_index = [...]uint8{0, 12, 14, 17} func (i TokenType) String() string { if i < 0 || i >= TokenType(len(_TokenType_index)-1) { diff --git a/templates/types.go b/templates/types.go index d112a581..3bc029c7 100644 --- a/templates/types.go +++ b/templates/types.go @@ -6,7 +6,7 @@ import "strings" type TokenType int const ( - Unknown TokenType = iota + NotSpecified TokenType = iota FT NFT ) @@ -16,14 +16,14 @@ func (s TokenType) MarshalText() ([]byte, error) { } func (s *TokenType) UnmarshalText(text []byte) error { - *s = StatusFromText(string(text)) + *s = TypeFromText(string(text)) return nil } -func StatusFromText(text string) TokenType { +func TypeFromText(text string) TokenType { switch strings.ToLower(text) { default: - return Unknown + return NotSpecified case "ft": return FT case "nft": diff --git a/tokens/account_events.go b/tokens/account_events.go index c04cff64..b2d2742c 100644 --- a/tokens/account_events.go +++ b/tokens/account_events.go @@ -3,9 +3,9 @@ package tokens import ( "fmt" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/templates" ) type AccountAddedHandler struct { diff --git a/tokens/chain_events.go b/tokens/chain_events.go index b139f442..cd4a80ec 100644 --- a/tokens/chain_events.go +++ b/tokens/chain_events.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/chain_events" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/chain_events" + "github.com/flow-hydraulics/flow-wallet-api/templates" "github.com/onflow/flow-go-sdk" ) diff --git a/tokens/service.go b/tokens/service.go index 4d1cba3b..58a37491 100644 --- a/tokens/service.go +++ b/tokens/service.go @@ -6,13 +6,13 @@ import ( "strconv" "strings" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/jobs" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/templates/template_strings" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/templates/template_strings" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "github.com/onflow/cadence" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" @@ -94,7 +94,7 @@ func (s *Service) Setup(ctx context.Context, sync bool, tokenName, address strin return job, tx, err } -func (s *Service) AccountTokens(address string, tType *templates.TokenType) ([]AccountToken, error) { +func (s *Service) AccountTokens(address string, tType templates.TokenType) ([]AccountToken, error) { // Check if the input is a valid address address, err := flow_helpers.ValidateAddress(address, s.cfg.ChainID) if err != nil { diff --git a/tokens/store.go b/tokens/store.go index 3c45345e..412b6722 100644 --- a/tokens/store.go +++ b/tokens/store.go @@ -1,11 +1,11 @@ package tokens -import "github.com/eqlabs/flow-wallet-api/templates" +import "github.com/flow-hydraulics/flow-wallet-api/templates" // Store manages data regarding tokens. type Store interface { // List an accounts enabled tokens - AccountTokens(address string, tokenType *templates.TokenType) ([]AccountToken, error) + AccountTokens(address string, tokenType templates.TokenType) ([]AccountToken, error) // Enable a token for an account InsertAccountToken(at *AccountToken) error diff --git a/tokens/store_gorm.go b/tokens/store_gorm.go index 8fa07eff..dbdb92ed 100644 --- a/tokens/store_gorm.go +++ b/tokens/store_gorm.go @@ -3,8 +3,8 @@ package tokens import ( "fmt" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "gorm.io/gorm" "gorm.io/gorm/clause" ) @@ -19,11 +19,11 @@ func NewGormStore(db *gorm.DB) *GormStore { return &GormStore{db} } -func (s *GormStore) AccountTokens(address string, tokenType *templates.TokenType) (att []AccountToken, err error) { +func (s *GormStore) AccountTokens(address string, tokenType templates.TokenType) (att []AccountToken, err error) { q := s.db - if tokenType != nil { + if tokenType != templates.NotSpecified { // Filter by type - q = q.Where(&AccountToken{AccountAddress: address, TokenType: *tokenType}) + q = q.Where(&AccountToken{AccountAddress: address, TokenType: tokenType}) } else { // Find all q = q.Where(&AccountToken{AccountAddress: address}) diff --git a/tokens/tokens.go b/tokens/tokens.go index a6d16a2b..5298daf2 100644 --- a/tokens/tokens.go +++ b/tokens/tokens.go @@ -5,9 +5,9 @@ package tokens import ( "time" - "github.com/eqlabs/flow-wallet-api/accounts" - "github.com/eqlabs/flow-wallet-api/templates" - "github.com/eqlabs/flow-wallet-api/transactions" + "github.com/flow-hydraulics/flow-wallet-api/accounts" + "github.com/flow-hydraulics/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/transactions" "gorm.io/gorm" ) diff --git a/transactions/service.go b/transactions/service.go index caa9f6bb..c0989998 100644 --- a/transactions/service.go +++ b/transactions/service.go @@ -6,12 +6,12 @@ import ( "net/http" "strings" - "github.com/eqlabs/flow-wallet-api/datastore" - "github.com/eqlabs/flow-wallet-api/errors" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/jobs" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/errors" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/jobs" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/templates" "github.com/onflow/cadence" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" diff --git a/transactions/store.go b/transactions/store.go index 09bea3e3..51bd633d 100644 --- a/transactions/store.go +++ b/transactions/store.go @@ -1,6 +1,6 @@ package transactions -import "github.com/eqlabs/flow-wallet-api/datastore" +import "github.com/flow-hydraulics/flow-wallet-api/datastore" // Store manages data regarding transactions. type Store interface { diff --git a/transactions/store_gorm.go b/transactions/store_gorm.go index 50daf664..ba0a85b7 100644 --- a/transactions/store_gorm.go +++ b/transactions/store_gorm.go @@ -1,7 +1,7 @@ package transactions import ( - "github.com/eqlabs/flow-wallet-api/datastore" + "github.com/flow-hydraulics/flow-wallet-api/datastore" "gorm.io/gorm" ) diff --git a/transactions/transactions.go b/transactions/transactions.go index cc041cf8..a7944e20 100644 --- a/transactions/transactions.go +++ b/transactions/transactions.go @@ -4,9 +4,9 @@ import ( "context" "time" - "github.com/eqlabs/flow-wallet-api/flow_helpers" - "github.com/eqlabs/flow-wallet-api/keys" - "github.com/eqlabs/flow-wallet-api/templates" + "github.com/flow-hydraulics/flow-wallet-api/flow_helpers" + "github.com/flow-hydraulics/flow-wallet-api/keys" + "github.com/flow-hydraulics/flow-wallet-api/templates" "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/client" "gorm.io/gorm"