feat(@wallet): multi transaction

This commit is contained in:
Anthony Laibe 2022-07-11 14:26:21 +02:00 committed by Anthony Laibe
parent 971d12ff42
commit cd5042e389
5 changed files with 58 additions and 33 deletions

View File

@ -89,13 +89,6 @@ proc getEstimateGasData*(self: MethodDto, tx: var TransactionDataDto, procDescri
tx.data = self.encodeAbi(procDescriptor)
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 =
success = true
tx.data = self.encodeAbi(procDescriptor)

View File

@ -1,4 +1,4 @@
import json, strutils, stint
import json, strutils, stint, json_serialization
include ../../common/json_utils
type
@ -12,6 +12,20 @@ type
proc event*(self:PendingTransactionTypeDto):string =
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
TransactionDto* = ref object of RootObj
id*: string

View File

@ -271,21 +271,24 @@ QtObject:
eth_utils.validateTransactionInput(from_addr, to_addr, assetAddress = "", value, gas,
gasPrice, data = "", eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas, uuid)
# TODO move this to another thread
var tx = ens_utils.buildTransaction(parseAddress(from_addr), eth2Wei(parseFloat(value), 18),
gas, gasPrice, eip1559Enabled, maxPriorityFeePerGas, maxFeePerGas)
tx.to = parseAddress(to_addr).some
let json: JsonNode = %tx
let response = eth.sendTransaction(parseInt(chainId), $json, password)
let output = %* { "result": response.result.getStr, "success": %(response.error.isNil), "uuid": %uuid }
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(result: $output))
# TODO ADD READ CHAIN
self.trackPendingTransaction(
response.result.getStr, from_addr, to_addr,
$PendingTransactionTypeDto.WalletTransfer, data = "", 1
let response = transactions.createMultiTransaction(
MultiTransactionDto(
fromAddress: from_addr,
toAddress: to_addr,
fromAsset: "ETH",
toAsset: "ETH",
fromAmount: "0x" & tx.value.unsafeGet.toHex,
multiTxtype: MultiTransactionType.MultiTransactionSend,
),
{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:
error "Error sending eth transfer transaction", msg = e.msg
return false
@ -316,20 +319,29 @@ QtObject:
var tx = ens_utils.buildTokenTransaction(parseAddress(from_addr), token.address,
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(
txHash, from_addr, to_addr,
$PendingTransactionTypeDto.WalletTransfer, data = "",
network.chainId
let weiValue = conversion.eth2Wei(parseFloat(value), token.decimals)
let transfer = Transfer(
to: parseAddress(to_addr),
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:
error "Error sending token transfer transaction", msg = e.msg
return false

View File

@ -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
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].} =
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

@ -1 +1 @@
Subproject commit b2ce92fd41a3b899749e2ed2ebd94ec8d4e1859f
Subproject commit ce0caa0f7f2a351abe3330b57fae903eb624e9ce