-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from cryptape/docs
doc: add detail document for SDK
- Loading branch information
Showing
8 changed files
with
899 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
## Account | ||
|
||
Account 封装了 TransactionManager,通过 CITAj 和账户的私钥进行实例化。 | ||
|
||
Account 使用了 CompiledContract 类,可以直接读取 Solidity 合约文件,生成 ABI 和 BIN 文件以供 TransactionManager 使用。 | ||
|
||
* [New account](#new-account) | ||
* [Deploy contract](#deploy-contract) | ||
* [Call Contract](#call-contract) | ||
|
||
### New account | ||
|
||
**方法名** | ||
|
||
`Account(String privateKey, CITAj service)` | ||
|
||
实例化Account对象。 | ||
|
||
**参数** | ||
|
||
* privateKey - 发送交易地址的私钥 | ||
* service - CITAj 实例 | ||
|
||
**返回值** | ||
|
||
Account | ||
|
||
**示例** | ||
|
||
``` | ||
String privateKey = "{private key}"; | ||
CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); | ||
Account account = new Account(privateKey, service); | ||
``` | ||
### Deploy contract | ||
|
||
**方法名** | ||
|
||
`AppSendTransaction deploy(File contractFile, BigInteger nonce, long quota, int version, int chainId, String value)` | ||
|
||
部署合约。 | ||
|
||
**参数** | ||
|
||
* contractFile - solidity智能合约文件 | ||
* nonce - 随机数用于防止重放攻击 | ||
* quota - 用户支付矿工的费用 | ||
* version - 链的版本信息 | ||
* chainId - 链Id | ||
* value - 交易中原生token的数量 | ||
|
||
**返回值** | ||
|
||
AppSendTransaction | ||
|
||
**示例** | ||
``` | ||
String privateKey = "{private key}"; | ||
CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); | ||
Account account = new Account(privateKey, service); | ||
AppSendTransaction appSendTransaction = account.deploy(new File(path), randomNonce(), quota, version, chainId, value); | ||
``` | ||
|
||
### Call contract | ||
|
||
**方法名** | ||
|
||
`Object callContract(String contractAddress, String funcName, BigInteger nonce, long quota, int version, int chainId, String value, Object... args)` | ||
|
||
调用合约方法,根据Abi中对方法的定义判断使用sendRawTransaction还是app_call。 | ||
|
||
**参数** | ||
|
||
* contractAddress - 合约地址 | ||
* funcName - 合约方法名称 | ||
* nonce - 随机数用于防止重放攻击 | ||
* quota - 用户支付矿工的费用 | ||
* version - 链的版本信息 | ||
* chainId - 链Id | ||
* value - 交易中原生token的数量 | ||
* args - 合约方法参数 | ||
|
||
**返回值** | ||
|
||
Object | ||
|
||
**示例** | ||
|
||
``` | ||
String privateKey = "{private key}"; | ||
CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); | ||
Account account = new Account(privateKey, service); | ||
AppSendTransaction appSendTransaction = (AppSendTransaction) account.callContract(contractAddress, transfer, randomNonce(), quota, version, chainId, value, toAddress, amount); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# cita-sdk-java API 文档 | ||
|
||
## 概述: | ||
|
||
cita-sdk-java 是对于 CITA 进行交互的 Java SDK 包,cita-sdk-java 使用 JSON-RPC 协议对 CITA 网络节点发送包含方法名和参数的请求,请求可以是转账或者合约的部署和调用。 | ||
|
||
在 cita-sdk-java 中,一共有三种方式实现和链上节点的交互: | ||
|
||
第一种: 通过 cita-sdk-java 定义的方法手动输入包括合约的Abi和Bin来进行操作。 | ||
|
||
第二种: 通过codeGen工具将Solidity合约生成Java类,该Java类继承自Contract类并包含合约中定义的所有方法。 | ||
相比于第一种方法的手动拼接参数,这个方式可以不用生成Abi和Bin文件而直接通过Java类中的方法来进行合约的部署和调用。 | ||
|
||
第三种: 通过封装在Account中的方法来构建并发送交易,Account会实例化TransactionManager,TransactionManager 提供了异步和同步方式对合约进行部署和调用。 | ||
|
||
## 目录: | ||
1. [JSON-RPC](jsonrpc.md) | ||
2. [Transaction](transaction.md) | ||
3. [Account](account.md) |
Oops, something went wrong.