mirror of
https://github.com/status-im/status-go.git
synced 2025-02-12 06:47:47 +00:00
* 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
49 lines
997 B
Go
49 lines
997 B
Go
package commands
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
persistence "github.com/status-im/status-go/services/connector/database"
|
|
)
|
|
|
|
type AccountsCommand struct {
|
|
Db *sql.DB
|
|
}
|
|
|
|
type AccountsResponse struct {
|
|
Accounts []types.Address `json:"accounts"`
|
|
}
|
|
|
|
func (c *AccountsCommand) dAppToAccountsResponse(dApp *persistence.DApp) (string, error) {
|
|
response := AccountsResponse{
|
|
Accounts: []types.Address{dApp.SharedAccount},
|
|
}
|
|
responseJSON, err := json.Marshal(response)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to marshal response: %v", err)
|
|
}
|
|
|
|
return string(responseJSON), nil
|
|
}
|
|
|
|
func (c *AccountsCommand) Execute(request RPCRequest) (string, error) {
|
|
err := request.Validate()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
dApp, err := persistence.SelectDAppByUrl(c.Db, request.URL)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if dApp == nil {
|
|
return "", ErrDAppIsNotPermittedByUser
|
|
}
|
|
|
|
return c.dAppToAccountsResponse(dApp)
|
|
}
|