Java SDK for CircleChain

Install

for maven user, please paste the following pom.xml configure:

    <dependency>
      <groupId>org.circle-node</groupId>
      <artifactId>circle-node-client</artifactId>
      <version>1.1.5</version>
    </dependency>

for gradle user, please paste the following configure:

dependencies {
    implementation 'org.circle-node:circle-node-client:1.1.5'
}

Usage

User register and login

UserApi userApi = UserApiClient.getInstance();
// 1. first register if you not signup or just login with verify code
/// option1: register and login
SendVerifyCodeRequest registerRequest = new SendVerifyCodeRequest(null, "circle-node@gmail.com");
BaseResonse<Boolean> sendRegisterResult = userApi.sendRegisterVerifyCode(registerRequest);
if (sendRegisterResult.isNotOk()) {
  throw new BlockchainException(sendRegisterResult.getStatus(), sendRegisterResult.getMessage());
}
// receive you verify code in email or your mobile phone.
UserRegisterPO userRegisterPO = UserRegisterPO.builder()
    .email("circle-node@gmail.com")
    .passwordInput1(passwordInput1)
    .passwordInput2(passwordInput2)
    .verifyCode(verifyCode)
    .build();
BaseResonse<Boolean> registerResult = userApi.register(userRegisterPO);
if (registerResult.isNotOk()) {
  throw new BlockchainException(sendRegisterResult.getStatus(), sendRegisterResult.getMessage());
}

// and then login
String password = "login password";
UserLoginPO userLoginPO = UserLoginPO.builder()
    .email("circle-node@gmail.com")
    .password(password)
    .build();
BaseResonse<UserLoginResult> loginResult = userApi.login(userLoginPO);
if (loginResult.isNotOk()) {
  throw new BlockchainException(loginResult.getStatus(), loginResult.getMessage());
}
UserLoginResult loginData = loginRequest.getData();
String sessionKey = loginData.getSessionKey(); // keep session key secret, not leak it.
ContextUtil.setSessionKey(sessionKey); // store the sessionKey in ContextUtil.
/// option2: login with verify code
// send the login verify code
SendVerifyCodeRequest loginRequest = new SendVerifyCodeRequest(null, "circle-node@gmail.com");
BaseResonse<Boolean> sendLoginResult = userApi.sendVerifyCode(loginRequest);
if (sendLoginResult.isNotOk()) {
  throw new BlockchainException(sendLoginResult.getStatus(), sendLoginResult.getMessage());
}
// receive you verify code in email or your mobile phone.
String verifyCode = "<verifyCode>";
UserLoginPO userLoginWithVerifyPO = UserLoginPO.builder()
    .email("circle-node@gmail.com")
    .verifyCode(verifyCode)
    .build();
BaseResonse<UserLoginResult> loginWithVerifyResult = userApi.login(userLoginWithVerifyPO);
if (loginWithVerifyResult.isNotOk()) {
  throw new BlockchainException(loginWithVerifyResult.getStatus(), loginWithVerifyResult.getMessage());
}
UserLoginResult loginWithVerifyData = loginWithVerifyResult.getData();
String sessionKey1 = loginWithVerifyData.getSessionKey(); // keep session key secret, not leak it.
ContextUtil.setSessionKey(sessionKey1); // store the sessionKey in ContextUtil.
/// for your login, option1 and option2 are ok, you just select one.

// 3. set pay password.
SendVerifyCodeRequest payVerifyCodeRequest = new SendVerifyCodeRequest(null, "circle-node@gmail.com");
BaseResponse<Boolean> payVerifyCodeResult = userApi.sendPayVerifyCode(payVerifyCodeRequest);
if (payVerifyCodeResult.isNotOk()) {
    throw new BlockchainException(payVerifyCodeResult.getStatus(), payVerifyCodeResult.getMessage());
}
// receive you payVerifyCode from your email.
String payPassword = "new pay password";
UserPayPasswordRequest userPayPasswordRequest = UserPayPasswordRequest.builder()
    .account(AccountPO.builder()
             .email("circle-node@gmail.com")
             .build())
    .verifyCode(payVerifyCode)
    .password(payPassword)
    .build();
BaseResponse<Boolean> setPayResult = userApi.setPayPassword(userPayPasswordRequest);
if (setPayResult.isNotOk()) {
    throw new BlockchainException(setPayResult.getStatus(), setPayResult.getMessage());
}
// now the pay password is set success.

Wallet functions


// 3. create your wallets, you can create 3 wallets at most.
WalletApiClient walletApiClient = WalletApiClient.getInstance();
BaseResponse<String> result = walletApiClient.createWallet();
if (result.isNotOk()) {
  throw new BlockchainException(result.getStatus(), result.getMessage());
}

// 4. see your wallets info
BaseResponse<List<String>> listResult = walletApiClient.listWallet("");
if (listResult.isNotOk()) {
  throw new BlockchainException(listResult.getStatus(), listResult.getMessage());
}
List<String> addressList = listResult.getData();
// ....
BaseResponse<AssetsInfo> assetsResult = walletApiClient.getAssetsOfWallet();
if (assetsResult.isNotOk()) {
  throw new BlockchainException(assetsResult.getStatus(), assetsResult.getMessage());
}
AssetsInfo assetsInfo = assetsResult.getData();
// ...

// 5. send assets to others
String uuid = "uuid string";
SendToRequest sendToRequest = SendToRequest.builder()
    .from("from address")
    .address("receive address")
    .transContent(TransactionContentPO.builder()
                 .type(TransactionTypeEnum.OWNERSHIP.getType())
                 .valueHex(Hex.encodeHexString(ByteUtils.toValueBytes(uuid)))
                 .build())
    .payPassword(payPassword)
    .build();
BaseResponse<Boolean> sendResult = walletApiClient.sendTo(sendToRequest);
if (sendResult.isNotOk()) {
  throw new BlockchainException(sendResult.getStatus(), sendResult.getMessage());
}
// now the uuid is sent success.

// 6. pay balance to others
PayRequest payRequest = PayRequest.builder()
    .from("from address")
    .to("receive address")
    .value(Hex.encodeHexString(ByteUtils.toValueBytes(100L)))
    .payPassword(payPassword)
    .build();
BaseResponse<Boolean> payResult = walletApiClient.pay(payRequest);
if (payResult.isNotOk()) {
  throw new BlockchainException(payResult.getStatus(), payResult.getMessage());
}
// now the balance is paid success.

// 7. let me try to mine the block
BaseResponse<TransactionInfo> letMeTryResult = walletApiClient.letMeTry();
if (letMeTryResult.isNotOk()) {
  throw new BlockchainException(letMeTryResult.getStatus(), letMeTryResult.getMessage());
}
// not let me try success, and you got the balance or assets!

// 8. even more, please refer the java sdk doc... :).

APIs

Node

  1. subcribe

  2. serverFeatures

  3. broadcastTransaction

User and Account

  1. sendVerifyCode
  2. login
  3. logout
  4. sendRegisterVerifyCode
  5. register
  6. addContacts
  7. listContacts
  8. sendPayVerifyCode
  9. setPayPassword
  10. havePayPassword
  11. sendResetPasswordVerifyCode
  12. resetPassword
  13. saveOrUpdateUserInfo
  14. getUserInfoPO

Wallets

cloud wallets

  1. createWallet
  2. listWallet
  3. getBalanceOfWallet
  4. getAssetsOfWallet
  5. getAssetsOfAddress
  6. getPublicKeyHashFromAddress
  7. getBalanceOfAddress
  8. sendTo
  9. pay
  10. searchTxByType
  11. searchTxByTime
  12. letMeTry

open wallets

  1. getAddressByUid
  2. getAssetsOfAddress
  3. getBalanceOfAddress
  4. searchTransaction

Blocks

  1. getBlockHashList
  2. getBlock
  3. getBlockHeaderList
  4. getBockData
  5. getBlockTailsHashList
  6. getBlockTailsPO
  7. getTransactionByTxId
  8. searchTxByTxId
  9. searchTxByAddress
  10. searchUTXOs