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

cannot decode log data if the destination data size > 32 bytes? #160

Closed
formingform opened this issue Feb 28, 2024 · 4 comments
Closed

cannot decode log data if the destination data size > 32 bytes? #160

formingform opened this issue Feb 28, 2024 · 4 comments

Comments

@formingform
Copy link

to docode the log data,

raw_data = "00000000000000000000000097ab3d4f7f5051f127b0e9f8d10772125d94d65b0000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000407c278b7e4320528bdbf5c02db611282b431dbaec2509b1fbebe3de4be7442a4114f1c9970ffd0c589afa8ef6262692efd4edae5d77c87641f21f44b1d082c3480000000000000000000000000000000000000000000000000000000000000030b969678ef2cf458b49b8c568d95e63221efe0f30383a9b0c5eb683bf2e23d118664631ce992d81ec4b6127ec0a760f8600000000000000000000000000000000"

data_bytes = Base.decode16!(raw_data , case: :mixed)

[owner, rate, pub_key, bls_key] = TypeDecoder.decode_raw(data_bytes, [:address, {:uint, 256}, {:bytes, 64},  {:bytes, 48}])

and get this error message, pub_key size is 64 bytes and bls_key size is 48 bytes.

** (FunctionClauseError) no function clause matching in ABI.TypeDecoder.decode_type/2    
    
    The following arguments were given to ABI.TypeDecoder.decode_type/2:
    
        # 1
        {:bytes, 48}
    
        # 2
        <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0, 0, 0, 0, 0, 48, 185, 105, 103, 142, 242, 207, 69, 139, 73, 184, 197, 104,
          217, 94, 99, 34, 30, 254, ...>>

    Attempted function clauses (showing 7 out of 7):

        defp decode_type(-{:uint, size_in_bits}-, data)
        defp decode_type(-{:int, size_in_bits}-, data)
        defp decode_type({:bytes, size}, data) when size > 0 and -size <= 32-
        defp decode_type(-{:array, type, size}-, data)
        defp decode_type(-{:tuple, types}-, data)
        defp decode_type(-:address-, data)
        defp decode_type(-:bool-, data)

    (ex_abi 0.7.0) lib/abi/type_decoder.ex:243: ABI.TypeDecoder.decode_type/2
    (ex_abi 0.7.0) lib/abi/type_decoder.ex:190: anonymous fn/3 in ABI.TypeDecoder.do_decode_raw/2
    (elixir 1.14.5) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_abi 0.7.0) lib/abi/type_decoder.ex:185: ABI.TypeDecoder.do_decode_raw/2
    (ex_abi 0.7.0) lib/abi/type_decoder.ex:179: ABI.TypeDecoder.decode_raw/2
@formingform
Copy link
Author

ex_abi version is 0.6.4 or 0.7.0

@alisinabh
Copy link
Contributor

alisinabh commented Feb 28, 2024

AFAIK there is no bytes64 type. For byte arrays larger than 32 bytes, just use :bytes (dynamic sized byte array).
For your example:

raw_data = "00000000000000000000000097ab3d4f7f5051f127b0e9f8d10772125d94d65b0000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000407c278b7e4320528bdbf5c02db611282b431dbaec2509b1fbebe3de4be7442a4114f1c9970ffd0c589afa8ef6262692efd4edae5d77c87641f21f44b1d082c3480000000000000000000000000000000000000000000000000000000000000030b969678ef2cf458b49b8c568d95e63221efe0f30383a9b0c5eb683bf2e23d118664631ce992d81ec4b6127ec0a760f8600000000000000000000000000000000"

data_bytes = Base.decode16!(raw_data , case: :mixed)

[owner, rate, pub_key, bls_key] = TypeDecoder.decode_raw(data_bytes, [:address, {:uint, 256}, :bytes,  :bytes])

@formingform
Copy link
Author

It worked. Thank you very much!

@formingform
Copy link
Author

great!

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

No branches or pull requests

2 participants