Skip to content

Commit 04b2743

Browse files
authored
Merge branch 'v2' into dependabot/github_actions/actions/cache-4
2 parents 26d4dbf + c1f1d3f commit 04b2743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2930
-874
lines changed

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ updates:
1111
interval: "daily"
1212
allow:
1313
- dependency-name: "github.com/onflow/flow-emulator"
14-
- dependency-name: "github.com/onflow/cadence"
14+
- dependency-name: "github.com/onflow/cadence"

.github/security.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Security Scanner
2+
on:
3+
pull_request:
4+
push:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: "0 4 * * *" # run once a day at 4 AM
8+
jobs:
9+
scan:
10+
name: gitleaks
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
- uses: gitleaks/gitleaks-action@v2
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}}
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Running govulncheck
25+
uses: Templum/govulncheck-action@latest
26+
with:
27+
go-version: 1.18
28+
vulncheck-version: latest
29+
package: ./...
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
fail-on-vuln: true

.github/workflows/ci.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ jobs:
1313
name: Test
1414
runs-on: ubuntu-latest
1515
steps:
16+
1617
- uses: actions/checkout@v4
1718
with:
1819
fetch-depth: 0
1920
- uses: actions/setup-go@v4
2021
with:
21-
go-version: '1.19'
22+
go-version: '1.22'
2223
- uses: actions/cache@v4
2324
with:
2425
path: ~/go/pkg/mod
@@ -32,18 +33,19 @@ jobs:
3233
runs-on: ubuntu-latest
3334
steps:
3435
- name: Install Go
36+
3537
uses: actions/setup-go@v4
3638
with:
37-
go-version: '1.19'
39+
go-version: '1.22'
3840
- name: Checkout code
3941
uses: actions/checkout@v4
4042
- name: Check Headers
4143
run: make check-headers
4244
- name: Check Tidy
4345
run: make check-tidy
4446
- name: Run golangci-lint
45-
uses: golangci/golangci-lint-action@v3.7.0
47+
uses: golangci/golangci-lint-action@v6.1.0
4648
with:
4749
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
48-
version: v1.49
50+
version: v1.61
4951
args: --timeout=10m

.github/workflows/codeql.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: '0 7 * * *'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'go' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
34+
- name: Autobuild
35+
uses: github/codeql-action/autobuild@v2
36+
37+
- name: Perform CodeQL Analysis
38+
uses: github/codeql-action/analyze@v2
39+
with:
40+
category: "/language:${{matrix.language}}"

.github/workflows/deploy.yml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "Deploy to Cloud Run"
2+
3+
on:
4+
push:
5+
branches:
6+
- v2
7+
8+
env:
9+
DOCKER_IMAGE_URL: ${{ vars.GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}
10+
GAR_LOCATION: ${{ vars.GCP_GAR_LOCATION }}
11+
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
12+
SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
13+
WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
id-token: write
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Google auth
25+
id: auth
26+
uses: google-github-actions/auth@v2
27+
with:
28+
token_format: 'access_token'
29+
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
30+
service_account: ${{ env.SERVICE_ACCOUNT }}
31+
32+
- name: Set up Cloud SDK
33+
uses: google-github-actions/setup-gcloud@v1
34+
with:
35+
project_id: ${{ env.PROJECT_ID }}
36+
37+
- name: Docker Auth
38+
run: |-
39+
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
40+
docker build -t ${{ env.DOCKER_IMAGE_URL }} --file Dockerfile .
41+
docker push ${{ env.DOCKER_IMAGE_URL }}
42+
43+
deploy-staging:
44+
needs: [build]
45+
environment: staging
46+
runs-on: ubuntu-latest
47+
permissions:
48+
id-token: write
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
53+
- name: Google auth
54+
id: auth
55+
uses: google-github-actions/auth@v2
56+
with:
57+
token_format: 'access_token'
58+
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
59+
service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}
60+
- name: Deploy to Cloud Run
61+
uses: google-github-actions/deploy-cloudrun@v1
62+
with:
63+
service: ${{ vars.GCP_SERVICE }}
64+
image: ${{ env.DOCKER_IMAGE_URL }}
65+
66+
deploy-production:
67+
needs: [build]
68+
environment: production
69+
runs-on: ubuntu-latest
70+
permissions:
71+
id-token: write
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v3
75+
76+
- name: Google auth
77+
id: auth
78+
uses: google-github-actions/auth@v2
79+
with:
80+
token_format: 'access_token'
81+
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
82+
service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}
83+
- name: Deploy to Cloud Run
84+
uses: google-github-actions/deploy-cloudrun@v1
85+
with:
86+
service: ${{ vars.GCP_SERVICE }}
87+
image: ${{ env.DOCKER_IMAGE_URL }}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.DS_Store
33
e2e-db
44
server/server
5-
test-results.log
5+
.vscode/launch.json
6+
test-results.log

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# syntax = docker/dockerfile:experimental
22

33
## (1) Build the app binary
4-
FROM golang:1.19 AS build-app
4+
FROM golang:1.22 AS build-app
55

66
ARG VERSION
77

@@ -17,7 +17,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
1717
--mount=type=cache,target=/root/.cache/go-build \
1818
GO111MODULE=on GOOS=linux GOARCH=amd64 \
1919
go build \
20-
-ldflags "-extldflags -static -X github.com/dapperlabs/flow-playground-api/build.version=${VERSION}" \
20+
-ldflags "-extldflags -static -X github.com/onflow/flow-playground-api/build.version=${VERSION}" \
2121
-o ./app ./server
2222

2323
RUN chmod a+x /app/app

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ run:
2424
FLOW_SESSIONCOOKIESSECURE=false \
2525
GO111MODULE=on \
2626
go run \
27-
-ldflags "-X github.com/dapperlabs/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
27+
-ldflags "-X github.com/onflow/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
2828
server/server.go
2929

3030
.PHONY: run-pg
@@ -38,7 +38,7 @@ run-pg:
3838
FLOW_DEBUG=true FLOW_SESSIONCOOKIESSECURE=false \
3939
GO111MODULE=on \
4040
go run \
41-
-ldflags "-X github.com/dapperlabs/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
41+
-ldflags "-X github.com/onflow/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
4242
server/server.go
4343

4444
.PHONY: install-linter

auth/auth.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ package auth
2121
import (
2222
"context"
2323
"fmt"
24-
legacyauth "github.com/dapperlabs/flow-playground-api/auth/legacy"
25-
"github.com/dapperlabs/flow-playground-api/middleware/sessions"
26-
"github.com/dapperlabs/flow-playground-api/model"
27-
"github.com/dapperlabs/flow-playground-api/storage"
2824
"github.com/getsentry/sentry-go"
2925
"github.com/google/uuid"
26+
legacyauth "github.com/onflow/flow-playground-api/auth/legacy"
27+
"github.com/onflow/flow-playground-api/middleware/sessions"
28+
"github.com/onflow/flow-playground-api/model"
29+
"github.com/onflow/flow-playground-api/storage"
3030
"github.com/pkg/errors"
3131
"sync"
3232
)

auth/legacy/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626

2727
gorillasessions "github.com/gorilla/sessions"
2828

29-
"github.com/dapperlabs/flow-playground-api/middleware/sessions"
30-
"github.com/dapperlabs/flow-playground-api/model"
29+
"github.com/onflow/flow-playground-api/middleware/sessions"
30+
"github.com/onflow/flow-playground-api/model"
3131
)
3232

3333
const projectSecretKeyName = "project-secret"

blockchain/Interceptor.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package blockchain
2020

2121
import (
22+
"encoding/json"
23+
"github.com/rs/zerolog"
2224
"io"
2325
"strings"
2426
)
@@ -42,14 +44,27 @@ func (logger *Interceptor) Write(p []byte) (n int, err error) {
4244
}
4345

4446
func (logger *Interceptor) ClearLogs() {
47+
zerolog.SetGlobalLevel(zerolog.DebugLevel)
4548
logger.logs = Logs{}
4649
}
4750

51+
type logMessage struct {
52+
Level string `json:"level"`
53+
Message string `json:"message"`
54+
}
55+
4856
func (logger *Interceptor) GetCadenceLogs() Logs {
4957
var filteredLogs Logs
58+
5059
for _, log := range logger.logs {
5160
if strings.Contains(log, `"message":"Cadence log:`) {
52-
filteredLogs = append(filteredLogs, strings.TrimSuffix(log, "\n"))
61+
//json decode string log to get the message
62+
parsedLog := logMessage{}
63+
err := json.NewDecoder(strings.NewReader(log)).Decode(&parsedLog)
64+
if err != nil {
65+
continue
66+
}
67+
filteredLogs = append(filteredLogs, parsedLog.Message)
5368
}
5469
}
5570
return filteredLogs

blockchain/flowkit.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ package blockchain
2121
import (
2222
"context"
2323
"fmt"
24-
25-
userErr "github.com/dapperlabs/flow-playground-api/middleware/errors"
2624
"github.com/onflow/cadence"
2725
jsoncdc "github.com/onflow/cadence/encoding/json"
2826
"github.com/onflow/cadence/runtime/common"
2927
"github.com/onflow/cadence/runtime/parser"
30-
kit "github.com/onflow/flow-cli/flowkit"
31-
"github.com/onflow/flow-cli/flowkit/accounts"
32-
"github.com/onflow/flow-cli/flowkit/config"
33-
"github.com/onflow/flow-cli/flowkit/gateway"
34-
"github.com/onflow/flow-cli/flowkit/output"
35-
"github.com/onflow/flow-cli/flowkit/transactions"
28+
kit "github.com/onflow/flowkit/v2"
29+
"github.com/onflow/flowkit/v2/accounts"
30+
"github.com/onflow/flowkit/v2/config"
31+
"github.com/onflow/flowkit/v2/gateway"
32+
"github.com/onflow/flowkit/v2/output"
33+
"github.com/onflow/flowkit/v2/transactions"
34+
3635
emu "github.com/onflow/flow-emulator/emulator"
3736
"github.com/onflow/flow-emulator/storage/memstore"
3837
"github.com/onflow/flow-go-sdk"
3938
"github.com/onflow/flow-go-sdk/crypto"
39+
userErr "github.com/onflow/flow-playground-api/middleware/errors"
4040
"github.com/pkg/errors"
4141
"github.com/rs/zerolog"
4242
)
@@ -95,7 +95,8 @@ type flowKit struct {
9595

9696
func newFlowkit() (*flowKit, error) {
9797
readerWriter := NewInternalReaderWriter()
98-
state, err := kit.Init(readerWriter, crypto.ECDSA_P256, crypto.SHA3_256)
98+
state, err := kit.Init(readerWriter)
99+
state, err = kit.Load([]string{"flow.json"}, readerWriter)
99100
if err != nil {
100101
return nil, errors.Wrap(err, "failed to create flow-kit state")
101102
}
@@ -211,7 +212,7 @@ func (fk *flowKit) bootstrapContracts() error {
211212

212213
state.Deployments().AddOrUpdate(config.Deployment{
213214
Network: config.EmulatorNetwork.Name,
214-
Account: fmt.Sprintf("Emulator Account 0x%d", i),
215+
Account: fmt.Sprintf("Emulator Account 0x%x", i),
215216
Contracts: emulatorContracts,
216217
})
217218
}
@@ -294,6 +295,7 @@ func (fk *flowKit) executeScript(script string, arguments []string) (cadence.Val
294295
Location: "",
295296
},
296297
kit.LatestScriptQuery)
298+
297299
if err != nil {
298300
return nil, nil, userErr.NewUserError(err.Error())
299301
}
@@ -391,7 +393,7 @@ func (fk *flowKit) createAccount() (*flow.Account, error) {
391393
return nil, err
392394
}
393395

394-
name := fmt.Sprintf("Account 0x0%d", len(state.Accounts().Names())-1)
396+
name := fmt.Sprintf("Account 0x0%x", len(state.Accounts().Names()))
395397

396398
state.Accounts().AddOrUpdate(&accounts.Account{
397399
Name: name,
@@ -534,7 +536,7 @@ func (fk *flowKit) sendTransaction(
534536
}
535537

536538
func (fk *flowKit) getLatestBlockHeight() (int, error) {
537-
block, err := fk.blockchain.Gateway().GetLatestBlock()
539+
block, err := fk.blockchain.Gateway().GetLatestBlock(context.Background())
538540
if err != nil {
539541
return 0, err
540542
}
@@ -546,7 +548,6 @@ func (fk *flowKit) getServiceAccount() (*accounts.Account, error) {
546548
if err != nil {
547549
return nil, err
548550
}
549-
550551
service, err := state.EmulatorServiceAccount()
551552
if err != nil {
552553
return nil, err

0 commit comments

Comments
 (0)