From 40e6cdf0b399d6a03f66db6d6b48c6fdb69d0b79 Mon Sep 17 00:00:00 2001 From: Serhii Date: Fri, 16 Feb 2024 20:12:24 +0200 Subject: [PATCH] Fix eth transaction hash for Thorchain Integration --- cw_evm/lib/pending_evm_chain_transaction.dart | 10 +++++++++- lib/exchange/provider/thorchain_exchange.provider.dart | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cw_evm/lib/pending_evm_chain_transaction.dart b/cw_evm/lib/pending_evm_chain_transaction.dart index 8129de728..0b367da68 100644 --- a/cw_evm/lib/pending_evm_chain_transaction.dart +++ b/cw_evm/lib/pending_evm_chain_transaction.dart @@ -3,6 +3,7 @@ import 'dart:typed_data'; import 'package:cw_core/pending_transaction.dart'; import 'package:web3dart/crypto.dart'; +import 'package:hex/hex.dart' as Hex; class PendingEVMChainTransaction with PendingTransaction { final Function sendTransaction; @@ -38,5 +39,12 @@ class PendingEVMChainTransaction with PendingTransaction { String get hex => bytesToHex(signedTransaction, include0x: true); @override - String get id => ''; + String get id { + final String eip1559Hex = '0x02${hex.substring(2)}'; + final Uint8List bytes = Uint8List.fromList(Hex.HEX.decode(eip1559Hex.substring(2))); + + var txid = keccak256(bytes); + + return '0x${Hex.HEX.encode(txid)}'; + } } diff --git a/lib/exchange/provider/thorchain_exchange.provider.dart b/lib/exchange/provider/thorchain_exchange.provider.dart index e40ad836d..29e64b18f 100644 --- a/lib/exchange/provider/thorchain_exchange.provider.dart +++ b/lib/exchange/provider/thorchain_exchange.provider.dart @@ -141,7 +141,8 @@ class ThorChainExchangeProvider extends ExchangeProvider { @override Future findTradeById({required String id}) async { if (id.isEmpty) throw Exception('Trade id is empty'); - final uri = Uri.parse('$_baseURL$_txInfoPath$id'); + final formattedId = id.startsWith('0x') ? id.substring(2) : id; + final uri = Uri.parse('$_baseURL$_txInfoPath$formattedId'); final response = await http.get(uri); if (response.statusCode == 404) {