Skip to content

Commit

Permalink
Merge pull request #36 from bianjieai/mh/v3
Browse files Browse the repository at this point in the history
V3 版本
  • Loading branch information
zhangyelong authored Sep 18, 2023
2 parents 0183701 + f9037b3 commit 3891d7c
Show file tree
Hide file tree
Showing 147 changed files with 4,913 additions and 1,753 deletions.
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 快速开始

### SDK 介绍

该 SDK 为 Avata v3 版本。 AVATA V3 是基于 v1 和 V2 两个版本,在产品架构、接口功能、核心服务、整体性能等方面都做了较大提升,同时兼容原生模块和智能合约模块;为 AVATA 平台用户提供多种功能与服务的组合使用,助力广大企业及开发者通过 AVATA 平台更加灵活便捷地对接底层链平台,打造开放多元的分布式商业应用。

### 引入依赖

```
Expand All @@ -15,17 +19,36 @@
### 创建和使用客户端

```
ai.bianjie.avatasdk.AvataClient client = new ai.bianjie.avatasdk.AvataClient.Builder()
.setDoMain("")
.setApiKey("")
.setApiSecret("")
.setHttpTimeout(10000)
.init();
public class AvataClientTest {
public static AvataClient getAvataClient() {
return new AvataClient.Builder()
.setDomain("域名,不同环境对应不同的域名,如测试环境: https://stage.apis.avata.bianjie.ai")
.setApiKey("项目参数 API KEY")
.setApiSecret("项目参数 API SECRET")
.setHttpTimeout(10000)
.init();
}
}
```
公共接口:

- [链账户接口示例代码](src/test/java/ai/bianjie/avatasdktest/AccountTest.java)
- [钱包用户接口示例代码](src/test/java/ai/bianjie/avatasdktest/UserTest.java)
- [充值接口示例代码](src/test/java/ai/bianjie/avatasdktest/OrderTest.java)

原生接口:

- [NFT 接口示例代码](src/test/java/ai/bianjie/avatasdktest/nat/NftTest.java)
- [MT 接口示例代码](src/test/java/ai/bianjie/avatasdktest/nat/MtTest.java)
- [存证接口示例代码](src/test/java/ai/bianjie/avatasdktest/nat/RecordsTest.java)
- [交易结果查询接口示例代码](src/test/java/ai/bianjie/avatasdktest/nat/TxTest.java)

智能合约接口:

- [NFT 接口示例代码](src/test/java/ai/bianjie/avatasdktest/evm/NftTest.java)
- [Web3 域名服务接口示例代码](src/test/java/ai/bianjie/avatasdktest/evm/NsTest.java)
- [智能合约服务接口示例代码](src/test/java/ai/bianjie/avatasdktest/evm/ContractTest.java)
- [交易结果查询接口示例代码](src/test/java/ai/bianjie/avatasdktest/evm/TxTest.java)

- [链账户接口示例代码](./src/test/java/AccountTest.java)
- [交易结果查询接口示例代码](./src/test/java/TxTest.java)
- [NFT 接口示例代码](./src/test/java/NftTest.java)
- [MT 接口示例代码](./src/test/java/MtTest.java)
- [充值接口示例代码](./src/test/java/OrderTest.java)
- [存证接口示例代码](./src/test/java/RecordTest.java)
[回调服务示例代码](src/test/java/ai/bianjie/avatasdktest/CallbackTest.java)
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@
<scope>test</scope>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand Down
40 changes: 22 additions & 18 deletions src/main/java/ai/bianjie/avatasdk/AvataClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@

import ai.bianjie.avatasdk.config.ConfigInfo;
import ai.bianjie.avatasdk.exception.AvataException;
import ai.bianjie.avatasdk.proxy.account.impl.AccountClient;
import ai.bianjie.avatasdk.proxy.mt.impl.MtClient;
import ai.bianjie.avatasdk.proxy.nft.impl.NftClient;
import ai.bianjie.avatasdk.proxy.order.impl.OrderClient;
import ai.bianjie.avatasdk.proxy.record.impl.RecordClient;
import ai.bianjie.avatasdk.proxy.tx.impl.TxClient;
import ai.bianjie.avatasdk.proxy.account.impl.Account;
import ai.bianjie.avatasdk.proxy.order.impl.Order;
import ai.bianjie.avatasdk.proxy.user.impl.User;
import ai.bianjie.avatasdk.util.HttpClient;
import com.dtflys.forest.Forest;
import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.http.ForestAsyncMode;
import com.dtflys.forest.retryer.BackOffRetryer;
import com.dtflys.forest.ssl.SSLUtils;
import com.dtflys.forest.utils.StringUtils;
import lombok.Data;

public class AvataClient {
public NftClient nftClient;
public AccountClient accountClient;
public MtClient mtClient;
public OrderClient orderClient;
public RecordClient recordsClient;
public TxClient txClient;

public Account account;
public Order order;
public User user;
public Native nat;
public Evm evm;

/**
* SDK initialization method
Expand All @@ -33,14 +32,15 @@ private AvataClient(Builder builder) {
configInfo.setApiSecret(builder.apiSecret);
configInfo.setHttpTimeout(builder.httpTimeout);

this.accountClient = new AccountClient(configInfo);
this.nftClient = new NftClient(configInfo);
this.mtClient = new MtClient(configInfo);
this.orderClient = new OrderClient(configInfo);
this.recordsClient = new RecordClient(configInfo);
this.txClient = new TxClient(configInfo);
HttpClient httpClient = new HttpClient(configInfo);
this.account = new Account(httpClient);
this.order = new Order(httpClient);
this.user = new User(httpClient);
this.nat = new Native(httpClient);
this.evm = new Evm(httpClient);
}

@Data
public static class Builder {
private String domain;
private String apiKey;
Expand Down Expand Up @@ -126,3 +126,7 @@ public AvataClient init() {
}
}
}




25 changes: 25 additions & 0 deletions src/main/java/ai/bianjie/avatasdk/Evm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ai.bianjie.avatasdk;

import ai.bianjie.avatasdk.proxy.evm.contract.impl.Contract;
import ai.bianjie.avatasdk.proxy.evm.nft.impl.Nft;
import ai.bianjie.avatasdk.proxy.evm.ns.impl.Ns;
import ai.bianjie.avatasdk.proxy.evm.tx.impl.Tx;
import ai.bianjie.avatasdk.util.HttpClient;

public class Evm {

public Nft nft;
public Tx tx;
public Contract contract;
public Ns ns;

/**
* SDK initialization method
*/
public Evm(HttpClient httpClient) {
this.nft = new Nft(httpClient);
this.tx = new Tx(httpClient);
this.contract = new Contract(httpClient);
this.ns = new Ns(httpClient);
}
}
25 changes: 25 additions & 0 deletions src/main/java/ai/bianjie/avatasdk/Native.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ai.bianjie.avatasdk;

import ai.bianjie.avatasdk.proxy.nat.mt.impl.Mt;
import ai.bianjie.avatasdk.proxy.nat.nft.impl.Nft;
import ai.bianjie.avatasdk.proxy.nat.records.impl.Records;
import ai.bianjie.avatasdk.proxy.nat.tx.impl.Tx;
import ai.bianjie.avatasdk.util.HttpClient;

public class Native {

public Nft nft;
public Mt mt;
public Records records;
public Tx tx;

/**
* SDK initialization method
*/
public Native(HttpClient httpClient) {
this.nft = new Nft(httpClient);
this.mt = new Mt(httpClient);
this.records = new Records(httpClient);
this.tx = new Tx(httpClient);
}
}
11 changes: 4 additions & 7 deletions src/main/java/ai/bianjie/avatasdk/config/ConfigInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

/**
* 配置项
*
* @author sxj
*/
@Data
public class ConfigInfo {

private String doMain;
private String doMain; // 域名

private String apiKey;
private String apiKey; // 项目参数 API KEY

private String apiSecret;

private Integer httpTimeout;
private String apiSecret; // 项目参数 API SECRET
private Integer httpTimeout; // 响应超时时间

public ConfigInfo() {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

/**
* SDK custom ai.bianjie.avatasdk.exception
*
* @author sxj
*/
@Data
public class AvataException extends RuntimeException {
Expand All @@ -23,9 +21,9 @@ public class AvataException extends RuntimeException {
public static final String ErrAPISecret = "the api secret the project is required";
public static final String ErrAmount = "amount should be integer yuan";

private final String codeSpace;
private final String code;
private final String message;
private final String codeSpace; // 命名空间
private final String code; // 错误码
private final String message; // 错误描述

public AvataException(String code, String codeSpace, String message) {
super(message);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ai/bianjie/avatasdk/model/ErrorResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ErrorResponse {
@NoArgsConstructor
@Data
public static class AvataError {
@JSONField(name = "code")
private String code;
@JSONField(name = "code_space")
private String codeSpace;
private String codeSpace; // 命名空间
@JSONField(name = "code")
private String code;// 错误码
@JSONField(name = "message")
private String message;
private String message;// 错误描述
}
}
5 changes: 1 addition & 4 deletions src/main/java/ai/bianjie/avatasdk/model/PublicResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ public class PublicResponse {

@NoArgsConstructor
@Data
public static class DataDTO {
@JSONField(name = "operation_id")
private String operationId;
}
public static class DataDTO { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

/**
* 批量创建链账户请求体
*
* @author sxj
*/
@NoArgsConstructor
@Data
public class BatchCreateAccountReq {

@JSONField(name = "count")
private Integer count;//批量创建链账户的数量
private Integer count;// 批量创建链账户的数量

@JSONField(name = "operation_id")
private String operationId;// 操作 ID,保证幂等性,避免重复请求,保证对于同一操作发起的一次请求或者多次请求的结果是一致的;由接入方生成的、针对每个 Project ID 唯一的、不超过 64 个大小写字母、数字、-、下划线的字符串组成。此操作 ID 仅限在查询链账户接口中使用,用于查询创建链账户的授权状态。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.List;

/**
* 批量创建链账户正确返回值
*/
@NoArgsConstructor
@Data
public class BatchCreateAccountRes {
Expand All @@ -16,9 +19,20 @@ public class BatchCreateAccountRes {
@NoArgsConstructor
@Data
public static class DataDTO {
@JSONField(name = "accounts")
private List<String> accounts;// 链账户地址列表
@JSONField(name = "operation_id")
private String operationId;// 操作 ID。此操作 ID 仅限在查询链账户接口中使用,用于查询创建链账户的授权状态。

@JSONField(name = "addresses")
private List<AccountsDTO> addresses;// 链账户地址列表

@NoArgsConstructor
@Data
public static class AccountsDTO {

@JSONField(name = "native_address")
private String nativeAddress;// 原生地址格式

@JSONField(name = "hex_address")
private String hexAddress;// 以太坊地址格式

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 创建链账户请求体
*/
@NoArgsConstructor
@Data
public class CreateAccountReq {

@JSONField(name = "name")
private String name;// 链账户名称,支持 1-20 位汉字、大小写字母及数字组成的字符串

@JSONField(name = "user_id")
private String userId;// 此字段针对区块链钱包应用项目设置,通过区块链钱包给某一具体终端用户创建链账户地址时,必需传入该字段。该字段值是由「创建用户」接口返回。

@JSONField(name = "operation_id")
private String operationId;// 操作 ID,保证幂等性,避免重复请求,保证对于同一操作发起的一次请求或者多次请求的结果是一致的;由接入方生成的、针对每个 Project ID 唯一的、不超过 64 个大小写字母、数字、-、下划线的字符串组成。此操作 ID 仅限在查询链账户接口中使用,用于查询创建链账户的授权状态。
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 创建链账户正确返回值
*/
@NoArgsConstructor
@Data
public class CreateAccountRes {
Expand All @@ -14,11 +17,13 @@ public class CreateAccountRes {
@NoArgsConstructor
@Data
public static class DataDTO {
@JSONField(name = "account")
private String account;// 链账户地址
@JSONField(name = "name")
private String name;// 链账户名称
@JSONField(name = "operation_id")
private String operationId;// 操作 ID。此操作 ID 仅限在查询链账户接口中使用,用于查询创建链账户的授权状态。

@JSONField(name = "native_address")
private String nativeAddress;// 原生地址格式

@JSONField(name = "hex_address")
private String hexAddress;// 以太坊地址格式

}
}

Loading

0 comments on commit 3891d7c

Please sign in to comment.