@@ -25,12 +25,12 @@ import (
25
25
"github.com/blocktree/openwallet/v2/timer"
26
26
)
27
27
28
- //deprecated
28
+ // deprecated
29
29
// BlockScanAddressFunc 扫描地址是否存在算法
30
30
// @return 地址所属源标识,是否存在
31
31
type BlockScanAddressFunc func (address string ) (string , bool )
32
32
33
- //deprecated
33
+ // deprecated
34
34
// BlockScanTargetFunc 扫描对象是否存在算法
35
35
// @return 对象所属源标识,是否存在
36
36
type BlockScanTargetFunc func (target ScanTarget ) (string , bool )
@@ -79,6 +79,12 @@ type ScanTargetResult struct {
79
79
TargetInfo interface {}
80
80
}
81
81
82
+ type BlockchainSyncStatus struct {
83
+ NetworkBlockHeight uint64
84
+ CurrentBlockHeight uint64
85
+ Syncing bool
86
+ }
87
+
82
88
// BlockScanner 区块扫描器
83
89
// 负责扫描新区块,给观察者推送订阅地址的新交易单。
84
90
type BlockScanner interface {
@@ -179,9 +185,13 @@ type BlockScanner interface {
179
185
//ExtractTransactionAndReceiptData 提取交易单及交易回执数据
180
186
//@required
181
187
ExtractTransactionAndReceiptData (txid string , scanTargetFunc BlockScanTargetFuncV2 ) (map [string ][]* TxExtractData , map [string ]* SmartContractReceipt , error )
188
+
189
+ //GetBlockchainSyncStatus 获取当前区块链同步状态
190
+ //@optional
191
+ GetBlockchainSyncStatus () (* BlockchainSyncStatus , error )
182
192
}
183
193
184
- //BlockScanNotificationObject 扫描被通知对象
194
+ // BlockScanNotificationObject 扫描被通知对象
185
195
type BlockScanNotificationObject interface {
186
196
187
197
//BlockScanNotify 新区块扫描完成通知
@@ -199,7 +209,7 @@ type BlockScanNotificationObject interface {
199
209
BlockExtractSmartContractDataNotify (sourceKey string , data * SmartContractReceipt ) error
200
210
}
201
211
202
- //TxExtractData 区块扫描后的交易单提取结果,每笔交易单
212
+ // TxExtractData 区块扫描后的交易单提取结果,每笔交易单
203
213
type TxExtractData struct {
204
214
205
215
//消费记录,交易单输入部分
@@ -224,7 +234,7 @@ const (
224
234
periodOfTask = 5 * time .Second //定时任务执行隔间
225
235
)
226
236
227
- //BlockScannerBase 区块链扫描器基本结构实现
237
+ // BlockScannerBase 区块链扫描器基本结构实现
228
238
type BlockScannerBase struct {
229
239
AddressInScanning map [string ]string //加入扫描的地址
230
240
scanTask * timer.TaskTimer //扫描定时器
@@ -242,7 +252,7 @@ type BlockScannerBase struct {
242
252
BlockchainDAI BlockchainDAI
243
253
}
244
254
245
- //NewBTCBlockScanner 创建区块链扫描器
255
+ // NewBTCBlockScanner 创建区块链扫描器
246
256
func NewBlockScannerBase () * BlockScannerBase {
247
257
bs := BlockScannerBase {}
248
258
bs .AddressInScanning = make (map [string ]string )
@@ -253,7 +263,7 @@ func NewBlockScannerBase() *BlockScannerBase {
253
263
return & bs
254
264
}
255
265
256
- //InitBlockScanner
266
+ // InitBlockScanner
257
267
func (bs * BlockScannerBase ) InitBlockScanner () error {
258
268
259
269
bs .blockProducer = make (chan interface {})
@@ -267,16 +277,16 @@ func (bs *BlockScannerBase) InitBlockScanner() error {
267
277
return nil
268
278
}
269
279
270
- //deprecated
271
- //SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法
280
+ // deprecated
281
+ // SetBlockScanAddressFunc 设置区块扫描过程,查找地址过程方法
272
282
func (bs * BlockScannerBase ) SetBlockScanAddressFunc (scanAddressFunc BlockScanAddressFunc ) error {
273
283
bs .ScanAddressFunc = scanAddressFunc
274
284
return nil
275
285
}
276
286
277
- //deprecated
278
- //SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法
279
- //@required
287
+ // deprecated
288
+ // SetBlockScanTargetFunc 设置区块扫描过程,查找扫描对象过程方法
289
+ // @required
280
290
func (bs * BlockScannerBase ) SetBlockScanTargetFunc (scanTargetFunc BlockScanTargetFunc ) error {
281
291
bs .ScanTargetFunc = scanTargetFunc
282
292
@@ -292,8 +302,8 @@ func (bs *BlockScannerBase) SetBlockScanTargetFunc(scanTargetFunc BlockScanTarge
292
302
return nil
293
303
}
294
304
295
- //SetBlockScanTargetFuncV2 设置区块扫描过程,查找扫描对象过程方法
296
- //@required
305
+ // SetBlockScanTargetFuncV2 设置区块扫描过程,查找扫描对象过程方法
306
+ // @required
297
307
func (bs * BlockScannerBase ) SetBlockScanTargetFuncV2 (scanTargetFuncV2 BlockScanTargetFuncV2 ) error {
298
308
bs .ScanTargetFuncV2 = scanTargetFuncV2
299
309
@@ -314,7 +324,7 @@ func (bs *BlockScannerBase) SetBlockScanTargetFuncV2(scanTargetFuncV2 BlockScanT
314
324
return nil
315
325
}
316
326
317
- //AddObserver 添加观测者
327
+ // AddObserver 添加观测者
318
328
func (bs * BlockScannerBase ) AddObserver (obj BlockScanNotificationObject ) error {
319
329
bs .Mu .Lock ()
320
330
@@ -333,7 +343,7 @@ func (bs *BlockScannerBase) AddObserver(obj BlockScanNotificationObject) error {
333
343
return nil
334
344
}
335
345
336
- //RemoveObserver 移除观测者
346
+ // RemoveObserver 移除观测者
337
347
func (bs * BlockScannerBase ) RemoveObserver (obj BlockScanNotificationObject ) error {
338
348
bs .Mu .Lock ()
339
349
defer bs .Mu .Unlock ()
@@ -343,12 +353,12 @@ func (bs *BlockScannerBase) RemoveObserver(obj BlockScanNotificationObject) erro
343
353
return nil
344
354
}
345
355
346
- //SetRescanBlockHeight 重置区块链扫描高度
356
+ // SetRescanBlockHeight 重置区块链扫描高度
347
357
func (bs * BlockScannerBase ) SetRescanBlockHeight (height uint64 ) error {
348
358
return nil
349
359
}
350
360
351
- //SetTask
361
+ // SetTask
352
362
func (bs * BlockScannerBase ) SetTask (task func ()) {
353
363
354
364
//if bs.scanTask == nil {
@@ -366,7 +376,7 @@ func (bs *BlockScannerBase) SetTask(task func()) {
366
376
bs .scanTask = taskTimer
367
377
}
368
378
369
- //Run 运行
379
+ // Run 运行
370
380
func (bs * BlockScannerBase ) Run () error {
371
381
372
382
if bs .IsClose () {
@@ -390,7 +400,7 @@ func (bs *BlockScannerBase) Run() error {
390
400
return nil
391
401
}
392
402
393
- //Stop 停止扫描
403
+ // Stop 停止扫描
394
404
func (bs * BlockScannerBase ) Stop () error {
395
405
396
406
if bs .IsClose () {
@@ -402,7 +412,7 @@ func (bs *BlockScannerBase) Stop() error {
402
412
return nil
403
413
}
404
414
405
- //Pause 暂停扫描
415
+ // Pause 暂停扫描
406
416
func (bs * BlockScannerBase ) Pause () error {
407
417
408
418
if bs .IsClose () {
@@ -414,7 +424,7 @@ func (bs *BlockScannerBase) Pause() error {
414
424
return nil
415
425
}
416
426
417
- //Restart 继续扫描
427
+ // Restart 继续扫描
418
428
func (bs * BlockScannerBase ) Restart () error {
419
429
420
430
if bs .IsClose () {
@@ -426,29 +436,29 @@ func (bs *BlockScannerBase) Restart() error {
426
436
return nil
427
437
}
428
438
429
- //IsClose 是否已经关闭
439
+ // IsClose 是否已经关闭
430
440
func (bs * BlockScannerBase ) IsClose () bool {
431
441
return bs .isClose
432
442
}
433
443
434
- //ScanBlock 扫描指定高度区块
444
+ // ScanBlock 扫描指定高度区块
435
445
func (bs * BlockScannerBase ) ScanBlock (height uint64 ) error {
436
446
//扫描指定高度区块
437
447
return fmt .Errorf ("ScanBlock is not implemented" )
438
448
}
439
449
440
- //GetCurrentBlockHeight 获取当前区块高度
450
+ // GetCurrentBlockHeight 获取当前区块高度
441
451
func (bs * BlockScannerBase ) GetCurrentBlockHeader () (* BlockHeader , error ) {
442
452
return nil , fmt .Errorf ("GetCurrentBlockHeader is not implemented" )
443
453
}
444
454
445
- //GetGlobalMaxBlockHeight 获取区块链全网最大高度
446
- //@required
455
+ // GetGlobalMaxBlockHeight 获取区块链全网最大高度
456
+ // @required
447
457
func (bs * BlockScannerBase ) GetGlobalMaxBlockHeight () uint64 {
448
458
return 0
449
459
}
450
460
451
- //GetScannedBlockHeight 获取已扫区块高度
461
+ // GetScannedBlockHeight 获取已扫区块高度
452
462
func (bs * BlockScannerBase ) GetScannedBlockHeight () uint64 {
453
463
return 0
454
464
}
@@ -457,13 +467,13 @@ func (bs *BlockScannerBase) ExtractTransactionData(txid string, scanTargetFunc B
457
467
return nil , fmt .Errorf ("ExtractTransactionData is not implemented" )
458
468
}
459
469
460
- //ExtractTransactionAndReceiptData 提取交易单及交易回执数据
461
- //@required
470
+ // ExtractTransactionAndReceiptData 提取交易单及交易回执数据
471
+ // @required
462
472
func (bs * BlockScannerBase ) ExtractTransactionAndReceiptData (txid string , scanTargetFunc BlockScanTargetFuncV2 ) (map [string ][]* TxExtractData , map [string ]* SmartContractReceipt , error ) {
463
473
return nil , nil , fmt .Errorf ("ExtractTransactionAndReceiptData is not implemented" )
464
474
}
465
475
466
- //GetBalanceByAddress 查询地址余额
476
+ // GetBalanceByAddress 查询地址余额
467
477
func (bs * BlockScannerBase ) GetBalanceByAddress (address ... string ) ([]* Balance , error ) {
468
478
return nil , fmt .Errorf ("GetBalanceByAddress is not implemented" )
469
479
}
@@ -473,33 +483,33 @@ func (bs *BlockScannerBase) GetBalanceByAddress(address ...string) ([]*Balance,
473
483
// return nil, nil
474
484
//}
475
485
476
- //GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址
477
- //返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算
486
+ // GetTransactionsByAddress 查询基于账户的交易记录,通过账户关系的地址
487
+ // 返回的交易记录以资产账户为集合的结果,转账数量以基于账户来计算
478
488
func (bs * BlockScannerBase ) GetTransactionsByAddress (offset , limit int , coin Coin , address ... string ) ([]* TxExtractData , error ) {
479
489
return nil , fmt .Errorf ("GetTransactionsByAddress is not implemented" )
480
490
}
481
491
482
- //SetBlockScanWalletDAI 设置区块扫描过程,上层提供一个钱包数据接口
483
- //@optional
492
+ // SetBlockScanWalletDAI 设置区块扫描过程,上层提供一个钱包数据接口
493
+ // @optional
484
494
func (bs * BlockScannerBase ) SetBlockScanWalletDAI (dai WalletDAI ) error {
485
495
bs .WalletDAI = dai
486
496
return nil
487
497
}
488
498
489
- //SupportBlockchainDAI 支持外部设置区块链数据访问接口
490
- //@optional
499
+ // SupportBlockchainDAI 支持外部设置区块链数据访问接口
500
+ // @optional
491
501
func (bs * BlockScannerBase ) SupportBlockchainDAI () bool {
492
502
return false
493
503
}
494
504
495
- //SetBlockchainDAI 设置区块链数据访问接口,读取持久化的区块数据
496
- //@optional
505
+ // SetBlockchainDAI 设置区块链数据访问接口,读取持久化的区块数据
506
+ // @optional
497
507
func (bs * BlockScannerBase ) SetBlockchainDAI (dai BlockchainDAI ) error {
498
508
bs .BlockchainDAI = dai
499
509
return nil
500
510
}
501
511
502
- //NewBlockNotify 获得新区块后,发送到通知通道
512
+ // NewBlockNotify 获得新区块后,发送到通知通道
503
513
func (bs * BlockScannerBase ) NewBlockNotify (block * BlockHeader ) error {
504
514
bs .Mu .RLock ()
505
515
defer bs .Mu .RUnlock ()
@@ -510,7 +520,7 @@ func (bs *BlockScannerBase) NewBlockNotify(block *BlockHeader) error {
510
520
return nil
511
521
}
512
522
513
- //CloseBlockScanner 关闭扫描器
523
+ // CloseBlockScanner 关闭扫描器
514
524
func (bs * BlockScannerBase ) CloseBlockScanner () error {
515
525
516
526
//保证只关闭一次
@@ -527,7 +537,7 @@ func (bs *BlockScannerBase) CloseBlockScanner() error {
527
537
return nil
528
538
}
529
539
530
- //newBlockNotifyConsume
540
+ // newBlockNotifyConsume
531
541
func (bs * BlockScannerBase ) newBlockNotifyConsume () {
532
542
533
543
for {
@@ -547,3 +557,9 @@ func (bs *BlockScannerBase) newBlockNotifyConsume() {
547
557
548
558
}
549
559
}
560
+
561
+ // GetBlockchainSyncStatus 获取当前区块链同步状态
562
+ // @optional
563
+ func (bs * BlockScannerBase ) GetBlockchainSyncStatus () (* BlockchainSyncStatus , error ) {
564
+ return nil , fmt .Errorf ("GetBlockchainSyncStatus is not implemented" )
565
+ }
0 commit comments