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

.to_message() fails on Arrays #16

Open
jvinet opened this issue Jun 10, 2022 · 6 comments
Open

.to_message() fails on Arrays #16

jvinet opened this issue Jun 10, 2022 · 6 comments

Comments

@jvinet
Copy link

jvinet commented Jun 10, 2022

Test code:

import os
from eip712_structs import Bytes, Array, EIP712Struct, make_domain

class TestStruct(EIP712Struct):
    byte_array = Array(Bytes(32), 4)

byte_array = [os.urandom(32) for _ in range(4)]

domain = make_domain(name='hello')
s = TestStruct(byte_array=byte_array)
print(s.to_message(domain))

This code will raise:

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print(s.to_message(domain))
  File "site-packages/eip712_structs/struct.py", line 165, in to_message
    structs = {domain, self}
  File "site-packages/eip712_structs/struct.py", line 315, in __hash__
    value_hashes = [hash(k) ^ hash(v) for k, v in self.values.items()]
  File "site-packages/eip712_structs/struct.py", line 315, in <listcomp>
    value_hashes = [hash(k) ^ hash(v) for k, v in self.values.items()]
TypeError: unhashable type: 'list'
@numpde
Copy link

numpde commented Jun 22, 2022

Same problem here. How about changing to
structs = [domain, self]
in that line?

@gqoew
Copy link

gqoew commented Jun 28, 2022

I have the same error when I used .to_message() on Arrays

and when I use .signable_bytes(domain) I get:

AttributeError: 'bytes' object has no attribute 'version'

@PierreMkt
Copy link

Same error. Any workaround found ?

@jvinet
Copy link
Author

jvinet commented Jul 20, 2022

This project appears to be dormant. I used a custom solution instead: https://github.com/jvinet/eip712

Perhaps it can work for you, too.

@josh-davis-vicinft
Copy link

This is fixed in my branch at https://github.com/ViciNFT/py-eip712-structs. The answer posted by @numpde is part of the solution, and there were a few other changes required.

@hao0707
Copy link

hao0707 commented Feb 15, 2023

Array should pass variables of type tuple.Like this:
byte_array = tuple([os.urandom(32) for _ in range(4)])

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

6 participants