2019-08-20 15:38:40 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-08-28 07:49:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/event"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-12-11 13:59:37 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
|
|
|
)
|
|
|
|
|
2019-08-28 07:49:03 +00:00
|
|
|
func NewAccountsAPI(db *accounts.Database, feed *event.Feed) *API {
|
|
|
|
return &API{db, feed}
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// API is class with methods available over RPC.
|
|
|
|
type API struct {
|
2019-08-28 07:49:03 +00:00
|
|
|
db *accounts.Database
|
|
|
|
feed *event.Feed
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) SaveAccounts(ctx context.Context, accounts []accounts.Account) error {
|
2019-08-28 07:49:03 +00:00
|
|
|
err := api.db.SaveAccounts(accounts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
api.feed.Send(accounts)
|
|
|
|
return nil
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) GetAccounts(ctx context.Context) ([]accounts.Account, error) {
|
|
|
|
return api.db.GetAccounts()
|
|
|
|
}
|
2019-12-16 15:23:36 +00:00
|
|
|
|
2019-12-11 13:59:37 +00:00
|
|
|
func (api *API) DeleteAccount(ctx context.Context, address types.Address) error {
|
2019-12-16 15:23:36 +00:00
|
|
|
return api.db.DeleteAccount(address)
|
|
|
|
}
|