chore(walletconnect): adapting to improvements done on the statusgo side

This commit is contained in:
Sale Djenic 2023-12-01 17:58:58 +01:00 committed by saledjenic
parent ba60c711f7
commit c5d1d5b77d
7 changed files with 65 additions and 68 deletions

View File

@ -1,17 +1,19 @@
import NimQml, strutils, logging, json, options import NimQml, strutils, logging, json, options
import backend/wallet_connect as backend import backend/wallet as backend_wallet
import backend/wallet_connect as backend_wallet_connect
import app/global/global_singleton import app/global/global_singleton
import app/core/eventemitter import app/core/eventemitter
import app/core/signals/types import app/core/signals/types
import app_service/common/utils as common_utils import app_service/common/utils as common_utils
from app_service/service/transaction/dto import PendingTransactionTypeDto
import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import constants import constants
import session_response_dto, helper import tx_response_dto, helper
const UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER* = "WalletConnect-Signing" const UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER* = "WalletConnect-Signing"
@ -20,6 +22,7 @@ QtObject:
Controller* = ref object of QObject Controller* = ref object of QObject
events: EventEmitter events: EventEmitter
sessionRequestJson: JsonNode sessionRequestJson: JsonNode
txResponseDto: TxResponseDto
hasActivePairings: Option[bool] hasActivePairings: Option[bool]
## Forward declarations ## Forward declarations
@ -61,7 +64,7 @@ QtObject:
proc pairSessionProposal(self: Controller, sessionProposalJson: string) {.slot.} = proc pairSessionProposal(self: Controller, sessionProposalJson: string) {.slot.} =
var res: JsonNode var res: JsonNode
let err = backend.pair(res, sessionProposalJson) let err = backend_wallet_connect.pair(res, sessionProposalJson)
if err.len > 0: if err.len > 0:
error "Failed to pair session" error "Failed to pair session"
return return
@ -70,20 +73,20 @@ QtObject:
self.proposeUserPair(sessionProposalJson, supportedNamespacesJson) self.proposeUserPair(sessionProposalJson, supportedNamespacesJson)
proc recordSuccessfulPairing(self: Controller, sessionProposalJson: string) {.slot.} = proc recordSuccessfulPairing(self: Controller, sessionProposalJson: string) {.slot.} =
if backend.recordSuccessfulPairing(sessionProposalJson): if backend_wallet_connect.recordSuccessfulPairing(sessionProposalJson):
if not self.hasActivePairings.get(false): if not self.hasActivePairings.get(false):
self.hasActivePairings = some(true) self.hasActivePairings = some(true)
proc deletePairing(self: Controller, topic: string) {.slot.} = proc deletePairing(self: Controller, topic: string) {.slot.} =
if backend.deletePairing(topic): if backend_wallet_connect.deletePairing(topic):
if self.hasActivePairings.get(false): if self.hasActivePairings.get(false):
self.hasActivePairings = some(backend.hasActivePairings()) self.hasActivePairings = some(backend_wallet_connect.hasActivePairings())
else: else:
error "Failed to delete pairing" error "Failed to delete pairing"
proc getHasActivePairings*(self: Controller): bool {.slot.} = proc getHasActivePairings*(self: Controller): bool {.slot.} =
if self.hasActivePairings.isNone: if self.hasActivePairings.isNone:
self.hasActivePairings = some(backend.hasActivePairings()) self.hasActivePairings = some(backend_wallet_connect.hasActivePairings())
return self.hasActivePairings.get(false) return self.hasActivePairings.get(false)
QtProperty[bool] hasActivePairings: QtProperty[bool] hasActivePairings:
@ -93,23 +96,25 @@ QtObject:
proc sendTransactionAndRespond(self: Controller, signature: string) = proc sendTransactionAndRespond(self: Controller, signature: string) =
let finalSignature = singletonInstance.utils.removeHexPrefix(signature) let finalSignature = singletonInstance.utils.removeHexPrefix(signature)
var res: JsonNode var txResponse: JsonNode
let err = backend.sendTransactionWithSignature(res, finalSignature) let err = backend_wallet.sendTransactionWithSignature(txResponse, self.txResponseDto.chainId,
if err.len > 0: $PendingTransactionTypeDto.WalletConnectTransfer, $self.txResponseDto.txArgsJson, finalSignature)
if err.len > 0 or txResponse.isNil:
error "Failed to send tx" error "Failed to send tx"
return return
let txHash = res.getStr let txHash = txResponse.getStr
self.respondSessionRequest($self.sessionRequestJson, txHash, false) self.respondSessionRequest($self.sessionRequestJson, txHash, false)
proc buildRawTransactionAndRespond(self: Controller, signature: string) = proc buildRawTransactionAndRespond(self: Controller, signature: string) =
let finalSignature = singletonInstance.utils.removeHexPrefix(signature) let finalSignature = singletonInstance.utils.removeHexPrefix(signature)
var res: JsonNode var txResponse: JsonNode
let err = backend.buildRawTransaction(res, finalSignature) let err = backend_wallet.buildRawTransaction(txResponse, self.txResponseDto.chainId, $self.txResponseDto.txArgsJson,
finalSignature)
if err.len > 0: if err.len > 0:
error "Failed to send tx" error "Failed to build raw tx"
return return
let txHash = res.getStr let txResponseDto = txResponse.toTxResponseDto()
self.respondSessionRequest($self.sessionRequestJson, txHash, false) self.respondSessionRequest($self.sessionRequestJson, txResponseDto.rawTx, false)
proc finishSessionRequest(self: Controller, signature: string) = proc finishSessionRequest(self: Controller, signature: string) =
let requestMethod = getRequestMethod(self.sessionRequestJson) let requestMethod = getRequestMethod(self.sessionRequestJson)
@ -130,25 +135,25 @@ QtObject:
try: try:
self.sessionRequestJson = parseJson(sessionRequestJson) self.sessionRequestJson = parseJson(sessionRequestJson)
var sessionRes: JsonNode var sessionRes: JsonNode
let err = backend.sessionRequest(sessionRes, sessionRequestJson) let err = backend_wallet_connect.sessionRequest(sessionRes, sessionRequestJson)
if err.len > 0: if err.len > 0:
error "Failed to request a session" error "Failed to request a session"
self.respondSessionRequest($sessionRequestJson, "", true) self.respondSessionRequest(sessionRequestJson, "", true)
return return
let sessionResponseDto = sessionRes.toSessionResponseDto() self.txResponseDto = sessionRes.toTxResponseDto()
if sessionResponseDto.signOnKeycard: if self.txResponseDto.signOnKeycard:
let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER, let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_WALLET_CONNECT_MODULE_SIGNING_IDENTIFIER,
keyUid: sessionResponseDto.keyUid, keyUid: self.txResponseDto.keyUid,
path: sessionResponseDto.addressPath, path: self.txResponseDto.addressPath,
dataToSign: singletonInstance.utils.removeHexPrefix(sessionResponseDto.messageToSign)) dataToSign: singletonInstance.utils.removeHexPrefix(self.txResponseDto.messageToSign))
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_SIGN_DATA, data) self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_SIGN_DATA, data)
else: else:
let hashedPasssword = common_utils.hashPassword(password) let hashedPasssword = common_utils.hashPassword(password)
var signMsgRes: JsonNode var signMsgRes: JsonNode
let err = backend.signMessage(signMsgRes, let err = backend_wallet.signMessage(signMsgRes,
sessionResponseDto.messageToSign, self.txResponseDto.messageToSign,
sessionResponseDto.address, self.txResponseDto.address,
hashedPasssword) hashedPasssword)
if err.len > 0: if err.len > 0:
error "Failed to sign message on statusgo side" error "Failed to sign message on statusgo side"

View File

@ -3,19 +3,25 @@ import json
include app_service/common/json_utils include app_service/common/json_utils
type type
SessionResponseDto* = ref object TxResponseDto* = ref object
keyUid*: string keyUid*: string
address*: string address*: string
addressPath*: string addressPath*: string
signOnKeycard*: bool signOnKeycard*: bool
chainId*: int
messageToSign*: string messageToSign*: string
signedMessage*: string txArgsJson*: JsonNode
rawTx*: string
txHash*: string
proc toSessionResponseDto*(jsonObj: JsonNode): SessionResponseDto = proc toTxResponseDto*(jsonObj: JsonNode): TxResponseDto =
result = SessionResponseDto() result = TxResponseDto()
discard jsonObj.getProp("keyUid", result.keyUid) discard jsonObj.getProp("keyUid", result.keyUid)
discard jsonObj.getProp("address", result.address) discard jsonObj.getProp("address", result.address)
discard jsonObj.getProp("addressPath", result.addressPath) discard jsonObj.getProp("addressPath", result.addressPath)
discard jsonObj.getProp("signOnKeycard", result.signOnKeycard) discard jsonObj.getProp("signOnKeycard", result.signOnKeycard)
discard jsonObj.getProp("chainId", result.chainId)
discard jsonObj.getProp("messageToSign", result.messageToSign) discard jsonObj.getProp("messageToSign", result.messageToSign)
discard jsonObj.getProp("signedMessage", result.signedMessage) discard jsonObj.getProp("txArgs", result.txArgsJson)
discard jsonObj.getProp("rawTx", result.rawTx)
discard jsonObj.getProp("txHash", result.txHash)

View File

@ -338,7 +338,7 @@ QtObject:
if data.eventType == collectibles_backend.eventCommunityCollectiblesReceived: if data.eventType == collectibles_backend.eventCommunityCollectiblesReceived:
self.processReceivedCollectiblesWalletEvent(data.message) self.processReceivedCollectiblesWalletEvent(data.message)
self.events.on(PendingTransactionTypeDto.SetSigner.event) do(e: Args): self.events.on(PendingTransactionTypeDto.SetSignerPublicKey.event) do(e: Args):
let receivedData = TransactionMinedArgs(e) let receivedData = TransactionMinedArgs(e)
self.processSetSignerTransactionEvent(receivedData) self.processSetSignerTransactionEvent(receivedData)
@ -999,7 +999,7 @@ QtObject:
transactionHash, transactionHash,
addressFrom, addressFrom,
contractAddress, contractAddress,
$PendingTransactionTypeDto.SetSigner, $PendingTransactionTypeDto.SetSignerPublicKey,
$(%contractDetails), $(%contractDetails),
chainId, chainId,
) )

View File

@ -32,6 +32,7 @@ type
BurnCommunityToken = "BurnCommunityToken" BurnCommunityToken = "BurnCommunityToken"
DeployOwnerToken = "DeployOwnerToken" DeployOwnerToken = "DeployOwnerToken"
SetSignerPublicKey = "SetSignerPublicKey" SetSignerPublicKey = "SetSignerPublicKey"
WalletConnectTransfer = "WalletConnectTransfer"
proc event*(self:PendingTransactionTypeDto):string = proc event*(self:PendingTransactionTypeDto):string =
result = "transaction:" & $self result = "transaction:" & $self

View File

@ -12,6 +12,11 @@ rpc(buildTransaction, "wallet"):
chainId: int chainId: int
sendTxArgsJson: string sendTxArgsJson: string
rpc(buildRawTransaction, "wallet"):
chainId: int
sendTxArgsJson: string
signature: string
rpc(sendTransactionWithSignature, "wallet"): rpc(sendTransactionWithSignature, "wallet"):
chainId: int chainId: int
txType: string txType: string
@ -59,6 +64,20 @@ proc buildTransaction*(resultOut: var JsonNode, chainId: int, sendTxArgsJson: st
return e.msg return e.msg
## Builds the raw tx with the provided tx args, chain id and signature
## `resultOut` represents a json object that corresponds to the status go `transfer.TxResponse` type, or `nil` if the call was unsuccessful
## `chainId` is the chain id of the network
## `txArgsJSON` is the json string of the tx, corresponds to the status go `transactions.SendTxArgs` type
## `signature` is the signature of the tx
## returns the error message if any, or an empty string
proc buildRawTransaction*(resultOut: var JsonNode, chainId: int, sendTxArgsJson: string, signature: string): string =
try:
let response = buildRawTransaction(chainId, sendTxArgsJson, signature)
return prepareResponse(resultOut, response)
except Exception as e:
warn e.msg
return e.msg
## Sends the tx with signature on provided chain, setting tx type ## Sends the tx with signature on provided chain, setting tx type
## `resultOut` represents a json object that contains the tx hash if the call was successful, or `nil` ## `resultOut` represents a json object that contains the tx hash if the call was successful, or `nil`
## `chainId` is the chain id of the network ## `chainId` is the chain id of the network

View File

@ -19,8 +19,6 @@ rpc(wCSignMessage, "wallet"):
rpc(wCBuildRawTransaction, "wallet"): rpc(wCBuildRawTransaction, "wallet"):
signature: string signature: string
rpc(wCSendRawTransaction, "wallet"):
rawTx: string
rpc(wCSendTransactionWithSignature, "wallet"): rpc(wCSendTransactionWithSignature, "wallet"):
signature: string signature: string
@ -52,38 +50,6 @@ proc prepareResponse(res: var JsonNode, rpcResponse: RpcResponse[JsonNode]): str
return "no result" return "no result"
res = rpcResponse.result res = rpcResponse.result
proc signMessage*(res: var JsonNode, message: string, address: string, password: string): string =
try:
let response = wCSignMessage(message, address, password)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc buildRawTransaction*(res: var JsonNode, signature: string): string =
try:
let response = wCBuildRawTransaction(signature)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc sendRawTransaction*(res: var JsonNode, rawTx: string): string =
try:
let response = wCSendRawTransaction(rawTx)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
proc sendTransactionWithSignature*(res: var JsonNode, signature: string): string =
try:
let response = wCSendTransactionWithSignature(signature)
return prepareResponse(res, response)
except Exception as e:
warn e.msg
return e.msg
# TODO #12434: async answer # TODO #12434: async answer
proc pair*(res: var JsonNode, sessionProposalJson: string): string = proc pair*(res: var JsonNode, sessionProposalJson: string): string =
try: try:

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 9acabc69955b6a1884154a133083e62f05406892 Subproject commit cfa542378d974c3628ba5f545e4a1610818bd24a