Skip to content
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

feat: add get transactions api. #57

Merged
merged 2 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/badges/branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,32 @@ TODO
- [x] sui_getRawObject
- [x] sui_getTotalTransactionNumber
- [x] sui_getTransaction
- [ ] sui_getTransactions
- [x] sui_getTransactions
- [x] sui_getTransactionsInRange
- [x] sui_mergeCoins
- [x] sui_moveCall
- [ ] sui_moveCall
- [x] sui_pay
- [x] sui_payAllSui
- [x] sui_paySui
- [x] sui_publish
- [ ] sui_publish
- [x] sui_splitCoin
- [x] sui_splitCoinEqual
- [ ] sui_subscribeEvent
- [x] sui_transferObject
- [x] sui_transferSui
- [ ] sui_tryGetPastObject
- [x] sui_tryGetPastObject

## Examples

### create client
### create query client

```java
final String BASE_URL="http://localhost:9000";
final JsonHandler jsonHandler=new GsonJsonHandler();

final JsonRpcClientProvider jsonRpcClientProvider=
new OkHttpJsonRpcClientProvider(BASE_URL,jsonHandler);
final SuiClient client=new SuiClientImpl(jsonRpcClientProvider);
final QueryClient client=new QueryClientImpl(jsonRpcClientProvider);
```

### sui_getCommitteeInfo
Expand Down
25 changes: 25 additions & 0 deletions src/integrationTest/java/io/sui/QueryClientImplIntTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import io.sui.models.objects.MoveNormalizedStruct;
import io.sui.models.objects.ObjectResponse;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.PaginatedTransactionDigests;
import io.sui.models.transactions.TransactionQuery;
import io.sui.models.transactions.TransactionQuery.AllQuery;
import io.sui.models.transactions.TransactionQuery.FromAddressQuery;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -440,4 +444,25 @@ void tryGetPastObject() throws ExecutionException, InterruptedException {
client.tryGetPastObject("0x163e344adfb74793481c77661f463811b990fe2a", 1);
System.out.println(res1.get());
}

/**
* Gets transactions.
*
* @throws ExecutionException the execution exception
* @throws InterruptedException the interrupted exception
*/
@Test
@DisplayName("Test getTransactions.")
void getTransactions() throws ExecutionException, InterruptedException {
TransactionQuery query = AllQuery.All;
CompletableFuture<PaginatedTransactionDigests> res =
client.getTransactions(query, null, 10, false);
System.out.println(res.get());

FromAddressQuery query1 = new FromAddressQuery();
query1.setFromAddress("0xea79464d86786b7a7a63e3f13f798f29f5e65947");
CompletableFuture<PaginatedTransactionDigests> res1 =
client.getTransactions(query1, null, 10, false);
System.out.println(res1.get());
}
}
14 changes: 14 additions & 0 deletions src/main/java/io/sui/clients/QueryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import io.sui.models.objects.MoveNormalizedStruct;
import io.sui.models.objects.ObjectResponse;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.PaginatedTransactionDigests;
import io.sui.models.transactions.TransactionQuery;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -175,4 +177,16 @@ CompletableFuture<MoveNormalizedStruct> getNormalizedMoveStruct(
* @return the completable future
*/
CompletableFuture<ObjectResponse> tryGetPastObject(String objectId, long version);

/**
* Gets transactions.
*
* @param query the query
* @param cursor the cursor
* @param limit the limit
* @param isDescOrder the is desc order
* @return the transactions
*/
CompletableFuture<PaginatedTransactionDigests> getTransactions(
TransactionQuery query, String cursor, int limit, boolean isDescOrder);
}
12 changes: 12 additions & 0 deletions src/main/java/io/sui/clients/QueryClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import io.sui.models.objects.MoveNormalizedStruct;
import io.sui.models.objects.ObjectResponse;
import io.sui.models.objects.SuiObjectInfo;
import io.sui.models.transactions.PaginatedTransactionDigests;
import io.sui.models.transactions.TransactionQuery;
import io.sui.models.transactions.TransactionResponse;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -206,4 +208,14 @@ public CompletableFuture<ObjectResponse> tryGetPastObject(String objectId, long
return this.jsonRpcClientProvider.callAndUnwrapResponse(
"/sui_tryGetPastObject", request, new TypeToken<ObjectResponse>() {}.getType());
}

@Override
public CompletableFuture<PaginatedTransactionDigests> getTransactions(
TransactionQuery query, String cursor, int limit, boolean isDescOrder) {
final JsonRpc20Request request =
this.jsonRpcClientProvider.createJsonRpc20Request(
"sui_getTransactions", Lists.newArrayList(query, cursor, limit, isDescOrder));
return this.jsonRpcClientProvider.callAndUnwrapResponse(
"/sui_getTransactions", request, new TypeToken<PaginatedTransactionDigests>() {}.getType());
}
}
16 changes: 16 additions & 0 deletions src/main/java/io/sui/jsonrpc/GsonJsonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import io.sui.models.transactions.ParsedTransactionResponseKind.ParsedPublishResponseKind;
import io.sui.models.transactions.ParsedTransactionResponseKind.ParsedSplitCoinResponseKind;
import io.sui.models.transactions.TransactionKind;
import io.sui.models.transactions.TransactionQuery;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -479,6 +480,20 @@ public InputObjectKind deserialize(
}
}

/** The type Transaction query serializer. */
public class TransactionQuerySerializer implements JsonSerializer<TransactionQuery> {

@Override
public JsonElement serialize(
TransactionQuery src, Type typeOfSrc, JsonSerializationContext context) {
if (src instanceof TransactionQuery.AllQuery) {
return new JsonPrimitive(AllQuery.All.name());
}

return gson.toJsonTree(src, typeOfSrc);
}
}

private final Gson gson;

/** Instantiates a new Gson json handler. */
Expand Down Expand Up @@ -509,6 +524,7 @@ AuthorityQuorumSignInfo.class, new AuthorityQuorumSignInfoDeserializer())
.registerTypeAdapter(CommitteeInfo.class, new CommitteeInfoDeserializer())
.registerTypeAdapter(MoveFunctionArgType.class, new MoveFunctionArgTypeDeserializer())
.registerTypeAdapter(InputObjectKind.class, new InputObjectKindDeserializer())
.registerTypeAdapter(TransactionQuery.class, new TransactionQuerySerializer())
.create();
}

Expand Down
123 changes: 123 additions & 0 deletions src/main/java/io/sui/models/transactions/MoveFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.transactions;


import java.util.Objects;

/**
* The type Move function.
*
* @author grapebaba
* @since 2022.11
*/
public class MoveFunction {

private String suiPackage;

private String module;

private String function;

/**
* Gets sui package.
*
* @return the sui package
*/
public String getSuiPackage() {
return suiPackage;
}

/**
* Sets sui package.
*
* @param suiPackage the sui package
*/
public void setSuiPackage(String suiPackage) {
this.suiPackage = suiPackage;
}

/**
* Gets module.
*
* @return the module
*/
public String getModule() {
return module;
}

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

/**
* Gets function.
*
* @return the function
*/
public String getFunction() {
return function;
}

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

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MoveFunction)) {
return false;
}
MoveFunction that = (MoveFunction) o;
return suiPackage.equals(that.suiPackage)
&& module.equals(that.module)
&& function.equals(that.function);
}

@Override
public int hashCode() {
return Objects.hash(suiPackage, module, function);
}

@Override
public String toString() {
return "MoveFunction{"
+ "suiPackage='"
+ suiPackage
+ '\''
+ ", module='"
+ module
+ '\''
+ ", function='"
+ function
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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.transactions;


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

/**
* The type Paginated transaction digests.
*
* @author grapebaba
* @since 2022.11
*/
public class PaginatedTransactionDigests {

private List<String> data;

private String nextCursor;

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

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

/**
* Gets next cursor.
*
* @return the next cursor
*/
public String getNextCursor() {
return nextCursor;
}

/**
* Sets next cursor.
*
* @param nextCursor the next cursor
*/
public void setNextCursor(String nextCursor) {
this.nextCursor = nextCursor;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof PaginatedTransactionDigests)) {
return false;
}
PaginatedTransactionDigests that = (PaginatedTransactionDigests) o;
return data.equals(that.data) && nextCursor.equals(that.nextCursor);
}

@Override
public String toString() {
return "PaginatedTransactionDigests{"
+ "data="
+ data
+ ", nextCursor='"
+ nextCursor
+ '\''
+ '}';
}

@Override
public int hashCode() {
return Objects.hash(data, nextCursor);
}
}
Loading