[#4200] Avoid tx watching for addresses which were not exposed
This commit is contained in:
parent
8206ffc736
commit
aee111e5ab
|
@ -29,6 +29,7 @@ type StatusBackend interface {
|
|||
// SelectAccount(loginParams account.LoginParams) error
|
||||
OpenAccounts() error
|
||||
GetAccounts() ([]multiaccounts.Account, error)
|
||||
LocalPairingStarted() error
|
||||
// SaveAccount(account multiaccounts.Account) error
|
||||
SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, settings settings.Settings, conf *params.NodeConfig, subaccs []*accounts.Account, keyHex string) error
|
||||
Recover(rpcParams personal.RecoverParams) (types.Address, error)
|
||||
|
|
|
@ -1352,6 +1352,7 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, customizati
|
|||
if mnemonic == "" {
|
||||
settings.Mnemonic = &info.Mnemonic
|
||||
settings.OmitTransfersHistoryScan = true
|
||||
//settings.MnemonicWasNotShown = true
|
||||
}
|
||||
|
||||
nodeConfig, err := defaultNodeConfig(settings.InstallationID, request)
|
||||
|
@ -1377,6 +1378,10 @@ func (b *GethStatusBackend) generateOrImportAccount(mnemonic string, customizati
|
|||
Name: walletAccountDefaultName,
|
||||
}
|
||||
|
||||
if mnemonic == "" {
|
||||
walletAccount.AddressWasNotShown = true
|
||||
}
|
||||
|
||||
chatDerivedAccount := derivedAddresses[pathDefaultChat]
|
||||
chatAccount := &accounts.Account{
|
||||
PublicKey: types.Hex2Bytes(chatDerivedAccount.PublicKey),
|
||||
|
@ -2294,6 +2299,19 @@ func (b *GethStatusBackend) GetActiveAccount() (*multiaccounts.Account, error) {
|
|||
return b.account, nil
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) LocalPairingStarted() error {
|
||||
if b.account == nil {
|
||||
return errors.New("master key account is nil in the GethStatusBackend")
|
||||
}
|
||||
|
||||
accountDB, err := accounts.NewDB(b.appDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return accountDB.MnemonicWasShown()
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) injectAccountsIntoWakuService(w types.WakuKeyManager, st *ext.Service) error {
|
||||
chatAccount, err := b.accountManager.SelectedChatAccount()
|
||||
if err != nil {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
ALTER TABLE keypairs_accounts ADD COLUMN address_was_not_shown BOOLEAN NOT NULL DEFAULT FALSE;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE settings ADD COLUMN mnemonic_was_not_shown BOOLEAN NOT NULL DEFAULT FALSE;
|
File diff suppressed because it is too large
Load Diff
|
@ -354,6 +354,7 @@ func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subacc
|
|||
|
||||
if *settings.Mnemonic != "" {
|
||||
settings.OmitTransfersHistoryScan = true
|
||||
settings.MnemonicWasNotShown = true
|
||||
}
|
||||
|
||||
var conf params.NodeConfig
|
||||
|
|
|
@ -58,6 +58,7 @@ type Account struct {
|
|||
Address types.Address `json:"address"`
|
||||
KeyUID string `json:"key-uid"`
|
||||
Wallet bool `json:"wallet"`
|
||||
AddressWasNotShown bool `json:"address-was-not-shown,omitempty"`
|
||||
Chat bool `json:"chat"`
|
||||
Type AccountType `json:"type,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
|
@ -354,6 +355,7 @@ func (db *Database) processRows(rows *sql.Rows) ([]*Keypair, []*Account, error)
|
|||
accRemoved sql.NullBool
|
||||
accProdPreferredChainIDs sql.NullString
|
||||
accTestPreferredChainIDs sql.NullString
|
||||
accAddressWasNotShown sql.NullBool
|
||||
)
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -364,7 +366,7 @@ func (db *Database) processRows(rows *sql.Rows) ([]*Keypair, []*Account, error)
|
|||
&kpKeyUID, &kpName, &kpType, &kpDerivedFrom, &kpLastUsedDerivationIndex, &kpSyncedFrom, &kpClock, &kpRemoved,
|
||||
&accAddress, &accKeyUID, &pubkey, &accPath, &accName, &accColorID, &accEmoji,
|
||||
&accWallet, &accChat, &accHidden, &accOperable, &accClock, &accCreatedAt, &accPosition, &accRemoved,
|
||||
&accProdPreferredChainIDs, &accTestPreferredChainIDs)
|
||||
&accProdPreferredChainIDs, &accTestPreferredChainIDs, &accAddressWasNotShown)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -440,6 +442,9 @@ func (db *Database) processRows(rows *sql.Rows) ([]*Keypair, []*Account, error)
|
|||
if accTestPreferredChainIDs.Valid {
|
||||
acc.TestPreferredChainIDs = accTestPreferredChainIDs.String
|
||||
}
|
||||
if accAddressWasNotShown.Valid {
|
||||
acc.AddressWasNotShown = accAddressWasNotShown.Bool
|
||||
}
|
||||
if lth := len(pubkey); lth > 0 {
|
||||
acc.PublicKey = make(types.HexBytes, lth)
|
||||
copy(acc.PublicKey, pubkey)
|
||||
|
@ -529,7 +534,8 @@ func (db *Database) getKeypairs(tx *sql.Tx, keyUID string, includeRemoved bool)
|
|||
ka.position,
|
||||
ka.removed,
|
||||
ka.prod_preferred_chain_ids,
|
||||
ka.test_preferred_chain_ids
|
||||
ka.test_preferred_chain_ids,
|
||||
ka.address_was_not_shown
|
||||
FROM
|
||||
keypairs k
|
||||
LEFT JOIN
|
||||
|
@ -631,7 +637,8 @@ func (db *Database) getAccounts(tx *sql.Tx, address types.Address, includeRemove
|
|||
ka.position,
|
||||
ka.removed,
|
||||
ka.prod_preferred_chain_ids,
|
||||
ka.test_preferred_chain_ids
|
||||
ka.test_preferred_chain_ids,
|
||||
ka.address_was_not_shown
|
||||
FROM
|
||||
keypairs_accounts ka
|
||||
LEFT JOIN
|
||||
|
@ -994,9 +1001,9 @@ func (db *Database) saveOrUpdateAccounts(tx *sql.Tx, accounts []*Account, update
|
|||
|
||||
_, err = tx.Exec(`
|
||||
INSERT OR IGNORE INTO
|
||||
keypairs_accounts (address, key_uid, pubkey, path, wallet, chat, created_at, updated_at)
|
||||
keypairs_accounts (address, key_uid, pubkey, path, wallet, address_was_not_shown, chat, created_at, updated_at)
|
||||
VALUES
|
||||
(?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'));
|
||||
(?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'));
|
||||
|
||||
UPDATE
|
||||
keypairs_accounts
|
||||
|
@ -1015,7 +1022,7 @@ func (db *Database) saveOrUpdateAccounts(tx *sql.Tx, accounts []*Account, update
|
|||
WHERE
|
||||
address = ?;
|
||||
`,
|
||||
acc.Address, keyUID, acc.PublicKey, acc.Path, acc.Wallet, acc.Chat,
|
||||
acc.Address, keyUID, acc.PublicKey, acc.Path, acc.Wallet, acc.AddressWasNotShown, acc.Chat,
|
||||
acc.Name, acc.ColorID, acc.Emoji, acc.Hidden, acc.Operable, acc.Clock, acc.Position, acc.Removed,
|
||||
acc.ProdPreferredChainIDs, acc.TestPreferredChainIDs, acc.Address)
|
||||
|
||||
|
@ -1644,3 +1651,20 @@ func (db *Database) CheckAndDeleteExpiredKeypairsAndAccounts(time uint64) error
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Database) AddressWasShown(address types.Address) error {
|
||||
tx, err := db.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(`UPDATE keypairs_accounts SET address_was_not_shown = 0 WHERE address = ?`, address)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -452,7 +452,11 @@ var (
|
|||
dBColumnName: "omit_transfers_history_scan",
|
||||
valueHandler: BoolHandler,
|
||||
}
|
||||
|
||||
MnemonicWasNotShown = SettingField{
|
||||
reactFieldName: "mnemonic-was-not-shown?",
|
||||
dBColumnName: "mnemonic_was_not_shown",
|
||||
valueHandler: BoolHandler,
|
||||
}
|
||||
SettingFieldRegister = []SettingField{
|
||||
AnonMetricsShouldSend,
|
||||
Appearance,
|
||||
|
|
|
@ -126,10 +126,11 @@ INSERT INTO settings (
|
|||
profile_pictures_show_to,
|
||||
profile_pictures_visibility,
|
||||
url_unfurling_mode,
|
||||
omit_transfers_history_scan
|
||||
omit_transfers_history_scan,
|
||||
mnemonic_was_not_shown
|
||||
) VALUES (
|
||||
?,?,?,?,?,?,?,?,?,?,?,?,?,
|
||||
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?)`,
|
||||
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?)`,
|
||||
s.Address,
|
||||
s.Currency,
|
||||
s.CurrentNetwork,
|
||||
|
@ -157,6 +158,7 @@ INSERT INTO settings (
|
|||
s.ProfilePicturesVisibility,
|
||||
s.URLUnfurlingMode,
|
||||
s.OmitTransfersHistoryScan,
|
||||
s.MnemonicWasNotShown,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -352,7 +354,7 @@ func (db *Database) GetSettings() (Settings, error) {
|
|||
waku_bloom_filter_mode, webview_allow_permission_requests, current_user_status, send_status_updates, gif_recents,
|
||||
gif_favorites, opensea_enabled, last_backup, backup_enabled, telemetry_server_url, auto_message_enabled, gif_api_key,
|
||||
test_networks_enabled, mutual_contact_enabled, profile_migration_needed, is_sepolia_enabled, url_unfurling_mode,
|
||||
omit_transfers_history_scan
|
||||
omit_transfers_history_scan, mnemonic_was_not_shown
|
||||
FROM
|
||||
settings
|
||||
WHERE
|
||||
|
@ -429,6 +431,7 @@ func (db *Database) GetSettings() (Settings, error) {
|
|||
&s.IsSepoliaEnabled,
|
||||
&s.URLUnfurlingMode,
|
||||
&s.OmitTransfersHistoryScan,
|
||||
&s.MnemonicWasNotShown,
|
||||
)
|
||||
|
||||
return s, err
|
||||
|
@ -613,6 +616,14 @@ func (db *Database) MnemonicRemoved() (result bool, err error) {
|
|||
return result, err
|
||||
}
|
||||
|
||||
func (db *Database) GetMnemonicWasNotShown() (result bool, err error) {
|
||||
err = db.makeSelectRow(MnemonicWasNotShown).Scan(&result)
|
||||
if err == sql.ErrNoRows {
|
||||
return result, nil
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (db *Database) GifAPIKey() (string, error) {
|
||||
return db.makeSelectString(GifAPIKey)
|
||||
}
|
||||
|
@ -742,3 +753,7 @@ func (db *Database) postChangesToSubscribers(change *SyncSettingField) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (db *Database) MnemonicWasShown() error {
|
||||
return db.SaveSettingField(MnemonicWasNotShown, false)
|
||||
}
|
||||
|
|
|
@ -142,11 +142,13 @@ type Settings struct {
|
|||
LogLevel *string `json:"log-level,omitempty"`
|
||||
MessagesFromContactsOnly bool `json:"messages-from-contacts-only"`
|
||||
Mnemonic *string `json:"mnemonic,omitempty"`
|
||||
MnemonicRemoved bool `json:"mnemonic-removed?,omitempty"`
|
||||
OmitTransfersHistoryScan bool `json:"omit-transfers-history-scan?,omitempty"`
|
||||
MutualContactEnabled bool `json:"mutual-contact-enabled?"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networks *json.RawMessage `json:"networks/networks"`
|
||||
// NOTE(rasom): negation here because it safer/simpler to have false by default
|
||||
MnemonicWasNotShown bool `json:"mnemonic-was-not-shown?,omitempty"`
|
||||
MnemonicRemoved bool `json:"mnemonic-removed?,omitempty"`
|
||||
OmitTransfersHistoryScan bool `json:"omit-transfers-history-scan?,omitempty"`
|
||||
MutualContactEnabled bool `json:"mutual-contact-enabled?"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networks *json.RawMessage `json:"networks/networks"`
|
||||
// NotificationsEnabled indicates whether local notifications should be enabled (android only)
|
||||
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
|
||||
PhotoPath string `json:"photo-path"`
|
||||
|
|
|
@ -46,7 +46,7 @@ func handleReceiveAccount(logger *zap.Logger, pr PayloadReceiver) http.HandlerFu
|
|||
}
|
||||
}
|
||||
|
||||
func handleSendAccount(logger *zap.Logger, pm PayloadMounter) http.HandlerFunc {
|
||||
func handleSendAccount(logger *zap.Logger, pm PayloadMounter, beforeSending func()) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingAccount})
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
|
@ -58,6 +58,7 @@ func handleSendAccount(logger *zap.Logger, pm PayloadMounter) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
beforeSending()
|
||||
_, err = w.Write(pm.ToSend())
|
||||
if err != nil {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventTransferError, Error: err.Error(), Action: ActionPairingAccount})
|
||||
|
@ -96,7 +97,7 @@ func handleParingSyncDeviceReceive(logger *zap.Logger, pr PayloadReceiver) http.
|
|||
}
|
||||
}
|
||||
|
||||
func handlePairingSyncDeviceSend(logger *zap.Logger, pm PayloadMounter) http.HandlerFunc {
|
||||
func handlePairingSyncDeviceSend(logger *zap.Logger, pm PayloadMounter, beforeSending func()) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionSyncDevice})
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
|
@ -110,6 +111,7 @@ func handlePairingSyncDeviceSend(logger *zap.Logger, pm PayloadMounter) http.Han
|
|||
return
|
||||
}
|
||||
|
||||
beforeSending()
|
||||
_, err = w.Write(pm.ToSend())
|
||||
if err != nil {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventTransferError, Error: err.Error(), Action: ActionSyncDevice})
|
||||
|
@ -148,7 +150,7 @@ func handleReceiveInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) h
|
|||
}
|
||||
}
|
||||
|
||||
func handleSendInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) http.HandlerFunc {
|
||||
func handleSendInstallation(logger *zap.Logger, pmr PayloadMounterReceiver, beforeSending func()) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess, Action: ActionPairingInstallation})
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
|
@ -160,6 +162,7 @@ func handleSendInstallation(logger *zap.Logger, pmr PayloadMounterReceiver) http
|
|||
return
|
||||
}
|
||||
|
||||
beforeSending()
|
||||
_, err = w.Write(pmr.ToSend())
|
||||
if err != nil {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventTransferError, Error: err.Error(), Action: ActionPairingInstallation})
|
||||
|
|
|
@ -108,6 +108,7 @@ type SenderServer struct {
|
|||
accountMounter PayloadMounter
|
||||
rawMessageMounter PayloadMounter
|
||||
installationMounter PayloadMounterReceiver
|
||||
backend *api.GethStatusBackend
|
||||
}
|
||||
|
||||
// NewSenderServer returns a *SenderServer init from the given *SenderServerConfig
|
||||
|
@ -130,14 +131,24 @@ func NewSenderServer(backend *api.GethStatusBackend, config *SenderServerConfig)
|
|||
accountMounter: am,
|
||||
rawMessageMounter: rmm,
|
||||
installationMounter: imr,
|
||||
backend: backend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SenderServer) startSendingData() error {
|
||||
logger := s.GetLogger()
|
||||
beforeSending := func() {
|
||||
if s.backend != nil {
|
||||
err := s.backend.LocalPairingStarted()
|
||||
if err != nil {
|
||||
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
s.SetHandlers(server.HandlerPatternMap{
|
||||
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
||||
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(s.GetLogger(), s.accountMounter)),
|
||||
pairingSendSyncDevice: middlewareChallenge(s.challengeGiver, handlePairingSyncDeviceSend(s.GetLogger(), s.rawMessageMounter)),
|
||||
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(logger, s.accountMounter, beforeSending)),
|
||||
pairingSendSyncDevice: middlewareChallenge(s.challengeGiver, handlePairingSyncDeviceSend(logger, s.rawMessageMounter, beforeSending)),
|
||||
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
||||
// the other handlers.
|
||||
// https://github.com/status-im/status-go/issues/3304
|
||||
|
@ -205,6 +216,7 @@ type ReceiverServer struct {
|
|||
accountReceiver PayloadReceiver
|
||||
rawMessageReceiver PayloadReceiver
|
||||
installationReceiver PayloadMounterReceiver
|
||||
backend *api.GethStatusBackend
|
||||
}
|
||||
|
||||
// NewReceiverServer returns a *SenderServer init from the given *ReceiverServerConfig
|
||||
|
@ -227,19 +239,29 @@ func NewReceiverServer(backend *api.GethStatusBackend, config *ReceiverServerCon
|
|||
accountReceiver: ar,
|
||||
rawMessageReceiver: rmr,
|
||||
installationReceiver: imr,
|
||||
backend: backend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ReceiverServer) startReceivingData() error {
|
||||
logger := s.GetLogger()
|
||||
beforeSending := func() {
|
||||
if s.backend != nil {
|
||||
err := s.backend.LocalPairingStarted()
|
||||
if err != nil {
|
||||
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
s.SetHandlers(server.HandlerPatternMap{
|
||||
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
||||
pairingReceiveAccount: handleReceiveAccount(s.GetLogger(), s.accountReceiver),
|
||||
pairingReceiveSyncDevice: handleParingSyncDeviceReceive(s.GetLogger(), s.rawMessageReceiver),
|
||||
pairingReceiveAccount: handleReceiveAccount(logger, s.accountReceiver),
|
||||
pairingReceiveSyncDevice: handleParingSyncDeviceReceive(logger, s.rawMessageReceiver),
|
||||
// TODO implement refactor of installation data exchange to follow the send/receive pattern of
|
||||
// the other handlers.
|
||||
// https://github.com/status-im/status-go/issues/3304
|
||||
// send installation data back to sender
|
||||
pairingSendInstallation: middlewareChallenge(s.challengeGiver, handleSendInstallation(s.GetLogger(), s.installationReceiver)),
|
||||
pairingSendInstallation: middlewareChallenge(s.challengeGiver, handleSendInstallation(logger, s.installationReceiver, beforeSending)),
|
||||
})
|
||||
return s.Start()
|
||||
}
|
||||
|
@ -301,6 +323,7 @@ func StartUpReceiverServer(backend *api.GethStatusBackend, configJSON string) (s
|
|||
type KeystoreFilesSenderServer struct {
|
||||
*BaseServer
|
||||
keystoreFilesMounter PayloadMounter
|
||||
backend *api.GethStatusBackend
|
||||
}
|
||||
|
||||
func NewKeystoreFilesSenderServer(backend *api.GethStatusBackend, config *KeystoreFilesSenderServerConfig) (*KeystoreFilesSenderServer, error) {
|
||||
|
@ -320,13 +343,23 @@ func NewKeystoreFilesSenderServer(backend *api.GethStatusBackend, config *Keysto
|
|||
return &KeystoreFilesSenderServer{
|
||||
BaseServer: bs,
|
||||
keystoreFilesMounter: kfm,
|
||||
backend: backend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *KeystoreFilesSenderServer) startSendingData() error {
|
||||
logger := s.GetLogger()
|
||||
beforeSending := func() {
|
||||
if s.backend != nil {
|
||||
err := s.backend.LocalPairingStarted()
|
||||
if err != nil {
|
||||
logger.Error("startSendingData backend.LocalPairingStarted()", zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
s.SetHandlers(server.HandlerPatternMap{
|
||||
pairingChallenge: handlePairingChallenge(s.challengeGiver),
|
||||
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(s.GetLogger(), s.keystoreFilesMounter)),
|
||||
pairingSendAccount: middlewareChallenge(s.challengeGiver, handleSendAccount(logger, s.keystoreFilesMounter, beforeSending)),
|
||||
})
|
||||
return s.Start()
|
||||
}
|
||||
|
|
|
@ -293,6 +293,10 @@ func (api *API) AddAccount(ctx context.Context, password string, account *accoun
|
|||
}
|
||||
}
|
||||
|
||||
if account.Type == accounts.AccountTypeGenerated {
|
||||
account.AddressWasNotShown = true
|
||||
}
|
||||
|
||||
return api.SaveAccount(ctx, account)
|
||||
}
|
||||
|
||||
|
@ -587,3 +591,7 @@ func (api *API) DeleteAllKeycardsWithKeyUID(ctx context.Context, keyUID string)
|
|||
func (api *API) UpdateKeycardUID(ctx context.Context, oldKeycardUID string, newKeycardUID string) error {
|
||||
return (*api.messenger).UpdateKeycardUID(ctx, oldKeycardUID, newKeycardUID)
|
||||
}
|
||||
|
||||
func (api *API) AddressWasShown(address types.Address) error {
|
||||
return api.db.AddressWasShown(address)
|
||||
}
|
||||
|
|
|
@ -186,3 +186,7 @@ func (api *SettingsAPI) AddOrReplaceSocialLinks(links identity.SocialLinks) erro
|
|||
|
||||
return (*api.messenger).AddOrReplaceSocialLinks(links)
|
||||
}
|
||||
|
||||
func (api *SettingsAPI) MnemonicWasShown() error {
|
||||
return api.db.MnemonicWasShown()
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
nodetypes "github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/rpc/chain"
|
||||
"github.com/status-im/status-go/services/wallet/async"
|
||||
"github.com/status-im/status-go/services/wallet/balance"
|
||||
|
@ -74,6 +76,7 @@ func (c *findNewBlocksCommand) Run(parent context.Context) (err error) {
|
|||
type findBlocksCommand struct {
|
||||
account common.Address
|
||||
db *Database
|
||||
accountsDB *accounts.Database
|
||||
blockRangeDAO *BlockRangeSequentialDAO
|
||||
chainClient chain.ClientInterface
|
||||
balanceCacher balance.Cacher
|
||||
|
@ -223,8 +226,27 @@ func (c *findBlocksCommand) checkERC20Tail(parent context.Context) ([]*DBHeader,
|
|||
return foundHeaders, nil
|
||||
}
|
||||
|
||||
var mnemonicCheckEnabled = false
|
||||
|
||||
func (c *findBlocksCommand) Run(parent context.Context) (err error) {
|
||||
log.Debug("start findBlocksCommand", "account", c.account, "chain", c.chainClient.NetworkID(), "noLimit", c.noLimit, "from", c.fromBlockNumber, "to", c.toBlockNumber)
|
||||
mnemonicWasNotShown, err := c.accountsDB.GetMnemonicWasNotShown()
|
||||
if err != nil {
|
||||
c.error = err
|
||||
return err
|
||||
}
|
||||
|
||||
if mnemonicCheckEnabled && mnemonicWasNotShown {
|
||||
account, err := c.accountsDB.GetAccountByAddress(nodetypes.BytesToAddress(c.account.Bytes()))
|
||||
if err != nil {
|
||||
c.error = err
|
||||
return err
|
||||
}
|
||||
if account.AddressWasNotShown {
|
||||
log.Info("skip findBlocksCommand, mnemonic has not been shown and the address has not been shared yet", "address", c.account)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
rangeSize := big.NewInt(int64(c.defaultNodeBlockChunkSize))
|
||||
|
||||
|
@ -513,7 +535,7 @@ func loadTransfersLoop(ctx context.Context, account common.Address, blockDAO *Bl
|
|||
}
|
||||
}
|
||||
|
||||
func newLoadBlocksAndTransfersCommand(account common.Address, db *Database,
|
||||
func newLoadBlocksAndTransfersCommand(account common.Address, db *Database, accountsDB *accounts.Database,
|
||||
blockDAO *BlockDAO, blockRangesSeqDAO *BlockRangeSequentialDAO, chainClient chain.ClientInterface, feed *event.Feed,
|
||||
transactionManager *TransactionManager, pendingTxManager *transactions.PendingTxTracker,
|
||||
tokenManager *token.Manager, balanceCacher balance.Cacher, omitHistory bool) *loadBlocksAndTransfersCommand {
|
||||
|
@ -522,6 +544,7 @@ func newLoadBlocksAndTransfersCommand(account common.Address, db *Database,
|
|||
account: account,
|
||||
db: db,
|
||||
blockRangeDAO: blockRangesSeqDAO,
|
||||
accountsDB: accountsDB,
|
||||
blockDAO: blockDAO,
|
||||
chainClient: chainClient,
|
||||
feed: feed,
|
||||
|
@ -537,6 +560,7 @@ func newLoadBlocksAndTransfersCommand(account common.Address, db *Database,
|
|||
type loadBlocksAndTransfersCommand struct {
|
||||
account common.Address
|
||||
db *Database
|
||||
accountsDB *accounts.Database
|
||||
blockRangeDAO *BlockRangeSequentialDAO
|
||||
blockDAO *BlockDAO
|
||||
chainClient chain.ClientInterface
|
||||
|
@ -554,7 +578,7 @@ type loadBlocksAndTransfersCommand struct {
|
|||
}
|
||||
|
||||
func (c *loadBlocksAndTransfersCommand) Run(parent context.Context) error {
|
||||
log.Debug("start load all transfers command", "chain", c.chainClient.NetworkID(), "account", c.account)
|
||||
log.Info("start load all transfers command", "chain", c.chainClient.NetworkID(), "account", c.account)
|
||||
|
||||
ctx := parent
|
||||
|
||||
|
@ -609,7 +633,6 @@ func (c *loadBlocksAndTransfersCommand) startTransfersLoop(ctx context.Context)
|
|||
}
|
||||
|
||||
func (c *loadBlocksAndTransfersCommand) fetchHistoryBlocks(ctx context.Context, group *async.Group, fromNum, toNum *big.Int, blocksLoadedCh chan []*DBHeader) error {
|
||||
|
||||
log.Debug("fetchHistoryBlocks start", "chainID", c.chainClient.NetworkID(), "account", c.account, "omit", c.omitHistory)
|
||||
|
||||
if c.omitHistory {
|
||||
|
@ -633,6 +656,7 @@ func (c *loadBlocksAndTransfersCommand) fetchHistoryBlocks(ctx context.Context,
|
|||
fbc := &findBlocksCommand{
|
||||
account: c.account,
|
||||
db: c.db,
|
||||
accountsDB: c.accountsDB,
|
||||
blockRangeDAO: c.blockRangeDAO,
|
||||
chainClient: c.chainClient,
|
||||
balanceCacher: c.balanceCacher,
|
||||
|
@ -667,12 +691,13 @@ func (c *loadBlocksAndTransfersCommand) fetchHistoryBlocks(ctx context.Context,
|
|||
|
||||
func (c *loadBlocksAndTransfersCommand) startFetchingNewBlocks(group *async.Group, address common.Address, blocksLoadedCh chan<- []*DBHeader) {
|
||||
|
||||
log.Debug("startFetchingNewBlocks", "chainID", c.chainClient.NetworkID(), "account", address)
|
||||
log.Debug("startFetchingNewBlocks", "chainID", c.chainClient.NetworkID(), "account", address, "db", c.accountsDB)
|
||||
|
||||
newBlocksCmd := &findNewBlocksCommand{
|
||||
findBlocksCommand: &findBlocksCommand{
|
||||
account: address,
|
||||
db: c.db,
|
||||
accountsDB: c.accountsDB,
|
||||
blockRangeDAO: c.blockRangeDAO,
|
||||
chainClient: c.chainClient,
|
||||
balanceCacher: c.balanceCacher,
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/balance"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/params"
|
||||
statusRpc "github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/rpc/network"
|
||||
|
@ -942,10 +943,13 @@ func TestFindBlocksCommand(t *testing.T) {
|
|||
Verified: true,
|
||||
},
|
||||
})
|
||||
accDB, err := accounts.NewDB(appdb)
|
||||
require.NoError(t, err)
|
||||
fbc := &findBlocksCommand{
|
||||
account: common.HexToAddress("0x1234"),
|
||||
db: wdb,
|
||||
blockRangeDAO: &BlockRangeSequentialDAO{wdb.client},
|
||||
accountsDB: accDB,
|
||||
chainClient: tc,
|
||||
balanceCacher: balance.NewCacherWithTTL(5 * time.Minute),
|
||||
feed: &event.Feed{},
|
||||
|
@ -1065,11 +1069,15 @@ func TestFetchTransfersForLoadedBlocks(t *testing.T) {
|
|||
|
||||
chainClient := newMockChainClient()
|
||||
tracker := transactions.NewPendingTxTracker(db, chainClient, nil, &event.Feed{}, transactions.PendingCheckInterval)
|
||||
accDB, err := accounts.NewDB(wdb.client)
|
||||
require.NoError(t, err)
|
||||
|
||||
cmd := &loadBlocksAndTransfersCommand{
|
||||
account: common.HexToAddress("0x1234"),
|
||||
db: wdb,
|
||||
blockRangeDAO: &BlockRangeSequentialDAO{wdb.client},
|
||||
blockDAO: &BlockDAO{db},
|
||||
accountsDB: accDB,
|
||||
chainClient: tc,
|
||||
feed: &event.Feed{},
|
||||
balanceCacher: balance.NewCacherWithTTL(5 * time.Minute),
|
||||
|
|
|
@ -110,7 +110,7 @@ func (c *Controller) CheckRecentHistory(chainIDs []uint64, accounts []common.Add
|
|||
}
|
||||
}
|
||||
|
||||
c.reactor = NewReactor(c.db, c.blockDAO, c.blockRangesSeqDAO, c.TransferFeed, c.transactionManager,
|
||||
c.reactor = NewReactor(c.db, c.blockDAO, c.blockRangesSeqDAO, c.accountsDB, c.TransferFeed, c.transactionManager,
|
||||
c.pendingTxManager, c.tokenManager, c.balanceCacher, omitHistory)
|
||||
|
||||
err = c.reactor.start(chainClients, accounts)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/rpc/chain"
|
||||
"github.com/status-im/status-go/services/wallet/balance"
|
||||
"github.com/status-im/status-go/services/wallet/token"
|
||||
|
@ -49,6 +50,7 @@ type Reactor struct {
|
|||
db *Database
|
||||
blockDAO *BlockDAO
|
||||
blockRangesSeqDAO *BlockRangeSequentialDAO
|
||||
accountsDB *accounts.Database
|
||||
feed *event.Feed
|
||||
transactionManager *TransactionManager
|
||||
pendingTxManager *transactions.PendingTxTracker
|
||||
|
@ -58,11 +60,12 @@ type Reactor struct {
|
|||
omitHistory bool
|
||||
}
|
||||
|
||||
func NewReactor(db *Database, blockDAO *BlockDAO, blockRangesSeqDAO *BlockRangeSequentialDAO, feed *event.Feed, tm *TransactionManager,
|
||||
func NewReactor(db *Database, blockDAO *BlockDAO, blockRangesSeqDAO *BlockRangeSequentialDAO, accountsDB *accounts.Database, feed *event.Feed, tm *TransactionManager,
|
||||
pendingTxManager *transactions.PendingTxTracker, tokenManager *token.Manager,
|
||||
balanceCacher balance.Cacher, omitHistory bool) *Reactor {
|
||||
return &Reactor{
|
||||
db: db,
|
||||
accountsDB: accountsDB,
|
||||
blockDAO: blockDAO,
|
||||
blockRangesSeqDAO: blockRangesSeqDAO,
|
||||
feed: feed,
|
||||
|
@ -101,6 +104,7 @@ func (r *Reactor) createFetchStrategy(chainClients map[uint64]chain.ClientInterf
|
|||
r.db,
|
||||
r.blockDAO,
|
||||
r.blockRangesSeqDAO,
|
||||
r.accountsDB,
|
||||
r.feed,
|
||||
r.transactionManager,
|
||||
r.pendingTxManager,
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/rpc/chain"
|
||||
"github.com/status-im/status-go/services/wallet/async"
|
||||
"github.com/status-im/status-go/services/wallet/balance"
|
||||
|
@ -16,7 +17,7 @@ import (
|
|||
"github.com/status-im/status-go/transactions"
|
||||
)
|
||||
|
||||
func NewSequentialFetchStrategy(db *Database, blockDAO *BlockDAO, blockRangesSeqDAO *BlockRangeSequentialDAO, feed *event.Feed,
|
||||
func NewSequentialFetchStrategy(db *Database, blockDAO *BlockDAO, blockRangesSeqDAO *BlockRangeSequentialDAO, accountsDB *accounts.Database, feed *event.Feed,
|
||||
transactionManager *TransactionManager, pendingTxManager *transactions.PendingTxTracker,
|
||||
tokenManager *token.Manager,
|
||||
chainClients map[uint64]chain.ClientInterface,
|
||||
|
@ -29,6 +30,7 @@ func NewSequentialFetchStrategy(db *Database, blockDAO *BlockDAO, blockRangesSeq
|
|||
db: db,
|
||||
blockDAO: blockDAO,
|
||||
blockRangesSeqDAO: blockRangesSeqDAO,
|
||||
accountsDB: accountsDB,
|
||||
feed: feed,
|
||||
transactionManager: transactionManager,
|
||||
pendingTxManager: pendingTxManager,
|
||||
|
@ -44,6 +46,7 @@ type SequentialFetchStrategy struct {
|
|||
db *Database
|
||||
blockDAO *BlockDAO
|
||||
blockRangesSeqDAO *BlockRangeSequentialDAO
|
||||
accountsDB *accounts.Database
|
||||
feed *event.Feed
|
||||
mu sync.Mutex
|
||||
group *async.Group
|
||||
|
@ -59,7 +62,7 @@ type SequentialFetchStrategy struct {
|
|||
func (s *SequentialFetchStrategy) newCommand(chainClient chain.ClientInterface,
|
||||
account common.Address) async.Commander {
|
||||
|
||||
return newLoadBlocksAndTransfersCommand(account, s.db, s.blockDAO, s.blockRangesSeqDAO, chainClient, s.feed,
|
||||
return newLoadBlocksAndTransfersCommand(account, s.db, s.accountsDB, s.blockDAO, s.blockRangesSeqDAO, chainClient, s.feed,
|
||||
s.transactionManager, s.pendingTxManager, s.tokenManager, s.balanceCacher, s.omitHistory)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue