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

Commit

Permalink
Removed mattercloud, no longer in service
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jun 6, 2022
1 parent 3aacbe5 commit 942b9d9
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 547 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ This repository was created using [MrZ's `go-template`](https://github.com/mrz18
- [libsv/go-bt](https://github.com/libsv/go-bt)
- [mrz1836/go-cache](https://github.com/mrz1836/go-cache)
- [mrz1836/go-logger](https://github.com/mrz1836/go-logger)
- [mrz1836/go-mattercloud](https://github.com/mrz1836/go-mattercloud)
- [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)
Expand Down
46 changes: 0 additions & 46 deletions chainstate/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,6 @@ func (c *Client) broadcast(ctx context.Context, id, hex string, timeout time.Dur
}
}

// Try next provider: MatterCloud
if !utils.StringInSlice(ProviderMatterCloud, c.options.config.excludedProviders) {
provider = ProviderMatterCloud
if err = broadcastMatterCloud(ctx, c, id, hex); err != nil {

// Check error response for (TX FAILURE)
if doesErrorContain(err.Error(), broadcastQuestionableErrors) {
err = checkInMempool(ctx, c, id, err.Error(), timeout)
return // Success, found in mempool (or on-chain)
}

// Provider error?
errorMessages = storeErrorMessage(c, errorMessages, err.Error(), provider)
} else { // Success!
return
}
}

// Try next provider: WhatsOnChain
if !utils.StringInSlice(ProviderWhatsOnChain, c.options.config.excludedProviders) {
provider = ProviderWhatsOnChain
Expand Down Expand Up @@ -210,34 +192,6 @@ func broadcastMAPI(ctx context.Context, client ClientInterface, miner *minercraf
return errors.New(resp.Results.ResultDescription)
}

// broadcastMatterCloud will broadcast a transaction to MatterCloud
func broadcastMatterCloud(ctx context.Context, client ClientInterface, id, hex string) error {
client.DebugLog("executing broadcast request for " + ProviderMatterCloud)

resp, err := client.MatterCloud().Broadcast(ctx, hex)
if err != nil {

// Check error message (for success error message)
if doesErrorContain(err.Error(), broadcastSuccessErrors) {
return nil
}
return err
}

// Something went wrong - got back an id that does not match
if !strings.EqualFold(resp.Result.TxID, id) {
return errors.New("returned tx id [" + resp.Result.TxID + "] does not match given tx id [" + id + "]")
}

// Success was a failure?
if !resp.Success {
return errors.New("returned response was unsuccessful")
}

// Success
return nil
}

// broadcastWhatsOnChain will broadcast a transaction to WhatsOnChain
func broadcastWhatsOnChain(ctx context.Context, client ClientInterface, id, hex string) error {
client.DebugLog("executing broadcast request for " + ProviderWhatsOnChain)
Expand Down
67 changes: 6 additions & 61 deletions chainstate/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestClient_Broadcast_Success(t *testing.T) {
WithMinercraft(&minerCraftBroadcastSuccess{}),
WithNowNodes(&nowNodesTxNotFound{}), // Not found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
context.Background(), broadcastExample1TxID, broadcastExample1TxHex, defaultBroadcastTimeOut,
Expand All @@ -45,28 +44,12 @@ func TestClient_Broadcast_Success(t *testing.T) {
assert.Equal(t, minercraft.MinerTaal, provider)
})

t.Run("broadcast - success (MatterCloud)", func(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithMatterCloud(&matterCloudBroadcastSuccess{}),
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
context.Background(), broadcastExample1TxID, broadcastExample1TxHex, defaultBroadcastTimeOut,
)
require.NoError(t, err)
assert.Equal(t, ProviderMatterCloud, provider)
})

t.Run("broadcast - success (WhatsOnChain)", func(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithWhatsOnChain(&whatsOnChainBroadcastSuccess{}),
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
context.Background(), broadcastExample1TxID, broadcastExample1TxHex, defaultBroadcastTimeOut,
Expand All @@ -80,7 +63,6 @@ func TestClient_Broadcast_Success(t *testing.T) {
context.Background(), t,
WithNowNodes(&nowNodesBroadcastSuccess{}),
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
Expand All @@ -100,22 +82,6 @@ func TestClient_Broadcast_OnChain(t *testing.T) {
context.Background(), t,
WithMinercraft(&minerCraftTxOnChain{}),
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
context.Background(), onChainExample1TxID, onChainExample1TxHex, defaultBroadcastTimeOut,
)
require.NoError(t, err)
assert.NotEmpty(t, provider)
})

t.Run("broadcast - tx already on-chain (MatterCloud)", func(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithMatterCloud(&matterCloudTxOnChain{}),
WithMinercraft(&minerCraftTxNotFound{}), // Not found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
Expand All @@ -129,9 +95,8 @@ func TestClient_Broadcast_OnChain(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithWhatsOnChain(&whatsOnChainTxOnChain{}),
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
context.Background(), onChainExample1TxID, onChainExample1TxHex, defaultBroadcastTimeOut,
Expand All @@ -145,7 +110,6 @@ func TestClient_Broadcast_OnChain(t *testing.T) {
context.Background(), t,
WithNowNodes(&nowNodesTxOnChain{}),
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
Expand All @@ -164,7 +128,6 @@ func TestClient_Broadcast_InMempool(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithMinercraft(&minerCraftInMempool{}),
WithMatterCloud(&matterCloudTxNotFound{}), // Not found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
)
Expand All @@ -175,28 +138,12 @@ func TestClient_Broadcast_InMempool(t *testing.T) {
assert.NotEmpty(t, provider)
})

t.Run("broadcast - in mempool (MatterCloud)", func(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithMatterCloud(&matterCloudInMempool{}),
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
context.Background(), broadcastExample1TxID, broadcastExample1TxHex, defaultBroadcastTimeOut,
)
require.NoError(t, err)
assert.NotEmpty(t, provider)
})

t.Run("broadcast - in mempool (WhatsOnChain)", func(t *testing.T) {
c := NewTestClient(
context.Background(), t,
WithWhatsOnChain(&whatsOnChainInMempool{}),
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
WithNowNodes(&nowNodesTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not found
)
provider, err := c.Broadcast(
context.Background(), broadcastExample1TxID, broadcastExample1TxHex, defaultBroadcastTimeOut,
Expand All @@ -210,7 +157,6 @@ func TestClient_Broadcast_InMempool(t *testing.T) {
context.Background(), t,
WithNowNodes(&nowNodeInMempool{}),
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
Expand Down Expand Up @@ -250,7 +196,6 @@ func TestClient_Broadcast(t *testing.T) {
context.Background(), t,
WithNowNodes(&nowNodesTxNotFound{}), // Not found
WithWhatsOnChain(&whatsOnChainTxNotFound{}), // Not found
WithMatterCloud(&matterCloudTxNotFound{}), // Not Found
WithMinercraft(&minerCraftTxNotFound{}), // Not Found
)
provider, err := c.Broadcast(
Expand Down
2 changes: 1 addition & 1 deletion chainstate/chainstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 -> MatterCloud -> NowNodes
// Note: this is slow, but follows a specific order: mAPI -> WhatsOnChain -> NowNodes
func (c *Client) QueryTransaction(
ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
) (*TransactionInfo, error) {
Expand Down
20 changes: 1 addition & 19 deletions chainstate/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/BuxOrg/bux/logger"
"github.com/BuxOrg/bux/utils"
"github.com/mrz1836/go-mattercloud"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
Expand All @@ -34,10 +33,8 @@ 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, MatterCloud)
httpClient HTTPInterface // Custom HTTP client (Minercraft, WOC)
mAPI *mAPIConfig // mAPI configuration
matterCloud mattercloud.ClientInterface // MatterCloud client
matterCloudAPIKey string // If set, use this key on the client
minercraft minercraft.ClientInterface // Minercraft client
network Network // Current network (mainnet, testnet, stn)
nowNodes nownodes.ClientInterface // NOWNodes client
Expand Down Expand Up @@ -88,11 +85,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
return nil, err
}

// Start MatterCloud
if err := client.startMatterCloud(ctx); err != nil {
return nil, err
}

// Start WhatsOnChain
client.startWhatsOnChain(ctx)

Expand Down Expand Up @@ -120,11 +112,6 @@ func (c *Client) Close(ctx context.Context) {
c.options.config.whatsOnChain = nil
}

// Close MatterCloud
if c.options.config.matterCloud != nil {
c.options.config.matterCloud = nil
}

// Close NowNodes
if c.options.config.nowNodes != nil {
c.options.config.nowNodes = nil
Expand Down Expand Up @@ -185,11 +172,6 @@ func (c *Client) WhatsOnChain() whatsonchain.ClientInterface {
return c.options.config.whatsOnChain
}

// MatterCloud will return the MatterCloud client
func (c *Client) MatterCloud() mattercloud.ClientInterface {
return c.options.config.matterCloud
}

// NowNodes will return the NowNodes client
func (c *Client) NowNodes() nownodes.ClientInterface {
return c.options.config.nowNodes
Expand Down
33 changes: 0 additions & 33 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-mattercloud"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
Expand Down Expand Up @@ -36,15 +35,6 @@ func (c *Client) defaultWhatsOnChainOptions() (opts *whatsonchain.Options) {
return
}

// defaultMatterCloudOptions will create the defaults
func (c *Client) defaultMatterCloudOptions() (opts *mattercloud.Options) {
opts = mattercloud.ClientDefaultOptions()
if len(c.options.userAgent) > 0 {
opts.UserAgent = c.options.userAgent
}
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 @@ -107,29 +97,6 @@ func (c *Client) startWhatsOnChain(ctx context.Context) {
}
}

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

if c.MatterCloud() == nil {

// go-matter cloud requires a key to load the library
if len(c.options.config.matterCloudAPIKey) == 0 {
c.options.config.matterCloudAPIKey = "your-api-key" // todo: hack for go-mattercloud (wants an api key)
}

c.options.config.matterCloud, err = mattercloud.NewClient(
c.options.config.matterCloudAPIKey,
c.Network().MatterCloud(),
c.defaultMatterCloudOptions(),
c.HTTPClient(),
)
}
return
}

// 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 {
Expand Down
29 changes: 4 additions & 25 deletions chainstate/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/BuxOrg/bux/logger"
"github.com/mrz1836/go-mattercloud"
"github.com/mrz1836/go-nownodes"
"github.com/mrz1836/go-whatsonchain"
"github.com/newrelic/go-agent/v3/newrelic"
Expand All @@ -32,12 +31,10 @@ func defaultClientOptions() *clientOptions {
broadcastMiners: bm,
queryMiners: qm,
},
matterCloud: nil,
matterCloudAPIKey: "",
minercraft: nil,
network: MainNet,
queryTimeout: defaultQueryTimeOut,
whatsOnChain: nil,
minercraft: nil,
network: MainNet,
queryTimeout: defaultQueryTimeOut,
whatsOnChain: nil,
},
debug: false,
newRelicEnabled: false,
Expand Down Expand Up @@ -124,15 +121,6 @@ func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps {
}
}

// WithMatterCloud will set a custom MatterCloud client
func WithMatterCloud(client mattercloud.ClientInterface) ClientOps {
return func(c *clientOptions) {
if client != nil {
c.config.matterCloud = client
}
}
}

// WithNowNodes will set a custom NowNodes client
func WithNowNodes(client nownodes.ClientInterface) ClientOps {
return func(c *clientOptions) {
Expand All @@ -151,15 +139,6 @@ func WithNowNodesAPIKey(apiKey string) ClientOps {
}
}

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

// WithWhatsOnChainAPIKey will set a custom WhatsOnChain API key
func WithWhatsOnChainAPIKey(apiKey string) ClientOps {
return func(c *clientOptions) {
Expand Down
Loading

0 comments on commit 942b9d9

Please sign in to comment.