mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-22 04:21:44 +00:00
feat(@wallet): multi transaction
This commit is contained in:
parent
971d12ff42
commit
cd5042e389
@ -89,13 +89,6 @@ proc getEstimateGasData*(self: MethodDto, tx: var TransactionDataDto, procDescri
|
|||||||
tx.data = self.encodeAbi(procDescriptor)
|
tx.data = self.encodeAbi(procDescriptor)
|
||||||
return %*[%tx]
|
return %*[%tx]
|
||||||
|
|
||||||
proc send*(self: MethodDto, chainId: int, tx: var TransactionDataDto, procDescriptor: object, password: string, success: var bool): RpcResponse[JsonNode] =
|
|
||||||
tx.data = self.encodeAbi(procDescriptor)
|
|
||||||
# this call should not be part of this file, we need to move it to appropriate place, or this should not be a DTO class.
|
|
||||||
let response = status_eth.sendTransaction(chainId, $(%tx), password)
|
|
||||||
success = response.error.isNil
|
|
||||||
return response
|
|
||||||
|
|
||||||
proc call[T](self: MethodDto, chainId: int, tx: var TransactionDataDto, procDescriptor: object, success: var bool): T =
|
proc call[T](self: MethodDto, chainId: int, tx: var TransactionDataDto, procDescriptor: object, success: var bool): T =
|
||||||
success = true
|
success = true
|
||||||
tx.data = self.encodeAbi(procDescriptor)
|
tx.data = self.encodeAbi(procDescriptor)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import json, strutils, stint
|
import json, strutils, stint, json_serialization
|
||||||
include ../../common/json_utils
|
include ../../common/json_utils
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -12,6 +12,20 @@ type
|
|||||||
proc event*(self:PendingTransactionTypeDto):string =
|
proc event*(self:PendingTransactionTypeDto):string =
|
||||||
result = "transaction:" & $self
|
result = "transaction:" & $self
|
||||||
|
|
||||||
|
type
|
||||||
|
MultiTransactionType* = enum
|
||||||
|
MultiTransactionSend = 0, MultiTransactionSwap = 1, MultiTransactionBridge = 2
|
||||||
|
|
||||||
|
type MultiTransactionDto* = ref object of RootObj
|
||||||
|
id* {.serializedFieldName("id").}: int
|
||||||
|
timestamp* {.serializedFieldName("timestamp").}: int
|
||||||
|
fromAddress* {.serializedFieldName("fromAddress").}: string
|
||||||
|
toAddress* {.serializedFieldName("toAddress").}: string
|
||||||
|
fromAsset* {.serializedFieldName("fromAsset").}: string
|
||||||
|
toAsset* {.serializedFieldName("toAsset").}: string
|
||||||
|
fromAmount* {.serializedFieldName("fromAmount").}: string
|
||||||
|
multiTxtype* {.serializedFieldName("type").}: MultiTransactionType
|
||||||
|
|
||||||
type
|
type
|
||||||
TransactionDto* = ref object of RootObj
|
TransactionDto* = ref object of RootObj
|
||||||
id*: string
|
id*: string
|
||||||
|
@ -271,21 +271,24 @@ QtObject:
|
|||||||
eth_utils.validateTransactionInput(from_addr, to_addr, assetAddress = "", value, gas,
|
eth_utils.validateTransactionInput(from_addr, to_addr, assetAddress = "", value, gas,
|
||||||
gasPrice, data = "", eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas, uuid)
|
gasPrice, data = "", eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas, uuid)
|
||||||
|
|
||||||
# TODO move this to another thread
|
|
||||||
var tx = ens_utils.buildTransaction(parseAddress(from_addr), eth2Wei(parseFloat(value), 18),
|
var tx = ens_utils.buildTransaction(parseAddress(from_addr), eth2Wei(parseFloat(value), 18),
|
||||||
gas, gasPrice, eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
|
gas, gasPrice, eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
|
||||||
tx.to = parseAddress(to_addr).some
|
tx.to = parseAddress(to_addr).some
|
||||||
|
|
||||||
let json: JsonNode = %tx
|
let response = transactions.createMultiTransaction(
|
||||||
let response = eth.sendTransaction(parseInt(chainId), $json, password)
|
MultiTransactionDto(
|
||||||
let output = %* { "result": response.result.getStr, "success": %(response.error.isNil), "uuid": %uuid }
|
fromAddress: from_addr,
|
||||||
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(result: $output))
|
toAddress: to_addr,
|
||||||
|
fromAsset: "ETH",
|
||||||
# TODO ADD READ CHAIN
|
toAsset: "ETH",
|
||||||
self.trackPendingTransaction(
|
fromAmount: "0x" & tx.value.unsafeGet.toHex,
|
||||||
response.result.getStr, from_addr, to_addr,
|
multiTxtype: MultiTransactionType.MultiTransactionSend,
|
||||||
$PendingTransactionTypeDto.WalletTransfer, data = "", 1
|
),
|
||||||
|
{chainId: @[tx]}.toTable,
|
||||||
|
password,
|
||||||
)
|
)
|
||||||
|
let output = %* { "result": response.result{"hashes"}{chainId}[0].getStr, "success": %(response.error.isNil), "uuid": %uuid }
|
||||||
|
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(result: $output))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error sending eth transfer transaction", msg = e.msg
|
error "Error sending eth transfer transaction", msg = e.msg
|
||||||
return false
|
return false
|
||||||
@ -316,20 +319,29 @@ QtObject:
|
|||||||
|
|
||||||
var tx = ens_utils.buildTokenTransaction(parseAddress(from_addr), token.address,
|
var tx = ens_utils.buildTokenTransaction(parseAddress(from_addr), token.address,
|
||||||
gas, gasPrice, eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
|
gas, gasPrice, eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
|
||||||
var success: bool
|
|
||||||
let transfer = Transfer(to: parseAddress(to_addr),
|
|
||||||
value: conversion.eth2Wei(parseFloat(value), token.decimals))
|
|
||||||
let transferproc = ERC20_procS.toTable["transfer"]
|
|
||||||
let response = transferproc.send(parseInt(chainId), tx, transfer, password, success)
|
|
||||||
let txHash = response.result.getStr
|
|
||||||
let output = %* { "result": txHash, "success": %success, "uuid": %uuid }
|
|
||||||
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(result: $output))
|
|
||||||
|
|
||||||
self.trackPendingTransaction(
|
let weiValue = conversion.eth2Wei(parseFloat(value), token.decimals)
|
||||||
txHash, from_addr, to_addr,
|
let transfer = Transfer(
|
||||||
$PendingTransactionTypeDto.WalletTransfer, data = "",
|
to: parseAddress(to_addr),
|
||||||
network.chainId
|
value: weiValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tx.data = ERC20_procS.toTable["transfer"].encodeAbi(transfer)
|
||||||
|
let response = transactions.createMultiTransaction(
|
||||||
|
MultiTransactionDto(
|
||||||
|
fromAddress: from_addr,
|
||||||
|
toAddress: to_addr,
|
||||||
|
fromAsset: tokenSymbol,
|
||||||
|
toAsset: tokenSymbol,
|
||||||
|
fromAmount: "0x" & weiValue.toHex,
|
||||||
|
multiTxtype: MultiTransactionType.MultiTransactionSend,
|
||||||
|
),
|
||||||
|
{chainId: @[tx]}.toTable,
|
||||||
|
password,
|
||||||
|
)
|
||||||
|
let txHash = response.result.getStr
|
||||||
|
let output = %* { "result": response.result{"hashes"}{chainId}[0].getStr, "success":true, "uuid": %uuid }
|
||||||
|
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(result: $output))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error sending token transfer transaction", msg = e.msg
|
error "Error sending token transfer transaction", msg = e.msg
|
||||||
return false
|
return false
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import json, stint, chronicles
|
import Tables, json, stint, chronicles, nimcrypto
|
||||||
|
|
||||||
|
import ../app_service/service/transaction/dto
|
||||||
|
import ../app_service/service/eth/dto/transaction
|
||||||
import ./core as core
|
import ./core as core
|
||||||
|
|
||||||
proc checkRecentHistory*(chainIds: seq[int], addresses: seq[string]) {.raises: [Exception].} =
|
proc checkRecentHistory*(chainIds: seq[int], addresses: seq[string]) {.raises: [Exception].} =
|
||||||
@ -43,3 +45,7 @@ proc getPendingOutboundTransactionsByAddress*(chainIds: seq[int], address: strin
|
|||||||
proc fetchCryptoServices*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc fetchCryptoServices*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
result = core.callPrivateRPC("wallet_getCryptoOnRamps", %* [])
|
result = core.callPrivateRPC("wallet_getCryptoOnRamps", %* [])
|
||||||
|
|
||||||
|
proc createMultiTransaction*(multiTransaction: MultiTransactionDto, data: Table[string, seq[TransactionDataDto]], password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
var hashed_password = "0x" & $keccak_256.digest(password)
|
||||||
|
let payload = %* [multiTransaction, data, hashed_password]
|
||||||
|
result = core.callPrivateRPC("wallet_createMultiTransaction", payload)
|
2
vendor/status-go
vendored
2
vendor/status-go
vendored
@ -1 +1 @@
|
|||||||
Subproject commit b2ce92fd41a3b899749e2ed2ebd94ec8d4e1859f
|
Subproject commit ce0caa0f7f2a351abe3330b57fae903eb624e9ce
|
Loading…
x
Reference in New Issue
Block a user