mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
07651d4d06
* 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>
47 lines
925 B
Go
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
|
|
}
|