Skip to content

Commit

Permalink
fix: missing account when gateway restart
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Nov 15, 2023
1 parent 0f231a3 commit 5975439
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions wallet_event/listenevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ type IAPIRegisterHub interface {
}

type APIRegisterHub struct {
weClient map[string]*walletevent.WalletEventClient
bus EventBus.Bus
lk sync.Mutex
weClient map[string]*walletevent.WalletEventClient
bus EventBus.Bus
lk sync.Mutex
supportAccounts []string
}

func NewAPIRegisterHub(lc fx.Lifecycle, signer types.IWalletHandler, bus EventBus.Bus, cfg *config.APIRegisterHubConfig) (*APIRegisterHub, error) {
apiRegister := &APIRegisterHub{
weClient: make(map[string]*walletevent.WalletEventClient),
bus: bus,
lk: sync.Mutex{},
weClient: make(map[string]*walletevent.WalletEventClient),
bus: bus,
lk: sync.Mutex{},
supportAccounts: cfg.SupportAccounts,
}

if len(cfg.RegisterAPI) == 0 {
Expand All @@ -53,7 +55,9 @@ func NewAPIRegisterHub(lc fx.Lifecycle, signer types.IWalletHandler, bus EventBu
return nil, err
}
mLog := log.With("api hub", apiHub)
walletEvent := walletevent.NewWalletEventClient(ctx, signer, walletEventClient, mLog, cfg.SupportAccounts)
walletEvent := walletevent.NewWalletEventClient(ctx, signer, walletEventClient, mLog, func() []string {
return apiRegister.supportAccounts
})
go walletEvent.ListenWalletRequest(ctx)
apiRegister.lk.Lock()
apiRegister.weClient[apiHub] = walletEvent
Expand Down Expand Up @@ -94,6 +98,18 @@ func (h *APIRegisterHub) SupportNewAccount(ctx context.Context, supportAccount s
return err
}
}

for i, account := range h.supportAccounts {
if account == supportAccount {
break
}

// not found in supportAccounts
if i == len(h.supportAccounts)-1 {
h.supportAccounts = append(h.supportAccounts, supportAccount)
}
}

return nil
}

Expand Down

0 comments on commit 5975439

Please sign in to comment.