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 #401 from BuxOrg/feat-rm-woc-ref
Browse files Browse the repository at this point in the history
feat(BUX-182): remove go-whatsonchain refs
  • Loading branch information
arkadiuszos4chain authored Sep 19, 2023
2 parents a4ff02d + 5b54a8c commit 56df9d9
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 151 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ This repository was created using [MrZ's `go-template`](https://github.com/mrz18
- [mrz1836/go-cachestore](https://github.com/mrz1836/go-cachestore)
- [mrz1836/go-datastore](https://github.com/mrz1836/go-datastore)
- [mrz1836/go-logger](https://github.com/mrz1836/go-logger)
- [mrz1836/go-nownodes](https://github.com/mrz1836/go-nownodes)
- [mrz1836/go-whatsonchain](https://github.com/mrz1836/go-whatsonchain)
- [newrelic/go-agent](https://github.com/newrelic/go-agent)
- [robfig/cron](https://github.com/robfig/cron)
- [stretchr/testify](https://github.com/stretchr/testify)
Expand Down
32 changes: 8 additions & 24 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-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
"github.com/tonicpow/go-minercraft/v2/apis/mapi"
Expand All @@ -36,16 +35,14 @@ type (

// syncConfig holds all the configuration about the different sync processes
syncConfig struct {
excludedProviders []string // List of provider names
httpClient HTTPInterface // Custom HTTP client (Minercraft, WOC)
minercraftConfig *minercraftConfig // minercraftConfig configuration
minercraft minercraft.ClientInterface // Minercraft client
network Network // Current network (mainnet, testnet, stn)
queryTimeout time.Duration // Timeout for transaction query
whatsOnChain whatsonchain.ClientInterface // WhatsOnChain client
whatsOnChainAPIKey string // If set, use this key
broadcastClient broadcast.Client // Broadcast client
broadcastClientConfig *broadcastClientConfig // Broadcast client config
excludedProviders []string // List of provider names
httpClient HTTPInterface // Custom HTTP client (Minercraft, WOC)
minercraftConfig *minercraftConfig // minercraftConfig configuration
minercraft minercraft.ClientInterface // Minercraft client
network Network // Current network (mainnet, testnet, stn)
queryTimeout time.Duration // Timeout for transaction query
broadcastClient broadcast.Client // Broadcast client
broadcastClientConfig *broadcastClientConfig // Broadcast client config
}

// minercraftConfig is specific for minercraft configuration
Expand Down Expand Up @@ -98,9 +95,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
return nil, err
}

// Start WhatsOnChain
client.startWhatsOnChain(ctx)

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

// Close WhatsOnChain
if c.options.config.whatsOnChain != nil {
c.options.config.whatsOnChain = nil
}

// Stop the active Monitor (if not already stopped)
if c.options.monitor != nil {
_ = c.options.monitor.Stop(ctx)
Expand Down Expand Up @@ -172,11 +161,6 @@ func (c *Client) Monitor() MonitorService {
return c.options.monitor
}

// WhatsOnChain will return the WhatsOnChain client
func (c *Client) WhatsOnChain() whatsonchain.ClientInterface {
return c.options.config.whatsOnChain
}

// BroadcastClient will return the BroadcastClient client
func (c *Client) BroadcastClient() broadcast.Client {
return c.options.config.broadcastClient
Expand Down
32 changes: 0 additions & 32 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-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
)
Expand All @@ -18,22 +17,6 @@ func (c *Client) defaultMinercraftOptions() (opts *minercraft.ClientOptions) {
return
}

// defaultWhatsOnChainOptions will create the defaults
func (c *Client) defaultWhatsOnChainOptions() (opts *whatsonchain.Options) {
opts = whatsonchain.ClientDefaultOptions()
if len(c.options.userAgent) > 0 {
opts.UserAgent = c.options.userAgent
}

// Set a custom API key
// todo: rate limit should be customizable
if len(c.options.config.whatsOnChainAPIKey) > 0 {
opts.APIKey = c.options.config.whatsOnChainAPIKey
opts.RateLimit = whatsOnChainRateLimitWithKey
}
return
}

// startMinerCraft will start Minercraft (if no custom client is found)
func (c *Client) startMinerCraft(ctx context.Context) (err error) {
if txn := newrelic.FromContext(ctx); txn != nil {
Expand Down Expand Up @@ -83,18 +66,3 @@ func (c *Client) startMinerCraft(ctx context.Context) (err error) {

return nil
}

// startWhatsOnChain will start WhatsOnChain (if no custom client is found)
func (c *Client) startWhatsOnChain(ctx context.Context) {
if txn := newrelic.FromContext(ctx); txn != nil {
defer txn.StartSegment("start_whatsonchain").End()
}

if c.WhatsOnChain() == nil {
c.options.config.whatsOnChain = whatsonchain.NewClient(
c.Network().WhatsOnChain(),
c.defaultWhatsOnChainOptions(),
c.HTTPClient(),
)
}
}
11 changes: 0 additions & 11 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-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
"github.com/tonicpow/go-minercraft/v2"
)
Expand Down Expand Up @@ -39,7 +38,6 @@ func defaultClientOptions() *clientOptions {
minercraft: nil,
network: MainNet,
queryTimeout: defaultQueryTimeOut,
whatsOnChain: nil,
broadcastClient: nil,
broadcastClientConfig: &broadcastClientConfig{
BroadcastClientApis: nil,
Expand Down Expand Up @@ -134,15 +132,6 @@ func WithArc() ClientOps {
}
}

// WithWhatsOnChain will set a custom WhatsOnChain client
func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps {
return func(c *clientOptions) {
if client != nil {
c.config.whatsOnChain = client
}
}
}

// WithBroadcastMiners will set a list of miners for broadcasting
func WithBroadcastMiners(miners []*Miner) ClientOps {
return func(c *clientOptions) {
Expand Down
19 changes: 0 additions & 19 deletions chainstate/client_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,6 @@ func TestWithMinercraft(t *testing.T) {
})
}

// TestWithWhatsOnChain will test the method WithWhatsOnChain()
func TestWithWhatsOnChain(t *testing.T) {
t.Parallel()

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

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

// TestWithBroadcastMiners will test the method WithBroadcastMiners()
func TestWithBroadcastMiners(t *testing.T) {
t.Parallel()
Expand Down
18 changes: 0 additions & 18 deletions chainstate/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/mrz1836/go-whatsonchain"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tonicpow/go-minercraft/v2"
Expand All @@ -26,7 +25,6 @@ func TestNewClient(t *testing.T) {
assert.Equal(t, false, c.IsDebug())
assert.Equal(t, MainNet, c.Network())
assert.Nil(t, c.HTTPClient())
assert.NotNil(t, c.WhatsOnChain())
assert.NotNil(t, c.Minercraft())
})

Expand All @@ -43,22 +41,6 @@ func TestNewClient(t *testing.T) {
assert.Equal(t, customClient, c.HTTPClient())
})

t.Run("custom whatsonchain client", func(t *testing.T) {
customClient := whatsonchain.NewClient(
MainNet.WhatsOnChain(), whatsonchain.ClientDefaultOptions(), nil,
)
require.NotNil(t, customClient)
c, err := NewClient(
context.Background(),
WithWhatsOnChain(customClient),
WithMinercraft(&MinerCraftBase{}),
)
require.NoError(t, err)
require.NotNil(t, c)
assert.NotNil(t, c.WhatsOnChain())
assert.Equal(t, customClient, c.WhatsOnChain())
})

t.Run("custom minercraft client", func(t *testing.T) {
customClient, err := minercraft.NewClient(
minercraft.DefaultClientOptions(), nil, "", nil, nil,
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-whatsonchain"
"github.com/tonicpow/go-minercraft/v2"
)

Expand Down Expand Up @@ -38,7 +37,6 @@ type ChainService interface {
// ProviderServices is the chainstate providers interface
type ProviderServices interface {
Minercraft() minercraft.ClientInterface
WhatsOnChain() whatsonchain.ClientInterface
BroadcastClient() broadcast.Client
}

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

import (
"github.com/mrz1836/go-whatsonchain"
)

// Network is the supported Bitcoin networks
type Network string

Expand All @@ -19,20 +15,6 @@ func (n Network) String() string {
return string(n)
}

// WhatsOnChain will return the WhatsOnChain network type
func (n Network) WhatsOnChain() whatsonchain.NetworkType {
switch n {
case MainNet:
return whatsonchain.NetworkMain
case TestNet:
return whatsonchain.NetworkTest
case StressTestNet:
return whatsonchain.NetworkStn
default:
return whatsonchain.NetworkMain // Default if none is found, return main
}
}

// Alternate is the alternate string version
func (n Network) Alternate() string {
switch n {
Expand Down
17 changes: 0 additions & 17 deletions chainstate/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chainstate
import (
"testing"

"github.com/mrz1836/go-whatsonchain"
"github.com/stretchr/testify/assert"
)

Expand All @@ -23,22 +22,6 @@ func TestNetwork_String(t *testing.T) {
})
}

// TestNetwork_WhatsOnChain will test the method WhatsOnChain()
func TestNetwork_WhatsOnChain(t *testing.T) {
t.Parallel()

t.Run("test all networks", func(t *testing.T) {
assert.Equal(t, whatsonchain.NetworkMain, MainNet.WhatsOnChain())
assert.Equal(t, whatsonchain.NetworkStn, StressTestNet.WhatsOnChain())
assert.Equal(t, whatsonchain.NetworkTest, TestNet.WhatsOnChain())
})

t.Run("unknown network", func(t *testing.T) {
un := Network("")
assert.Equal(t, whatsonchain.NetworkMain, un.WhatsOnChain())
})
}

// TestNetwork_Alternate will test the method Alternate()
func TestNetwork_Alternate(t *testing.T) {
t.Parallel()
Expand Down
1 change: 0 additions & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions mock_chainstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/utils"
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
"github.com/mrz1836/go-whatsonchain"
"github.com/tonicpow/go-minercraft/v2"
)

Expand Down Expand Up @@ -71,10 +70,6 @@ func (c *chainStateBase) QueryTimeout() time.Duration {
return 10 * time.Second
}

func (c *chainStateBase) WhatsOnChain() whatsonchain.ClientInterface {
return nil
}

func (c *chainStateBase) ValidateMiners(_ context.Context) {}

type chainStateEverythingInMempool struct {
Expand Down

0 comments on commit 56df9d9

Please sign in to comment.