Skip to content

Commit

Permalink
feat: wrap sui helper.
Browse files Browse the repository at this point in the history
Signed-off-by: grapebaba <[email protected]>
  • Loading branch information
GrapeBaBa committed Dec 9, 2022
1 parent 744b535 commit 8cac38a
Show file tree
Hide file tree
Showing 9 changed files with 1,040 additions and 166 deletions.
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contribute to sui4j

## Create a fork

First, create a fork of the sui4j repo in your own account so that you can work with your own copy.

**To create a fork using the website**

1. Log in to your Github account.
1. Browse to the [sui4j repo](https://github.com/GrapeBaBa/sui4j) on GitHub.
1. Choose **Fork** in the top-right, then choose **Create new fork**.
1. For **Owner**, select your username.
1. For **Repository name**, we suggest keeping the name sui4j, but you can use any name.
1. Optional. To contribute you need only the main branch of the repo. To include all branches, unselect the checkbox for **Copy the `main` branch only**.
1. Click **Create fork**.

### Clone your fork

Next, clone your fork of the repo to your local workspace.

**To clone your fork to your local workspace**
1. Open the GitHub page for your fork of the repo, then click **Sync fork**.
1. Click **Code**, then click **HTTPS** and copy the web URL displayed.
1. Open a terminal session and navigate to the folder to use, then run the following command, replacing the URL with the URL you copied from the Git page:

`git clone https://github.com/github-user-name/sui4j.git`

The repo is automatically cloned into the `sui4j` folder in your workspace.
Create a branch of your fork with following command (or follow the [GitHub topic on branching](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository))

`git checkout -b your-branch-name`

Use the following command to set the [remote upstream repo](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-for-a-fork):

`git remote add upstream https://github.com/GrapeBaBa/sui4j.git`

You now have a fork of the sui4j repo set up in your local workspace. You can make changes to the files in the workspace, add commits, then push your changes to your fork of the repo to then create a Pull Request.

`./gradlew build`

Run build before you submit a Pull Request.
169 changes: 57 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ expect frequent breaking changes in the short-term. We expect the API to stabili
upcoming TestNet launch.

## Using

### Maven

```xml
<!-- https://mvnrepository.com/artifact/me.grapebaba/sui4j -->
<dependency>
<groupId>me.grapebaba</groupId>
<artifactId>sui4j</artifactId>
<version>0.2.0</version>
<groupId>me.grapebaba</groupId>
<artifactId>sui4j</artifactId>
<version>0.3.1</version>
</dependency>
```

### Gradle

```groovy
// https://mvnrepository.com/artifact/me.grapebaba/sui4j
implementation 'me.grapebaba:sui4j:0.2.0'
implementation 'me.grapebaba:sui4j:0.3.1'
```

## Building Locally
Expand Down Expand Up @@ -75,11 +78,8 @@ cd sui/target/release
./gradlew integrationTest
```

### To run E2E tests against DevNet

TODO

## Supported APIs

- [x] sui_batchTransaction
- [x] sui_dryRunTransaction
- [x] sui_executeTransaction
Expand Down Expand Up @@ -112,113 +112,58 @@ TODO
- [x] sui_transferObject
- [x] sui_transferSui
- [x] sui_tryGetPastObject
- [ ] sui_getTransactionAuthSigners
- [ ] sui_getSuiSystemState

## Examples

### 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 QueryClient client=new QueryClientImpl(jsonRpcClientProvider);
```

### sui_getCommitteeInfo

```java
CompletableFuture<CommitteeInfoResponse> res=client.getCommitteeInfo(1L);
```

### sui_getEvents

```java
TransactionEventQuery query=new TransactionEventQuery();
query.setTransaction("ov1tDrhdOqRW2uFweTbSSTaQbBbnjHWmrsh675lwb0Q=");
CompletableFuture<PaginatedEvents> res=client.getEvents(query,null,1,false);
```

### sui_getMoveFunctionArgTypes

```java
CompletableFuture<List<MoveFunctionArgType>>res=
client.getMoveFunctionArgTypes("0x0000000000000000000000000000000000000002","bag","add");
```

### sui_getNormalizedMoveFunction

```java
CompletableFuture<MoveNormalizedFunction> res=
client.getNormalizedMoveFunction(
"0x0000000000000000000000000000000000000002","bag","add");
```

### sui_getNormalizedMoveModule

```java
CompletableFuture<MoveNormalizedModule> res=
client.getNormalizedMoveModule("0x0000000000000000000000000000000000000002","bag");
```

### sui_getNormalizedMoveModulesByPackage
> Note: Event subscribe API and KeyPair generation will be supported soon.
```java
CompletableFuture<Map<String, MoveNormalizedModule>>res=
client.getNormalizedMoveModulesByPackage("0x0000000000000000000000000000000000000002");
```

### sui_getNormalizedMoveStruct

```java
CompletableFuture<MoveNormalizedStruct> res=
client.getNormalizedMoveStruct("0x0000000000000000000000000000000000000002","bag","Bag");
```

### sui_getObject

```java
CompletableFuture<GetObjectResponse> res=
client.getObject("0x342950ba2451c2f27ed128e591c2b4551e5177c2");
```

### sui_getObjectsOwnedByAddress
## Examples

```java
CompletableFuture<List<SuiObjectInfo>>res=
client.getObjectsOwnedByAddress("0xea79464d86786b7a7a63e3f13f798f29f5e65947");
```

### sui_getObjectsOwnedByObject
String BASE_URL="http://localhost:9000";
// It must be a absolute path
String TEST_KEY_STORE_PATH=
System.getProperty("user.home")+"/.sui/sui_config/sui.keystore";
Sui sui=new Sui(BASE_URL,TEST_KEY_STORE_PATH);

```java
// query objects
CompletableFuture<List<SuiObjectInfo>>res=
client.getObjectsOwnedByObject("0xde2952390ab3d0cfbb0a0602532480ed5ec99cf3");
```

### sui_getRawObject

```java
CompletableFuture<GetObjectResponse> res=
client.getRawObject("0x342950ba2451c2f27ed128e591c2b4551e5177c2");
```

### sui_getTotalTransactionNumber

```java
CompletableFuture<Long> res=client.getTotalTransactionNumber();
```

### sui_getTransaction

```java
CompletableFuture<TransactionResponse> res=
client.getTransaction("3Dda4/74LXf6GmOxMxp3qdbW/WdQ6/8EHobZ1LvSyYk=");
```

### sui_getTransactionsInRange

```java
CompletableFuture<List<String>>res=client.getTransactionsInRange(0L,100L);
```
sui.getObjectsOwnedByAddress("0xea79464d86786b7a7a63e3f13f798f29f5e65947");
List<SuiObjectInfo> objects=res.get();
String coinObjectId=objects.get(0).getObjectId();
List<String> addresses=new ArrayList<>(sui.addresses());

// Transfer sui
CompletableFuture<ExecuteTransactionResponse> res1=
sui.transferSui(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
coinObjectId,
100L,
addresses.get(0),
2000L,
ExecuteTransactionRequestType.WaitForLocalExecution);

CompletableFuture<ExecuteTransactionResponse> res2=
sui.moveCall(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
"0x0000000000000000000000000000000000000002",
"devnet_nft",
"mint",
Lists.newArrayList(),
Lists.newArrayList(
"Example NFT",
"An example NFT.",
"ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"),
null,
2000L,
ExecuteTransactionRequestType.WaitForLocalExecution);
```

For more examples, you can see [SuiIntTests](src/integrationTest/java/io/sui/SuiIntTests.java)

## Further

Will add [BCS](https://github.com/diem/bcs) to implement local transaction serialization soon.

## Contribution
To help sui4j grow, follow [Contributing to sui4j](CONTRIBUTING.md).
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {


group 'me.grapebaba'
version '0.3.0'
version '0.3.1'

repositories {
mavenCentral()
Expand Down Expand Up @@ -65,7 +65,8 @@ jacocoTestReport {
fileTree(dir: it, exclude: [
"io/sui/models/**",
"io/sui/jsonrpc/JsonRpc20Request.class",
"io/sui/jsonrpc/JsonRpc20Response*.class"
"io/sui/jsonrpc/JsonRpc20Response*.class",
"io/sui/Sui.class"
])
}))
}
Expand All @@ -81,7 +82,8 @@ jacocoTestCoverageVerification {
fileTree(dir: it, exclude: [
"io/sui/models/**",
"io/sui/jsonrpc/JsonRpc20Request.class",
"io/sui/jsonrpc/JsonRpc20Response*.class"
"io/sui/jsonrpc/JsonRpc20Response*.class",
"io/sui/Sui.class"
])
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ void transferObject() throws ExecutionException, InterruptedException {
transactionBuilder.transferObject(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
"0x26cab55541e4b0f362211f9394200b7e41fd45eb",
"0x51de405091c9f971fc6085d384f9ba764f268fca",
"0x26cab55541e4b0f362211f9394200b7e41fd45eb",
1L,
"0x51de405091c9f971fc6085d384f9ba764f268fca");
1L);
CompletableFuture<Object> future = new CompletableFuture<>();
res.whenComplete(
(transactionResponse, throwable) -> {
Expand Down Expand Up @@ -362,6 +362,30 @@ void moveCall() throws ExecutionException, InterruptedException {
}
});
System.out.println(future.get());

CompletableFuture<TransactionBytes> res2 =
transactionBuilder.moveCall(
"0xea79464d86786b7a7a63e3f13f798f29f5e65947",
"0x0000000000000000000000000000000000000002",
"devnet_nft",
"mint",
Lists.newArrayList(),
Lists.newArrayList(
"Example NFT",
"An example NFT.",
"ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"),
null,
5000L);
CompletableFuture<Object> future1 = new CompletableFuture<>();
res2.whenComplete(
(transactionResponse, throwable) -> {
if (throwable != null) {
future1.complete(throwable);
} else {
future1.complete(transactionResponse);
}
});
System.out.println(future1.get());
}

/**
Expand Down
Loading

0 comments on commit 8cac38a

Please sign in to comment.