feat: enable sending contract calls from the browser
This commit is contained in:
parent
0c1156b33c
commit
70177b803a
|
@ -113,15 +113,21 @@ QtObject:
|
|||
let request = data.request.parseJson
|
||||
let fromAddress = request["params"][0]["from"].getStr()
|
||||
let to = request["params"][0]["to"].getStr()
|
||||
let value = request["params"][0]["value"].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 txData = if (request["params"][0]["data"] != nil):
|
||||
request["params"][0]["data"].getStr()
|
||||
else:
|
||||
""
|
||||
|
||||
var success: bool
|
||||
# TODO make this async
|
||||
let response = status.wallet.sendTransaction(fromAddress, to, value, selectedGasLimit, selectedGasPrice, password, success)
|
||||
debug "Response", response, success
|
||||
let response = status.wallet.sendTransaction(fromAddress, to, value, selectedGasLimit, selectedGasPrice, password, success, txData)
|
||||
let errorMessage = if not success:
|
||||
if response == "":
|
||||
"web3-response-error"
|
||||
|
@ -134,8 +140,12 @@ QtObject:
|
|||
"type": ResponseTypes.Web3SendAsyncCallback,
|
||||
"messageId": data.messageId,
|
||||
"error": errorMessage,
|
||||
"result": {
|
||||
"jsonrpc": "2.0",
|
||||
"id": data.payload.id,
|
||||
"result": if (success): response else: ""
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
error "Error sending the transaction", msg = e.msg
|
||||
return $ %* {
|
||||
|
|
|
@ -8,12 +8,13 @@ import
|
|||
libstatus/types
|
||||
from libstatus/utils as status_utils import toUInt64, gwei2Wei, parseAddress
|
||||
|
||||
proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = ""): EthSend =
|
||||
proc buildTransaction*(source: Address, value: Uint256, gas = "", gasPrice = "", data = ""): EthSend =
|
||||
result = EthSend(
|
||||
source: source,
|
||||
value: value.some,
|
||||
gas: (if gas.isEmptyOrWhitespace: Quantity.none else: Quantity(cast[uint64](parseFloat(gas).toUInt64)).some),
|
||||
gasPrice: (if gasPrice.isEmptyOrWhitespace: int.none else: gwei2Wei(parseFloat(gasPrice)).truncate(int).some)
|
||||
gasPrice: (if gasPrice.isEmptyOrWhitespace: int.none else: gwei2Wei(parseFloat(gasPrice)).truncate(int).some),
|
||||
data: data
|
||||
)
|
||||
|
||||
proc buildTokenTransaction*(source, contractAddress: Address, gas = "", gasPrice = ""): EthSend =
|
||||
|
|
|
@ -118,10 +118,10 @@ proc estimateTokenGas*(self: WalletModel, source, to, assetAddress, value: strin
|
|||
let response = contract.methods["transfer"].estimateGas(tx, transfer, success)
|
||||
result = fromHex[int](response)
|
||||
|
||||
proc sendTransaction*(self: WalletModel, source, to, value, gas, gasPrice, password: string, success: var bool): string =
|
||||
proc sendTransaction*(self: WalletModel, source, to, value, gas, gasPrice, password: string, success: var bool, data = ""): string =
|
||||
var tx = transactions.buildTransaction(
|
||||
parseAddress(source),
|
||||
eth2Wei(parseFloat(value), 18), gas, gasPrice
|
||||
eth2Wei(parseFloat(value), 18), gas, gasPrice, data
|
||||
)
|
||||
tx.to = parseAddress(to).some
|
||||
|
||||
|
|
|
@ -193,7 +193,6 @@ Item {
|
|||
|
||||
// TODO change sendTransaction function to the postMessage one
|
||||
sendDialog.sendTransaction = function (selectedGasLimit, selectedGasPrice, enteredPassword) {
|
||||
console.log('OK', selectedGasLimit, selectedGasPrice, enteredPassword)
|
||||
request.payload.selectedGasLimit = selectedGasLimit
|
||||
request.payload.selectedGasPrice = selectedGasPrice
|
||||
request.payload.password = enteredPassword
|
||||
|
@ -215,7 +214,7 @@ Item {
|
|||
toastMessage.source = "../../img/loading.svg"
|
||||
toastMessage.iconColor = Style.current.primary
|
||||
toastMessage.iconRotates = true
|
||||
toastMessage.link = `${walletModel.etherscanLink}/${responseOnj.result}`
|
||||
toastMessage.link = `${walletModel.etherscanLink}/${responseObj.result}`
|
||||
toastMessage.open()
|
||||
} catch (e) {
|
||||
if (e.message.includes("could not decrypt key with given password")){
|
||||
|
|
Loading…
Reference in New Issue