Skip to content

Commit 7fed144

Browse files
committed
Code review with Gimantha, Thisaru and Tharik
1 parent 566812c commit 7fed144

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

app/src/main/java/io/ballerina/web3/cli/Cli.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* specific language governing permissions and limitations
1616
* under the License.
1717
*/
18-
18+
// TODO: io.ballerina.lib.web3
1919
package io.ballerina.web3.cli;
2020

2121
import io.ballerina.cli.BLauncherCmd;

app/src/main/java/io/ballerina/web3/generator/ClientGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
* under the License.
1717
*/
1818

19+
// TODO: Latest copy writes
20+
21+
1922
package io.ballerina.web3.generator;
2023

24+
// TODO: import only specific classes rather than the whole package
2125
import io.ballerina.compiler.syntax.tree.*;
2226
import io.ballerina.tools.text.TextDocument;
2327
import io.ballerina.tools.text.TextDocuments;

app/src/main/java/io/ballerina/web3/generator/DynamicFunctionGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ private static String convertAbiTypeToBallerina(String abiType) {
4040
return convertAbiTypeToBallerina(abiType.replace("[]", "")) + "[]";
4141
}
4242

43+
// TODO : Use specific data types
4344
return switch (abiType) {
4445
case "uint256", "int256", "uint8", "int8", "uint16", "int16" -> "decimal";
4546
case "bool" -> "boolean";
4647
case "address" -> "string";
48+
// TODO: bytes -> byte array
4749
case "string", "bytes" -> "string";
4850
default -> "anydata"; // Fallback
4951
};
@@ -56,10 +58,12 @@ private static String generateBallerinaReturnType(List<AbiOutput> outputs, Strin
5658

5759
// If there's only one output, return its native type
5860
if (outputs.size() == 1) {
61+
// TODO: Handle error type
5962
return convertAbiTypeToBallerina(outputs.get(0).getType()) + "|error?";
6063
}
6164

6265
// If multiple outputs, generate a record type
66+
// Todo : Record name first char cap
6367
String recordName = functionName + "Response";
6468
StringBuilder recordType = new StringBuilder("type ").append(recordName).append(" record {| ");
6569

@@ -80,6 +84,7 @@ private static String generateResourceFunctionSignature(List<AbiInput> inputs, L
8084
StringBuilder data = new StringBuilder();
8185

8286
// Define the function signature
87+
// TODO: isolated res func
8388
data.append("resource isolated function post ").append(methodName).append("(");
8489

8590
// Add function parameters
@@ -108,6 +113,7 @@ private static String generateResourceFunctionSignature(List<AbiInput> inputs, L
108113
private static String generateDecodingLogic(List<AbiOutput> outputs) {
109114
String outputType = outputs.get(0).getType(); // Assuming single output for simplicity
110115

116+
// TODO : Handle other outputs
111117
switch (outputType) {
112118
case "uint256":
113119
case "int256":
@@ -118,7 +124,8 @@ private static String generateDecodingLogic(List<AbiOutput> outputs) {
118124
return "string result = \"0x\" + response.result.substring(26);\n"; // Last 20 bytes
119125
case "string":
120126
return "string result = response.result.substring(2);\n";
121-
case "tuple[]":
127+
// TODO: handle tuple
128+
case "tuple[]":
122129
return "anydata[] result = []; // Not yet supported \n";
123130
default:
124131
return "string result = response;\n // Unsupported type: " + outputType + "\n";

app/src/main/java/io/ballerina/web3/generator/Generator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class Generator {
2828
public static void generate(List<AbiEntry> abiEntries, String outputDir) throws FormatterException {
2929
String sourceCode = ClientGenerator.generate(abiEntries);
3030

31+
// TODO : Use path for file.seperator
32+
// TODO : Code gen dir
3133
FileUtils.writeToFile(outputDir + "/main.bal", sourceCode);
3234
FileUtils.copyResourceToOutput("utils.bal", outputDir);
3335
}

app/src/main/java/io/ballerina/web3/generator/utils/AbiUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
package io.ballerina.web3.generator.utils;
20+
2021
import java.nio.charset.StandardCharsets;
2122
import java.util.List;
2223

@@ -32,6 +33,7 @@ public static String encodeParameters(List<AbiInput> params) {
3233
if (param instanceof Integer || param instanceof Long) {
3334
paramEncoded = String.format("%064x", (Integer) param); // 64-character hex
3435
} else if (param instanceof Boolean) {
36+
// TODO: Restruct
3537
paramEncoded = ((Boolean) param) ? "0000000000000000000000000000000000000000000000000000000000000001"
3638
: "0000000000000000000000000000000000000000000000000000000000000000";
3739
} else if (param instanceof String strParam) {
@@ -50,7 +52,6 @@ public static String encodeParameters(List<AbiInput> params) {
5052
return encodedParams.toString();
5153
}
5254

53-
5455
private static String stringToHex(String input) {
5556
byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
5657
StringBuilder hexString = new StringBuilder();

app/src/main/java/io/ballerina/web3/generator/utils/BallerinaUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
public class BallerinaUtils {
2424
// List of Reserved Keywords in Ballerina
25+
// TODO: use keywords from compiler
2526
private static final Set<String> RESERVED_KEYWORDS = Set.of(
2627
"function", "int", "boolean", "string", "record", "resource", "isolated",
2728
"error", "returns", "public", "private", "remote", "client", "self", "if", "else",

0 commit comments

Comments
 (0)