Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update API to Cadence 1.0 #365

Merged
merged 22 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ updates:
interval: "daily"
allow:
- dependency-name: "github.com/onflow/flow-emulator"
- dependency-name: "github.com/onflow/cadence"
- dependency-name: "github.com/onflow/cadence"
31 changes: 31 additions & 0 deletions .github/security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Security Scanner
on:
pull_request:
push:
workflow_dispatch:
schedule:
- cron: "0 4 * * *" # run once a day at 4 AM
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}}
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Running govulncheck
uses: Templum/govulncheck-action@latest
with:
go-version: 1.18
vulncheck-version: latest
package: ./...
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-vuln: true
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -32,6 +33,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go

uses: actions/setup-go@v4
with:
go-version: '1.19'
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '0 7 * * *'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.DS_Store
e2e-db
server/server
test-results.log
.vscode/launch.json
test-results.log
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GO111MODULE=on GOOS=linux GOARCH=amd64 \
go build \
-ldflags "-extldflags -static -X github.com/dapperlabs/flow-playground-api/build.version=${VERSION}" \
-ldflags "-extldflags -static -X github.com/onflow/flow-playground-api/build.version=${VERSION}" \
-o ./app ./server

RUN chmod a+x /app/app
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ run:
FLOW_SESSIONCOOKIESSECURE=false \
GO111MODULE=on \
go run \
-ldflags "-X github.com/dapperlabs/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
-ldflags "-X github.com/onflow/flow-playground-api/build.version=$(LAST_KNOWN_VERSION)" \
server/server.go

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

.PHONY: install-linter
Expand Down
8 changes: 4 additions & 4 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ package auth
import (
"context"
"fmt"
legacyauth "github.com/dapperlabs/flow-playground-api/auth/legacy"
"github.com/dapperlabs/flow-playground-api/middleware/sessions"
"github.com/dapperlabs/flow-playground-api/model"
"github.com/dapperlabs/flow-playground-api/storage"
"github.com/getsentry/sentry-go"
"github.com/google/uuid"
legacyauth "github.com/onflow/flow-playground-api/auth/legacy"
"github.com/onflow/flow-playground-api/middleware/sessions"
"github.com/onflow/flow-playground-api/model"
"github.com/onflow/flow-playground-api/storage"
"github.com/pkg/errors"
"sync"
)
Expand Down
4 changes: 2 additions & 2 deletions auth/legacy/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

gorillasessions "github.com/gorilla/sessions"

"github.com/dapperlabs/flow-playground-api/middleware/sessions"
"github.com/dapperlabs/flow-playground-api/model"
"github.com/onflow/flow-playground-api/middleware/sessions"
"github.com/onflow/flow-playground-api/model"
)

const projectSecretKeyName = "project-secret"
Expand Down
17 changes: 16 additions & 1 deletion blockchain/Interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package blockchain

import (
"encoding/json"
"github.com/rs/zerolog"
"io"
"strings"
)
Expand All @@ -42,14 +44,27 @@ func (logger *Interceptor) Write(p []byte) (n int, err error) {
}

func (logger *Interceptor) ClearLogs() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
logger.logs = Logs{}
}

type logMessage struct {
Level string `json:"level"`
Message string `json:"message"`
}

func (logger *Interceptor) GetCadenceLogs() Logs {
var filteredLogs Logs

for _, log := range logger.logs {
if strings.Contains(log, `"message":"Cadence log:`) {
filteredLogs = append(filteredLogs, strings.TrimSuffix(log, "\n"))
//json decode string log to get the message
parsedLog := logMessage{}
err := json.NewDecoder(strings.NewReader(log)).Decode(&parsedLog)
if err != nil {
continue
}
filteredLogs = append(filteredLogs, parsedLog.Message)
}
}
return filteredLogs
Expand Down
27 changes: 14 additions & 13 deletions blockchain/flowkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ package blockchain
import (
"context"
"fmt"

userErr "github.com/dapperlabs/flow-playground-api/middleware/errors"
"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/parser"
kit "github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flow-cli/flowkit/accounts"
"github.com/onflow/flow-cli/flowkit/config"
"github.com/onflow/flow-cli/flowkit/gateway"
"github.com/onflow/flow-cli/flowkit/output"
"github.com/onflow/flow-cli/flowkit/transactions"
kit "github.com/onflow/flowkit/v2"
"github.com/onflow/flowkit/v2/accounts"
"github.com/onflow/flowkit/v2/config"
"github.com/onflow/flowkit/v2/gateway"
"github.com/onflow/flowkit/v2/output"
"github.com/onflow/flowkit/v2/transactions"

emu "github.com/onflow/flow-emulator/emulator"
"github.com/onflow/flow-emulator/storage/memstore"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/crypto"
userErr "github.com/onflow/flow-playground-api/middleware/errors"
"github.com/pkg/errors"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -95,7 +95,8 @@ type flowKit struct {

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

state.Deployments().AddOrUpdate(config.Deployment{
Network: config.EmulatorNetwork.Name,
Account: fmt.Sprintf("Emulator Account 0x%d", i),
Account: fmt.Sprintf("Emulator Account 0x%x", i),
Contracts: emulatorContracts,
})
}
Expand Down Expand Up @@ -294,6 +295,7 @@ func (fk *flowKit) executeScript(script string, arguments []string) (cadence.Val
Location: "",
},
kit.LatestScriptQuery)

if err != nil {
return nil, nil, userErr.NewUserError(err.Error())
}
Expand Down Expand Up @@ -391,7 +393,7 @@ func (fk *flowKit) createAccount() (*flow.Account, error) {
return nil, err
}

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

state.Accounts().AddOrUpdate(&accounts.Account{
Name: name,
Expand Down Expand Up @@ -534,7 +536,7 @@ func (fk *flowKit) sendTransaction(
}

func (fk *flowKit) getLatestBlockHeight() (int, error) {
block, err := fk.blockchain.Gateway().GetLatestBlock()
block, err := fk.blockchain.Gateway().GetLatestBlock(context.Background())
if err != nil {
return 0, err
}
Expand All @@ -546,7 +548,6 @@ func (fk *flowKit) getServiceAccount() (*accounts.Account, error) {
if err != nil {
return nil, err
}

service, err := state.EmulatorServiceAccount()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions blockchain/flowkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package blockchain

import (
"context"
"github.com/onflow/flowkit/v2/accounts"
"testing"

"github.com/onflow/flow-cli/flowkit/accounts"
"github.com/onflow/flow-go-sdk"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -97,11 +97,11 @@ func Test_FlowJsonExport(t *testing.T) {
assert.Contains(t, flowJson, Networks)

// Accounts
assert.Contains(t, flowJson, "Account 0x05")
assert.Contains(t, flowJson, "Account 0x06")
assert.Contains(t, flowJson, "Account 0x07")
assert.Contains(t, flowJson, "Account 0x08")
assert.Contains(t, flowJson, "Account 0x09")
assert.Contains(t, flowJson, "Account 0x0a")
assert.Contains(t, flowJson, "Service Account")
assert.Contains(t, flowJson, "emulator-account")
}
4 changes: 2 additions & 2 deletions blockchain/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ package blockchain

import (
"fmt"
"github.com/dapperlabs/flow-playground-api/model"
"github.com/dapperlabs/flow-playground-api/storage"
"github.com/getsentry/sentry-go"
"github.com/google/uuid"
flowsdk "github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-playground-api/model"
"github.com/onflow/flow-playground-api/storage"
"github.com/pkg/errors"
)

Expand Down
Loading
Loading