feat(@wallet): verify json rpc URL

This commit is contained in:
Anthony Laibe 2023-07-12 07:58:33 +02:00 committed by Anthony Laibe
parent 313e5a5b69
commit 3ea5464c33
11 changed files with 94 additions and 9 deletions

View File

@ -34,6 +34,10 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args): self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
self.delegate.refreshNetworks() self.delegate.refreshNetworks()
self.events.on(SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED) do(e: Args):
let args = ChainIdForUrlArgs(e)
self.delegate.chainIdFetchedForUrl(args.url, args.chainId, args.success)
proc getNetworks*(self: Controller): seq[CombinedNetworkDto] = proc getNetworks*(self: Controller): seq[CombinedNetworkDto] =
return self.networkService.getCombinedNetworks() return self.networkService.getCombinedNetworks()
@ -43,5 +47,8 @@ proc areTestNetworksEnabled*(self: Controller): bool =
proc toggleTestNetworksEnabled*(self: Controller) = proc toggleTestNetworksEnabled*(self: Controller) =
self.walletAccountService.toggleTestNetworksEnabled() self.walletAccountService.toggleTestNetworksEnabled()
proc fetchChainIdForUrl*(self: Controller, url: string) =
self.walletAccountService.fetchChainIdForUrl(url)
proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) = proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)

View File

@ -30,3 +30,9 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) {.base.} = method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method fetchChainIdForUrl*(self: AccessInterface, url: string) {.base.} =
raise newException(ValueError, "No implementation available")
method chainIdFetchedForUrl*(self: AccessInterface, url: string, chainId: int, success: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -93,3 +93,9 @@ method toggleTestNetworksEnabled*(self: Module) =
method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) = method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
method fetchChainIdForUrl*(self: Module, url: string) =
self.controller.fetchChainIdForUrl(url)
method chainIdFetchedForUrl*(self: Module, url: string, chainId: int, success: bool) =
self.view.chainIdFetchedForUrl(url, chainId, success)

View File

@ -62,3 +62,8 @@ QtObject:
proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) = proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
proc fetchChainIdForUrl*(self: View, url: string) {.slot.} =
self.delegate.fetchChainIdForUrl(url)
proc chainIdFetchedForUrl*(self: View, url: string, chainId: int, success: bool) {.signal.}

View File

@ -154,4 +154,30 @@ const deleteKeycardAccountsTask*: Task = proc(argEncoded: string) {.gcsafe, nimc
responseJson["success"] = %* success responseJson["success"] = %* success
except Exception as e: except Exception as e:
error "error remove accounts from keycard: ", message = e.msg error "error remove accounts from keycard: ", message = e.msg
arg.finish(responseJson) arg.finish(responseJson)
#################################################
# Async fetch chain id for url
#################################################
type
FetchChainIdForUrlTaskArg* = ref object of QObjectTaskArg
url: string
const fetchChainIdForUrlTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[FetchChainIdForUrlTaskArg](argEncoded)
try:
let response = backend.fetchChainIDForURL(arg.url)
arg.finish(%*{
"success": true,
"chainId": response.result.getInt,
"url": arg.url
})
except Exception as e:
error "error when fetching chaind id from url: ", message = e.msg
arg.finish(%*{
"success": false,
"chainId": -1,
"url": arg.url
})

View File

@ -35,7 +35,8 @@ const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FETCHED* = "walletAccount/derivedA
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FROM_MNEMONIC_FETCHED* = "walletAccount/derivedAddressesFromMnemonicFetched" const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FROM_MNEMONIC_FETCHED* = "walletAccount/derivedAddressesFromMnemonicFetched"
const SIGNAL_WALLET_ACCOUNT_ADDRESS_DETAILS_FETCHED* = "walletAccount/addressDetailsFetched" const SIGNAL_WALLET_ACCOUNT_ADDRESS_DETAILS_FETCHED* = "walletAccount/addressDetailsFetched"
const SIGNAL_WALLET_ACCOUNT_POSITION_UPDATED* = "walletAccount/positionUpdated" const SIGNAL_WALLET_ACCOUNT_POSITION_UPDATED* = "walletAccount/positionUpdated"
const SIGNAL_WALLET_ACCOUNT_OPERABILITY_UPDATED* = "walletAccount/operabilityUpdated" # TODO: will be used later, when we deal with account operability const SIGNAL_WALLET_ACCOUNT_OPERABILITY_UPDATED* = "walletAccount/operabilityUpdated"
const SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED* = "walletAccount/chainIdForUrlFetched"
const SIGNAL_KEYPAIR_SYNCED* = "keypairSynced" const SIGNAL_KEYPAIR_SYNCED* = "keypairSynced"
const SIGNAL_KEYPAIR_NAME_CHANGED* = "keypairNameChanged" const SIGNAL_KEYPAIR_NAME_CHANGED* = "keypairNameChanged"
@ -96,6 +97,16 @@ type TokensPerAccountArgs* = ref object of Args
hasBalanceCache*: bool hasBalanceCache*: bool
hasMarketValuesCache*: bool hasMarketValuesCache*: bool
type KeycardActivityArgs* = ref object of Args
success*: bool
oldKeycardUid*: string
keycard*: KeycardDto
type ChainIdForUrlArgs* = ref object of Args
chainId*: int
success*: bool
url*: string
proc responseHasNoErrors(procName: string, response: RpcResponse[JsonNode]): bool = proc responseHasNoErrors(procName: string, response: RpcResponse[JsonNode]): bool =
var errMsg = "" var errMsg = ""
if not response.error.isNil: if not response.error.isNil:
@ -999,3 +1010,20 @@ QtObject:
proc toggleIncludeWatchOnlyAccount*(self: Service) = proc toggleIncludeWatchOnlyAccount*(self: Service) =
self.settingsService.toggleIncludeWatchOnlyAccount() self.settingsService.toggleIncludeWatchOnlyAccount()
proc onFetchChainIdForUrl*(self: Service, jsonString: string) {.slot.} =
let response = parseJson(jsonString)
self.events.emit(SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED, ChainIdForUrlArgs(
chainId: response{"chainId"}.getInt,
success: response{"success"}.getBool,
url: response{"url"}.getStr,
))
proc fetchChainIdForUrl*(self: Service, url: string) =
let arg = FetchChainIdForUrlTaskArg(
tptr: cast[ByteAddress](fetchChainIdForUrlTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onFetchChainIdForUrl",
url: url
)
self.threadpool.start(arg)

View File

@ -73,6 +73,9 @@ rpc(addEthereumChain, "wallet"):
rpc(deleteEthereumChain, "wallet"): rpc(deleteEthereumChain, "wallet"):
chainId: int chainId: int
rpc(fetchChainIDForURL, "wallet"):
url: string
rpc(upsertSavedAddress, "wakuext"): rpc(upsertSavedAddress, "wakuext"):
savedAddress: SavedAddress savedAddress: SavedAddress

View File

@ -52,7 +52,7 @@ QtObject {
} }
function evaluateRpcEndPoint(url) { function evaluateRpcEndPoint(url) {
// TODO: connect with nim api once its ready return networksModule.fetchChainIdForUrl(url)
} }
function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) { function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) {

View File

@ -13,7 +13,7 @@ ColumnLayout {
property var network property var network
property var networksModule property var networksModule
signal evaluateEndPoint(string url) signal evaluateRpcEndPoint(string url)
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl) signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl)
enum EvaluationState { enum EvaluationState {
@ -29,7 +29,7 @@ ColumnLayout {
property int evaluationStatus: EditNetworkForm.UnTouched property int evaluationStatus: EditNetworkForm.UnTouched
property int evaluationStatusFallBackRpc: EditNetworkForm.UnTouched property int evaluationStatusFallBackRpc: EditNetworkForm.UnTouched
property var evaluateRpcEndPoint: Backpressure.debounce(root, 400, function (value) { property var evaluateRpcEndPoint: Backpressure.debounce(root, 400, function (value) {
root.evaluateEndPoint(value) root.evaluateRpcEndPoint(value)
}) })
function revertValues() { function revertValues() {
@ -61,7 +61,11 @@ ColumnLayout {
Connections { Connections {
target: networksModule target: networksModule
function onUrlVerified(url, status) { function onChainIdFetchedForUrl(url, chainId, success) {
let status = EditNetworkForm.PingUnsuccessful
if(success) {
status = EditNetworkForm.Verified
}
if(url === mainRpcInput.text) { if(url === mainRpcInput.text) {
d.evaluationStatus = status d.evaluationStatus = status
} }

View File

@ -38,7 +38,7 @@ ColumnLayout {
id: editLiveNetwork id: editLiveNetwork
network: !!root.combinedNetwork ? root.combinedNetwork.prod: null network: !!root.combinedNetwork ? root.combinedNetwork.prod: null
networksModule: root.networksModule networksModule: root.networksModule
onEvaluateEndPoint: root.evaluateRpcEndPoint(url) onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl) onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
} }
@ -46,7 +46,7 @@ ColumnLayout {
id: editTestNetwork id: editTestNetwork
network: !!root.combinedNetwork ? root.combinedNetwork.test: null network: !!root.combinedNetwork ? root.combinedNetwork.test: null
networksModule: root.networksModule networksModule: root.networksModule
onEvaluateEndPoint: root.evaluateRpcEndPoint(url) onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url)
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl) onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
} }
} }

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 9674bc463f08907887317bd030444666a1022126 Subproject commit 0f8347dc59c7058c275c5eb72431ad7e445f0f9d