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

Commit

Permalink
feat(BUX-417): remove monitor, ITC flag and IncomingTransaction (#532)
Browse files Browse the repository at this point in the history
* chore(BUX-417): remove monitor

* chore(BUX-417): remove ITC flag

* chore(BUX-417): remove incoming tx
  • Loading branch information
pawellewandowski98 authored and jakubmkowalski committed Feb 12, 2024
1 parent 292c86b commit 04af3e4
Show file tree
Hide file tree
Showing 35 changed files with 143 additions and 1,428 deletions.
9 changes: 7 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
}
],
"[go][go.mod]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}
18 changes: 5 additions & 13 deletions action_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package bux

import (
"context"
"database/sql"
"time"

"github.com/mrz1836/go-datastore"
customTypes "github.com/mrz1836/go-datastore/custom_types"
)

// NewDestination will get a new destination for an existing xPub
//
// xPubKey is the raw public xPub
func (c *Client) NewDestination(ctx context.Context, xPubKey string, chain uint32,
destinationType string, monitor bool, opts ...ModelOps) (*Destination, error) {
destinationType string, opts ...ModelOps) (*Destination, error) {

// Check for existing NewRelic transaction
ctx = c.GetOrStartTxn(ctx, "new_destination")
Expand All @@ -39,13 +35,6 @@ func (c *Client) NewDestination(ctx context.Context, xPubKey string, chain uint3
return nil, err
}

if monitor {
destination.Monitor = customTypes.NullTime{NullTime: sql.NullTime{
Valid: true,
Time: time.Now(),
}}
}

// Save the destination
if err = destination.Save(ctx); err != nil {
return nil, err
Expand All @@ -57,7 +46,7 @@ func (c *Client) NewDestination(ctx context.Context, xPubKey string, chain uint3

// NewDestinationForLockingScript will create a new destination based on a locking script
func (c *Client) NewDestinationForLockingScript(ctx context.Context, xPubID, lockingScript string,
monitor bool, opts ...ModelOps) (*Destination, error) {
opts ...ModelOps) (*Destination, error) {

// Check for existing NewRelic transaction
ctx = c.GetOrStartTxn(ctx, "new_destination_for_locking_script")
Expand All @@ -77,6 +66,7 @@ func (c *Client) NewDestinationForLockingScript(ctx context.Context, xPubID, loc
return nil, ErrUnknownLockingScript
}

<<<<<<< HEAD
// set the monitoring, passed down from the initiating function
// this will be set when calling NewDestination from http, but not for instance paymail
if monitor {
Expand All @@ -86,6 +76,8 @@ func (c *Client) NewDestinationForLockingScript(ctx context.Context, xPubID, loc
}}
}

=======
>>>>>>> 06feaba (feat(BUX-417): remove monitor, ITC flag and IncomingTransaction (#532))
// Save the destination
if err := destination.Save(ctx); err != nil {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions action_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {

var destination *Destination
destination, err = tc.client.NewDestination(
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, false, opts...,
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, opts...,
)
assert.NoError(t, err)
assert.Equal(t, "fc1e635d98151c6008f29908ee2928c60c745266f9853e945c917b1baa05973e", destination.ID)
Expand All @@ -42,7 +42,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {
assert.Equal(t, "test-value", destination.Metadata["test-key"])

destination2, err2 := tc.client.NewDestination(
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, false, opts...,
ctx, testXPub, utils.ChainExternal, utils.ScriptTypePubKeyHash, opts...,
)
assert.NoError(t, err2)
assert.Equal(t, testXPubID, destination2.XpubID)
Expand All @@ -65,7 +65,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestination() {

destination, err := tc.client.NewDestination(
context.Background(), testXPub, utils.ChainExternal,
utils.ScriptTypePubKeyHash, false, opts...,
utils.ScriptTypePubKeyHash, opts...,
)
require.Error(t, err)
require.Nil(t, destination)
Expand Down Expand Up @@ -99,7 +99,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestinationForLockingScript() {

var destination *Destination
destination, err = tc.client.NewDestinationForLockingScript(
tc.ctx, testXPubID, lockingScript, false, opts...,
tc.ctx, testXPubID, lockingScript, opts...,
)
assert.NoError(t, err)
assert.Equal(t, "a64c7aca7110c7cde92245252a58bb18a4317381fc31fc293f6aafa3fcc7019f", destination.ID)
Expand All @@ -118,7 +118,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_NewDestinationForLockingScript() {
opts := append(tc.client.DefaultModelOptions(), WithMetadatas(metadata))

destination, err := tc.client.NewDestinationForLockingScript(
tc.ctx, testXPubID, "", false,
tc.ctx, testXPubID, "",
opts...,
)
require.Error(t, err)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinations() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -176,7 +176,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinations() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -212,7 +212,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByAddress() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -240,7 +240,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByAddress() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -276,7 +276,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByLockingScript() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -305,7 +305,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_GetDestinationByLockingScript() {

// Create a new destination
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down Expand Up @@ -340,7 +340,7 @@ func (ts *EmbeddedDBTestSuite) TestClient_UpdateDestinationMetadata() {
opts := tc.client.DefaultModelOptions()
opts = append(opts, WithMetadatas(metadata))
destination, err := tc.client.NewDestination(
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash, false,
tc.ctx, rawKey, utils.ChainExternal, utils.ScriptTypePubKeyHash,
opts...,
)
require.NoError(t, err)
Expand Down
8 changes: 1 addition & 7 deletions action_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ func (c *Client) RecordRawTransaction(ctx context.Context, txHex string,
) (*Transaction, error) {
ctx = c.GetOrStartTxn(ctx, "record_raw_transaction")

allowUnknown := true
monitor := c.options.chainstate.Monitor()
if monitor != nil {
allowUnknown = monitor.AllowUnknownTransactions()
}

return saveRawTransaction(ctx, c, allowUnknown, txHex, opts...)
return saveRawTransaction(ctx, c, true, txHex, opts...)
}

// NewTransaction will create a new draft transaction and return it
Expand Down
4 changes: 2 additions & 2 deletions bux_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package bux
import (
"context"
"fmt"
"github.com/rs/zerolog"
"sync"
"testing"
"time"

"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/logging"
"github.com/BuxOrg/bux/taskmanager"
"github.com/BuxOrg/bux/tester"
"github.com/DATA-DOG/go-sqlmock"
Expand Down Expand Up @@ -68,7 +68,7 @@ type EmbeddedDBTestSuite struct {
func (ts *EmbeddedDBTestSuite) serveMySQL() {
defer ts.wg.Done()

logger := logging.GetDefaultLogger()
logger := zerolog.Nop()

for {
err := ts.MySQLServer.Start()
Expand Down
5 changes: 0 additions & 5 deletions chainstate/chainstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"time"
)

// MonitorBlockHeaders will start up a block headers monitor
func (c *Client) MonitorBlockHeaders(_ context.Context) error {
return nil
}

// Broadcast will attempt to broadcast a transaction using the given providers
func (c *Client) Broadcast(ctx context.Context, id, txHex string, timeout time.Duration) (string, error) {
// Basic validation
Expand Down
11 changes: 0 additions & 11 deletions chainstate/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type (
config *syncConfig // Configuration for broadcasting and other chain-state actions
debug bool // For extra logs and additional debug information
logger *zerolog.Logger // Logger interface
monitor MonitorService // Monitor service
newRelicEnabled bool // If NewRelic is enabled (parent application)
userAgent string // Custom user agent for outgoing HTTP Requests
}
Expand Down Expand Up @@ -100,11 +99,6 @@ func (c *Client) Close(ctx context.Context) {
c.options.config.minercraft = nil
}

// Stop the active Monitor (if not already stopped)
if c.options.monitor != nil {
_ = c.options.monitor.Stop(ctx)
c.options.monitor = nil
}
}
}

Expand Down Expand Up @@ -143,11 +137,6 @@ func (c *Client) Minercraft() minercraft.ClientInterface {
return c.options.config.minercraft
}

// Monitor will return the Monitor client
func (c *Client) Monitor() MonitorService {
return c.options.monitor
}

// BroadcastClient will return the BroadcastClient client
func (c *Client) BroadcastClient() broadcast.Client {
return c.options.config.broadcastClient
Expand Down
19 changes: 0 additions & 19 deletions chainstate/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,6 @@ func WithLogger(customLogger *zerolog.Logger) ClientOps {
}
}

// WithMonitoring will create a new monitorConfig interface with the given options
func WithMonitoring(ctx context.Context, monitorOptions *MonitorOptions) ClientOps {
return func(c *clientOptions) {
if monitorOptions != nil {
// Create the default Monitor for monitoring destinations
c.monitor = NewMonitor(ctx, monitorOptions)
}
}
}

// WithMonitoringInterface will set the interface to use for monitoring the blockchain
func WithMonitoringInterface(monitor MonitorService) ClientOps {
return func(c *clientOptions) {
if monitor != nil {
c.monitor = monitor
}
}
}

// WithExcludedProviders will set a list of excluded providers
func WithExcludedProviders(providers []string) ClientOps {
return func(c *clientOptions) {
Expand Down
1 change: 0 additions & 1 deletion chainstate/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (
defaultFalsePositiveRate = 0.01
defaultFeeLastCheckIgnore = 2 * time.Minute
defaultMaxNumberOfDestinations = 100000
defaultMonitorDays = 7
defaultQueryTimeOut = 15 * time.Second
whatsOnChainRateLimitWithKey = 20
)
Expand Down
3 changes: 0 additions & 3 deletions chainstate/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ var ErrMissingBroadcastMiners = errors.New("missing: broadcasting miners")

// ErrMissingQueryMiners is when query miners are missing
var ErrMissingQueryMiners = errors.New("missing: query miners")

// ErrMonitorNotAvailable is when the monitor processor is not available
var ErrMonitorNotAvailable = errors.New("monitor processor not available")
55 changes: 0 additions & 55 deletions chainstate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/BuxOrg/bux/utils"
"github.com/bitcoin-sv/go-broadcast-client/broadcast"
"github.com/centrifugal/centrifuge-go"
"github.com/libsv/go-bc"
"github.com/rs/zerolog"
"github.com/tonicpow/go-minercraft/v2"
)

Expand Down Expand Up @@ -51,64 +49,11 @@ type ClientInterface interface {
HTTPClient() HTTPInterface
IsDebug() bool
IsNewRelicEnabled() bool
Monitor() MonitorService
Network() Network
QueryTimeout() time.Duration
FeeUnit() *utils.FeeUnit
}

// MonitorClient interface
type MonitorClient interface {
AddFilter(regex, item string) (centrifuge.PublishResult, error)
Connect() error
Disconnect() error
SetToken(token string)
}

// MonitorHandler interface
type MonitorHandler interface {
SocketHandler
RecordBlockHeader(ctx context.Context, bh bc.BlockHeader) error
RecordTransaction(ctx context.Context, txHex string) error
SetMonitor(monitor *Monitor)
}

// MonitorProcessor struct that defines interface to all filter processors
type MonitorProcessor interface {
Add(regexString, item string) error
Debug(bool)
FilterTransaction(txHex string) (string, error)
FilterTransactionPublishEvent(eData []byte) (string, error)
GetFilters() map[string]*BloomProcessorFilter
GetHash() string
IsDebug() bool
Logger() *zerolog.Logger
Reload(regexString string, items []string) error
SetFilter(regex string, filter []byte) error
SetLogger(logger *zerolog.Logger)
Test(regexString string, item string) bool
}

// MonitorService for the monitoring
type MonitorService interface {
Add(regexpString string, item string) error
Connected()
Disconnected()
GetFalsePositiveRate() float64
GetLockID() string
GetMaxNumberOfDestinations() int
GetMonitorDays() int
IsConnected() bool
IsDebug() bool
LoadMonitoredDestinations() bool
AllowUnknownTransactions() bool
Logger() *zerolog.Logger
Processor() MonitorProcessor
SaveDestinations() bool
Start(ctx context.Context, handler MonitorHandler, onStop func()) error
Stop(ctx context.Context) error
}

// SocketHandler is composite interface of centrifuge handlers interfaces
type SocketHandler interface {
OnConnect(*centrifuge.Client, centrifuge.ConnectEvent)
Expand Down
Loading

0 comments on commit 04af3e4

Please sign in to comment.