2024-07-18 15:30:10 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2024-07-26 16:18:01 +00:00
|
|
|
"strconv"
|
2024-07-18 15:30:10 +00:00
|
|
|
|
2024-07-26 16:18:01 +00:00
|
|
|
"github.com/status-im/status-go/services/connector/chainutils"
|
2024-07-18 15:30:10 +00:00
|
|
|
persistence "github.com/status-im/status-go/services/connector/database"
|
|
|
|
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ChainIDCommand struct {
|
2024-07-26 16:18:01 +00:00
|
|
|
NetworkManager NetworkManagerInterface
|
|
|
|
Db *sql.DB
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ChainIDCommand) 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 {
|
2024-07-26 16:18:01 +00:00
|
|
|
defaultChainID, err := chainutils.GetDefaultChainID(c.NetworkManager)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-07-26 20:00:12 +00:00
|
|
|
|
|
|
|
chainId, err := chainutils.GetHexChainID(strconv.FormatUint(defaultChainID, 16))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return chainId, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
chainId, err := chainutils.GetHexChainID(walletCommon.ChainID(dApp.ChainID).String())
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|
|
|
|
|
2024-07-26 20:00:12 +00:00
|
|
|
return chainId, nil
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|