github.com/status-im/status-go@v1.1.0/services/connector/commands/accounts.go (about)

     1  package commands
     2  
     3  import (
     4  	"database/sql"
     5  	"strings"
     6  
     7  	"github.com/status-im/status-go/eth-node/types"
     8  	persistence "github.com/status-im/status-go/services/connector/database"
     9  )
    10  
    11  type AccountsCommand struct {
    12  	Db *sql.DB
    13  }
    14  
    15  func FormatAccountAddressToResponse(address types.Address) []string {
    16  	return []string{strings.ToLower(address.Hex())}
    17  }
    18  
    19  func (c *AccountsCommand) Execute(request RPCRequest) (interface{}, error) {
    20  	err := request.Validate()
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  
    25  	dApp, err := persistence.SelectDAppByUrl(c.Db, request.URL)
    26  	if err != nil {
    27  		return "", err
    28  	}
    29  
    30  	if dApp == nil {
    31  		return "", ErrDAppIsNotPermittedByUser
    32  	}
    33  
    34  	return FormatAccountAddressToResponse(dApp.SharedAccount), nil
    35  }