Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Nov 12, 2024
1 parent 094e29c commit b82e02c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
22 changes: 7 additions & 15 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public static CompletableFuture<EvmAddress> getEvmAddressFromMirrorNodeAsync(Cli
String apiEndpoint = "/accounts/" + num;
return performQueryToMirrorNodeAsync(client, apiEndpoint, null, false)
.thenApply(response ->
EvmAddress.fromString(parseEvmAddressFromMirrorNodeResponse(response, "evm_address")));
EvmAddress.fromString(parseStringMirrorNodeResponse(response, "evm_address")));
}

/**
Expand All @@ -338,24 +338,12 @@ public static CompletableFuture<Long> getContractNumFromMirrorNodeAsync(Client c
}





private static long parseNumFromMirrorNodeResponse(String responseBody, String memberName) {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(responseBody).getAsJsonObject();

String num = jsonObject.get(memberName).getAsString();

return Long.parseLong(num.substring(num.lastIndexOf(".") + 1));
}

public static CompletableFuture<String> getContractAddressFromMirrorNodeAsync(Client client, String id) {
String apiEndpoint = "/contracts/" + id;
CompletableFuture<String> responseFuture = performQueryToMirrorNodeAsync(client, apiEndpoint, null, false);

return responseFuture.thenApply(response ->
parseEvmAddressFromMirrorNodeResponse(response, "evm_address"));
parseStringMirrorNodeResponse(response, "evm_address"));
}

static CompletableFuture<String> performQueryToMirrorNodeAsync(Client client, String apiEndpoint, String jsonBody, boolean isContractCall) {
Expand Down Expand Up @@ -406,12 +394,16 @@ static CompletableFuture<String> performQueryToMirrorNodeAsync(Client client, St
});
}

private static String parseEvmAddressFromMirrorNodeResponse(String responseBody, String memberName) {
private static String parseStringMirrorNodeResponse(String responseBody, String memberName) {
JsonObject jsonObject = JsonParser.parseString(responseBody).getAsJsonObject();
String evmAddress = jsonObject.get(memberName).getAsString();
return evmAddress.substring(evmAddress.lastIndexOf(".") + 1);
}

private static long parseNumFromMirrorNodeResponse(String responseBody, String memberName) {
return Long.parseLong(parseStringMirrorNodeResponse(responseBody, memberName));
}

@FunctionalInterface
interface WithIdNums<R> {
R apply(long shard, long realm, long num, @Nullable String checksum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ void canExecuteContractMethods() throws Exception {
var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);

Thread.sleep(2000);
// TODO: estimates lower than actual

var gas = new MirrorNodeContractQuery()
.setContractId(contractId)
.setFunction("setMessage", new ContractFunctionParameters().addString("new message"))
.estimate(testEnv.client);

var receipt = new ContractExecuteTransaction()
.setContractId(contractId)
.setGas(gas + 15000)
.setGas(gas + 10000)
.setFunction("setMessage", new ContractFunctionParameters().addString("new message"))
.execute(testEnv.client)
.getReceipt(testEnv.client);
Expand Down

0 comments on commit b82e02c

Please sign in to comment.