2024-07-18 15:30:10 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2024-09-19 18:24:06 +00:00
|
|
|
"context"
|
2024-07-18 15:30:10 +00:00
|
|
|
"database/sql"
|
2024-08-02 07:43:31 +00:00
|
|
|
"strings"
|
2024-07-18 15:30:10 +00:00
|
|
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2024-08-02 07:43:31 +00:00
|
|
|
func FormatAccountAddressToResponse(address types.Address) []string {
|
|
|
|
return []string{strings.ToLower(address.Hex())}
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2024-09-19 18:24:06 +00:00
|
|
|
func (c *AccountsCommand) Execute(ctx context.Context, request RPCRequest) (interface{}, error) {
|
2024-07-18 15:30:10 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-08-02 07:43:31 +00:00
|
|
|
return FormatAccountAddressToResponse(dApp.SharedAccount), nil
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|