Skip to content

Commit

Permalink
refactor: Make SourceHub dep internal-only (#2963)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2962

## Description

I was mostly curious if this will make the vuln checker go green (it
doesn't, it just reports it from our internal acp package now), but it
is a good change anyway IMO to avoid embedded Go client users from
having to directly import the dependency.
  • Loading branch information
AndrewSisley authored Aug 26, 2024
1 parent af15a33 commit d5b034f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"syscall"

"github.com/sourcenetwork/immutable"
"github.com/sourcenetwork/sourcehub/sdk"
"github.com/spf13/cobra"

"github.com/sourcenetwork/defradb/errors"
Expand Down Expand Up @@ -101,7 +100,7 @@ func MakeStartCommand() *cobra.Command {
if err != nil {
return err
}
opts = append(opts, node.WithTxnSigner(immutable.Some[sdk.TxSigner](signer)))
opts = append(opts, node.WithTxnSigner(immutable.Some[node.TxSigner](signer)))
}
}

Expand Down
5 changes: 3 additions & 2 deletions keyring/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/sourcenetwork/sourcehub/sdk"

"github.com/sourcenetwork/defradb/node"
)

type txnSigner struct {
Expand All @@ -25,7 +26,7 @@ type txnSigner struct {
accAddress string
}

var _ sdk.TxSigner = (*txnSigner)(nil)
var _ node.TxSigner = (*txnSigner)(nil)

// NewTxSignerFromKeyringKey creates a new TxSigner backed by a keyring.
//
Expand Down
15 changes: 12 additions & 3 deletions node/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ package node
import (
"context"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/sourcenetwork/immutable"
"github.com/sourcenetwork/sourcehub/sdk"

"github.com/sourcenetwork/defradb/acp"
)
Expand All @@ -36,12 +36,21 @@ type ACPOptions struct {
// This is only used for local acp.
path string

signer immutable.Option[sdk.TxSigner]
signer immutable.Option[TxSigner]
sourceHubChainID string
sourceHubGRPCAddress string
sourceHubCometRPCAddress string
}

// TxSigner models an entity capable of providing signatures for a Tx.
//
// Effectively, it can be either a secp256k1 cosmos-sdk key or a pointer to a
// secp256k1 key in a cosmos-sdk like keyring.
type TxSigner interface {
GetAccAddress() string
GetPrivateKey() cryptotypes.PrivKey
}

// DefaultACPOptions returns new options with default values.
func DefaultACPOptions() *ACPOptions {
return &ACPOptions{
Expand Down Expand Up @@ -71,7 +80,7 @@ func WithACPPath(path string) ACPOpt {
// WithKeyring sets the txn signer for Defra to use.
//
// It is only required when SourceHub ACP is active.
func WithTxnSigner(signer immutable.Option[sdk.TxSigner]) ACPOpt {
func WithTxnSigner(signer immutable.Option[TxSigner]) ACPOpt {
return func(o *ACPOptions) {
o.signer = signer
}
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/decred/dcrd/dcrec/secp256k1/v4"
toml "github.com/pelletier/go-toml"
"github.com/sourcenetwork/immutable"
"github.com/sourcenetwork/sourcehub/sdk"
"github.com/stretchr/testify/require"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
Expand Down Expand Up @@ -352,7 +351,7 @@ cmdReaderLoop:
}

return []node.ACPOpt{
node.WithTxnSigner(immutable.Some[sdk.TxSigner](signer)),
node.WithTxnSigner(immutable.Some[node.TxSigner](signer)),
node.WithSourceHubChainID(chainID),
node.WithSourceHubGRPCAddress(gRpcAddress),
node.WithSourceHubCometRPCAddress(rpcAddress),
Expand Down

0 comments on commit d5b034f

Please sign in to comment.