Skip to content

Commit

Permalink
feat: add sui_getNormalizedMoveModulesByPackage api
Browse files Browse the repository at this point in the history
Signed-off-by: grapebaba <281165273@qq.com>
  • Loading branch information
GrapeBaBa committed Nov 16, 2022
1 parent 1e0c0a2 commit 6b77827
Show file tree
Hide file tree
Showing 15 changed files with 14,313 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/integrationTest/java/io/sui/SuiClientImplIntTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import io.sui.models.events.EventQuery.TransactionEventQuery;
import io.sui.models.events.PaginatedEvents;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.MoveNormalizedModule;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -51,6 +53,7 @@ class SuiClientImplIntTests {

private static SuiClient client;

/** Before all. */
@BeforeAll
static void beforeAll() {
JsonRpcClientProvider jsonRpcClientProvider =
Expand Down Expand Up @@ -316,6 +319,20 @@ void getEvents() throws ExecutionException, InterruptedException {
System.out.println(res.get());
}

/**
* Gets normalized move modules by package.
*
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test getNormalizedMoveModulesByPackage.")
void getNormalizedMoveModulesByPackage() throws ExecutionException, InterruptedException {
CompletableFuture<Map<String, MoveNormalizedModule>> res =
client.getNormalizedMoveModulesByPackage("0x0000000000000000000000000000000000000002");
System.out.println(res.get());
}

/**
* Gets committee info.
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/sui/SuiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import io.sui.models.events.EventQuery;
import io.sui.models.events.PaginatedEvents;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.MoveNormalizedModule;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
Expand Down Expand Up @@ -103,6 +105,15 @@ public interface SuiClient {
CompletableFuture<PaginatedEvents> getEvents(
EventQuery query, EventId cursor, int limit, boolean isDescOrder);

/**
* Gets normalized move modules by package.
*
* @param packageId the package id
* @return the normalized move modules by package
*/
CompletableFuture<Map<String, MoveNormalizedModule>> getNormalizedMoveModulesByPackage(
String packageId);

/**
* Gets committee info.
*
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/sui/SuiClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import io.sui.models.events.EventQuery;
import io.sui.models.events.PaginatedEvents;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.MoveNormalizedModule;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.TransactionResponse;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
Expand Down Expand Up @@ -114,6 +116,18 @@ public CompletableFuture<PaginatedEvents> getEvents(
return call("/sui_getEvents", request, new TypeToken<PaginatedEvents>() {}.getType());
}

@Override
public CompletableFuture<Map<String, MoveNormalizedModule>> getNormalizedMoveModulesByPackage(
String packageId) {
final JsonRpc20Request request =
createJsonRpc20Request(
"sui_getNormalizedMoveModulesByPackage", Lists.newArrayList(packageId));
return call(
"/sui_getNormalizedMoveModulesByPackage",
request,
new TypeToken<Map<String, MoveNormalizedModule>>() {}.getType());
}

@Override
public CompletableFuture<CommitteeInfoResponse> getCommitteeInfo(Long epoch) {
final JsonRpc20Request request =
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/sui/jsonrpc/GsonJsonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
import io.sui.models.events.EventQuery.AllQuery;
import io.sui.models.events.MoveModule;
import io.sui.models.objects.GetObjectResponse;
import io.sui.models.objects.MoveNormalizedType;
import io.sui.models.objects.MoveNormalizedType.MoveNormalizedStructType;
import io.sui.models.objects.MoveNormalizedType.MoveNormalizedTypeParameterType;
import io.sui.models.objects.MoveNormalizedType.MutableReferenceMoveNormalizedType;
import io.sui.models.objects.MoveNormalizedType.ReferenceMoveNormalizedType;
import io.sui.models.objects.MoveNormalizedType.TypeMoveNormalizedType;
import io.sui.models.objects.MoveNormalizedType.VectorReferenceMoveNormalizedType;
import io.sui.models.objects.SuiData;
import io.sui.models.objects.SuiObject;
import io.sui.models.objects.SuiObjectOwner;
Expand Down Expand Up @@ -375,6 +382,42 @@ public CommitteeInfo deserialize(
}
}

/** The type Move normalized type deserializer. */
public class MoveNormalizedTypeDeserializer implements JsonDeserializer<MoveNormalizedType> {

@Override
public MoveNormalizedType deserialize(
JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
if (json.isJsonPrimitive()) {
return TypeMoveNormalizedType.valueOf(json.getAsString());
}
if (json.isJsonObject()) {
if (json.getAsJsonObject().get("TypeParameter") != null
&& !json.getAsJsonObject().get("TypeParameter").isJsonNull()) {
return gson.fromJson(json, MoveNormalizedTypeParameterType.class);
}
if (json.getAsJsonObject().get("Reference") != null
&& !json.getAsJsonObject().get("Reference").isJsonNull()) {
return gson.fromJson(json, ReferenceMoveNormalizedType.class);
}
if (json.getAsJsonObject().get("MutableReference") != null
&& !json.getAsJsonObject().get("MutableReference").isJsonNull()) {
return gson.fromJson(json, MutableReferenceMoveNormalizedType.class);
}
if (json.getAsJsonObject().get("Vector") != null
&& !json.getAsJsonObject().get("Vector").isJsonNull()) {
return gson.fromJson(json, VectorReferenceMoveNormalizedType.class);
}
if (json.getAsJsonObject().get("Struct") != null
&& !json.getAsJsonObject().get("Struct").isJsonNull()) {
return gson.fromJson(json, MoveNormalizedStructType.class);
}
}
return null;
}
}

private final Gson gson;

/** Instantiates a new Gson json handler. */
Expand Down Expand Up @@ -402,6 +445,7 @@ ParsedPublishResponse.class, new ParsedPublishResponseDeserializer())
AuthorityQuorumSignInfo.class, new AuthorityQuorumSignInfoDeserializer())
.registerTypeAdapter(MoveModule.class, new MoveModuleSerializer())
.registerTypeAdapter(EventQuery.class, new EventQuerySerializer())
.registerTypeAdapter(MoveNormalizedType.class, new MoveNormalizedTypeDeserializer())
.registerTypeAdapter(CommitteeInfo.class, new CommitteeInfoDeserializer())
.create();
}
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/io/sui/models/objects/MoveAbilitySet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2022 281165273grape@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.sui.models.objects;


import java.util.List;
import java.util.Objects;

/**
* The type Move ability set.
*
* @author grapebaba
* @since 2022.11
*/
public class MoveAbilitySet {

private List<String> abilities;

/**
* Gets abilities.
*
* @return the abilities
*/
public List<String> getAbilities() {
return abilities;
}

/**
* Sets abilities.
*
* @param abilities the abilities
*/
public void setAbilities(List<String> abilities) {
this.abilities = abilities;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MoveAbilitySet)) {
return false;
}
MoveAbilitySet that = (MoveAbilitySet) o;
return abilities.equals(that.abilities);
}

@Override
public int hashCode() {
return Objects.hash(abilities);
}

@Override
public String toString() {
return "MoveAbilitySet{" + "abilities=" + abilities + '}';
}
}
91 changes: 91 additions & 0 deletions src/main/java/io/sui/models/objects/MoveModuleId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2022 281165273grape@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.sui.models.objects;


import java.util.Objects;

/**
* The type Move module id.
*
* @author grapebaba
* @since 2022.11
*/
public class MoveModuleId {

private String address;

private String name;

/**
* Gets address.
*
* @return the address
*/
public String getAddress() {
return address;
}

/**
* Sets address.
*
* @param address the address
*/
public void setAddress(String address) {
this.address = address;
}

/**
* Gets name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Sets name.
*
* @param name the name
*/
public void setName(String name) {
this.name = name;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MoveModuleId)) {
return false;
}
MoveModuleId that = (MoveModuleId) o;
return address.equals(that.address) && name.equals(that.name);
}

@Override
public int hashCode() {
return Objects.hash(address, name);
}

@Override
public String toString() {
return "MoveModuleId{" + "address='" + address + '\'' + ", name='" + name + '\'' + '}';
}
}
Loading

0 comments on commit 6b77827

Please sign in to comment.