Dmitry Shulyak 0165b028c9
Watch new accounts aftter they were saved to accounts table (#1569)
* Watch new accounts once they are saved in accounts table

* Add test that reactor can be restarted and watch new accounts
2019-08-28 10:49:03 +03:00

32 lines
655 B
Go

package accounts
import (
"context"
"github.com/ethereum/go-ethereum/event"
"github.com/status-im/status-go/multiaccounts/accounts"
)
func NewAccountsAPI(db *accounts.Database, feed *event.Feed) *API {
return &API{db, feed}
}
// API is class with methods available over RPC.
type API struct {
db *accounts.Database
feed *event.Feed
}
func (api *API) SaveAccounts(ctx context.Context, accounts []accounts.Account) error {
err := api.db.SaveAccounts(accounts)
if err != nil {
return err
}
api.feed.Send(accounts)
return nil
}
func (api *API) GetAccounts(ctx context.Context) ([]accounts.Account, error) {
return api.db.GetAccounts()
}