-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Contract wrapper generator should convert array items to native types #346
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
Conversation
…rray was converted to List but contained items remained unchanged. All tests pass
Codecov Report
@@ Coverage Diff @@
## master #346 +/- ##
============================================
- Coverage 76.78% 76.47% -0.32%
- Complexity 1597 1621 +24
============================================
Files 214 215 +1
Lines 5880 6052 +172
Branches 925 956 +31
============================================
+ Hits 4515 4628 +113
- Misses 1149 1192 +43
- Partials 216 232 +16
Continue to review full report at Codecov.
|
Thanks for spotting this and submitting a fix. There is one issue with generating the streams - all smart contract wrapper code that is generated should be Java 1.6 compatible, otherwise Android users would have to use a different version of the command line tools which is not appropriate. Is it possible to submit the change against the contract class and manually insert into the smart contract wrappers you're working with? |
Sorry, I didn't quite catch what you mean. But if you are talking about wrapper java 1.6 compatibility it can be easily achieved by moving If you need web3j source code to be compatible with java 1.6 too, you can rewrite protected static <OriginalType, NewType> List<NewType> convertToNative(List<OriginalType> arr) {
List<NewType> out = new ArrayList<NewType>();
for(Iterator<OriginalType> it = arr.iterator(); it.hasNext(); ){
out.add(it.next());
}
return out;
} Will it solve the problem? If yes I can update the pull request with these changes. |
@dukei Please go ahead and update this PR as you have suggested so it can be merged. |
Moved convertToNative to Contract class
@iikirilov I have made the changes to support Java 6. I am a bit confused why coverage tests fail this time. I have mostly removed some code since the last commit. |
@@ -9,6 +9,7 @@ | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.concurrent.Callable; | |||
import java.util.stream.Collectors; |
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.
This still needs removing.
@@ -430,4 +431,13 @@ public final String getDeployedAddress(String networkId) { | |||
return addr == null ? getStaticDeployedAddress(networkId) : addr; | |||
8000 td> | } | ||
|
|||
@SuppressWarnings("unchecked") | |||
protected static <OriginalTypeT extends Type, NewTypeT> |
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.
Could we just use S & T here? I'm not so keen on lengthy parameterised type names.
@conor10 I made the changes you requested |
Thanks! |
Contract wrapper generator should convert array items to native types
This pull request fixes the following bug:
Suppose contract function returns
bytes32[]
. The generator generates method returningList<byte[]>
(for--javaTypes
flag). But in fact the method returnsList<Bytes32>
- onlyArray
gets converted. So web3j codegen does not convert items in arrays to native types.Suggested fix: generated functions perform deep conversion for arrays.
Warning: for converting arrays the generator creates method
convertToNative
in each contract class. This method currently uses Java8 streams. Consider rewriting this function (and moving it to baseContract
class) to support Android.I did not move it to
Contract
base class myself because in this case I will not be able to load web3j from maven until you release the version with this pull request merged. Now only code generator is affected.All tests passed.