From 5ddf3afc9a1c16b29caa539b474b705017585512 Mon Sep 17 00:00:00 2001 From: Sergei Tikhomirov Date: Wed, 11 Dec 2024 16:47:09 +0100 Subject: [PATCH] use Address.fromHex conversion from eth-web3 --- waku/incentivization/txid_proof.nim | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/waku/incentivization/txid_proof.nim b/waku/incentivization/txid_proof.nim index 8c946a8ca..7fa94108d 100644 --- a/waku/incentivization/txid_proof.nim +++ b/waku/incentivization/txid_proof.nim @@ -3,24 +3,6 @@ import std/options, chronos, web3, stew/byteutils, stint, strutils import waku/incentivization/rpc -# Function to convert a hex string to Address -proc toAddress*(hexStr: string): Address = - #[]# - # Remove the "0x" prefix if it exists - let cleaned = if hexStr.startsWith("0x"): hexStr[2..^1] else: hexStr - - # Ensure the length is exactly 40 characters (20 bytes) - if cleaned.len != 40: - raise newException(ValueError, "Invalid hexadecimal string length for Address") - - var arr: array[20, byte] - for i in 0 ..< 20: - let byteValue = cleaned[i * 2 ..< i * 2 + 2] # Get two hex characters - arr[i] = byte(parseHexInt(byteValue)) - - result = Address(arr) - - proc checkTxIdIsEligible(txHash: TxHash, ethClient: string): Future[bool] {.async.} = let web3 = await newWeb3(ethClient) try: @@ -44,7 +26,7 @@ proc checkTxIdIsEligible(txHash: TxHash, ethClient: string): Future[bool] {.asyn let hasExpectedValue = (txValue == 200500000000005063.u256) # check that the to address is "as expected" (hard-coded for now) let toAddress = toAddressOption.get() - let hasExpectedToAddress = (toAddress == toAddress("0x5e809a85aa182a9921edd10a4163745bb3e36284")) + let hasExpectedToAddress = (toAddress == Address.fromHex("0x5e809a85aa182a9921edd10a4163745bb3e36284")) result = true except ValueError as e: result = false