@@ -11,8 +11,7 @@ import (
11
11
"github.com/ark-network/ark/pkg/client-sdk/client"
12
12
"github.com/ark-network/ark/pkg/client-sdk/explorer"
13
13
"github.com/ark-network/ark/pkg/client-sdk/internal/utils"
14
- "github.com/ark-network/ark/pkg/client-sdk/store"
15
- "github.com/ark-network/ark/pkg/client-sdk/store/domain"
14
+ "github.com/ark-network/ark/pkg/client-sdk/types"
16
15
"github.com/ark-network/ark/pkg/client-sdk/wallet"
17
16
singlekeywallet "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey"
18
17
walletstore "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey/store"
@@ -29,8 +28,8 @@ const (
29
28
// wallet
30
29
SingleKeyWallet = wallet .SingleKeyWallet
31
30
// store
32
- FileStore = store .FileStore
33
- InMemoryStore = store .InMemoryStore
31
+ FileStore = types .FileStore
32
+ InMemoryStore = types .InMemoryStore
34
33
// explorer
35
34
BitcoinExplorer = explorer .BitcoinExplorer
36
35
LiquidExplorer = explorer .LiquidExplorer
@@ -54,25 +53,65 @@ var (
54
53
)
55
54
56
55
type arkClient struct {
57
- * domain. ConfigData
58
- wallet wallet.WalletService
59
- sdkRepository domain. SdkRepository
60
- explorer explorer.Explorer
61
- client client.ASPClient
56
+ * types. Config
57
+ wallet wallet.WalletService
58
+ store types. Store
59
+ explorer explorer.Explorer
60
+ client client.ASPClient
62
61
63
62
txStreamCtxCancel context.CancelFunc
64
63
}
65
64
66
65
func (a * arkClient ) GetConfigData (
67
66
_ context.Context ,
68
- ) (* domain. ConfigData , error ) {
69
- if a .ConfigData == nil {
67
+ ) (* types. Config , error ) {
68
+ if a .Config == nil {
70
69
return nil , fmt .Errorf ("client sdk not initialized" )
71
70
}
72
- return a .ConfigData , nil
71
+ return a .Config , nil
73
72
}
74
73
75
- func (a * arkClient ) InitWithWallet (
74
+ func (a * arkClient ) Unlock (ctx context.Context , pasword string ) error {
75
+ _ , err := a .wallet .Unlock (ctx , pasword )
76
+ return err
77
+ }
78
+
79
+ func (a * arkClient ) Lock (ctx context.Context , pasword string ) error {
80
+ return a .wallet .Lock (ctx , pasword )
81
+ }
82
+
83
+ func (a * arkClient ) IsLocked (ctx context.Context ) bool {
84
+ return a .wallet .IsLocked ()
85
+ }
86
+
87
+ func (a * arkClient ) Dump (ctx context.Context ) (string , error ) {
88
+ return a .wallet .Dump (ctx )
89
+ }
90
+
91
+ func (a * arkClient ) Receive (ctx context.Context ) (string , string , error ) {
92
+ offchainAddr , boardingAddr , err := a .wallet .NewAddress (ctx , false )
93
+ if err != nil {
94
+ return "" , "" , err
95
+ }
96
+
97
+ return offchainAddr , boardingAddr , nil
98
+ }
99
+
100
+ func (a * arkClient ) GetTransactionEventChannel () chan types.TransactionEvent {
101
+ return a .store .TransactionStore ().GetEventChannel ()
102
+ }
103
+
104
+ func (a * arkClient ) Stop () error {
105
+ if a .Config .WithTransactionFeed {
106
+ a .txStreamCtxCancel ()
107
+ }
108
+
109
+ a .store .Close ()
110
+
111
+ return nil
112
+ }
113
+
114
+ func (a * arkClient ) initWithWallet (
76
115
ctx context.Context , args InitWithWalletArgs ,
77
116
) error {
78
117
if err := args .validate (); err != nil {
@@ -107,7 +146,7 @@ func (a *arkClient) InitWithWallet(
107
146
return fmt .Errorf ("failed to parse asp pubkey: %s" , err )
108
147
}
109
148
110
- storeData := domain. ConfigData {
149
+ storeData := types. Config {
111
150
AspUrl : args .AspUrl ,
112
151
AspPubkey : aspPubkey ,
113
152
WalletType : args .Wallet .GetType (),
@@ -119,26 +158,27 @@ func (a *arkClient) InitWithWallet(
119
158
Dust : info .Dust ,
120
159
BoardingDescriptorTemplate : info .BoardingDescriptorTemplate ,
121
160
ForfeitAddress : info .ForfeitAddress ,
161
+ WithTransactionFeed : args .ListenTransactionStream ,
122
162
}
123
- if err := a .sdkRepository . ConfigRepository ().AddData (ctx , storeData ); err != nil {
163
+ if err := a .store . ConfigStore ().AddData (ctx , storeData ); err != nil {
124
164
return err
125
165
}
126
166
127
167
if _ , err := args .Wallet .Create (ctx , args .Password , args .Seed ); err != nil {
128
168
//nolint:all
129
- a .sdkRepository . ConfigRepository ().CleanData (ctx )
169
+ a .store . ConfigStore ().CleanData (ctx )
130
170
return err
131
171
}
132
172
133
- a .ConfigData = & storeData
173
+ a .Config = & storeData
134
174
a .wallet = args .Wallet
135
175
a .explorer = explorerSvc
136
176
a .client = clientSvc
137
177
138
178
return nil
139
179
}
140
180
141
- func (a * arkClient ) Init (
181
+ func (a * arkClient ) init (
142
182
ctx context.Context , args InitArgs ,
143
183
) error {
144
184
if err := args .validate (); err != nil {
@@ -173,7 +213,7 @@ func (a *arkClient) Init(
173
213
return fmt .Errorf ("failed to parse asp pubkey: %s" , err )
174
214
}
175
215
176
- cfgData := domain. ConfigData {
216
+ cfgData := types. Config {
177
217
AspUrl : args .AspUrl ,
178
218
AspPubkey : aspPubkey ,
179
219
WalletType : args .WalletType ,
@@ -186,72 +226,31 @@ func (a *arkClient) Init(
186
226
BoardingDescriptorTemplate : info .BoardingDescriptorTemplate ,
187
227
ExplorerURL : args .ExplorerURL ,
188
228
ForfeitAddress : info .ForfeitAddress ,
229
+ WithTransactionFeed : args .ListenTransactionStream ,
189
230
}
190
- walletSvc , err := getWallet (a .sdkRepository . ConfigRepository (), & cfgData , supportedWallets )
231
+ walletSvc , err := getWallet (a .store . ConfigStore (), & cfgData , supportedWallets )
191
232
if err != nil {
192
233
return err
193
234
}
194
235
195
- if err := a .sdkRepository . ConfigRepository ().AddData (ctx , cfgData ); err != nil {
236
+ if err := a .store . ConfigStore ().AddData (ctx , cfgData ); err != nil {
196
237
return err
197
238
}
198
239
199
240
if _ , err := walletSvc .Create (ctx , args .Password , args .Seed ); err != nil {
200
241
//nolint:all
201
- a .sdkRepository . ConfigRepository ().CleanData (ctx )
242
+ a .store . ConfigStore ().CleanData (ctx )
202
243
return err
203
244
}
204
245
205
- a .ConfigData = & cfgData
246
+ a .Config = & cfgData
206
247
a .wallet = walletSvc
207
248
a .explorer = explorerSvc
208
249
a .client = clientSvc
209
250
210
251
return nil
211
252
}
212
253
213
- func (a * arkClient ) Unlock (ctx context.Context , pasword string ) error {
214
- _ , err := a .wallet .Unlock (ctx , pasword )
215
- return err
216
- }
217
-
218
- func (a * arkClient ) Lock (ctx context.Context , pasword string ) error {
219
- return a .wallet .Lock (ctx , pasword )
220
- }
221
-
222
- func (a * arkClient ) IsLocked (ctx context.Context ) bool {
223
- return a .wallet .IsLocked ()
224
- }
225
-
226
- func (a * arkClient ) Dump (ctx context.Context ) (string , error ) {
227
- return a .wallet .Dump (ctx )
228
- }
229
-
230
- func (a * arkClient ) Receive (ctx context.Context ) (string , string , error ) {
231
- offchainAddr , boardingAddr , err := a .wallet .NewAddress (ctx , false )
232
- if err != nil {
233
- return "" , "" , err
234
- }
235
-
236
- return offchainAddr , boardingAddr , nil
237
- }
238
-
239
- func (a * arkClient ) GetTransactionEventChannel () chan domain.TransactionEvent {
240
- return a .sdkRepository .AppDataRepository ().TransactionRepository ().GetEventChannel ()
241
- }
242
-
243
- func (a * arkClient ) Stop () error {
244
- if a .ConfigData .ListenTransactionStream {
245
- a .txStreamCtxCancel ()
246
- }
247
-
248
- if err := a .sdkRepository .AppDataRepository ().Stop (); err != nil {
249
- return err
250
- }
251
-
252
- return nil
253
- }
254
-
255
254
func (a * arkClient ) ping (
256
255
ctx context.Context , paymentID string ,
257
256
) func () {
@@ -289,11 +288,11 @@ func getExplorer(explorerURL, network string) (explorer.Explorer, error) {
289
288
}
290
289
291
290
func getWallet (
292
- configRepo domain. ConfigRepository , data * domain. ConfigData , supportedWallets utils.SupportedType [struct {}],
291
+ configStore types. ConfigStore , data * types. Config , supportedWallets utils.SupportedType [struct {}],
293
292
) (wallet.WalletService , error ) {
294
293
switch data .WalletType {
295
294
case wallet .SingleKeyWallet :
296
- return getSingleKeyWallet (configRepo , data .Network .Name )
295
+ return getSingleKeyWallet (configStore , data .Network .Name )
297
296
default :
298
297
return nil , fmt .Errorf (
299
298
"unsuported wallet type '%s', please select one of: %s" ,
@@ -303,24 +302,24 @@ func getWallet(
303
302
}
304
303
305
304
func getSingleKeyWallet (
306
- configRepo domain. ConfigRepository , network string ,
305
+ configStore types. ConfigStore , network string ,
307
306
) (wallet.WalletService , error ) {
308
- walletStore , err := getWalletStore (configRepo .GetType (), configRepo .GetDatadir ())
307
+ walletStore , err := getWalletStore (configStore .GetType (), configStore .GetDatadir ())
309
308
if err != nil {
310
309
return nil , err
311
310
}
312
311
313
312
if strings .Contains (network , "liquid" ) {
314
- return singlekeywallet .NewLiquidWallet (configRepo , walletStore )
313
+ return singlekeywallet .NewLiquidWallet (configStore , walletStore )
315
314
}
316
- return singlekeywallet .NewBitcoinWallet (configRepo , walletStore )
315
+ return singlekeywallet .NewBitcoinWallet (configStore , walletStore )
317
316
}
318
317
319
318
func getWalletStore (storeType , datadir string ) (walletstore.WalletStore , error ) {
320
319
switch storeType {
321
- case store .InMemoryStore :
320
+ case types .InMemoryStore :
322
321
return inmemorystore .NewWalletStore ()
323
- case store .FileStore :
322
+ case types .FileStore :
324
323
return filestore .NewWalletStore (datadir )
325
324
default :
326
325
return nil , fmt .Errorf ("unknown wallet store type" )
0 commit comments