diff --git a/.github/workflows/070_lint_and_test_go_bridge.yaml b/.github/workflows/070_lint_and_test_go_bridge.yaml new file mode 100644 index 000000000..41c6aad90 --- /dev/null +++ b/.github/workflows/070_lint_and_test_go_bridge.yaml @@ -0,0 +1,49 @@ +name: Lint Go bridge + +on: + push: + paths: + - bridge/tfchain_bridge/** + workflow_dispatch: + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + submodules: "true" + sparse-checkout: | + clients/tfchain-client-go + bridge/tfchain_bridge + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.20" + cache: false + # cache-dependency-path: bridge/tfchain_bridge/go.sum + id: go + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3.7.0 + with: + args: --timeout 3m --verbose + working-directory: bridge/tfchain_bridge + + - name: staticcheck + uses: dominikh/staticcheck-action@v1.3.0 + with: + version: "2022.1.3" + working-directory: bridge/tfchain_bridge + env: + GO111MODULE: on + + - name: gofmt + uses: Jerome1337/gofmt-action@v1.0.5 + with: + gofmt-path: './bridge/tfchain_bridge' + gofmt-flags: "-l -d" diff --git a/bridge/tfchain_bridge/go.mod b/bridge/tfchain_bridge/go.mod index 9e95a6ebb..da1ebb8a0 100644 --- a/bridge/tfchain_bridge/go.mod +++ b/bridge/tfchain_bridge/go.mod @@ -1,4 +1,4 @@ -module github.com/threefoldtech/tfchain_bridge +module github.com/threefoldtech/tfchain/bridge/tfchain_bridge go 1.17 @@ -52,4 +52,4 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) -replace github.com/threefoldtech/tfchain/clients/tfchain-client-go => ../../clients/tfchain-client-go \ No newline at end of file +replace github.com/threefoldtech/tfchain/clients/tfchain-client-go => ../../clients/tfchain-client-go diff --git a/bridge/tfchain_bridge/main.go b/bridge/tfchain_bridge/main.go index c6d2a630b..f8f677567 100644 --- a/bridge/tfchain_bridge/main.go +++ b/bridge/tfchain_bridge/main.go @@ -9,9 +9,9 @@ import ( "github.com/rs/zerolog/log" flag "github.com/spf13/pflag" - "github.com/threefoldtech/tfchain_bridge/pkg" - "github.com/threefoldtech/tfchain_bridge/pkg/bridge" - "github.com/threefoldtech/tfchain_bridge/pkg/logger" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/bridge" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger" ) func main() { diff --git a/bridge/tfchain_bridge/pkg/bridge/bridge.go b/bridge/tfchain_bridge/pkg/bridge/bridge.go index 28f17ab25..92c9d48d7 100644 --- a/bridge/tfchain_bridge/pkg/bridge/bridge.go +++ b/bridge/tfchain_bridge/pkg/bridge/bridge.go @@ -8,9 +8,9 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/threefoldtech/tfchain_bridge/pkg" - "github.com/threefoldtech/tfchain_bridge/pkg/stellar" - subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/stellar" + subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate" ) const ( diff --git a/bridge/tfchain_bridge/pkg/bridge/mint.go b/bridge/tfchain_bridge/pkg/bridge/mint.go index 9228f547f..244f001b8 100644 --- a/bridge/tfchain_bridge/pkg/bridge/mint.go +++ b/bridge/tfchain_bridge/pkg/bridge/mint.go @@ -10,9 +10,9 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" hProtocol "github.com/stellar/go/protocols/horizon" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" + _logger "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger" substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go" - "github.com/threefoldtech/tfchain_bridge/pkg" - _logger "github.com/threefoldtech/tfchain_bridge/pkg/logger" ) // mint handler for stellar diff --git a/bridge/tfchain_bridge/pkg/bridge/refund.go b/bridge/tfchain_bridge/pkg/bridge/refund.go index 9f36b9f47..f713595ac 100644 --- a/bridge/tfchain_bridge/pkg/bridge/refund.go +++ b/bridge/tfchain_bridge/pkg/bridge/refund.go @@ -7,9 +7,9 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" hProtocol "github.com/stellar/go/protocols/horizon" - "github.com/threefoldtech/tfchain_bridge/pkg" - _logger "github.com/threefoldtech/tfchain_bridge/pkg/logger" - subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" + _logger "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger" + subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate" ) // refund handler for stellar diff --git a/bridge/tfchain_bridge/pkg/bridge/withdraw.go b/bridge/tfchain_bridge/pkg/bridge/withdraw.go index d55dc48c9..55c4a5450 100644 --- a/bridge/tfchain_bridge/pkg/bridge/withdraw.go +++ b/bridge/tfchain_bridge/pkg/bridge/withdraw.go @@ -9,9 +9,9 @@ import ( "github.com/centrifuge/go-substrate-rpc-client/v4/types" "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" + subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate" substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go" - "github.com/threefoldtech/tfchain_bridge/pkg" - subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate" ) func (bridge *Bridge) handleWithdrawCreated(ctx context.Context, withdraw subpkg.WithdrawCreatedEvent) error { diff --git a/bridge/tfchain_bridge/pkg/stellar/stellar.go b/bridge/tfchain_bridge/pkg/stellar/stellar.go index 4c9c1cb21..b498e02a2 100644 --- a/bridge/tfchain_bridge/pkg/stellar/stellar.go +++ b/bridge/tfchain_bridge/pkg/stellar/stellar.go @@ -21,8 +21,8 @@ import ( horizoneffects "github.com/stellar/go/protocols/horizon/effects" "github.com/stellar/go/protocols/horizon/operations" "github.com/stellar/go/txnbuild" + "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg" substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go" - "github.com/threefoldtech/tfchain_bridge/pkg" ) const ( @@ -42,6 +42,8 @@ type StellarWallet struct { sequenceNumber int64 } +type TraceIdKey struct{} + func NewStellarWallet(ctx context.Context, config *pkg.StellarConfig) (*StellarWallet, error) { kp, err := keypair.ParseFull(config.StellarSeed) @@ -93,7 +95,7 @@ func (w *StellarWallet) CreatePaymentAndReturnSignature(ctx context.Context, tar } func (w *StellarWallet) CreatePaymentWithSignaturesAndSubmit(ctx context.Context, target string, amount uint64, txHash string, signatures []substrate.StellarSignature, sequenceNumber int64) error { - ctx_with_trace_id := context.WithValue(ctx, "trace_id", txHash) + ctx_with_trace_id := context.WithValue(ctx, TraceIdKey{}, txHash) txnBuild, err := w.generatePaymentOperation(amount, target, sequenceNumber) if err != nil { @@ -122,7 +124,7 @@ func (w *StellarWallet) CreatePaymentWithSignaturesAndSubmit(ctx context.Context } func (w *StellarWallet) CreateRefundPaymentWithSignaturesAndSubmit(ctx context.Context, target string, amount uint64, txHash string, signatures []substrate.StellarSignature, sequenceNumber int64) error { - ctx_with_trace_id := context.WithValue(ctx, "trace_id", txHash) + ctx_with_trace_id := context.WithValue(ctx, TraceIdKey{}, txHash) txnBuild, err := w.generatePaymentOperation(amount, target, sequenceNumber) if err != nil { return err