@@ -47,31 +47,6 @@ const (
47
47
DefaultGasLimit = 25000000
48
48
)
49
49
50
- /*
51
- type sender struct {
52
- c *Client
53
- src module.BtpAddress
54
- dst module.BtpAddress
55
- w Wallet
56
- l log.Logger
57
- opt struct {
58
- }
59
-
60
- bmc *binding.BMC
61
-
62
- evtLogRawFilter struct {
63
- addr []byte
64
- signature []byte
65
- next []byte
66
- seq []byte
67
- }
68
- evtReq *BlockRequest
69
- isFoundOffsetBySeq bool
70
- cb module.ReceiveCallback
71
-
72
- mutex sync.Mutex
73
- }
74
- */
75
50
76
51
type senderOptions struct {
77
52
GasLimit uint64 `json:"gas_limit"`
@@ -360,135 +335,3 @@ func revertReason(data []byte) string {
360
335
length := binary .BigEndian .Uint64 (data [24 :32 ])
361
336
return string (data [32 : 32 + length ])
362
337
}
363
-
364
- /*
365
- func (s *sender) newTransactionParam(prev string, rm *RelayMessage) (*TransactionParam, error) {
366
- b, err := codec.RLP.MarshalToBytes(rm)
367
- if err != nil {
368
- return nil, err
369
- }
370
- rmp := BMCRelayMethodParams{
371
- Prev: prev,
372
- //Messages: base64.URLEncoding.EncodeToString(b[:]),
373
- Messages: string(b[:]),
374
- }
375
- s.l.Debugf("HandleRelayMessage msg: %s", base64.URLEncoding.EncodeToString(b))
376
- p := &TransactionParam{
377
- Params: rmp,
378
- }
379
- return p, nil
380
- }
381
-
382
- func (s *sender) Relay(segment *module.Segment) (module.GetResultParam, error) {
383
- s.mutex.Lock()
384
- defer s.mutex.Unlock()
385
- p, ok := segment.TransactionParam.(*TransactionParam)
386
- if !ok {
387
- return nil, fmt.Errorf("casting failure")
388
- }
389
- t, err := s.c.newTransactOpts(s.w)
390
- if err != nil {
391
- return nil, err
392
- }
393
- rmp := p.Params.(BMCRelayMethodParams)
394
- var tx *types.Transaction
395
- tx, err = s.bmc.HandleRelayMessage(t, rmp.Prev, rmp.Messages)
396
- if err != nil {
397
- s.l.Errorf("handleRelayMessage: ", err.Error())
398
- return nil, err
399
- }
400
- thp := &TransactionHashParam{}
401
- thp.Hash = tx.Hash()
402
- s.l.Debugf("HandleRelayMessage tx hash:%s, prev %s, msg: %s", thp.Hash, rmp.Prev, base64.URLEncoding.EncodeToString([]byte(rmp.Messages)))
403
- return thp, nil
404
- }
405
-
406
- func (s *sender) GetResult(p module.GetResultParam) (module.TransactionResult, error) {
407
- if txh, ok := p.(*TransactionHashParam); ok {
408
- for {
409
- _, pending, err := s.c.GetTransaction(txh.Hash)
410
- if err != nil {
411
- return nil, err
412
- }
413
- if pending {
414
- <-time.After(DefaultGetRelayResultInterval)
415
- continue
416
- }
417
- tx, err := s.c.GetTransactionReceipt(txh.Hash)
418
- if err != nil {
419
- return nil, err
420
- }
421
- return tx, nil //mapErrorWithTransactionResult(&types.Receipt{}, err) // TODO: map transaction.js result error
422
- }
423
- } else {
424
- return nil, fmt.Errorf("fail to casting TransactionHashParam %T", p)
425
- }
426
- }
427
-
428
- func (s *sender) GetStatus() (*module.BMCLinkStatus, error) {
429
- var status binding.TypesLinkStats
430
- status, err := s.bmc.GetStatus(nil, s.src.String())
431
-
432
- if err != nil {
433
- s.l.Errorf("Error retrieving relay status from BMC")
434
- return nil, err
435
- }
436
-
437
- ls := &module.BMCLinkStatus{}
438
- ls.TxSeq = status.TxSeq.Int64()
439
- ls.RxSeq = status.RxSeq.Int64()
440
- ls.BMRIndex = int(status.RelayIdx.Int64())
441
- ls.RotateHeight = status.RotateHeight.Int64()
442
- ls.RotateTerm = int(status.RotateTerm.Int64())
443
- ls.DelayLimit = int(status.DelayLimit.Int64())
444
- ls.MaxAggregation = int(status.MaxAggregation.Int64())
445
- ls.CurrentHeight = status.CurrentHeight.Int64()
446
- ls.RxHeight = status.RxHeight.Int64()
447
- ls.RxHeightSrc = status.RxHeightSrc.Int64()
448
- return ls, nil
449
- }
450
-
451
- func (s *sender) isOverLimit(size int) bool {
452
- return txSizeLimit < float64(size)
453
- }
454
-
455
- func (s *sender) MonitorLoop(height int64, cb module.MonitorCallback, scb func()) error {
456
- s.l.Debugf("MonitorLoop (sender) connected")
457
- br := &BlockRequest{
458
- Height: big.NewInt(height),
459
- }
460
- return s.c.MonitorBlock(br,
461
- func(v *BlockNotification) error {
462
- return cb(v.Height.Int64())
463
- })
464
- }
465
-
466
- func (s *sender) StopMonitorLoop() {
467
- s.c.CloseAllMonitor()
468
- }
469
- func (s *sender) FinalizeLatency() int {
470
- //on-the-next
471
- return 1
472
- }
473
-
474
- func NewSender(src, dst module.BtpAddress, w Wallet, endpoints []string, opt map[string]interface{}, l log.Logger) module.Sender {
475
- s := &sender{
476
- src: src,
477
- dst: dst,
478
- w: w,
479
- l: l,
480
- }
481
- b, err := json.Marshal(opt)
482
- if err != nil {
483
- l.Panicf("fail to marshal opt:%#v err:%+v", opt, err)
484
- }
485
- if err = json.Unmarshal(b, &s.opt); err != nil {
486
- l.Panicf("fail to unmarshal opt:%#v err:%+v", opt, err)
487
- }
488
- s.c = NewClient(endpoints, l)
489
-
490
- s.bmc, _ = binding.NewBMC(HexToAddress(s.dst.ContractAddress()), s.c.ethcl)
491
-
492
- return s
493
- }
494
- */
0 commit comments