refactor: move provider logic to status-go
This commit is contained in:
parent
8bc678dacd
commit
f5d53f9112
|
@ -34,6 +34,9 @@ method getDapp*(self: Controller, dapp:string): Option[dapp_permissions_service.
|
||||||
method hasPermission*(self: Controller, dapp: string, permission: dapp_permissions_service.Permission):bool =
|
method hasPermission*(self: Controller, dapp: string, permission: dapp_permissions_service.Permission):bool =
|
||||||
return self.dappPermissionsService.hasPermission(dapp, permission)
|
return self.dappPermissionsService.hasPermission(dapp, permission)
|
||||||
|
|
||||||
|
method addPermission*(self: Controller, dapp: string, permission: dapp_permissions_service.Permission) =
|
||||||
|
discard self.dappPermissionsService.addPermission(dapp, permission)
|
||||||
|
|
||||||
method clearPermissions*(self: Controller, dapp: string) =
|
method clearPermissions*(self: Controller, dapp: string) =
|
||||||
discard self.dappPermissionsService.clearPermissions(dapp)
|
discard self.dappPermissionsService.clearPermissions(dapp)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ method getDapps*(self: AccessInterface): seq[dapp_permissions_service.Dapp] {.ba
|
||||||
method getDapp*(self: AccessInterface, dapp: string): Option[dapp_permissions_service.Dapp] {.base.} =
|
method getDapp*(self: AccessInterface, dapp: string): Option[dapp_permissions_service.Dapp] {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method addPermission*(self: AccessInterface, dapp: string, permission: dapp_permissions_service.Permission) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method hasPermission*(self: AccessInterface, dapp: string, permission: dapp_permissions_service.Permission):bool {.base.} =
|
method hasPermission*(self: AccessInterface, dapp: string, permission: dapp_permissions_service.Permission):bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,9 @@ method viewDidLoad*(self: Module) =
|
||||||
method hasPermission*(self: Module, hostname: string, permission: string): bool =
|
method hasPermission*(self: Module, hostname: string, permission: string): bool =
|
||||||
self.controller.hasPermission(hostname, permission.toPermission())
|
self.controller.hasPermission(hostname, permission.toPermission())
|
||||||
|
|
||||||
|
method addPermission*(self: Module, hostname: string, permission: string) =
|
||||||
|
self.controller.addPermission(hostname, permission.toPermission())
|
||||||
|
|
||||||
method clearPermissions*(self: Module, dapp: string) =
|
method clearPermissions*(self: Module, dapp: string) =
|
||||||
self.controller.clearPermissions(dapp)
|
self.controller.clearPermissions(dapp)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool =
|
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method addPermission*(self: AccessInterface, hostname: string, permission: string) =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method clearPermissions*(self: AccessInterface, dapp: string) =
|
method clearPermissions*(self: AccessInterface, dapp: string) =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,9 @@ QtObject:
|
||||||
proc hasPermission(self: View, hostname: string, permission: string): bool {.slot.} =
|
proc hasPermission(self: View, hostname: string, permission: string): bool {.slot.} =
|
||||||
return self.delegate.hasPermission(hostname, permission)
|
return self.delegate.hasPermission(hostname, permission)
|
||||||
|
|
||||||
|
proc addPermission(self: View, hostname: string, permission: string) {.slot.} =
|
||||||
|
self.delegate.addPermission(hostname, permission)
|
||||||
|
|
||||||
proc clearPermissions(self: View, dapp: string): string {.slot.} =
|
proc clearPermissions(self: View, dapp: string): string {.slot.} =
|
||||||
self.delegate.clearPermissions(dapp)
|
self.delegate.clearPermissions(dapp)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Tables
|
import tables
|
||||||
import controller_interface
|
import controller_interface
|
||||||
import io_interface
|
import io_interface
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ method getCurrentNetworkDetails*(self: Controller): NetworkDetails =
|
||||||
method disconnect*(self: Controller) =
|
method disconnect*(self: Controller) =
|
||||||
discard self.dappPermissionsService.revoke("web3".toPermission())
|
discard self.dappPermissionsService.revoke("web3".toPermission())
|
||||||
|
|
||||||
method postMessage*(self: Controller, message: string): string =
|
method postMessage*(self: Controller, requestType: string, message: string): string =
|
||||||
return self.providerService.postMessage(message)
|
return self.providerService.postMessage(requestType, message)
|
||||||
|
|
||||||
method hasPermission*(self: Controller, hostname: string, permission: string): bool =
|
method hasPermission*(self: Controller, hostname: string, permission: string): bool =
|
||||||
return self.dappPermissionsService.hasPermission(hostname, permission.toPermission())
|
return self.dappPermissionsService.hasPermission(hostname, permission.toPermission())
|
||||||
|
|
|
@ -22,7 +22,7 @@ method getCurrentNetworkDetails*(self: AccessInterface): NetworkDetails {.base.}
|
||||||
method disconnect*(self: AccessInterface) {.base.} =
|
method disconnect*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method postMessage*(self: AccessInterface, message: string): string {.base.} =
|
method postMessage*(self: AccessInterface, requestType: string, message: string): string {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool {.base.} =
|
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool {.base.} =
|
||||||
|
|
|
@ -58,8 +58,8 @@ method viewDidLoad*(self: Module) =
|
||||||
method disconnect*(self: Module) =
|
method disconnect*(self: Module) =
|
||||||
self.controller.disconnect()
|
self.controller.disconnect()
|
||||||
|
|
||||||
method postMessage*(self: Module, message: string): string =
|
method postMessage*(self: Module, requestType: string, message: string): string =
|
||||||
return self.controller.postMessage(message)
|
return self.controller.postMessage(requestType, message)
|
||||||
|
|
||||||
method hasPermission*(self: Module, hostname: string, permission: string): bool =
|
method hasPermission*(self: Module, hostname: string, permission: string): bool =
|
||||||
return self.controller.hasPermission(hostname, permission)
|
return self.controller.hasPermission(hostname, permission)
|
||||||
|
|
|
@ -7,7 +7,7 @@ method onDappAddressChanged*(self: AccessInterface, newDappAddress: string) {.ba
|
||||||
method disconnect*(self: AccessInterface) {.base.} =
|
method disconnect*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method postMessage*(self: AccessInterface, message: string): string {.base.} =
|
method postMessage*(self: AccessInterface, requestType: string, message: string): string {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool {.base.} =
|
method hasPermission*(self: AccessInterface, hostname: string, permission: string): bool {.base.} =
|
||||||
|
|
|
@ -59,8 +59,8 @@ QtObject:
|
||||||
proc disconnect*(self: View) {.slot.} =
|
proc disconnect*(self: View) {.slot.} =
|
||||||
self.delegate.disconnect()
|
self.delegate.disconnect()
|
||||||
|
|
||||||
proc postMessage*(self: View, message: string): string {.slot.} =
|
proc postMessage*(self: View, requestType: string, message: string): string {.slot.} =
|
||||||
return self.delegate.postMessage(message)
|
return self.delegate.postMessage(requestType, message)
|
||||||
|
|
||||||
proc hasPermission(self: View, hostname: string, permission: string): bool {.slot.} =
|
proc hasPermission(self: View, hostname: string, permission: string): bool {.slot.} =
|
||||||
return self.delegate.hasPermission(hostname, permission)
|
return self.delegate.hasPermission(hostname, permission)
|
||||||
|
|
|
@ -68,6 +68,12 @@ QtObject:
|
||||||
let uintValue = status_utils.eth2Wei(parseFloat(eth), decimals)
|
let uintValue = status_utils.eth2Wei(parseFloat(eth), decimals)
|
||||||
return uintValue.toString()
|
return uintValue.toString()
|
||||||
|
|
||||||
|
proc eth2Hex*(self: UtilsView, eth: float): string {.slot.} =
|
||||||
|
return "0x" & status_utils.eth2Wei(eth, 18).toHex()
|
||||||
|
|
||||||
|
proc gwei2Hex*(self: UtilsView, gwei: float): string {.slot.} =
|
||||||
|
return "0x" & status_utils.gwei2wei(gwei).toHex()
|
||||||
|
|
||||||
proc getStickerMarketAddress(self: UtilsView): string {.slot.} =
|
proc getStickerMarketAddress(self: UtilsView): string {.slot.} =
|
||||||
$self.status.stickers.getStickerMarketAddress
|
$self.status.stickers.getStickerMarketAddress
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,9 @@ var NODE_CONFIG* = %* {
|
||||||
"ClusterConfig": {
|
"ClusterConfig": {
|
||||||
"Enabled": true
|
"Enabled": true
|
||||||
},
|
},
|
||||||
|
"Web3ProviderConfig": {
|
||||||
|
"Enabled": true
|
||||||
|
},
|
||||||
"DataDir": "./ethereum/mainnet",
|
"DataDir": "./ethereum/mainnet",
|
||||||
"EnableNTPSync": true,
|
"EnableNTPSync": true,
|
||||||
"KeyStoreDir": "./keystore",
|
"KeyStoreDir": "./keystore",
|
||||||
|
|
|
@ -10,6 +10,7 @@ import service_interface
|
||||||
import status/statusgo_backend_new/permissions as status_go_permissions
|
import status/statusgo_backend_new/permissions as status_go_permissions
|
||||||
import status/statusgo_backend_new/accounts as status_go_accounts
|
import status/statusgo_backend_new/accounts as status_go_accounts
|
||||||
import status/statusgo_backend_new/core as status_go_core
|
import status/statusgo_backend_new/core as status_go_core
|
||||||
|
import status/statusgo_backend_new/provider as status_go_provider
|
||||||
import stew/byteutils
|
import stew/byteutils
|
||||||
export service_interface
|
export service_interface
|
||||||
|
|
||||||
|
@ -18,72 +19,6 @@ logScope:
|
||||||
|
|
||||||
const HTTPS_SCHEME* = "https"
|
const HTTPS_SCHEME* = "https"
|
||||||
|
|
||||||
type
|
|
||||||
RequestTypes {.pure.} = enum
|
|
||||||
Web3SendAsyncReadOnly = "web3-send-async-read-only",
|
|
||||||
HistoryStateChanged = "history-state-changed",
|
|
||||||
APIRequest = "api-request"
|
|
||||||
Unknown = "unknown"
|
|
||||||
|
|
||||||
ResponseTypes {.pure.} = enum
|
|
||||||
Web3SendAsyncCallback = "web3-send-async-callback",
|
|
||||||
APIResponse = "api-response",
|
|
||||||
Web3ResponseError = "web3-response-error"
|
|
||||||
|
|
||||||
type
|
|
||||||
Payload = ref object
|
|
||||||
id: JsonNode
|
|
||||||
rpcMethod: string
|
|
||||||
|
|
||||||
Web3SendAsyncReadOnly = ref object
|
|
||||||
messageId: JsonNode
|
|
||||||
payload: Payload
|
|
||||||
request: string
|
|
||||||
hostname: string
|
|
||||||
|
|
||||||
APIRequest = ref object
|
|
||||||
isAllowed: bool
|
|
||||||
messageId: JsonNode
|
|
||||||
permission: Permission
|
|
||||||
hostname: string
|
|
||||||
|
|
||||||
const AUTH_METHODS = toHashSet(["eth_accounts", "eth_coinbase", "eth_sendTransaction", "eth_sign", "keycard_signTypedData", "eth_signTypedData", "eth_signTypedData_v3", "personal_sign", "personal_ecRecover"])
|
|
||||||
const SIGN_METHODS = toHashSet(["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"])
|
|
||||||
const ACC_METHODS = toHashSet(["eth_accounts", "eth_coinbase"])
|
|
||||||
|
|
||||||
proc requestType(message: string): RequestTypes =
|
|
||||||
let data = message.parseJson
|
|
||||||
result = RequestTypes.Unknown
|
|
||||||
try:
|
|
||||||
result = parseEnum[RequestTypes](data["type"].getStr())
|
|
||||||
except:
|
|
||||||
warn "Unknown request type received", value=data["permission"].getStr()
|
|
||||||
|
|
||||||
|
|
||||||
proc toWeb3SendAsyncReadOnly(message: string): Web3SendAsyncReadOnly =
|
|
||||||
let data = message.parseJson
|
|
||||||
result = Web3SendAsyncReadOnly(
|
|
||||||
messageId: data["messageId"],
|
|
||||||
request: $data["payload"],
|
|
||||||
hostname: data{"hostname"}.getStr(),
|
|
||||||
payload: Payload(
|
|
||||||
id: data["payload"]{"id"},
|
|
||||||
rpcMethod: data["payload"]["method"].getStr()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
proc toAPIRequest(message: string): APIRequest =
|
|
||||||
let data = message.parseJson
|
|
||||||
|
|
||||||
result = APIRequest(
|
|
||||||
messageId: data["messageId"],
|
|
||||||
isAllowed: data{"isAllowed"}.getBool(),
|
|
||||||
permission: data["permission"].getStr().toPermission(),
|
|
||||||
hostname: data{"hostname"}.getStr()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Service* = ref object of service_interface.ServiceInterface
|
Service* = ref object of service_interface.ServiceInterface
|
||||||
dappPermissionsService: dapp_permissions_service.ServiceInterface
|
dappPermissionsService: dapp_permissions_service.ServiceInterface
|
||||||
|
@ -104,199 +39,17 @@ proc newService*(dappPermissionsService: dapp_permissions_service.ServiceInterfa
|
||||||
method init*(self: Service) =
|
method init*(self: Service) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc process(self: Service, data: Web3SendAsyncReadOnly): string =
|
|
||||||
if AUTH_METHODS.contains(data.payload.rpcMethod) and not self.dappPermissionsService.hasPermission(data.hostname, Permission.Web3):
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": {
|
|
||||||
"code": 4100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if data.payload.rpcMethod == "eth_sendTransaction":
|
|
||||||
try:
|
|
||||||
let request = data.request.parseJson
|
|
||||||
let fromAddress = request["params"][0]["from"].getStr()
|
|
||||||
let to = request["params"][0]{"to"}.getStr()
|
|
||||||
let value = if (request["params"][0]["value"] != nil):
|
|
||||||
request["params"][0]["value"].getStr()
|
|
||||||
else:
|
|
||||||
"0"
|
|
||||||
let password = request["password"].getStr()
|
|
||||||
let selectedGasLimit = request["selectedGasLimit"].getStr()
|
|
||||||
let selectedGasPrice = request["selectedGasPrice"].getStr()
|
|
||||||
let selectedTipLimit = request{"selectedTipLimit"}.getStr()
|
|
||||||
let selectedOverallLimit = request{"selectedOverallLimit"}.getStr()
|
|
||||||
let txData = if (request["params"][0].hasKey("data") and request["params"][0]["data"].kind != JNull):
|
|
||||||
request["params"][0]["data"].getStr()
|
|
||||||
else:
|
|
||||||
""
|
|
||||||
|
|
||||||
var success: bool
|
|
||||||
var errorMessage = ""
|
|
||||||
var response = ""
|
|
||||||
var validInput: bool = true
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: use the transaction service to send the trx
|
|
||||||
|
|
||||||
#[
|
|
||||||
let eip1559Enabled = self.wallet.isEIP1559Enabled()
|
|
||||||
|
|
||||||
try:
|
|
||||||
validateTransactionInput(fromAddress, to, "", value, selectedGasLimit, selectedGasPrice, txData, eip1559Enabled, selectedTipLimit, selectedOverallLimit, "dummy")
|
|
||||||
except Exception as e:
|
|
||||||
validInput = false
|
|
||||||
success = false
|
|
||||||
errorMessage = e.msg
|
|
||||||
|
|
||||||
if validInput:
|
|
||||||
# TODO make this async
|
|
||||||
response = wallet.sendTransaction(fromAddress, to, value, selectedGasLimit, selectedGasPrice, eip1559Enabled, selectedTipLimit, selectedOverallLimit, password, success, txData)
|
|
||||||
errorMessage = if not success:
|
|
||||||
if response == "":
|
|
||||||
"web3-response-error"
|
|
||||||
else:
|
|
||||||
response
|
|
||||||
else:
|
|
||||||
""
|
|
||||||
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": errorMessage,
|
|
||||||
"result": {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": data.payload.id,
|
|
||||||
"result": if (success): response else: ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
]#
|
|
||||||
# TODO: delete this:
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": "",
|
|
||||||
"result": {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": data.payload.id,
|
|
||||||
"result": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
error "Error sending the transaction", msg = e.msg
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": {
|
|
||||||
"code": 4100,
|
|
||||||
"message": e.msg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if SIGN_METHODS.contains(data.payload.rpcMethod):
|
|
||||||
try:
|
|
||||||
let request = data.request.parseJson
|
|
||||||
var params = request["params"]
|
|
||||||
let password = hashPassword(request["password"].getStr())
|
|
||||||
let dappAddress = self.settingsService.getDappsAddress()
|
|
||||||
var rpcResult = "{}"
|
|
||||||
|
|
||||||
case data.payload.rpcMethod:
|
|
||||||
of "eth_signTypedData", "eth_signTypedData_v3":
|
|
||||||
rpcResult = signTypedData(params[1].getStr(), dappAddress, password)
|
|
||||||
else:
|
|
||||||
rpcResult = signMessage($ %* {
|
|
||||||
"data": params[0].getStr(),
|
|
||||||
"password": password,
|
|
||||||
"account": dappAddress
|
|
||||||
})
|
|
||||||
|
|
||||||
let jsonRpcResult = rpcResult.parseJson
|
|
||||||
let success: bool = not jsonRpcResult.hasKey("error")
|
|
||||||
let errorMessage = if success: "" else: jsonRpcResult["error"]{"message"}.getStr()
|
|
||||||
let response = if success: jsonRpcResult["result"].getStr() else: ""
|
|
||||||
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": errorMessage,
|
|
||||||
"result": {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": if data.payload.id == nil: newJNull() else: data.payload.id,
|
|
||||||
"result": if (success): response else: ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
error "Error signing message", msg = e.msg
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": {
|
|
||||||
"code": 4100,
|
|
||||||
"message": e.msg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ACC_METHODS.contains(data.payload.rpcMethod):
|
|
||||||
let dappAddress = self.settingsService.getDappsAddress()
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"result": {
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": data.payload.id,
|
|
||||||
"result": if data.payload.rpcMethod == "eth_coinbase": newJString(dappAddress) else: %*[dappAddress]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let rpcResult = callRPC(data.request)
|
|
||||||
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.Web3SendAsyncCallback,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"error": (if rpcResult == "": newJString("web3-response-error") else: newJNull()),
|
|
||||||
"result": rpcResult.parseJson
|
|
||||||
}
|
|
||||||
|
|
||||||
proc process(self: Service, data: APIRequest): string =
|
|
||||||
var value:JsonNode = case data.permission
|
|
||||||
of Permission.Web3: %* [self.settingsService.getDappsAddress()]
|
|
||||||
of Permission.ContactCode: %* self.settingsService.getPubKey()
|
|
||||||
of Permission.Unknown: newJNull()
|
|
||||||
|
|
||||||
let isAllowed = data.isAllowed and data.permission != Permission.Unknown
|
|
||||||
|
|
||||||
info "API request received", host=data.hostname, value=data.permission, isAllowed
|
|
||||||
|
|
||||||
if isAllowed:
|
|
||||||
discard self.dappPermissionsService.addPermission(data.hostname, data.permission)
|
|
||||||
|
|
||||||
return $ %* {
|
|
||||||
"type": ResponseTypes.APIResponse,
|
|
||||||
"isAllowed": isAllowed,
|
|
||||||
"permission": data.permission,
|
|
||||||
"messageId": data.messageId,
|
|
||||||
"data": value
|
|
||||||
}
|
|
||||||
|
|
||||||
method postMessage*(self: Service, message: string): string =
|
|
||||||
case message.requestType():
|
|
||||||
of RequestTypes.Web3SendAsyncReadOnly: self.process(message.toWeb3SendAsyncReadOnly())
|
|
||||||
of RequestTypes.HistoryStateChanged: """{"type":"TODO-IMPLEMENT-THIS"}""" ############# TODO:
|
|
||||||
of RequestTypes.APIRequest: self.process(message.toAPIRequest())
|
|
||||||
else: """{"type":"TODO-IMPLEMENT-THIS"}""" ##################### TODO:
|
|
||||||
|
|
||||||
method ensResourceURL*(self: Service, username: string, url: string): (string, string, string, string, bool) =
|
method ensResourceURL*(self: Service, username: string, url: string): (string, string, string, string, bool) =
|
||||||
let (scheme, host, path) = self.ensService.resourceUrl(username)
|
let (scheme, host, path) = self.ensService.resourceUrl(username)
|
||||||
if host == "":
|
if host == "":
|
||||||
return (url, url, HTTPS_SCHEME, "", false)
|
return (url, url, HTTPS_SCHEME, "", false)
|
||||||
|
|
||||||
return (url, host, scheme, path, true)
|
|
||||||
|
method postMessage*(self: Service, requestType: string, message: string): string =
|
||||||
|
try:
|
||||||
|
return $providerRequest(requestType, message).result
|
||||||
|
except Exception as e:
|
||||||
|
let errDescription = e.msg
|
||||||
|
error "error: ", errDescription
|
||||||
|
|
|
@ -8,7 +8,7 @@ method delete*(self: ServiceInterface) {.base.} =
|
||||||
method init*(self: ServiceInterface) {.base.} =
|
method init*(self: ServiceInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method postMessage*(self: ServiceInterface, message: string): string {.base.} =
|
method postMessage*(self: ServiceInterface, requestType: string, message: string): string {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method ensResourceURL*(self: ServiceInterface, ens: string, url: string): (string, string, string, string, bool) =
|
method ensResourceURL*(self: ServiceInterface, ens: string, url: string): (string, string, string, string, bool) =
|
||||||
|
|
|
@ -858,30 +858,17 @@ You may add additional accurate notices of copyright ownership.
|
||||||
window.ethereum.on("accountsChanged", () => {});
|
window.ethereum.on("accountsChanged", () => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
const bridgeSend = data => {
|
const bridgeSend = (requestType, data) => {
|
||||||
data.hostname = new URL(document.location).host;
|
data.hostname = new URL(document.location).host;
|
||||||
data.title = document.title;
|
data.title = document.title;
|
||||||
backend.postMessage(JSON.stringify(data));
|
backend.postMessage(requestType, JSON.stringify(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
let history = window.history;
|
|
||||||
let pushState = history.pushState;
|
|
||||||
history.pushState = function(state) {
|
|
||||||
setTimeout(function () {
|
|
||||||
bridgeSend({
|
|
||||||
type: "history-state-changed",
|
|
||||||
navState: { url: location.href, title: document.title },
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
return pushState.apply(history, arguments);
|
|
||||||
};
|
|
||||||
|
|
||||||
function sendAPIrequest(permission, params) {
|
function sendAPIrequest(permission, params) {
|
||||||
const messageId = callbackId++;
|
const messageId = callbackId++;
|
||||||
params = params || {};
|
params = params || {};
|
||||||
|
|
||||||
bridgeSend({
|
bridgeSend('api-request', {
|
||||||
type: 'api-request',
|
|
||||||
permission: permission,
|
permission: permission,
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
params: params
|
params: params
|
||||||
|
@ -1047,8 +1034,7 @@ You may add additional accurate notices of copyright ownership.
|
||||||
params: requestArguments.params,
|
params: requestArguments.params,
|
||||||
};
|
};
|
||||||
|
|
||||||
bridgeSend({
|
bridgeSend("web3-send-async-read-only", {
|
||||||
type: "web3-send-async-read-only",
|
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
});
|
});
|
||||||
|
@ -1094,16 +1080,14 @@ You may add additional accurate notices of copyright ownership.
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let i in payload) {
|
for (let i in payload) {
|
||||||
bridgeSend({
|
bridgeSend("web3-send-async-read-only", {
|
||||||
type: "web3-send-async-read-only",
|
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
payload: payload[i],
|
payload: payload[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callbacks[messageId] = { callback: callback };
|
callbacks[messageId] = { callback: callback };
|
||||||
bridgeSend({
|
bridgeSend("web3-send-async-read-only", {
|
||||||
type: "web3-send-async-read-only",
|
|
||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,9 +31,11 @@ StatusModal {
|
||||||
|
|
||||||
function postMessage(isAllowed){
|
function postMessage(isAllowed){
|
||||||
interactedWith = true
|
interactedWith = true
|
||||||
request.isAllowed = isAllowed;
|
|
||||||
currentTabConnected = isAllowed
|
currentTabConnected = isAllowed
|
||||||
provider.web3Response(Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request)));
|
if(isAllowed){
|
||||||
|
Web3ProviderStore.addPermission(request.hostname, request.permission)
|
||||||
|
}
|
||||||
|
provider.web3Response(Web3ProviderStore.web3ProviderInst.postMessage("api-request", JSON.stringify(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
onClosed: {
|
onClosed: {
|
||||||
|
|
|
@ -94,7 +94,7 @@ Popup {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Web3ProviderStore.web3ProviderInst.disconnect();
|
Web3ProviderStore.web3ProviderInst.disconnect();
|
||||||
provider.postMessage(`{"type":"web3-disconnect-account"}`);
|
provider.postMessage("web3-disconnect-account", "{}");
|
||||||
popup.close();
|
popup.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,12 @@ QtObject {
|
||||||
function generateIdenticon(pk) {
|
function generateIdenticon(pk) {
|
||||||
return utilsModel.generateIdenticon(pk)
|
return utilsModel.generateIdenticon(pk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEth2Hex(eth) {
|
||||||
|
return utilsModel.eth2Hex(eth)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGwei2Hex(gwei){
|
||||||
|
return utilsModel.gwei2Hex(gwei)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ QtObject {
|
||||||
dappPermissionsModule.revokeAllPermissions()
|
dappPermissionsModule.revokeAllPermissions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addPermission(permission, hostName ){
|
||||||
|
dappPermissionsModule.addPermission(permission, hostName)
|
||||||
|
}
|
||||||
|
|
||||||
function determineRealURL(text){
|
function determineRealURL(text){
|
||||||
var url = RootStore.getUrlFromUserInput(text);
|
var url = RootStore.getUrlFromUserInput(text);
|
||||||
var host = providerModule.getHost(url);
|
var host = providerModule.getHost(url);
|
||||||
|
|
|
@ -21,7 +21,7 @@ QtObject {
|
||||||
return RootStore.getAscii2Hex(input)
|
return RootStore.getAscii2Hex(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
function postMessage(data) {
|
function postMessage(requestType, data) {
|
||||||
var request;
|
var request;
|
||||||
try {
|
try {
|
||||||
request = JSON.parse(data)
|
request = JSON.parse(data)
|
||||||
|
@ -34,8 +34,10 @@ QtObject {
|
||||||
if (ensAddr) {
|
if (ensAddr) {
|
||||||
request.hostname = ensAddr;
|
request.hostname = ensAddr;
|
||||||
}
|
}
|
||||||
|
if (requestType === Constants.web3DisconnectAccount) {
|
||||||
if (request.type === Constants.api_request) {
|
browserWindow.currentTabConnected = true
|
||||||
|
web3Response(JSON.stringify({type: Constants.web3DisconnectAccount}));
|
||||||
|
} else if (requestType === Constants.api_request) {
|
||||||
if (!Web3ProviderStore.web3ProviderInst.hasPermission(request.hostname, request.permission)) {
|
if (!Web3ProviderStore.web3ProviderInst.hasPermission(request.hostname, request.permission)) {
|
||||||
browserWindow.currentTabConnected = false
|
browserWindow.currentTabConnected = false
|
||||||
var dialog = accessDialogComponent.createObject(browserWindow);
|
var dialog = accessDialogComponent.createObject(browserWindow);
|
||||||
|
@ -43,10 +45,9 @@ QtObject {
|
||||||
dialog.open();
|
dialog.open();
|
||||||
} else {
|
} else {
|
||||||
browserWindow.currentTabConnected = true
|
browserWindow.currentTabConnected = true
|
||||||
request.isAllowed = true;
|
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request)));
|
||||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request)));
|
|
||||||
}
|
}
|
||||||
} else if (request.type === Constants.web3SendAsyncReadOnly &&
|
} else if (requestType === Constants.web3SendAsyncReadOnly &&
|
||||||
request.payload.method === "eth_sendTransaction") {
|
request.payload.method === "eth_sendTransaction") {
|
||||||
var acc = WalletStore.dappBrowserAccount
|
var acc = WalletStore.dappBrowserAccount
|
||||||
const value = RootStore.getWei2Eth(request.payload.params[0].value, 18);
|
const value = RootStore.getWei2Eth(request.payload.params[0].value, 18);
|
||||||
|
@ -73,16 +74,22 @@ QtObject {
|
||||||
selectedAmount: value
|
selectedAmount: value
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO change sendTransaction function to the postMessage one
|
|
||||||
sendDialog.sendTransaction = function (selectedGasLimit, selectedGasPrice, selectedTipLimit, selectedOverallLimit, enteredPassword) {
|
sendDialog.sendTransaction = function (selectedGasLimit, selectedGasPrice, selectedTipLimit, selectedOverallLimit, enteredPassword) {
|
||||||
request.payload.selectedGasLimit = selectedGasLimit
|
let trx = request.payload.params[0]
|
||||||
request.payload.selectedGasPrice = selectedGasPrice
|
// TODO: use bignumber instead of floats
|
||||||
request.payload.selectedTipLimit = selectedTipLimit
|
trx.value = RootStore.getEth2Hex(parseFloat(value))
|
||||||
request.payload.selectedOverallLimit = selectedOverallLimit
|
trx.gas = "0x" + parseInt(selectedGasLimit, 10).toString(16)
|
||||||
request.payload.password = enteredPassword
|
if (walletModel.transactionsView.isEIP1559Enabled) {
|
||||||
request.payload.params[0].value = value
|
trx.maxPriorityFeePerGas = RootStore.getGwei2Hex(parseFloat(selectedTipLimit))
|
||||||
|
trx.maxFeePerGas = RootStore.getGwei2Hex(parseFloat(selectedOverallLimit))
|
||||||
|
} else {
|
||||||
|
trx.gasPrice = RootStore.getGwei2Hex(parseFloat(selectedGasPrice))
|
||||||
|
}
|
||||||
|
|
||||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request))
|
request.payload.password = enteredPassword
|
||||||
|
request.payload.params[0] = trx
|
||||||
|
|
||||||
|
const response = Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request))
|
||||||
provider.web3Response(response)
|
provider.web3Response(response)
|
||||||
|
|
||||||
let responseObj
|
let responseObj
|
||||||
|
@ -116,7 +123,7 @@ QtObject {
|
||||||
|
|
||||||
sendDialog.open();
|
sendDialog.open();
|
||||||
WalletStore.getGasPrice()
|
WalletStore.getGasPrice()
|
||||||
} else if (request.type === Constants.web3SendAsyncReadOnly && ["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"].indexOf(request.payload.method) > -1) {
|
} else if (requestType === Constants.web3SendAsyncReadOnly && ["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"].indexOf(request.payload.method) > -1) {
|
||||||
const signDialog = signMessageModalComponent.createObject(browserWindow, {
|
const signDialog = signMessageModalComponent.createObject(browserWindow, {
|
||||||
request,
|
request,
|
||||||
selectedAccount: {
|
selectedAccount: {
|
||||||
|
@ -134,12 +141,12 @@ QtObject {
|
||||||
case Constants.eth_sign:
|
case Constants.eth_sign:
|
||||||
request.payload.params[1] = signValue(request.payload.params[1]);
|
request.payload.params[1] = signValue(request.payload.params[1]);
|
||||||
}
|
}
|
||||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request));
|
const response = Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request));
|
||||||
provider.web3Response(response);
|
provider.web3Response(response);
|
||||||
try {
|
try {
|
||||||
let responseObj = JSON.parse(response)
|
let responseObj = JSON.parse(response)
|
||||||
if (responseObj.error) {
|
if (responseObj.error) {
|
||||||
throw new Error(responseObj.error)
|
throw new Error(responseObj.error.message)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (Utils.isInvalidPasswordMessage(e.message)){
|
if (Utils.isInvalidPasswordMessage(e.message)){
|
||||||
|
@ -159,7 +166,7 @@ QtObject {
|
||||||
} else if (request.type === Constants.web3DisconnectAccount) {
|
} else if (request.type === Constants.web3DisconnectAccount) {
|
||||||
web3Response(data);
|
web3Response(data);
|
||||||
} else {
|
} else {
|
||||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(data));
|
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(requestType, data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue