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
-
subcribe
-
serverFeatures
-
broadcastTransaction
User and Account
- sendVerifyCode
- login
- logout
- sendRegisterVerifyCode
- register
- addContacts
- listContacts
- sendPayVerifyCode
- setPayPassword
- havePayPassword
- sendResetPasswordVerifyCode
- resetPassword
- saveOrUpdateUserInfo
- getUserInfoPO
Wallets
cloud wallets
- createWallet
- listWallet
- getBalanceOfWallet
- getAssetsOfWallet
- getAssetsOfAddress
- getPublicKeyHashFromAddress
- getBalanceOfAddress
- sendTo
- pay
- searchTxByType
- searchTxByTime
- letMeTry
open wallets
- getAddressByUid
- getAssetsOfAddress
- getBalanceOfAddress
- searchTransaction
Blocks
- getBlockHashList
- getBlock
- getBlockHeaderList
- getBockData
- getBlockTailsHashList
- getBlockTailsPO
- getTransactionByTxId
- searchTxByTxId
- searchTxByAddress
- searchUTXOs