From 90bcdb6d5118d941b8be7ce956d6a8fdfd0002b4 Mon Sep 17 00:00:00 2001 From: Christian Wesselhoeft Date: Mon, 13 Oct 2025 08:19:35 -0600 Subject: [PATCH 1/2] Fix 1.19 compiler warnings --- lib/ethers/transaction/signed.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ethers/transaction/signed.ex b/lib/ethers/transaction/signed.ex index 8cc0ac1..fb32079 100644 --- a/lib/ethers/transaction/signed.ex +++ b/lib/ethers/transaction/signed.ex @@ -79,7 +79,7 @@ defmodule Ethers.Transaction.Signed do defp maybe_add_chain_id(%__MODULE__{payload: %Legacy{chain_id: nil} = legacy_tx} = signed_tx) do {chain_id, _recovery_id} = extract_chain_id_and_recovery_id(signed_tx) - %__MODULE__{signed_tx | payload: %Legacy{legacy_tx | chain_id: chain_id}} + %{signed_tx | payload: %{legacy_tx | chain_id: chain_id}} end defp maybe_add_chain_id(%__MODULE__{} = tx), do: tx From 82cdaea1623b5e0d6a54e577dd8330d960b8380c Mon Sep 17 00:00:00 2001 From: Christian Wesselhoeft Date: Mon, 13 Oct 2025 08:20:13 -0600 Subject: [PATCH 2/2] Fix "previous clause always matches" error --- lib/ethers/signer/local.ex | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/ethers/signer/local.ex b/lib/ethers/signer/local.ex index d57071d..2f556b7 100644 --- a/lib/ethers/signer/local.ex +++ b/lib/ethers/signer/local.ex @@ -21,41 +21,41 @@ defmodule Ethers.Signer.Local do alias Ethers.Transaction.Signed alias Ethers.Utils - if not Code.ensure_loaded?(secp256k1_module()) do + if Code.ensure_loaded?(secp256k1_module()) do @impl true - def sign_transaction(_tx, _opts), do: {:error, :secp256k1_module_not_loaded} + def sign_transaction(transaction, opts) do + with {:ok, private_key} <- private_key(opts), + :ok <- validate_private_key(private_key, Keyword.get(opts, :from)), + encoded = Transaction.encode(transaction), + sign_hash = keccak_module().hash_256(encoded), + {:ok, {r, s, recovery_id}} <- secp256k1_module().sign(sign_hash, private_key) do + signed_transaction = + %Signed{ + payload: transaction, + signature_r: r, + signature_s: s, + signature_y_parity_or_v: Signed.calculate_y_parity_or_v(transaction, recovery_id) + } + + encoded_signed_transaction = Transaction.encode(signed_transaction) + + {:ok, Utils.hex_encode(encoded_signed_transaction)} + end + end @impl true - def accounts(_opts), do: {:error, :secp256k1_module_not_loaded} - end - - @impl true - def sign_transaction(transaction, opts) do - with {:ok, private_key} <- private_key(opts), - :ok <- validate_private_key(private_key, Keyword.get(opts, :from)), - encoded = Transaction.encode(transaction), - sign_hash = keccak_module().hash_256(encoded), - {:ok, {r, s, recovery_id}} <- secp256k1_module().sign(sign_hash, private_key) do - signed_transaction = - %Signed{ - payload: transaction, - signature_r: r, - signature_s: s, - signature_y_parity_or_v: Signed.calculate_y_parity_or_v(transaction, recovery_id) - } - - encoded_signed_transaction = Transaction.encode(signed_transaction) - - {:ok, Utils.hex_encode(encoded_signed_transaction)} + def accounts(opts) do + with {:ok, private_key} <- private_key(opts), + {:ok, address} <- do_get_address(private_key) do + {:ok, [address]} + end end - end + else + @impl true + def sign_transaction(_tx, _opts), do: {:error, :secp256k1_module_not_loaded} - @impl true - def accounts(opts) do - with {:ok, private_key} <- private_key(opts), - {:ok, address} <- do_get_address(private_key) do - {:ok, [address]} - end + @impl true + def accounts(_opts), do: {:error, :secp256k1_module_not_loaded} end defp do_get_address(private_key) do