diff --git a/README.md b/README.md index a77508bb..27b62dd1 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/chainstate/broadcast.go b/chainstate/broadcast.go index e286f15f..cae06a57 100644 --- a/chainstate/broadcast.go +++ b/chainstate/broadcast.go @@ -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 @@ -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) diff --git a/chainstate/broadcast_test.go b/chainstate/broadcast_test.go index b2a51fc1..65063769 100644 --- a/chainstate/broadcast_test.go +++ b/chainstate/broadcast_test.go @@ -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, @@ -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, @@ -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( @@ -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( @@ -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, @@ -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( @@ -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 ) @@ -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, @@ -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( @@ -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( diff --git a/chainstate/chainstate.go b/chainstate/chainstate.go index 36b4591a..f814478c 100644 --- a/chainstate/chainstate.go +++ b/chainstate/chainstate.go @@ -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) { diff --git a/chainstate/client.go b/chainstate/client.go index 4878b803..c34f9484 100644 --- a/chainstate/client.go +++ b/chainstate/client.go @@ -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" @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/chainstate/client_internal.go b/chainstate/client_internal.go index a8873721..d8585b04 100644 --- a/chainstate/client_internal.go +++ b/chainstate/client_internal.go @@ -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" @@ -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 { @@ -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 { diff --git a/chainstate/client_options.go b/chainstate/client_options.go index df3be07d..a524802e 100644 --- a/chainstate/client_options.go +++ b/chainstate/client_options.go @@ -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" @@ -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, @@ -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) { @@ -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) { diff --git a/chainstate/client_options_test.go b/chainstate/client_options_test.go index bb998977..91d791a8 100644 --- a/chainstate/client_options_test.go +++ b/chainstate/client_options_test.go @@ -162,63 +162,6 @@ func TestWithWhatsOnChainAPIKey(t *testing.T) { }) } -// TestWithMatterCloud will test the method WithMatterCloud() -func TestWithMatterCloud(t *testing.T) { - t.Parallel() - - t.Run("check type", func(t *testing.T) { - opt := WithMatterCloud(nil) - assert.IsType(t, *new(ClientOps), opt) - }) - - t.Run("test applying nil", func(t *testing.T) { - options := &clientOptions{ - config: &syncConfig{}, - } - opt := WithMatterCloud(nil) - opt(options) - assert.Nil(t, options.config.matterCloud) - }) - - t.Run("test applying option", func(t *testing.T) { - options := &clientOptions{ - config: &syncConfig{}, - } - customClient := &matterCloudTxOnChain{} - opt := WithMatterCloud(customClient) - opt(options) - assert.Equal(t, customClient, options.config.matterCloud) - }) -} - -// TestWithMatterCloudAPIKey will test the method WithMatterCloudAPIKey() -func TestWithMatterCloudAPIKey(t *testing.T) { - t.Parallel() - - t.Run("check type", func(t *testing.T) { - opt := WithMatterCloudAPIKey("") - assert.IsType(t, *new(ClientOps), opt) - }) - - t.Run("test applying empty string", func(t *testing.T) { - options := &clientOptions{ - config: &syncConfig{}, - } - opt := WithMatterCloudAPIKey("") - opt(options) - assert.Equal(t, "", options.config.matterCloudAPIKey) - }) - - t.Run("test applying option", func(t *testing.T) { - options := &clientOptions{ - config: &syncConfig{}, - } - opt := WithMatterCloudAPIKey(testDummyKey) - opt(options) - assert.Equal(t, testDummyKey, options.config.matterCloudAPIKey) - }) -} - // TestWithNowNodes will test the method WithNowNodes() func TestWithNowNodes(t *testing.T) { t.Parallel() diff --git a/chainstate/client_test.go b/chainstate/client_test.go index d11af309..4de12f1f 100644 --- a/chainstate/client_test.go +++ b/chainstate/client_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - "github.com/mrz1836/go-mattercloud" "github.com/mrz1836/go-whatsonchain" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -48,7 +47,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.MatterCloud()) assert.NotNil(t, c.WhatsOnChain()) assert.NotNil(t, c.Minercraft()) }) @@ -80,34 +78,6 @@ func TestNewClient(t *testing.T) { assert.Equal(t, customClient, c.WhatsOnChain()) }) - t.Run("custom mattercloud client", func(t *testing.T) { - customClient, err := mattercloud.NewClient( - testDummyKey, MainNet.MatterCloud(), mattercloud.ClientDefaultOptions(), nil, - ) - require.NoError(t, err) - require.NotNil(t, customClient) - - var c ClientInterface - c, err = NewClient( - context.Background(), - WithMatterCloud(customClient), - ) - require.NoError(t, err) - require.NotNil(t, c) - assert.NotNil(t, c.MatterCloud()) - assert.Equal(t, customClient, c.MatterCloud()) - }) - - t.Run("custom matter cloud api key", func(t *testing.T) { - c, err := NewClient( - context.Background(), - WithMatterCloudAPIKey(testDummyKey), - ) - require.NoError(t, err) - require.NotNil(t, c) - assert.NotNil(t, c.MatterCloud()) - }) - t.Run("custom whats on chain api key", func(t *testing.T) { c, err := NewClient( context.Background(), diff --git a/chainstate/definitions.go b/chainstate/definitions.go index e3db6845..da2bccab 100644 --- a/chainstate/definitions.go +++ b/chainstate/definitions.go @@ -46,7 +46,6 @@ const ( const ( ProviderAll = "all" // All providers (used for errors etc) ProviderMAPI = "mapi" // Query & broadcast provider for mAPI (using given miners) - ProviderMatterCloud = "mattercloud" // Query & broadcast provider for MatterCloud ProviderNowNodes = "nownodes" // Query & broadcast provider for NowNodes ProviderWhatsOnChain = "whatsonchain" // Query & broadcast provider for WhatsOnChain ) diff --git a/chainstate/interface.go b/chainstate/interface.go index 8c49ea39..f4313a90 100644 --- a/chainstate/interface.go +++ b/chainstate/interface.go @@ -7,7 +7,6 @@ import ( "github.com/centrifugal/centrifuge-go" "github.com/libsv/go-bc" - "github.com/mrz1836/go-mattercloud" "github.com/mrz1836/go-nownodes" "github.com/mrz1836/go-whatsonchain" "github.com/tonicpow/go-minercraft" @@ -37,7 +36,6 @@ type ChainService interface { // ProviderServices is the chainstate providers interface type ProviderServices interface { - MatterCloud() mattercloud.ClientInterface Minercraft() minercraft.ClientInterface NowNodes() nownodes.ClientInterface WhatsOnChain() whatsonchain.ClientInterface diff --git a/chainstate/mock_mattercloud_test.go b/chainstate/mock_mattercloud_test.go deleted file mode 100644 index c6f5b98e..00000000 --- a/chainstate/mock_mattercloud_test.go +++ /dev/null @@ -1,163 +0,0 @@ -package chainstate - -import ( - "context" - "errors" - - "github.com/libsv/go-bt/v2" - "github.com/mrz1836/go-mattercloud" -) - -type matterCloudBase struct{} - -func (mt *matterCloudBase) Network() mattercloud.NetworkType { - return mattercloud.NetworkMain -} - -func (mt *matterCloudBase) AddressBalance(context.Context, string) (balance *mattercloud.Balance, err error) { - return -} - -func (mt *matterCloudBase) AddressBalanceBatch(context.Context, []string) (balances []*mattercloud.Balance, err error) { - return -} - -func (mt *matterCloudBase) AddressHistory(context.Context, string) (history *mattercloud.History, err error) { - return -} - -func (mt *matterCloudBase) AddressHistoryBatch(context.Context, []string) (history *mattercloud.History, err error) { - return -} - -func (mt *matterCloudBase) AddressUtxos(context.Context, string) (utxos []*mattercloud.UnspentTransaction, err error) { - return -} - -func (mt *matterCloudBase) AddressUtxosBatch(context.Context, []string) (utxos []*mattercloud.UnspentTransaction, err error) { - return -} - -func (mt *matterCloudBase) Broadcast(context.Context, string) (response *mattercloud.BroadcastResponse, err error) { - return -} - -func (mt *matterCloudBase) Transaction(context.Context, string) (transaction *mattercloud.Transaction, err error) { - return -} - -func (mt *matterCloudBase) TransactionBatch(context.Context, []string) (transactions []*mattercloud.Transaction, err error) { - return -} - -func (mt *matterCloudBase) Request(context.Context, string, string, []byte) (response string, err error) { - return -} - -type matterCloudTxOnChain struct { - matterCloudBase -} - -func (mt *matterCloudTxOnChain) Broadcast(context.Context, string) (*mattercloud.BroadcastResponse, error) { - /* - { - "success": false, - "code": 500, - "error": "GENERAL_ERROR: ERROR: Missing inputs", - "message": "GENERAL_ERROR: ERROR: Missing inputs" - } - */ - return nil, errors.New("GENERAL_ERROR: ERROR: Missing inputs") -} - -func (mt *matterCloudTxOnChain) Transaction(_ context.Context, - tx string) (transaction *mattercloud.Transaction, err error) { - - if tx == onChainExample1TxID { - transaction = &mattercloud.Transaction{ - BlockHash: onChainExample1BlockHash, - BlockHeight: onChainExample1BlockHeight, - BlockTime: 1642777896, - Confirmations: onChainExample1Confirmations, - Fees: 0.00000443, - Hash: onChainExample1TxID, - LockTime: 0, - RawTx: "01000000025b7439a0c9effa3f19d0e441d2eea596e44a8c49240b6e389c29498285f92ad3010000006a4730440" + - "220482c1c896678d7307e1de35cef2aae4907f2684617a26d8abd24c444d527c80d02204c550f8f9d69b9cf65780e2e0660417" + - "50261702639d02605a2eb694ade4ca1d64121029ce7958b2aa3c627334f50bb810c678e2b284db0ef6f7d067f7fccfa05d0f09" + - "5ffffffff1998b0e4955e1d8ba976d943c43f32e143ba90e805f0e882d3b8edc0f7473b77020000006a47304402204beb486e5" + - "d99a15d4d2267e328abb5466a05fdc20d64903d0ace1c4fabb71a34022024803ae9e18b3c11683b2ff2b5fb4ca973a22fdd390" + - "f6ab1f99396604a3f06af4121038ea0f258fb838b5193e9739ddd808bb97aaab52a60ba8a83958b13109ab183ccffffffff030" + - "000000000000000fd8901006a0372756e0105004d7d017b22696e223a312c22726566223a5b226538643931343037646434616" + - "461643633663337393530323038613835326535623063343830373335636562353461336533343335393461633138396163316" + - "25f6f31222c2237613534646232616230303030616130303531613438323034316233613565376163623938633336313536386" + - "3623334393063666564623066653161356438385f6f33225d2c226f7574223a5b2233356463303036313539393333623438353" + - "433343565663663633363366261663165666462353263343837313933386632366539313034343632313562343036225d2c226" + - "4656c223a5b5d2c22637265223a5b5d2c2265786563223a5b7b226f70223a2243414c4c222c2264617461223a5b7b22246a696" + - "7223a307d2c22757064617465222c5b7b22246a6967223a317d2c7b2267726164756174696f6e506f736974696f6e223a6e756" + - "c6c2c226c6576656c223a382c226e616d65223a22e38395e383abe38380222c227870223a373030307d5d5d7d5d7d110100000" + - "00000001976a914058cae340a2ef8fd2b43a074b75fb6b38cb2765788acd4020000000000001976a914160381a3811b474ff77" + - "f31f64f4e57a5bb5ebf1788ac00000000", - Size: 776, - Time: 1642777896, - TxID: onChainExample1TxID, - ValueIn: 0.0000144, - ValueOut: 0.00000997, - Version: 1, - // NOTE: no vin / vout since they are not being used - } - } - - return -} - -type matterCloudBroadcastSuccess struct { - matterCloudBase -} - -func (mt *matterCloudBroadcastSuccess) Broadcast(_ context.Context, hex string) (*mattercloud.BroadcastResponse, error) { - tx, err := bt.NewTxFromString(hex) - if err != nil { - return nil, err - } - - return &mattercloud.BroadcastResponse{ - Success: true, - Result: &mattercloud.BroadcastResult{TxID: tx.TxID()}, - }, nil -} - -type matterCloudInMempool struct { - matterCloudBase -} - -func (mt *matterCloudInMempool) Broadcast(_ context.Context, hex string) (*mattercloud.BroadcastResponse, error) { - /*{ - "success": false, - "code": 422, - "error": "TXN-ALREADY-KNOWN", - "message": "TXN-ALREADY-KNOWN" - }*/ - return nil, errors.New("TXN-ALREADY-KNOWN") -} - -type matterCloudTxNotFound struct { - matterCloudBase -} - -func (mt *matterCloudTxNotFound) Transaction(context.Context, - string) (transaction *mattercloud.Transaction, err error) { - return nil, errors.New("unexpected error occurred") -} - -func (mt *matterCloudTxNotFound) Broadcast(context.Context, string) (*mattercloud.BroadcastResponse, error) { - /* - { - "success": false, - "code": 500, - "error": "GENERAL_ERROR: ERROR: Missing inputs", - "message": "GENERAL_ERROR: ERROR: Missing inputs" - } - */ - return nil, errors.New("GENERAL_ERROR: ERROR: Mempool conflict") -} diff --git a/chainstate/network.go b/chainstate/network.go index e9e7877d..e11e78e2 100644 --- a/chainstate/network.go +++ b/chainstate/network.go @@ -1,7 +1,6 @@ package chainstate import ( - "github.com/mrz1836/go-mattercloud" "github.com/mrz1836/go-whatsonchain" ) @@ -34,20 +33,6 @@ func (n Network) WhatsOnChain() whatsonchain.NetworkType { } } -// MatterCloud will return the MatterCloud network type -func (n Network) MatterCloud() mattercloud.NetworkType { - switch n { - case MainNet: - return mattercloud.NetworkMain - case TestNet: - return mattercloud.NetworkTest - case StressTestNet: - return mattercloud.NetworkStn - default: - return mattercloud.NetworkMain // Default if none is found, return main - } -} - // Alternate is the alternate string version func (n Network) Alternate() string { switch n { diff --git a/chainstate/network_test.go b/chainstate/network_test.go index 840208a6..f7a30de4 100644 --- a/chainstate/network_test.go +++ b/chainstate/network_test.go @@ -3,7 +3,6 @@ package chainstate import ( "testing" - "github.com/mrz1836/go-mattercloud" "github.com/mrz1836/go-whatsonchain" "github.com/stretchr/testify/assert" ) @@ -40,22 +39,6 @@ func TestNetwork_WhatsOnChain(t *testing.T) { }) } -// TestNetwork_MatterCloud will test the method MatterCloud() -func TestNetwork_MatterCloud(t *testing.T) { - t.Parallel() - - t.Run("test all networks", func(t *testing.T) { - assert.Equal(t, mattercloud.NetworkMain, MainNet.MatterCloud()) - assert.Equal(t, mattercloud.NetworkStn, StressTestNet.MatterCloud()) - assert.Equal(t, mattercloud.NetworkTest, TestNet.MatterCloud()) - }) - - t.Run("unknown network", func(t *testing.T) { - un := Network("") - assert.Equal(t, mattercloud.NetworkMain, un.MatterCloud()) - }) -} - // TestNetwork_Alternate will test the method Alternate() func TestNetwork_Alternate(t *testing.T) { t.Parallel() diff --git a/chainstate/transaction.go b/chainstate/transaction.go index 00fab0b8..f2813335 100644 --- a/chainstate/transaction.go +++ b/chainstate/transaction.go @@ -43,15 +43,6 @@ func (c *Client) query(ctx context.Context, id string, requiredIn RequiredIn, } } - // Next: try MatterCloud - if !utils.StringInSlice(ProviderMatterCloud, c.options.config.excludedProviders) { - if resp, err := queryMatterCloud( - ctxWithCancel, c, id, - ); err == nil && checkRequirement(requiredIn, id, resp) { - return resp - } - } - // Next: try NowNodes (if loaded) if !utils.StringInSlice(ProviderNowNodes, c.options.config.excludedProviders) { if c.NowNodes() != nil && c.Network() == MainNet { @@ -75,7 +66,7 @@ func (c *Client) fastestQuery(ctx context.Context, id string, requiredIn Require resultsChannel := make( chan *TransactionInfo, // len(c.options.config.mAPI.queryMiners)+2, - ) // All miners & WhatsOnChain & MatterCloud + ) // All miners & WhatsOnChain // Create a context (to cancel or timeout) ctxWithCancel, cancel := context.WithTimeout(ctx, timeout) @@ -116,19 +107,6 @@ func (c *Client) fastestQuery(ctx context.Context, id string, requiredIn Require }(ctxWithCancel, c, id, requiredIn) } - // Backup: MatterCloud - if !utils.StringInSlice(ProviderMatterCloud, c.options.config.excludedProviders) { - wg.Add(1) - go func(ctx context.Context, client *Client, id string, requiredIn RequiredIn) { - defer wg.Done() - if resp, err := queryMatterCloud( - ctx, client, id, - ); err == nil && checkRequirement(requiredIn, id, resp) { - resultsChannel <- resp - } - }(ctxWithCancel, c, id, requiredIn) - } - // Backup: NowNodes if !utils.StringInSlice(ProviderNowNodes, c.options.config.excludedProviders) { if c.NowNodes() != nil && c.Network() == MainNet { @@ -191,25 +169,6 @@ func queryWhatsOnChain(ctx context.Context, client ClientInterface, id string) ( return nil, ErrTransactionIDMismatch } -// queryMatterCloud will request MatterCloud for transaction information -func queryMatterCloud(ctx context.Context, client ClientInterface, id string) (*TransactionInfo, error) { - client.DebugLog("executing request in mattercloud") - if resp, err := client.MatterCloud().Transaction(ctx, id); err != nil { - client.DebugLog("error executing request in mattercloud: " + err.Error()) - return nil, err - } else if resp != nil && strings.EqualFold(resp.TxID, id) { - return &TransactionInfo{ - BlockHash: resp.BlockHash, - BlockHeight: resp.BlockHeight, - Confirmations: resp.Confirmations, - ID: resp.TxID, - Provider: ProviderMatterCloud, - MinerID: "", - }, nil - } - return nil, ErrTransactionIDMismatch -} - // queryNowNodes will request NowNodes for transaction information func queryNowNodes(ctx context.Context, client ClientInterface, id string) (*TransactionInfo, error) { client.DebugLog("executing request in nownodes") diff --git a/chainstate/transaction_test.go b/chainstate/transaction_test.go index 8d92d04f..4579810a 100644 --- a/chainstate/transaction_test.go +++ b/chainstate/transaction_test.go @@ -35,12 +35,11 @@ func TestClient_Transaction(t *testing.T) { assert.ErrorIs(t, err, ErrInvalidRequirements) }) - t.Run("valid - all four", func(t *testing.T) { + t.Run("valid - all three", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxOnChain{}), WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNowNodes(&nowNodesTxOnChain{}), ) @@ -58,12 +57,11 @@ func TestClient_Transaction(t *testing.T) { assert.Equal(t, "030d1fe5c1b560efe196ba40540ce9017c20daa9504c4c4cec6184fc702d9f274e", info.MinerID) }) - t.Run("mAPI not found - woc, mattercloud, nownodes", func(t *testing.T) { + t.Run("mAPI not found - woc, nownodes", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNowNodes(&nowNodesTxOnChain{}), ) @@ -80,12 +78,11 @@ func TestClient_Transaction(t *testing.T) { assert.Equal(t, ProviderWhatsOnChain, info.Provider) }) - t.Run("mAPI, WOC not found - mattercloud, nownodes", func(t *testing.T) { + t.Run("mAPI, WOC not found - nownodes", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxNotFound{}), // NOT going to find the TX - WithMatterCloud(&matterCloudTxOnChain{}), WithNowNodes(&nowNodesTxOnChain{}), ) @@ -99,15 +96,13 @@ func TestClient_Transaction(t *testing.T) { assert.Equal(t, onChainExample1BlockHash, info.BlockHash) assert.Equal(t, onChainExample1BlockHeight, info.BlockHeight) assert.Equal(t, onChainExample1Confirmations, info.Confirmations) - assert.Equal(t, ProviderMatterCloud, info.Provider) }) - t.Run("mAPI, WOC, mattercloud not found - nownodes", func(t *testing.T) { + t.Run("mAPI, WOC, nownodes", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxNotFound{}), // NOT going to find the TX - WithMatterCloud(&matterCloudTxNotFound{}), // NOT going to find the TX WithNowNodes(&nowNodesTxOnChain{}), ) @@ -129,7 +124,6 @@ func TestClient_Transaction(t *testing.T) { context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxNotFound{}), // NOT going to find the TX - WithMatterCloud(&matterCloudTxNotFound{}), // NOT going to find the TX WithNowNodes(&nowNodesTxNotFound{}), // NOT going to find the TX ) @@ -147,7 +141,6 @@ func TestClient_Transaction(t *testing.T) { context.Background(), t, WithMinercraft(&minerCraftTxOnChain{}), WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNetwork(StressTestNet), ) @@ -161,7 +154,7 @@ func TestClient_Transaction(t *testing.T) { assert.Equal(t, onChainExample1BlockHash, info.BlockHash) assert.Equal(t, onChainExample1BlockHeight, info.BlockHeight) assert.Equal(t, onChainExample1Confirmations, info.Confirmations) - assert.Contains(t, []string{ProviderWhatsOnChain, ProviderMatterCloud}, info.Provider) + assert.Contains(t, []string{ProviderWhatsOnChain}, info.Provider) }) t.Run("valid - test network", func(t *testing.T) { @@ -169,7 +162,6 @@ func TestClient_Transaction(t *testing.T) { context.Background(), t, WithMinercraft(&minerCraftTxOnChain{}), WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNetwork(TestNet), ) @@ -213,12 +205,11 @@ func TestClient_TransactionFastest(t *testing.T) { assert.ErrorIs(t, err, ErrInvalidRequirements) }) - t.Run("valid - all four", func(t *testing.T) { + t.Run("valid - all three", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxOnChain{}), WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNowNodes(&nowNodesTxOnChain{}), ) @@ -234,12 +225,11 @@ func TestClient_TransactionFastest(t *testing.T) { assert.Equal(t, onChainExample1Confirmations, info.Confirmations) }) - t.Run("mAPI not found - woc, mattercloud, nownodes", func(t *testing.T) { + t.Run("mAPI not found - woc, nownodes", func(t *testing.T) { c := NewTestClient( context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNowNodes(&nowNodesTxOnChain{}), ) @@ -260,7 +250,6 @@ func TestClient_TransactionFastest(t *testing.T) { context.Background(), t, WithMinercraft(&minerCraftTxNotFound{}), // NOT going to find the TX WithWhatsOnChain(&whatsOnChainTxNotFound{}), // NOT going to find the TX - WithMatterCloud(&matterCloudTxNotFound{}), // NOT going to find the TX WithNowNodes(&nowNodesTxNotFound{}), // NOT going to find the TX ) @@ -278,7 +267,6 @@ func TestClient_TransactionFastest(t *testing.T) { context.Background(), t, WithMinercraft(&minerCraftTxOnChain{}), WithWhatsOnChain(&whatsOnChainTxOnChain{}), - WithMatterCloud(&matterCloudTxOnChain{}), WithNetwork(StressTestNet), ) @@ -292,6 +280,6 @@ func TestClient_TransactionFastest(t *testing.T) { assert.Equal(t, onChainExample1BlockHash, info.BlockHash) assert.Equal(t, onChainExample1BlockHeight, info.BlockHeight) assert.Equal(t, onChainExample1Confirmations, info.Confirmations) - assert.Contains(t, []string{ProviderWhatsOnChain, ProviderMatterCloud}, info.Provider) + assert.Contains(t, []string{ProviderWhatsOnChain}, info.Provider) }) } diff --git a/client_options.go b/client_options.go index 8b536a58..15497324 100644 --- a/client_options.go +++ b/client_options.go @@ -621,15 +621,6 @@ func WithNowNodesAPIKey(apiKey string) ClientOps { } } -// WithMatterCloudAPIKey will set the API key -func WithMatterCloudAPIKey(apiKey string) ClientOps { - return func(c *clientOptions) { - if len(apiKey) > 0 { - c.chainstate.options = append(c.chainstate.options, chainstate.WithMatterCloudAPIKey(apiKey)) - } - } -} - // WithExcludedProviders will set a list of excluded providers func WithExcludedProviders(providers []string) ClientOps { return func(c *clientOptions) { diff --git a/mock_chainstate_test.go b/mock_chainstate_test.go index 57de12ec..145244fc 100644 --- a/mock_chainstate_test.go +++ b/mock_chainstate_test.go @@ -6,7 +6,6 @@ import ( "github.com/BuxOrg/bux/chainstate" "github.com/BuxOrg/bux/utils" - "github.com/mrz1836/go-mattercloud" "github.com/mrz1836/go-nownodes" "github.com/mrz1836/go-whatsonchain" "github.com/tonicpow/go-minercraft" @@ -52,10 +51,6 @@ func (c *chainStateBase) IsNewRelicEnabled() bool { return true } -func (c *chainStateBase) MatterCloud() mattercloud.ClientInterface { - return nil -} - func (c *chainStateBase) Minercraft() minercraft.ClientInterface { return nil }