Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode transaction body #76

Merged
merged 13 commits into from
Jan 30, 2024
Merged

Conversation

wchenNL
Copy link
Contributor

@wchenNL wchenNL commented Jan 8, 2024

Per the conversation

Decode the transaction body, need a bit more discussion.

@wchenNL wchenNL marked this pull request as ready for review January 12, 2024 18:17
@wchenNL wchenNL changed the title [Draft] Decode transaction body Decode transaction body Jan 12, 2024
tx_body =
%{
type: tx_type,
chain_id: decode_key(tx, "chainId"),
Copy link

@lishawnl lishawnl Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I miss it, are we missing value field? :P

@@ -210,4 +261,13 @@ defmodule Ethers.Transaction do

defp trim_leading(<<0, rest::binary>>), do: trim_leading(rest)
defp trim_leading(<<bin::binary>>), do: bin

defp decode_key(tx, key) do
decoded_value = Map.get(tx, key) |> Ethers.Utils.hex_to_integer()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this may already be thought about. Would it be possible that key has value nil, will the next_to_integer() throw error in this case

@wchenNL
Copy link
Contributor Author

wchenNL commented Jan 15, 2024

nice catch @lishawnl

The response after decoding should look like this now

%Ethers.Transaction{
   type: :eip1559,
   chain_id: 11155111,
   nonce: 2792,
   gas: 586616,
   from: "0x0fbb16c4d35a7e1fc09afe3e947202db611b34f0",
   to: "0x95ff8d3ce9dcb7455beb7845143bea84fe5c4f6f",
   value: 1,
   data: nil,
   gas_price: 91002661038,
   max_fee_per_gas: 161786308691,
   max_priority_fee_per_gas: 3,
   access_list: [],
   signature_r: "0x7327535623ed763a55305a7cc7822b3afe49685bc04517d7b261c18d11ef865",
   signature_s: "0x3a355998f4564859afbbbae2b831906941635d37fa493fc2440ee8829882185d",
   signature_recovery_id: nil,
   block_hash: "0xed868075a51e358f816e87b30d31f471dbb8ed44f43ae51eaa9299abea1b741d",
   block_number: 5092858,
   hash: "0xfe7d305239837db59c07c00f6367585e5426131458657627aeb2b961eed4694d",
   input: "0xb6d5a39700000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000a09f36d26665571c132780605640847b0310211e4cbc199a6d1ef71f14552380160000000000000000000000000fbb16c4d35a7e1fc09afe3e947202db611b34f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000fbb16c4d35a7e1fc09afe3e947202db611b34f00000000000000000000000000000000000000000000000000000000065a5b8420000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000004158a6328072ce7ca695266d66cc2939b34950800c8f296730bf73bfa254df903837437257231b883cddad958acfcbf6689aaded5ee45f29b111ce90f14b5463961c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003964f93961b9041802f9041483028c5f028462590080846259008183037d779438d80da17dc0c72fd8acc276fc917b69899415f480b903a43593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000065a5b17000000000000000000000000000000000000000000000000000000000000000020a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000f0380c236eb7c3fc51a9b46706d27ba738b0be7f000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000065cd3d74000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d80da17dc0c72fd8acc276fc917b69899415f40000000000000000000000000000000000000000000000000000000065a5b77c00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000004172d2b237c388767dbab74d382dd8642f908d97f325290e4e56756334a01170bf41bc322ae24de7758a605766053ff0d7ab49305abb232e8f5083ec3b1b3bd21d1c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000327b20000000000000000000000000000000000000000000000005908d5c384e8b20c00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bf0380c236eb7c3fc51a9b46706d27ba738b0be7f0000649833dca11f178dbaf2b88da42557da2970534430000000000000000000000000000000000000000000c001a090cea1c4ddea9b039d0ffd4f7f275d1f55c436f53da6974ef40b29237a0714ffa07676b6ecb1fd6163b676c4388a4d31fe9d6f0ab8f97114471f0a72f93897a374b90c9b02f90c9783028c5f830159df8459682f008459682f028308d9fe94100077770000000000000000000000000000000480b90c24ec9b31210000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000c1a5b000000000000000000000000e09e50ba3c936e6a1a5a25b442616e27c90728720000000000000000000000000000000000000000000000000000000000aa36a70000000000000000000000000000000000000000000000000000000000028c5f000000000000000000000000e09e50ba3c936e6a1a5a25b442616e27c9072872000000000000000000000000e09e50ba3c936e6a1a5a25b442616e27c9072872000000000000000000000000e09e50ba3c936e6a1a5a25b442616e27c907287200000000000000000000000000000000000000000000000006b8c48e96a54000000000" <> ...,
   transaction_index: 243,
   v: 1,
   y_parity: 1
 }

%{
type: tx_type,
chain_id: decode_key(tx, "chainId"),
nonce: decode_key(tx, "nonce"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I forgot is that all values in this Transaction struct is expected to by either a binary or a hex encoded binary (0x..) as stated in the type spec . Decoding those values to integers will break that contract!

I see two possible solutions here:

  1. Use raw binary values to construct the Transaction struct and have another function (e.g. expand_values) which actually decodes these values to integers.
  2. Move this logic into Ethers.post_process and return decoded maps instead of a Transaction struct.

What do you guys thing? @wchenNL @lishawnl

hash: binary() | nil,
input: binary() | nil,
transaction_index: binary() | nil,
v: binary() | nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe v == signature_recovery_id. Can you confirm this and if so, we can just use signature_recovery_id for consistency.

@alisinabh alisinabh force-pushed the decode_transaction_body branch from 424d1da to f804a45 Compare January 28, 2024 21:04
@alisinabh alisinabh requested a review from lishawnl January 28, 2024 21:08
Copy link

@lishawnl lishawnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates 💟

@alisinabh alisinabh force-pushed the decode_transaction_body branch from d12589e to 83d526d Compare January 29, 2024 17:18
@alisinabh alisinabh merged commit ecfe3da into ExWeb3:main Jan 30, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants