@@ -17,15 +17,7 @@ import (
1717 paymailclient "github.com/bitcoin-sv/spv-wallet/engine/paymail"
1818 "github.com/bitcoin-sv/spv-wallet/engine/spverrors"
1919 "github.com/bitcoin-sv/spv-wallet/engine/taskmanager"
20- "github.com/bitcoin-sv/spv-wallet/engine/v2/addresses"
21- "github.com/bitcoin-sv/spv-wallet/engine/v2/data"
22- "github.com/bitcoin-sv/spv-wallet/engine/v2/database/repository"
23- "github.com/bitcoin-sv/spv-wallet/engine/v2/operations"
24- "github.com/bitcoin-sv/spv-wallet/engine/v2/paymails"
25- "github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/outlines"
26- "github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/record"
27- "github.com/bitcoin-sv/spv-wallet/engine/v2/transaction/txsync"
28- "github.com/bitcoin-sv/spv-wallet/engine/v2/users"
20+ "github.com/bitcoin-sv/spv-wallet/engine/v2/engine"
2921 "github.com/bitcoin-sv/spv-wallet/models/bsv"
3022 "github.com/go-resty/resty/v2"
3123 "github.com/mrz1836/go-cachestore"
@@ -37,39 +29,32 @@ type (
3729 // Client is the SPV Wallet Engine client & options
3830 Client struct {
3931 options * clientOptions
32+ // TEMPORARY: to limit the changes in the codebase
33+ V2Interface
4034 }
4135
4236 // clientOptions holds all the configuration for the client
4337 clientOptions struct {
44- cacheStore * cacheStoreOptions // Configuration options for Cachestore (ristretto, redis, etc.)
45- cluster * clusterOptions // Configuration options for the cluster coordinator
46- dataStore * dataStoreOptions // Configuration options for the DataStore (PostgreSQL, etc.)
47- debug bool // If the client is in debug mode
48- encryptionKey string // Encryption key for encrypting sensitive information (IE: paymail xPub) (hex encoded key)
49- httpClient * resty.Client // HTTP client to use for http calls
50- iuc bool // (Input UTXO Check) True will check input utxos when saving transactions
51- logger * zerolog.Logger // Internal logging
52- metrics * metrics.Metrics // Metrics with a collector interface
53- notifications * notificationsOptions // Configuration options for Notifications
54- paymail * paymailOptions // Paymail options & client
55- transactionOutlinesService outlines.Service // Service for transaction outlines
56- transactionRecordService * record.Service // Service for recording transactions
57- taskManager * taskManagerOptions // Configuration options for the TaskManager (TaskQ, etc.)
58- userAgent string // User agent for all outgoing requests
59- chainService chain.Service // Chain service
60- arcConfig chainmodels.ARCConfig // Configuration for ARC
61- bhsConfig chainmodels.BHSConfig // Configuration for BHS
62- feeUnit * bsv.FeeUnit // Fee unit for transactions
63-
64- // v2
65- repositories * repository.All // Repositories for all db models
66- users * users.Service // User domain service
67- paymails * paymails.Service // Paymail domain service
68- addresses * addresses.Service
69- operations * operations.Service
70- txSync * txsync.Service
71- data * data.Service
72- config * config.AppConfig
38+ cacheStore * cacheStoreOptions // Configuration options for Cachestore (ristretto, redis, etc.)
39+ cluster * clusterOptions // Configuration options for the cluster coordinator
40+ dataStore * dataStoreOptions // Configuration options for the DataStore (PostgreSQL, etc.)
41+ debug bool // If the client is in debug mode
42+ encryptionKey string // Encryption key for encrypting sensitive information (IE: paymail xPub) (hex encoded key)
43+ httpClient * resty.Client // HTTP client to use for http calls
44+ iuc bool // (Input UTXO Check) True will check input utxos when saving transactions
45+ logger * zerolog.Logger // Internal logging
46+ metrics * metrics.Metrics // Metrics with a collector interface
47+ notifications * notificationsOptions // Configuration options for Notifications
48+ paymail * paymailOptions // Paymail options & client
49+ taskManager * taskManagerOptions // Configuration options for the TaskManager (TaskQ, etc.)
50+ userAgent string // User agent for all outgoing requests
51+ feeUnit * bsv.FeeUnit // Fee unit for transactions
52+
53+ chainService chain.Service // Chain service
54+ arcConfig chainmodels.ARCConfig // Configuration for ARC
55+ bhsConfig chainmodels.BHSConfig // Configuration for BHS
56+
57+ config * config.AppConfig
7358 }
7459
7560 // cacheStoreOptions holds the cache configuration and client
@@ -138,6 +123,16 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
138123 client .options .logger = logging .GetDefaultLogger ()
139124 }
140125
126+ if client .options .config != nil && client .options .config .ExperimentalFeatures .V2 {
127+ client .V2Interface = engine .NewEngine (
128+ client .options .config ,
129+ * client .options .logger ,
130+ engine .WithResty (client .options .httpClient ),
131+ engine .WithPaymailClient (client .options .paymail .client ),
132+ )
133+ return client , nil
134+ }
135+
141136 // Load the Cachestore client
142137 var err error
143138 if err = client .loadCache (ctx ); err != nil {
@@ -158,14 +153,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
158153 return nil , err
159154 }
160155
161- client .loadRepositories ()
162-
163- client .loadUsersService ()
164- client .loadPaymailsService ()
165- client .loadAddressesService ()
166- client .loadDataService ()
167- client .loadOperationsService ()
168-
169156 // Load the Paymail client and service (if does not exist)
170157 if err = client .loadPaymailComponents (); err != nil {
171158 return nil , err
@@ -182,11 +169,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
182169 }
183170
184171 client .loadChainService ()
185- client .loadTxSyncService ()
186-
187- if err = client .loadTransactionRecordService (); err != nil {
188- return nil , err
189- }
190172
191173 // Register all cron jobs
192174 if err = client .registerCronJobs (); err != nil {
@@ -203,10 +185,6 @@ func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)
203185 }
204186 }
205187
206- if err = client .loadTransactionOutlinesService (); err != nil {
207- return nil , err
208- }
209-
210188 // Return the client
211189 return client , nil
212190}
@@ -229,6 +207,14 @@ func (c *Client) Cluster() cluster.ClientInterface {
229207
230208// Close will safely close any open connections (cache, datastore, etc.)
231209func (c * Client ) Close (ctx context.Context ) error {
210+ if c .V2Interface != nil {
211+ err := c .V2Interface .Close (ctx )
212+ if err != nil {
213+ return spverrors .Wrapf (err , "failed to close envine V2" )
214+ }
215+ return nil
216+ }
217+
232218 // Close WebhookManager
233219 if c .options .notifications != nil && c .options .notifications .webhookManager != nil {
234220 c .options .notifications .webhookManager .Stop ()
@@ -351,38 +337,3 @@ func (c *Client) LogBHSReadiness(ctx context.Context) {
351337func (c * Client ) FeeUnit () bsv.FeeUnit {
352338 return * c .options .feeUnit
353339}
354-
355- // Repositories will return all the repositories
356- func (c * Client ) Repositories () * repository.All {
357- return c .options .repositories
358- }
359-
360- // UsersService will return the user domain service
361- func (c * Client ) UsersService () * users.Service {
362- return c .options .users
363- }
364-
365- // PaymailsService will return the paymail domain service
366- func (c * Client ) PaymailsService () * paymails.Service {
367- return c .options .paymails
368- }
369-
370- // AddressesService will return the address domain service
371- func (c * Client ) AddressesService () * addresses.Service {
372- return c .options .addresses
373- }
374-
375- // DataService will return the data domain service
376- func (c * Client ) DataService () * data.Service {
377- return c .options .data
378- }
379-
380- // OperationsService will return the operations domain service
381- func (c * Client ) OperationsService () * operations.Service {
382- return c .options .operations
383- }
384-
385- // TxSyncService will return the transaction sync service
386- func (c * Client ) TxSyncService () * txsync.Service {
387- return c .options .txSync
388- }
0 commit comments