Commit 4cf08ae
authored
Thiagodeev/Fix SNIP-12 JSON Marshaling for TypedData (#789)
* refactor: update benchmarks in typedData_test.go
- Moved fileNames to a global variable for better accessibility across tests.
- Updated BenchmarkGetMessageHash to utilize the new fileNames variable.
- Removed unused BMockTypedData helper
- Added BenchmarkUnmarshalJSON to test the performance of the UnmarshalJSON function with various test data files.
* test: add TestMarshalJSON to validate JSON marshaling of TypedData
* refactor: add JSON tags to TypedData fields for improved JSON serialization
* feat: implement MarshalJSON for TypeDefinition to enable JSON serialization
* refactor: enhance Domain struct for improved JSON marshaling
- Added custom logic in UnmarshalJSON to handle both `chainId` and `chain_id` fields.
- Introduced flags to track the type of `chainId` for accurate marshaling.
- Implemented MarshalJSON to ensure `chainId` is serialized correctly based on its original format.
* refactor: enhance Domain struct for JSON marshaling with revision support
- Added logic in UnmarshalJSON to handle the `revision` field, including a flag to track its type.
- Updated MarshalJSON to ensure the `Revision` field is serialized correctly based on its original format.
- Improved comments for clarity on the purpose of marshaling logic for both `chainId` and `revision` fields.
* refactor: improve handling of chainId and chain_id in EncodeData function
- Updated logic to accommodate both `chainId` and `chain_id` fields in the domainMap.
- Added checks to copy values between the two fields as a workaround for compatibility.
- Enhanced comments for better understanding of the changes made.
* chore: update changelog with the changes
* refactor: improve error messages in UnmarshalJSON for Domain struct
- Updated error messages in UnmarshalJSON to specify 'JSON field' instead of 'struct' for clarity
* refactor: simplify error handling in UnmarshalJSON for Domain struct
- Removed redundant error check for 'chainId' retrieval in UnmarshalJSON.
* refactor: enhance error handling in MarshalJSON for Domain struct
- Improved error message for 'chainId' parsing to provide clearer context on failure.1 parent ff34dcd commit 4cf08ae
3 files changed
+185
-69
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
421 | 426 | | |
422 | 427 | | |
423 | 428 | | |
| 429 | + | |
424 | 430 | | |
425 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
426 | 439 | | |
427 | 440 | | |
428 | 441 | | |
| |||
886 | 899 | | |
887 | 900 | | |
888 | 901 | | |
889 | | - | |
| 902 | + | |
890 | 903 | | |
891 | 904 | | |
892 | 905 | | |
| |||
902 | 915 | | |
903 | 916 | | |
904 | 917 | | |
905 | | - | |
906 | | - | |
907 | | - | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
908 | 923 | | |
909 | | - | |
910 | | - | |
911 | | - | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
912 | 936 | | |
913 | 937 | | |
914 | | - | |
915 | | - | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
916 | 943 | | |
917 | 944 | | |
918 | 945 | | |
919 | | - | |
| 946 | + | |
| 947 | + | |
920 | 948 | | |
921 | | - | |
922 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
923 | 953 | | |
924 | 954 | | |
| 955 | + | |
925 | 956 | | |
926 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
927 | 967 | | |
928 | 968 | | |
929 | 969 | | |
930 | 970 | | |
931 | 971 | | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
932 | 976 | | |
933 | 977 | | |
934 | 978 | | |
935 | 979 | | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
26 | 16 | | |
27 | 17 | | |
28 | 18 | | |
| |||
34 | 24 | | |
35 | 25 | | |
36 | 26 | | |
| 27 | + | |
37 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
67 | 61 | | |
68 | | - | |
69 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
70 | 95 | | |
71 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
72 | 102 | | |
73 | 103 | | |
74 | 104 | | |
| |||
157 | 187 | | |
158 | 188 | | |
159 | 189 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
| |||
0 commit comments