mirror of
https://github.com/status-im/status-go.git
synced 2025-01-11 23:25:29 +00:00
4c6ca00520
* feat(connector)_: impl `eth_requestAccounts` for browser plugin * feat(connector)_: add impl for `wallet_switchEthereumChain` and `eth_chainId` * feat(connector)_: add impl for `eth_sendTransaction` * feat(connector)_: add a signal and an endpoint for wallet ui side * chore_: refactor connector tests * feat(connector)_: impl `eth_requestAccounts` with signal * chore(connector)_: Add test, covering full transaction flow And polish impl & test for connector endpoints * fix(connector)_: temporary allow all origins for ws connection * chore_: review fixes * fix(connector)_: make user select chain id for dApp * fix(connector)_: add requestID and fine tune endpoints * chore(connector)_: naming fixes and tests improvments
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package persistence
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
)
|
|
|
|
const upsertDAppQuery = "INSERT INTO connector_dapps (url, name, icon_url, shared_account, chain_id) VALUES (?, ?, ?, ?, ?) ON CONFLICT(url) DO UPDATE SET name = excluded.name, icon_url = excluded.icon_url, shared_account = excluded.shared_account, chain_id = excluded.chain_id"
|
|
const selectDAppByUrlQuery = "SELECT name, icon_url, shared_account, chain_id FROM connector_dapps WHERE url = ?"
|
|
const deleteDAppQuery = "DELETE FROM connector_dapps WHERE url = ?"
|
|
|
|
type DApp struct {
|
|
URL string `json:"url"`
|
|
Name string `json:"name"`
|
|
IconURL string `json:"iconUrl"`
|
|
SharedAccount types.Address `json:"sharedAccount"`
|
|
ChainID uint64 `json:"chainId"`
|
|
}
|
|
|
|
func UpsertDApp(db *sql.DB, dApp *DApp) error {
|
|
_, err := db.Exec(upsertDAppQuery, dApp.URL, dApp.Name, dApp.IconURL, dApp.SharedAccount, dApp.ChainID)
|
|
return err
|
|
}
|
|
|
|
func SelectDAppByUrl(db *sql.DB, url string) (*DApp, error) {
|
|
dApp := &DApp{
|
|
URL: url,
|
|
}
|
|
err := db.QueryRow(selectDAppByUrlQuery, url).Scan(&dApp.Name, &dApp.IconURL, &dApp.SharedAccount, &dApp.ChainID)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
return dApp, err
|
|
}
|
|
|
|
func DeleteDApp(db *sql.DB, url string) error {
|
|
_, err := db.Exec(deleteDAppQuery, url)
|
|
return err
|
|
}
|