-
Notifications
You must be signed in to change notification settings - Fork 13
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
Update codebase to ensure idiomatic Java code #463
base: main
Are you sure you want to change the base?
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.
What about default constructors generated for data classes. I think they should have @JvmOverloads
or secondary constructors as well, WDYT?
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, I applied @JvmOverloads
in Class
and FeltArray
constructors. Can't see any other data classes which need an overloaded constructor.
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.
What I'm referring to are data class
'es, e.g. InvokeTransactionV1
, EmittedEvent
or some TransactionPayload
classes.
Which will have overloaded constructor with defaults in Kotlin, but won't have one in Java.
Come to think of it, I wonder if we shouldn't make some of these constructors private/internal:
- For instance, it's strange we're allowing to set
TransactionType
of something that is calledInvokeTransactionV1
- Also,
TransactionFactory
should be used for creatingTransaction
objects anyways.- If we'd create overloaded constructors for these classes, we might consider removing
TransactionFactory
altogether for consistency
- If we'd create overloaded constructors for these classes, we might consider removing
I understand that this might be too much. To satisfy the issue, I suppose it would be enough to just create necessary overloads / add @JvmOverloads
. But we could also use this / another stacked PR to solve some related problems.
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 added @JvmOverloads
to EmittedEvent
, InvokeTransactionV1
and DeclareTransactionV3
.
I also created overloaded constructors in data classes representing transactions, and this way we could get rid of TransactionFactory
.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #463 +/- ##
==========================================
- Coverage 71.12% 69.07% -2.05%
==========================================
Files 75 75
Lines 3338 3247 -91
Branches 367 361 -6
==========================================
- Hits 2374 2243 -131
- Misses 798 849 +51
+ Partials 166 155 -11 ☔ View full report in Codecov by Sentry. |
… into chore/403-ensure-idtiomatic-java-code
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.
What I'm referring to are data class
'es, e.g. InvokeTransactionV1
, EmittedEvent
or some TransactionPayload
classes.
Which will have overloaded constructor with defaults in Kotlin, but won't have one in Java.
Come to think of it, I wonder if we shouldn't make some of these constructors private/internal:
- For instance, it's strange we're allowing to set
TransactionType
of something that is calledInvokeTransactionV1
- Also,
TransactionFactory
should be used for creatingTransaction
objects anyways.- If we'd create overloaded constructors for these classes, we might consider removing
TransactionFactory
altogether for consistency
- If we'd create overloaded constructors for these classes, we might consider removing
I understand that this might be too much. To satisfy the issue, I suppose it would be enough to just create necessary overloads / add @JvmOverloads
. But we could also use this / another stacked PR to solve some related problems.
…b.com/software-mansion/starknet-jvm into chore/403-ensure-idtiomatic-java-code
…ransactionFactory`
@@ -87,15 +85,14 @@ class StandardAccount @JvmOverloads constructor( | |||
nonce: Felt, | |||
forFeeEstimate: Boolean, | |||
): DeployAccountTransactionV1Payload { | |||
val signVersion = if (forFeeEstimate) TransactionVersion.V1_QUERY else TransactionVersion.V1 |
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.
Instead of passing version
, we can pass forFeeEstimate
flag to the class constructor and based on that, indicate the version in the transaction.
- It's more comfortable in usage.
- It prevents creating transactions with wrong versions.
@@ -270,7 +332,7 @@ data class InvokeTransactionV0( | |||
val maxFee: Felt, | |||
|
|||
@SerialName("version") | |||
override val version: TransactionVersion = TransactionVersion.V0, | |||
override val version: TransactionVersion, |
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.
We can get rid of setting default version
, because now it's being set in private constructor based on forFeeEstimate
param.
Describe your changes
Update codebase to follow principles listed in readme i.e. ensure idiomatic Java code
@JvmOverloads
to constructor in:FeltArray
,Call
signDeployAccountV3
,signDeclareV2
,signDeclareV3
inAccount
@JvmOverloads
to constructors in data classes representing transactionsTransactionFactory
Linked issues
Closes #403
Breaking changes