-
Notifications
You must be signed in to change notification settings - Fork 86
fix: Pass enum values directly to TokenCreateTransaction protobuf to fix type conflict #732
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
Open
Pranay22077
wants to merge
1
commit into
hiero-ledger:main
Choose a base branch
from
Pranay22077:tct
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
In lines 490 to 494 you see we have a function that attempts to resolve
token_type_value to be like the proto --
see:
token_type_value = (
self._token_params.token_type.value
if isinstance(self._token_params.token_type, TokenType)
else int(self._token_params.token_type or 0)
)
so when you suggest
tokenType=self_token_params.token_type.value
Its doing very similar thing
Current type error:
Argument of type "int" cannot be assigned to parameter "tokenType" of type "TokenType | str | None" in function "init"
Type "int" is not assignable to type "TokenType | str | None"
"int" is not assignable to "TokenType"
"int" is not assignable to "str"
"int" is not assignable to "None"
The reason this errors is because either the type checker is not able to pick up on the correct type in the proto, or the underlying protobuf expects tokenType: TokenType | str | None
Currently, it thinks we are passing ints, even if you delete the int normalisation (lines 490 to 494, and just provide your idea, it will still conflict as it would be type Literal[0,1]
SOLUTION
the solution is to cast the the token type to the proto value
This was per my original suggestion:
tokenType=basic_types_pb2.TokenType(self._token_params.token_type.value)
This works because its taken the token type enum Literal of [0,1] and wrapping it into the proto token type.
or
you can change lines 490 to 494, which in hindsight probably makes more sense
and do
so it takes that token type literal and wraps it to proto friendly term
the underlying issue is we lack an easy to proto method for token type and supply type that would mean we can avoid writing all this custom conversions, and probably the type checker is not picking up on the type inference
Then we could just do
tokenType=self._token_params.token_type._to_proto()
and both the code will work (as it currently does) but the type checker will be happy too
Uh oh!
There was an error while loading. Please reload this page.
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.
Currently testing if this would work,
My suggestion probably won't work
TypeError: 'EnumTypeWrapper' object is not callable
Not yet sure how to fix underlying issue, which seems to be caused by the type checker
@Pranay22077 can't find a way to fix the issue, let me know if you do! else feel free to start a new issue. Thanks
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.
Sure @exploreriii
That's becoming a little too complex
Will update you about it in some time, after trying other steps