Skip to content

Commit 916d2d4

Browse files
authored
Fix decode to work with decoded binaries (#172)
* Fix decode to work with decoded binaries * Update CHANGELOG.md
1 parent ae7d21f commit 916d2d4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug Fixes
66

77
- Remove leading zeros from signature r and s values
8+
- Support hex decoded raw transaction in `Ethers.Transaction.decode/1`
89

910
## v0.6.0 (2025-01-01)
1011

lib/ethers/transaction.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,16 @@ defmodule Ethers.Transaction do
167167
- `{:ok, transaction}` - Decoded transaction struct
168168
- `{:error, reason}` - Error decoding transaction
169169
"""
170-
@spec decode(String.t()) :: {:ok, t()} | {:error, term()}
170+
@spec decode(String.t() | binary()) :: {:ok, t()} | {:error, term()}
171171
def decode("0x" <> raw_transaction) do
172-
case raw_transaction
173-
|> Utils.hex_decode!()
174-
|> decode_transaction_data() do
172+
case Utils.hex_decode(raw_transaction) do
173+
{:ok, hex_decoded} -> decode(hex_decoded)
174+
:error -> {:error, :invalid_hex}
175+
end
176+
end
177+
178+
def decode(raw_transaction_bin) when is_binary(raw_transaction_bin) do
179+
case decode_transaction_data(raw_transaction_bin) do
175180
{:ok, transaction, signature} ->
176181
maybe_decode_signature(transaction, signature)
177182

0 commit comments

Comments
 (0)