-
Notifications
You must be signed in to change notification settings - Fork 21
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
Improve Transaction API validation #371
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good first PR 🎉
I pointed some comments to improve it
|> cast_embed(:ownerships) | ||
|> validate_length(:code, | ||
max: @code_max_size, | ||
message: "code size can't be more than " <> Integer.to_string(@code_max_size) <> " bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want you can use string interpolation:
"code size can't be more than #{Integer.to_string(@code_max_size)} bytes"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 😅😅
max: @code_max_size, | ||
message: "code size can't be more than " <> Integer.to_string(@code_max_size) <> " bytes" | ||
) | ||
|> validate_length(:ownerships, max: 256, message: "ownerships can not be more that 256") | ||
|> validate_content_size() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove it and use validate_length
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay sure
# Validate data size here | ||
# Calculate max. content size here based on args | ||
# Custom validators in ecto | ||
# validate_length // works with lists, strings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little miss here 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup will clean this also
config/config.exs
Outdated
@@ -57,6 +57,9 @@ config :archethic, :marker, "-=%=-=%=-=%=-" | |||
# size represents in bytes binary | |||
config :archethic, :transaction_data_content_max_size, 3_145_728 | |||
|
|||
# size represents in bytes binary | |||
config :archethic, :transaction_data_code_max_size, 5_242_880 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ~42KB ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5242880 Bytes = 5 MB. I think that is good enough for the code size and can be changed in config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to 24Kb in Config
Description
Additional Checks on Structure Changesets to validate proper lengths for following
Fixes #330
Type of change
Forces API to precheck the sizes which are supported by transaction encoding before serializing
How Has This Been Tested?
Checklist: