Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #391 from BuxOrg/feat/delete-nownodes
Browse files Browse the repository at this point in the history
feat(BUX-221): remove go-nownodes from dependencies
  • Loading branch information
mergify[bot] authored Sep 18, 2023
2 parents e809ee7 + 292e454 commit 987f698
Show file tree
Hide file tree
Showing 16 changed files with 4 additions and 390 deletions.
2 changes: 1 addition & 1 deletion chainstate/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func shouldBroadcastWithMAPI(c *Client) bool {

func shouldBroadcastWithBroadcastClient(c *Client) bool {
return !utils.StringInSlice(ProviderBroadcastClient, c.options.config.excludedProviders) &&
c.BroadcastClient() != nil // Only if NowNodes is loaded (requires API key)
c.BroadcastClient() != nil
}

func broadcastToProvider(ctx, fallbackCtx context.Context, provider txBroadcastProvider, txID string,
Expand Down
1 change: 0 additions & 1 deletion chainstate/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestClient_Broadcast_Success(t *testing.T) {
assert.True(t, containsAtLeastOneElement(miners, minercraft.MinerTaal, minercraft.MinerMempool, minercraft.MinerGorillaPool, minercraft.MinerMatterpool))

assert.NotContains(t, miners, ProviderWhatsOnChain)
assert.NotContains(t, miners, ProviderNowNodes)
})
}

Expand Down
2 changes: 1 addition & 1 deletion chainstate/chainstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Client) Broadcast(ctx context.Context, id, txHex string, timeout time.D

// QueryTransaction will get the transaction info from all providers returning the "first" valid result
//
// Note: this is slow, but follows a specific order: mAPI -> WhatsOnChain -> NowNodes
// Note: this is slow, but follows a specific order: mAPI -> WhatsOnChain
func (c *Client) QueryTransaction(
ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
) (*TransactionInfo, error) {
Expand Down
16 changes: 0 additions & 16 deletions chainstate/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
broadcastClient "github.com/bitcoin-sv/go-broadcast-client/broadcast/broadcast-client"
"github.com/libsv/go-bt/v2"
zLogger "github.com/mrz1836/go-logger"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
Expand Down Expand Up @@ -42,8 +41,6 @@ type (
minercraftConfig *minercraftConfig // minercraftConfig configuration
minercraft minercraft.ClientInterface // Minercraft client
network Network // Current network (mainnet, testnet, stn)
nowNodes nownodes.ClientInterface // NOWNodes client
nowNodesAPIKey string // If set, use this key
queryTimeout time.Duration // Timeout for transaction query
whatsOnChain whatsonchain.ClientInterface // WhatsOnChain client
whatsOnChainAPIKey string // If set, use this key
Expand Down Expand Up @@ -104,9 +101,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
// Start WhatsOnChain
client.startWhatsOnChain(ctx)

// Start NowNodes
client.startNowNodes(ctx)

// Return the client
return client, nil
}
Expand All @@ -128,11 +122,6 @@ func (c *Client) Close(ctx context.Context) {
c.options.config.whatsOnChain = nil
}

// Close NowNodes
if c.options.config.nowNodes != nil {
c.options.config.nowNodes = nil
}

// Stop the active Monitor (if not already stopped)
if c.options.monitor != nil {
_ = c.options.monitor.Stop(ctx)
Expand Down Expand Up @@ -188,11 +177,6 @@ func (c *Client) WhatsOnChain() whatsonchain.ClientInterface {
return c.options.config.whatsOnChain
}

// NowNodes will return the NowNodes client
func (c *Client) NowNodes() nownodes.ClientInterface {
return c.options.config.nowNodes
}

// BroadcastClient will return the BroadcastClient client
func (c *Client) BroadcastClient() broadcast.Client {
return c.options.config.broadcastClient
Expand Down
15 changes: 0 additions & 15 deletions chainstate/client_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/BuxOrg/bux/utils"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
Expand Down Expand Up @@ -99,17 +98,3 @@ func (c *Client) startWhatsOnChain(ctx context.Context) {
)
}
}

// startNowNodes will start NowNodes if API key is set (if no custom client is found)
func (c *Client) startNowNodes(ctx context.Context) {
if txn := newrelic.FromContext(ctx); txn != nil {
defer txn.StartSegment("start_nownodes").End()
}

if c.NowNodes() == nil && len(c.options.config.nowNodesAPIKey) > 0 {
c.options.config.nowNodes = nownodes.NewClient(
nownodes.WithAPIKey(c.options.config.nowNodesAPIKey),
nownodes.WithHTTPClient(c.HTTPClient()),
)
}
}
19 changes: 0 additions & 19 deletions chainstate/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
broadcastClient "github.com/bitcoin-sv/go-broadcast-client/broadcast/broadcast-client"
zLogger "github.com/mrz1836/go-logger"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
Expand Down Expand Up @@ -144,24 +143,6 @@ func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps {
}
}

// WithNowNodes will set a custom NowNodes client
func WithNowNodes(client nownodes.ClientInterface) ClientOps {
return func(c *clientOptions) {
if client != nil {
c.config.nowNodes = client
}
}
}

// WithNowNodesAPIKey will set a custom NowNodes API key
func WithNowNodesAPIKey(apiKey string) ClientOps {
return func(c *clientOptions) {
if len(apiKey) > 0 {
c.config.nowNodesAPIKey = apiKey
}
}
}

// WithWhatsOnChainAPIKey will set a custom WhatsOnChain API key
func WithWhatsOnChainAPIKey(apiKey string) ClientOps {
return func(c *clientOptions) {
Expand Down
57 changes: 0 additions & 57 deletions chainstate/client_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,63 +168,6 @@ func TestWithWhatsOnChainAPIKey(t *testing.T) {
})
}

// TestWithNowNodes will test the method WithNowNodes()
func TestWithNowNodes(t *testing.T) {
t.Parallel()

t.Run("check type", func(t *testing.T) {
opt := WithNowNodes(nil)
assert.IsType(t, *new(ClientOps), opt)
})

t.Run("test applying nil", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithNowNodes(nil)
opt(options)
assert.Nil(t, options.config.nowNodes)
})

t.Run("test applying option", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
customClient := &nowNodesTxOnChain{}
opt := WithNowNodes(customClient)
opt(options)
assert.Equal(t, customClient, options.config.nowNodes)
})
}

// TestWithNowNodesAPIKey will test the method WithNowNodesAPIKey()
func TestWithNowNodesAPIKey(t *testing.T) {
t.Parallel()

t.Run("check type", func(t *testing.T) {
opt := WithNowNodesAPIKey("")
assert.IsType(t, *new(ClientOps), opt)
})

t.Run("test applying empty string", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithNowNodesAPIKey("")
opt(options)
assert.Equal(t, "", options.config.nowNodesAPIKey)
})

t.Run("test applying option", func(t *testing.T) {
options := &clientOptions{
config: &syncConfig{},
}
opt := WithNowNodesAPIKey(testDummyKey)
opt(options)
assert.Equal(t, testDummyKey, options.config.nowNodesAPIKey)
})
}

// TestWithBroadcastMiners will test the method WithBroadcastMiners()
func TestWithBroadcastMiners(t *testing.T) {
t.Parallel()
Expand Down
1 change: 0 additions & 1 deletion chainstate/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const (
const (
ProviderAll = "all" // All providers (used for errors etc)
ProviderMAPI = "mapi" // Query & broadcast provider for mAPI (using given miners)
ProviderNowNodes = "nownodes" // Query & broadcast provider for NowNodes
ProviderWhatsOnChain = "whatsonchain" // Query & broadcast provider for WhatsOnChain
ProviderBroadcastClient = "broadcastclient" // Query & broadcast provider for configured miners
)
Expand Down
2 changes: 0 additions & 2 deletions chainstate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
"github.com/centrifugal/centrifuge-go"
"github.com/libsv/go-bc"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/tonicpow/go-minercraft/v2"
)
Expand Down Expand Up @@ -39,7 +38,6 @@ type ChainService interface {
// ProviderServices is the chainstate providers interface
type ProviderServices interface {
Minercraft() minercraft.ClientInterface
NowNodes() nownodes.ClientInterface
WhatsOnChain() whatsonchain.ClientInterface
BroadcastClient() broadcast.Client
}
Expand Down
165 changes: 0 additions & 165 deletions chainstate/mock_nownodes_test.go

This file was deleted.

Loading

0 comments on commit 987f698

Please sign in to comment.