From 5c2b356240e057e1f606f310e04a29167defeae1 Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Wed, 16 Jun 2021 22:58:48 +0300 Subject: [PATCH 1/6] Clean up --- accounts/service.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/accounts/service.go b/accounts/service.go index 258ad40b..eceb68b4 100644 --- a/accounts/service.go +++ b/accounts/service.go @@ -183,10 +183,5 @@ func (s *Service) AccountFungibleTokens(address string) ([]AccountToken, error) address = flow_helpers.HexString(address) - tt, err := s.db.AccountTokens(address) - if err != nil { - return []AccountToken{}, err - } - - return tt, nil + return s.db.AccountTokens(address) } From 3df2978ab95b441ac11ef5938fff5b84707abfe5 Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 17 Jun 2021 11:32:57 +0300 Subject: [PATCH 2/6] Update github ci workflow to include versioning --- .github/workflows/ci.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aea426f7..83af545d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,16 @@ +# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md + name: ci on: push: branches: - - main + - 'main' + tags: + - 'v*.*.*' + pull_request: + branches: + - 'main' jobs: docker: @@ -12,6 +19,21 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + ghcr.io/eqlabs/flow-wallet-service + # generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -40,8 +62,9 @@ jobs: with: context: . file: ./docker/wallet/Dockerfile - push: true - tags: ghcr.io/eqlabs/flow-wallet-service:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - From 34c4ae01dd65b7762df973bd9b6b5490b26587af Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 17 Jun 2021 12:12:38 +0300 Subject: [PATCH 3/6] Document the new API endpoints --- accounts/accounts.go | 2 +- api/debug.http | 3 + api/openapi.yaml | 192 ++++++++++++++++++++++++++++++++++++++++--- api/tokens.http | 8 +- 4 files changed, 187 insertions(+), 18 deletions(-) create mode 100644 api/debug.http diff --git a/accounts/accounts.go b/accounts/accounts.go index 0e7e605e..ed0e011a 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -31,8 +31,8 @@ type Account struct { type AccountToken struct { ID int `json:"-" gorm:"primaryKey"` AccountAddress string `json:"-" gorm:"uniqueIndex:addressname;index;not null"` - TokenAddress string `json:"-" gorm:"uniqueIndex:addressname;index;not null"` TokenName string `json:"name" gorm:"uniqueIndex:addressname;index;not null"` + TokenAddress string `json:"address" gorm:"uniqueIndex:addressname;index;not null"` CreatedAt time.Time `json:"-"` UpdatedAt time.Time `json:"-"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` diff --git a/api/debug.http b/api/debug.http new file mode 100644 index 00000000..e3b09d86 --- /dev/null +++ b/api/debug.http @@ -0,0 +1,3 @@ +### Get debug +GET http://localhost:3000/v1/debug HTTP/1.1 +content-type: application/json diff --git a/api/openapi.yaml b/api/openapi.yaml index 6c61e361..0b68d727 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -9,6 +9,19 @@ servers: components: schemas: + debugInfo: + type: string + example: | + url: GET /v1/debug + Headers: + User-Agent: vscode-restclient + Content-Type: application/json + Connection: close + + ver: https://github.com/eqlabs/flow-wallet-service/commit/ + built on: + api version called: v1 + account: type: object properties: @@ -78,6 +91,49 @@ components: plainValue: type: string + token: + type: object + properties: + name: + type: string + example: "FlowToken" + address: + type: string + example: "0xf8d6e0586b0a20c7" + + tokenDetails: + type: object + properties: + name: + type: string + example: "FlowToken" + balance: + type: string + example: "9999999999.99700000" + + tokenWithdrawal: + type: object + properties: + transactionId: + type: string + example: "f1e272ee125b370e5129215179705791220764bf71da2aa938c94181b2c06685" + amount: + type: string + example: "1.0" + token: + type: string + example: "FlowToken" + recipient: + type: string + example: "0x01cf0e2f2f715450" + createdAt: + type: string + example: "2021-06-167T12:05:24.613704+03:00" + updatedAt: + type: string + example: "2021-06-16T12:05:24.617898+03:00" + + parameters: limit: name: limit @@ -121,8 +177,8 @@ components: required: true schema: type: string - enum: [FLOW, FUSD] - example: FLOW + enum: [flow-token, FUSD] + example: flow-token transactionId: name: transactionId @@ -133,6 +189,48 @@ components: example: "9613c9689a50a5ed9198dc43839cd90ef39203dfdd7ab54f0fc5ca12f256eef0" paths: + /debug: + get: + summary: Get debug information about the running instance. + responses: + "200": + description: OK + content: + text/plain: + schema: + $ref: "#/components/schemas/debugInfo" + + /fungible-tokens: + get: + summary: Get all fungible tokens + description: Get all fungible tokens that are enabled in this instance. + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/token" + /scripts: + post: + summary: Execute a script on chain + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/script" + responses: + "200": + description: Ok + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/cadenceValue" + - $ref: "#/components/schemas/plainValue" + /jobs: get: summary: List all jobs @@ -253,20 +351,88 @@ paths: schema: $ref: "#/components/schemas/transaction" - /scripts: + /accounts/{address}/fungible-tokens: + parameters: + - $ref: "#/components/parameters/address" + get: + summary: Get account fungible tokens + description: Get all fungible tokens that are enabled for an account. + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/token" + + /accounts/{address}/fungible-tokens/{tokenName}: + parameters: + - $ref: "#/components/parameters/address" + - $ref: "#/components/parameters/tokenName" + get: + summary: Get fungible tokens details for an account + description: Get details (balance) regarding a fungible token for an account. + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/tokenDetails" post: - summary: Execute a script on chain - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/script" + summary: Enable a fungible token for an account + responses: + "201": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/job" + + /accounts/{address}/fungible-tokens/{tokenName}/withdrawals: + parameters: + - $ref: "#/components/parameters/address" + - $ref: "#/components/parameters/tokenName" + get: + summary: List all withdrawals of a fungible token responses: "200": - description: Ok + description: OK content: application/json: schema: - oneOf: - - $ref: "#/components/schemas/cadenceValue" - - $ref: "#/components/schemas/plainValue" + type: array + items: + $ref: "#/components/schemas/tokenWithdrawal" + post: + summary: Create a fungible token withdrawal + responses: + "201": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/job" + + /accounts/{address}/fungible-tokens/{tokenName}/withdrawals/{transactionId}: + parameters: + - $ref: "#/components/parameters/address" + - $ref: "#/components/parameters/tokenName" + - $ref: "#/components/parameters/transactionId" + get: + summary: Get details of a fungible token withdrawal + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/tokenWithdrawal" diff --git a/api/tokens.http b/api/tokens.http index d7bd4c32..a4b6512d 100644 --- a/api/tokens.http +++ b/api/tokens.http @@ -34,11 +34,11 @@ content-type: application/json "amount":"1.0" } -### Get FlowToken withdrawals for admin account +### List FlowToken withdrawals for admin account GET http://localhost:3000/v1/accounts/{{$dotenv ADMIN_ADDRESS}}/fungible-tokens/flow-token/withdrawals HTTP/1.1 content-type: application/json -### Get FUSD withdrawals for admin account +### List FUSD withdrawals for admin account GET http://localhost:3000/v1/accounts/{{$dotenv ADMIN_ADDRESS}}/fungible-tokens/fusd/withdrawals HTTP/1.1 content-type: application/json @@ -82,11 +82,11 @@ content-type: application/json "amount":"1.0" } -### Get FlowToken withdrawals for custody account +### List FlowToken withdrawals for custody account GET http://localhost:3000/v1/accounts/{{emulatorCustodyAccount}}/fungible-tokens/flow-token/withdrawals HTTP/1.1 content-type: application/json -### Get FUSD withdrawals for custody account +### List FUSD withdrawals for custody account GET http://localhost:3000/v1/accounts/{{emulatorCustodyAccount}}/fungible-tokens/fusd/withdrawals HTTP/1.1 content-type: application/json From 677260b2e6ea71803f21b93a5fe7895b68bb787a Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 17 Jun 2021 12:19:47 +0300 Subject: [PATCH 4/6] Add documentation regarding enabled tokens --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45bc55d2..e942225b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ A custodial wallet service for tokens on the Flow blockchain. DEFAULT_KEY_TYPE=local # Will store keys in your database, use "google_kms" if you have that setup ENCRYPTION_KEY=passphrasewhichneedstobe32bytes! # replace this with something that is 32 bytes + ENABLED_TOKENS=FlowToken:0x7e60df042a9c0868 + Running: docker run -d --name flow-wallet-service --env-file .env ghcr.io/eqlabs/flow-wallet-service:0.0.1 @@ -56,11 +58,22 @@ Run: # edit .env.test # feel free to use the private key in the example file as it is only for testing # admin address is always the same with flow emulator - docker-compose up -d + make build-cli + make up + make deploy go test -v ./... ## Configuration +### Enabled tokens + +A comma separated list of fungible tokens and their corresponding addresses enabled for this instance. Make sure to name each token exactly as it is in the corresponding cadence code (FlowToken, FUSD etc.). Include at least FlowToken as functionality without it is undetermined. + +Examples: + + ENABLED_TOKENS=FlowToken:0x0ae53cb6e3f42a79 + ENABLED_TOKENS=FlowToken:0x0ae53cb6e3f42a79,FUSD:0xf8d6e0586b0a20c7 + ### Database | Config variable | Environment variable | Description | Default | Examples | @@ -122,6 +135,8 @@ Configure Google KMS as the key storage for `flow-wallet-service` and set the ne PORT=3000 ACCESS_API_HOST=localhost:3569 + ENABLED_TOKENS=FlowToken:0x0ae53cb6e3f42a79 + DATABASE_DSN=wallet.db DATABASE_TYPE=sqlite From 385f97a11b1b0f0fd83e9db588e1e192e9123e85 Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 17 Jun 2021 12:22:13 +0300 Subject: [PATCH 5/6] Bump version number --- README.md | 4 ++-- api/openapi.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e942225b..b5f8a825 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Flow Wallet Service v0.0.1 +# Flow Wallet Service v0.0.2 A custodial wallet service for tokens on the Flow blockchain. @@ -22,7 +22,7 @@ A custodial wallet service for tokens on the Flow blockchain. Running: - docker run -d --name flow-wallet-service --env-file .env ghcr.io/eqlabs/flow-wallet-service:0.0.1 + docker run -d --name flow-wallet-service --env-file .env ghcr.io/eqlabs/flow-wallet-service:0.0.2 ## Developing diff --git a/api/openapi.yaml b/api/openapi.yaml index 0b68d727..6c061c67 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.0.3 info: title: Flow Wallet Service API - version: 0.0.1 + version: 0.0.2 servers: - url: http://localhost:3000/v1 From fb92478cdac56423020efdd7bf11ba71a4d54e6d Mon Sep 17 00:00:00 2001 From: Lauri Junkkari Date: Thu, 17 Jun 2021 12:52:47 +0300 Subject: [PATCH 6/6] Update tests --- main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 8691bff6..4864e6f8 100644 --- a/main_test.go +++ b/main_test.go @@ -999,7 +999,7 @@ func TestTokenHandlers(t *testing.T) { method: http.MethodGet, contentType: "application/json", url: fmt.Sprintf("/%s/fungible-tokens", aa[1].Address), - expected: `\[.*{"name":"FUSD"}.*{"name":"FlowToken"}.*\]`, + expected: `\[.*"name":"FUSD".*"name":"FlowToken".*\]`, status: http.StatusOK, }, }