status-go/services/wallet/favourite.go
Anthony Laibe 07651d4d06
feat: enable wallet without network binding (#2349)
* feat: enable wallet without network binding

* feat: make transfer network aware

* feat: allow to pass initial networks via config

* fix: nil check and feed

* feat: Add documentation with better function name

* fix: do not init the manager more than once

* fix: PR feedbacks

* Bump version

* Update Jenkinsfile.tests

* Convert int to string

Co-authored-by: RichΛrd <info@richardramos.me>
2021-09-09 16:28:54 +02:00

47 lines
925 B
Go

package wallet
import (
"database/sql"
"github.com/ethereum/go-ethereum/common"
)
type Favourite struct {
Address common.Address `json:"address"`
Name string `json:"name"`
}
type FavouriteManager struct {
db *sql.DB
}
func (fm *FavouriteManager) GetFavourites() ([]*Favourite, error) {
rows, err := fm.db.Query(`SELECT address, name FROM favourites`)
if err != nil {
return nil, err
}
defer rows.Close()
var rst []*Favourite
for rows.Next() {
favourite := &Favourite{}
err := rows.Scan(&favourite.Address, &favourite.Name)
if err != nil {
return nil, err
}
rst = append(rst, favourite)
}
return rst, nil
}
func (fm *FavouriteManager) AddFavourite(favourite Favourite) error {
insert, err := fm.db.Prepare("INSERT OR REPLACE INTO favourites (address, name) VALUES (?, ?)")
if err != nil {
return err
}
_, err = insert.Exec(favourite.Address, favourite.Name)
return err
}