Skip to content

Commit

Permalink
Merge branch 'stan/78-cmd' of https://github.com/gonative-cc/relayer
Browse files Browse the repository at this point in the history
…into stan/78-cmd
  • Loading branch information
sczembor committed Jan 14, 2025
2 parents 0f917f0 + bec097c commit 3d0ec15
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
9 changes: 9 additions & 0 deletions bitcoin/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bitcoin

import "errors"

// ErrNoBtcConfig is returned when the btc config is missing.
var ErrNoBtcConfig = errors.New("missing bitcoin node configuration")

// ErrNoNativeProcessor is returned when the btcProcessor is nil.
var ErrNoBtcProcessor = errors.New("btcProcessor cannot be nil")
6 changes: 6 additions & 0 deletions dal/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dal

import "errors"

// ErrNoDB is returned when the database is nil.
var ErrNoDB = errors.New("database cannot be nil")
18 changes: 0 additions & 18 deletions errors/errors.go

This file was deleted.

8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ require (
github.com/joho/godotenv v1.5.1
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/tinylib/msgp v1.2.5
golang.org/x/sync v0.10.0
google.golang.org/grpc v1.69.2
google.golang.org/grpc v1.69.4

// cosmossdk.io/api v0.7.5
// github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
// github.com/cosmos/cosmos-sdk v0.52.0-beta.1
)

require (
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
github.com/tinylib/msgp v1.2.5 // indirect
)
require github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect

require (
cosmossdk.io/api v0.7.6 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -956,8 +956,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1002,8 +1002,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
5 changes: 2 additions & 3 deletions ika2btc/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/errors"
"github.com/rs/zerolog/log"
)

Expand All @@ -29,11 +28,11 @@ func NewProcessor(
) (*Processor, error) {

if db == nil {
return nil, errors.ErrNoDB
return nil, dal.ErrNoDB
}

if btcClientConfig.Host == "" || btcClientConfig.User == "" || btcClientConfig.Pass == "" {
return nil, errors.ErrNoBtcConfig
return nil, bitcoin.ErrNoBtcConfig
}

client, err := rpcclient.New(&btcClientConfig, nil)
Expand Down
5 changes: 2 additions & 3 deletions ika2btc/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/dal/daltest"
"github.com/gonative-cc/relayer/errors"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -43,14 +42,14 @@ func TestCheckConfirmations(t *testing.T) {
func TestNewProcessor(t *testing.T) {
// missing db
processor, err := NewProcessor(btcClientConfig, 6, nil)
assert.ErrorIs(t, err, errors.ErrNoDB)
assert.ErrorIs(t, err, dal.ErrNoDB)
assert.Assert(t, processor == nil)

// missing BTC config
db := daltest.InitTestDB(t)
btcClientConfig.Host = ""
processor, err = NewProcessor(btcClientConfig, 6, db)
assert.ErrorIs(t, err, errors.ErrNoBtcConfig)
assert.ErrorIs(t, err, bitcoin.ErrNoBtcConfig)
assert.Assert(t, processor == nil)
}

Expand Down
9 changes: 9 additions & 0 deletions native/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package native

import "errors"

// ErrNoFetcher is returned when the fetcher is nil.
var ErrNoFetcher = errors.New("sign requests fetcher cannot be nil")

// ErrNoNativeProcessor is returned when the nativeProcessor is nil.
var ErrNoNativeProcessor = errors.New("nativeProcessor cannot be nil")
10 changes: 5 additions & 5 deletions nbtc/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"time"

"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
err "github.com/gonative-cc/relayer/errors"
"github.com/gonative-cc/relayer/ika2btc"
"github.com/gonative-cc/relayer/native"
"github.com/gonative-cc/relayer/native2ika"
Expand Down Expand Up @@ -54,19 +54,19 @@ func NewRelayer(
) (*Relayer, error) {

if db == nil {
return nil, err.ErrNoDB
return nil, dal.ErrNoDB
}

if nativeProcessor == nil {
return nil, err.ErrNoNativeProcessor
return nil, native.ErrNoNativeProcessor
}

if btcProcessor == nil {
return nil, err.ErrNoBtcProcessor
return nil, bitcoin.ErrNoBtcProcessor
}

if fetcher == nil {
return nil, err.ErrNoFetcher
return nil, native.ErrNoFetcher
}

if relayerConfig.ProcessTxsInterval == 0 {
Expand Down
9 changes: 4 additions & 5 deletions nbtc/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/dal/daltest"
err "github.com/gonative-cc/relayer/errors"
"github.com/gonative-cc/relayer/ika"
"github.com/gonative-cc/relayer/ika2btc"
"github.com/gonative-cc/relayer/native"
Expand Down Expand Up @@ -106,31 +105,31 @@ func TestNewRelayer_ErrorCases(t *testing.T) {
db: nil,
nativeProcessor: ts.nativeProcessor,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoDB,
expectedError: dal.ErrNoDB,
fetcher: ts.signReqFetcher,
},
{
name: "NativeProcessorError",
db: ts.db,
nativeProcessor: nil,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoNativeProcessor,
expectedError: native.ErrNoNativeProcessor,
fetcher: ts.signReqFetcher,
},
{
name: "BtcProcessorError",
db: ts.db,
nativeProcessor: ts.nativeProcessor,
btcProcessor: nil,
expectedError: err.ErrNoBtcProcessor,
expectedError: bitcoin.ErrNoBtcProcessor,
fetcher: ts.signReqFetcher,
},
{
name: "BlockchainError",
db: ts.db,
nativeProcessor: ts.nativeProcessor,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoFetcher,
expectedError: native.ErrNoFetcher,
fetcher: nil,
},
}
Expand Down

0 comments on commit 3d0ec15

Please sign in to comment.