Skip to content

Commit 60e64eb

Browse files
committed
abi reading
1 parent 45dbdf8 commit 60e64eb

File tree

3 files changed

+5
-243
lines changed

3 files changed

+5
-243
lines changed

app/src/main/java/io/ballerina/web3/abi/AbiReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public AbiReader(String abiPath) {
3333
}
3434

3535
private static final List<String> METHODS_TO_SKIP = List.of(
36-
"safeTransferFrom", "approve", "setApprovalForAll", "transferFrom", "renounceOwnership");
36+
"safeTransferFrom", "approve", "setApprovalForAll", "transferFrom", "renounceOwnership",
37+
"isApprovedForAll", "owner", "supportsInterface", "symbol", "getApproved");
3738

3839
public List<AbiEntry> read() throws Exception {
3940

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
public class DynamicFunctionGenerator {
3636

3737
private static String convertAbiTypeToBallerina(String abiType) {
38+
System.out.println("n" + abiType);
3839
if (abiType.endsWith("[]")) {
3940
return convertAbiTypeToBallerina(abiType.replace("[]", "")) + "[]";
4041
}
@@ -118,7 +119,7 @@ private static String generateDecodingLogic(List<AbiOutput> outputs) {
118119
case "string":
119120
return "string result = response.result.substring(2);\n";
120121
default:
121-
return "// Unsupported type: " + outputType + "\n";
122+
return "string result = response;\n // Unsupported type: " + outputType + "\n";
122123
}
123124
}
124125

app/src/output/main.bal

Lines changed: 1 addition & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,6 @@ public client class Web3 {
114114
return weiAmount;
115115
}
116116

117-
resource isolated function post approve(string to, decimal tokenId) returns error? {
118-
// Encode function parameters
119-
string encodedParameters = encodeParameters([to, tokenId]);
120-
string callData = "0x" + "81c81e27" + encodedParameters;
121-
122-
// Generate the JSON-RPC request body
123-
json requestBody = {
124-
"jsonrpc": "2.0",
125-
"method": "eth_call",
126-
"params": [
127-
{"to": self.address, "data": callData},
128-
"latest"
129-
],
130-
"id": 1
131-
};
132-
133-
// Send the request and get response
134-
record {string result;} response = check self.rpcClient->post("/", requestBody);
135-
136-
}
137-
138117
resource isolated function post balanceOf(string owner) returns decimal|error? {
139118
// Encode function parameters
140119
string encodedParameters = encodeParameters([owner]);
@@ -158,52 +137,6 @@ public client class Web3 {
158137
return result;
159138
}
160139

161-
resource isolated function post getApproved(decimal tokenId) returns string|error? {
162-
// Encode function parameters
163-
string encodedParameters = encodeParameters([tokenId]);
164-
string callData = "0x" + "081812fc" + encodedParameters;
165-
166-
// Generate the JSON-RPC request body
167-
json requestBody = {
168-
"jsonrpc": "2.0",
169-
"method": "eth_call",
170-
"params": [
171-
{"to": self.address, "data": callData},
172-
"latest"
173-
],
174-
"id": 1
175-
};
176-
177-
// Send the request and get response
178-
record {string result;} response = check self.rpcClient->post("/", requestBody);
179-
180-
string result = "0x" + response.result.substring(26);
181-
return result;
182-
}
183-
184-
resource isolated function post isApprovedForAll(string owner, string operator) returns boolean|error? {
185-
// Encode function parameters
186-
string encodedParameters = encodeParameters([owner, operator]);
187-
string callData = "0x" + "0936ab2e" + encodedParameters;
188-
189-
// Generate the JSON-RPC request body
190-
json requestBody = {
191-
"jsonrpc": "2.0",
192-
"method": "eth_call",
193-
"params": [
194-
{"to": self.address, "data": callData},
195-
"latest"
196-
],
197-
"id": 1
198-
};
199-
200-
// Send the request and get response
201-
record {string result;} response = check self.rpcClient->post("/", requestBody);
202-
203-
boolean result = response.result == "0x1";
204-
return result;
205-
}
206-
207140
resource isolated function post name() returns string|error? {
208141
// Encode function parameters
209142
string encodedParameters = encodeParameters([]);
@@ -227,29 +160,6 @@ public client class Web3 {
227160
return result;
228161
}
229162

230-
resource isolated function post owner() returns string|error? {
231-
// Encode function parameters
232-
string encodedParameters = encodeParameters([]);
233-
string callData = "0x" + "8da5cb5b" + encodedParameters;
234-
235-
// Generate the JSON-RPC request body
236-
json requestBody = {
237-
"jsonrpc": "2.0",
238-
"method": "eth_call",
239-
"params": [
240-
{"to": self.address, "data": callData},
241-
"latest"
242-
],
243-
"id": 1
244-
};
245-
246-
// Send the request and get response
247-
record {string result;} response = check self.rpcClient->post("/", requestBody);
248-
249-
string result = "0x" + response.result.substring(26);
250-
return result;
251-
}
252-
253163
resource isolated function post ownerOf(decimal tokenId) returns string|error? {
254164
// Encode function parameters
255165
string encodedParameters = encodeParameters([tokenId]);
@@ -273,136 +183,6 @@ public client class Web3 {
273183
return result;
274184
}
275185

276-
resource isolated function post renounceOwnership() returns error? {
277-
// Encode function parameters
278-
string encodedParameters = encodeParameters([]);
279-
string callData = "0x" + "715018a6" + encodedParameters;
280-
281-
// Generate the JSON-RPC request body
282-
json requestBody = {
283-
"jsonrpc": "2.0",
284-
"method": "eth_call",
285-
"params": [
286-
{"to": self.address, "data": callData},
287-
"latest"
288-
],
289-
"id": 1
290-
};
291-
292-
// Send the request and get response
293-
record {string result;} response = check self.rpcClient->post("/", requestBody);
294-
295-
}
296-
297-
resource isolated function post safeTransferFrom(string from_param, string to, decimal tokenId) returns error? {
298-
// Encode function parameters
299-
string encodedParameters = encodeParameters([from_param, to, tokenId]);
300-
string callData = "0x" + "1bca66ec" + encodedParameters;
301-
302-
// Generate the JSON-RPC request body
303-
json requestBody = {
304-
"jsonrpc": "2.0",
305-
"method": "eth_call",
306-
"params": [
307-
{"to": self.address, "data": callData},
308-
"latest"
309-
],
310-
"id": 1
311-
};
312-
313-
// Send the request and get response
314-
record {string result;} response = check self.rpcClient->post("/", requestBody);
315-
316-
}
317-
318-
resource isolated function post safeTransferFrom2(string from_param, string to, decimal tokenId, string data) returns error? {
319-
// Encode function parameters
320-
string encodedParameters = encodeParameters([from_param, to, tokenId, data]);
321-
string callData = "0x" + "fd43c5ac" + encodedParameters;
322-
323-
// Generate the JSON-RPC request body
324-
json requestBody = {
325-
"jsonrpc": "2.0",
326-
"method": "eth_call",
327-
"params": [
328-
{"to": self.address, "data": callData},
329-
"latest"
330-
],
331-
"id": 1
332-
};
333-
334-
// Send the request and get response
335-
record {string result;} response = check self.rpcClient->post("/", requestBody);
336-
337-
}
338-
339-
resource isolated function post setApprovalForAll(string operator, boolean approved) returns error? {
340-
// Encode function parameters
341-
string encodedParameters = encodeParameters([operator, approved]);
342-
string callData = "0x" + "7122a46a" + encodedParameters;
343-
344-
// Generate the JSON-RPC request body
345-
json requestBody = {
346-
"jsonrpc": "2.0",
347-
"method": "eth_call",
348-
"params": [
349-
{"to": self.address, "data": callData},
350-
"latest"
351-
],
352-
"id": 1
353-
};
354-
355-
// Send the request and get response
356-
record {string result;} response = check self.rpcClient->post("/", requestBody);
357-
358-
}
359-
360-
resource isolated function post supportsInterface(anydata interfaceId) returns boolean|error? {
361-
// Encode function parameters
362-
string encodedParameters = encodeParameters([interfaceId]);
363-
string callData = "0x" + "01ffc9a7" + encodedParameters;
364-
365-
// Generate the JSON-RPC request body
366-
json requestBody = {
367-
"jsonrpc": "2.0",
368-
"method": "eth_call",
369-
"params": [
370-
{"to": self.address, "data": callData},
371-
"latest"
372-
],
373-
"id": 1
374-
};
375-
376-
// Send the request and get response
377-
record {string result;} response = check self.rpcClient->post("/", requestBody);
378-
379-
boolean result = response.result == "0x1";
380-
return result;
381-
}
382-
383-
resource isolated function post symbol() returns string|error? {
384-
// Encode function parameters
385-
string encodedParameters = encodeParameters([]);
386-
string callData = "0x" + "95d89b41" + encodedParameters;
387-
388-
// Generate the JSON-RPC request body
389-
json requestBody = {
390-
"jsonrpc": "2.0",
391-
"method": "eth_call",
392-
"params": [
393-
{"to": self.address, "data": callData},
394-
"latest"
395-
],
396-
"id": 1
397-
};
398-
399-
// Send the request and get response
400-
record {string result;} response = check self.rpcClient->post("/", requestBody);
401-
402-
string result = response.result.substring(2);
403-
return result;
404-
}
405-
406186
resource isolated function post tokenCounter() returns decimal|error? {
407187
// Encode function parameters
408188
string encodedParameters = encodeParameters([]);
@@ -495,27 +275,6 @@ public client class Web3 {
495275
return result;
496276
}
497277

498-
resource isolated function post transferFrom(string from_param, string to, decimal tokenId) returns error? {
499-
// Encode function parameters
500-
string encodedParameters = encodeParameters([from_param, to, tokenId]);
501-
string callData = "0x" + "944179b4" + encodedParameters;
502-
503-
// Generate the JSON-RPC request body
504-
json requestBody = {
505-
"jsonrpc": "2.0",
506-
"method": "eth_call",
507-
"params": [
508-
{"to": self.address, "data": callData},
509-
"latest"
510-
],
511-
"id": 1
512-
};
513-
514-
// Send the request and get response
515-
record {string result;} response = check self.rpcClient->post("/", requestBody);
516-
517-
}
518-
519278
resource isolated function post transferOwnership(string newOwner) returns error? {
520279
// Encode function parameters
521280
string encodedParameters = encodeParameters([newOwner]);
@@ -598,6 +357,7 @@ public client class Web3 {
598357
// Send the request and get response
599358
record {string result;} response = check self.rpcClient->post("/", requestBody);
600359

360+
string result = response;
601361
// Unsupported type: tuple[]
602362
return result;
603363
}

0 commit comments

Comments
 (0)