From ec24e98eb654443cb77ad6f328c1035067bd9197 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 14:05:36 +0800 Subject: [PATCH 1/9] doc: add account api document --- .../cita/protocol/account/Account.java | 7 +- .../cryptape/cita/tx/TransactionManager.java | 3 +- docs/Account.md | 82 +++++++++++++++++++ 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 docs/Account.md diff --git a/core/src/main/java/com/cryptape/cita/protocol/account/Account.java b/core/src/main/java/com/cryptape/cita/protocol/account/Account.java index c6762fd7..7c2a6cb8 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/account/Account.java +++ b/core/src/main/java/com/cryptape/cita/protocol/account/Account.java @@ -70,7 +70,6 @@ public Future deployAsync( version, chainId, value); } - // eth_call: nonce and quota is null // sendTransaction: nonce and quota is necessary public Object callContract( String contractAddress, String funcName, @@ -101,7 +100,7 @@ public Object callContract( Function func; if (functionAbi.isConstant()) { - // eth_call + // call List retsType = new ArrayList<>(); List> retsTypeRef = new ArrayList<>(); List outputs = functionAbi.getOutputs(); @@ -111,7 +110,7 @@ public Object callContract( retsTypeRef.add(retType.getTypeReference()); } func = new Function(functionAbi.getName(), params, retsTypeRef); - return ethCall(contractAddress, func, retsType); + return appCall(contractAddress, func, retsType); } else { // send_transaction func = new Function(functionAbi.getName(), params, Collections.emptyList()); @@ -120,7 +119,7 @@ public Object callContract( } } - public Object ethCall(String contractAddress, Function func, List retsType) + public Object appCall(String contractAddress, Function func, List retsType) throws IOException { String data = FunctionEncoder.encode(func); AppCall call = this.service.appCall(new Call(this.transactionManager.getFromAddress(), diff --git a/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java b/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java index 110ed81b..280a7c5d 100644 --- a/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java +++ b/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java @@ -12,11 +12,10 @@ import com.cryptape.cita.protocol.exceptions.TransactionException; /** - * Transaction manager abstraction for executing transactions with Ethereum client via + * Transaction manager abstraction for executing transactions with CITA client via * various mechanisms. */ -///TODO this class includes ethereum methods: remove them later public abstract class TransactionManager { public static final int DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40; diff --git a/docs/Account.md b/docs/Account.md new file mode 100644 index 00000000..08921fb8 --- /dev/null +++ b/docs/Account.md @@ -0,0 +1,82 @@ +## 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。 + +**参数** +to - 交易将要的发送地址 +data - 编码后交易数据(abi) +quota - 用户支付矿工的费用 +nonce - 随机数用于防止重放攻击 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 + +**返回值** +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); +``` \ No newline at end of file From 29aeaef2663c7d71c5a0888cda8fbc988b63239c Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 14:38:58 +0800 Subject: [PATCH 2/9] doc: add cita rpc document --- docs/Account.md | 6 +- docs/CITA_RPC.md | 457 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 460 insertions(+), 3 deletions(-) create mode 100644 docs/CITA_RPC.md diff --git a/docs/Account.md b/docs/Account.md index 08921fb8..e1aae316 100644 --- a/docs/Account.md +++ b/docs/Account.md @@ -4,9 +4,9 @@ Account 封装了 TransactionManager,通过 CITAj 和账户的私钥进行实 Account 使用了 CompiledContract 类,可以直接读取 Solidity 合约文件,生成 ABI 和 BIN 文件以供 TransactionManager 使用。 -[New account](#new-account) -[Deploy contract](#deploy-contract) -[Call Contract](#call-contract) +* [New account](#new-account) +* [Deploy contract](#deploy-contract) +* [Call Contract](#call-contract) #### New account diff --git a/docs/CITA_RPC.md b/docs/CITA_RPC.md new file mode 100644 index 00000000..1b4b2266 --- /dev/null +++ b/docs/CITA_RPC.md @@ -0,0 +1,457 @@ +CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比如JsonRpc2_0CITAj),提供了方法以发送交易的方式对合约进行部署和函数调用。 + +[Build CITAj](#build-citaj) +[netPeer](#netpeer) +[appMetaData](#appmetadata) +[appBlockNumber](#appblocknumber) +[appGetBalance](#appgetbalance) +[appGetAbi](#appgetabi) +[appGetTransactionCount](#appgettransactioncount) +[appGetCode](#appgetcode) +[appSendRawTransaction](#appsendrawtransaction) +[appCall](#appcall) +[appGetBlockByHash](#appgetblockbyhash) +[appGetBlockByNumber](#appgetblockbynumber) +[appGetTransactionByHash](#appgettransactionbyhash) +[appGetTransactionReceipt](#appgettransactionreceipt) +[appNewBlockFilter](#appnewblockfilter) +[appBlockHashObservable](#appblockhashobservable) +[appNewFilter](#appnewfilter) +[appUninstallFilter](#appuninstallfilter) +[appGetFilterChanges](#appgetfilterchanges) +[appGetFilterLogs](#appgetfilterlogs) +[appLogObservable](#applogobservable) + +#### Build CITAj + +**方法名** +`CITAj build (CITAjService citaj)` +根据 CITAjService 类型实例化 CITAj。 + +**参数** +citaj - CITAjService 实例 + +**返回值** +CITAj 实例 + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +``` + +#### netPeer + +**方法名** +`Request netPeer()` +获取当前连接节点数。 + +**参数** +无 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +NetPeerCount netPeerCount = service.netPeerCount().send(); +BigInteger peerCount = netPeerCount.getQuantity(); +``` + +#### appMetaData + +**方法名** +`Request appMetaData(DefaultBlockParameter defaultBlockParameter)` +获取指定块高的元数据。 + +**参数** +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +DefaultBlockParameter defaultParam = DefaultBlockParameter.valueOf("latest"); +AppMetaDataResult result = service.appMetaData(defaultParam).send(); +int chainId = result.chainId; +String chainName = result.chainName; +String genesisTS = result.genesisTimestamp; +``` +#### appBlockNumber + +**方法名** +`Request appBlockNumber()` +获取当前块高度。 + +**参数** +无 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +AppBlockNumber result = service.appBlockNumber().send(); +BigInteger blockNumber = result.getBlockNumber(); +``` +#### appGetBalance + +**方法名** +`Request appGetBalance(String address, DefaultBlockParameter defaultBlockParameter))` +获取地址余额。 + +**参数** +address - 所要查询的地址 +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +string addr = "{hex cita address starting with 0x}"; +DefaultBlockParameter defaultBlockParameter = DefaultBlockParamter.valueOf("latest"); +AppGetBalance getBalance = service.appGetBalance(addr, defaultBlockParamter).send(); +BigInteger balance = getBalance.getBalance(); +``` + +#### appGetAbi + +**方法名** +`Request appGetAbi(String contractAddress, DefaultBlockParameter defaultBlockParameter)` +获取合约的Abi。 + +**参数** +address - 所要查询Abi的合约地址 +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +string addr = "{hex cita address starting with 0x}"; +DefaultBlockParameter defaultBlockParameter = DefaultBlockParamter.valueOf("latest"); +AppGetAbi getAbi = service.appGetAbi(addr, defaultBlockParamter).send(); +String abi = getAbi.getAbi(); +``` + +#### appGetTransactionCount + +**方法名** +`Request appGetTransactionCount(String address, DefaultBlockParameter defaultBlockParameter)` +获取账户发送合约数量。 + +**参数** +address - 所要查询的地址 +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +string addr = "{hex cita address starting with 0x}"; +DefaultBlockParameter defaultBlockParameter = DefaultBlockParamter.valueOf("latest"); +AppGetTransactionCount getTransactionCount = service.appGetTransactionCount(addr, defaultBlockParamter).send(); +BigInteger txCount = getTransactionCount.getTransactionCount(); +``` + +#### appGetCode + +**方法名** +`Request appGetCode(String address, DefaultBlockParameter defaultBlockParameter)` +获取合约代码。 + +**参数** +address - 所要查询的地址 +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +string addr = "{hex cita address starting with 0x}"; +DefaultBlockParameter defaultBlockParameter = DefaultBlockParamter.valueOf("latest"); +AppGetCode getCode = service.appGetCode(addr, defaultBlockParamter).send(); +Sring code = getCode.getCode(); +``` + +#### appSendRawTransaction + +**方法名** +`Request appSendRawTransaction(String signedTransactionData)` +向区块链节点发送序列化交易。 + +**参数** +signedTransaction - 经过签名的交易数据 + +**返回值** +Request + +**示例** +``` +//create a signed transaction +Transaction tx = Transaction.createContractTransaction(BigInteger.valueOf(nonce), this.config.getQuota(), this.currentHeight + 88, 0, chainId, value, this.config.getCode()); +tx.sign(this.config.getPrivateKey(), false, false); + +//instantiate a CITAj and send the transaction +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +AppSendTransaction sendTransaction = service.appSendRawTransaction(tx).send(); + +//get hash of the transaction +String hash = sendTransaction.getHash(); +``` + +#### appCall + +**方法名** +`Request appCall(Call call, DefaultBlockParameter defaultBlockParameter)` +调用合约接口。 + +**参数** +call - 合约方法的call的封装 +defaultBlockParameter - 块高度的接口:数字或者关键字 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +Call call = new Call(from, to, data); +AppCall appCall = service.appCall(call, DefaultBlockParameter.valueOf("latest")).send(); +String result = call.getValue(); +``` + +#### appGetBlockByHash + +**方法名** +`Request appGetBlockByHash(String blockHash, boolean returnFullTransactionObjects)` +根据块的哈希值查询块信息。 + +**参数** +blockHash - 块高度的接口:数字或者关键字 +returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +String blockHash = "{block hash to search}"; +AppBlock appBlock = service.appGetBlockByHash(blockHash, false).send(); +``` + +#### appGetBlockByNumber + +**方法名** +`Request appGetBlockByNumber(DefaultBlockParameter defaultBlockParameter, boolean returnFullTransactionObjects)` +根据块高度查询块信息。 + +**参数** +defaultBlockParameter - 块高度的接口:数字或者关键字 +returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +AppBlock appBlock = service.appGetBlockByHash(DefaultBlockParameter.valueOf("latest"), false).send(); +``` + + +#### appGetTransactionByHash + +**方法名** +`Request appGetTransactionByHash(String transactionHash)` +根据哈希查询交易信息。 + +**参数** +transactionHash - 交易哈希 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +String txHash = "{hash of transactino to be searched}"; +AppTransaction responseTx = service.appGetTransactionByHash(txHash).send(); +``` +#### appGetTransactionReceipt + +**方法名** +`Request appGetTransactionReceipt(String transactionHash)` +根据交易哈希查询交易回执。 + +**参数** +transactionHash - 交易哈希 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +String txHash = "{hash of transactino to be searched}"; +AppGetTransactionReceipt txReceipt = service.appGetTransactionReceipt(txHash).send(); +``` + +#### appNewBlockFilter + +**方法名** +`Request appNewBlockFilter()` +创建一个新的块过滤器,当有新的块写入时通知。 + +**参数** +无 + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +AppFilter appFilter = service.appNewBlockFilter().send(); +BigInteger filterId = appFilter.getFilterId(); +``` + +#### appBlockHashObservable + +**方法名** +`Observable appBlockHashObservable()` +新建一个Block Filter来监听新增块的哈希,返回一个Observable,可以用交互的形式来监听块高的变化。 + +**参数** +无 + +**返回值** +Observable + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +Observable blockFitlerObservable = service.appBlockHashObservable(); +AppLog logs = service.appGetFilterLogs(filterId).send(); + blockFitlerObservable.subscribe(block -> { + System.out.println(block.toString()); + }); +``` + +#### appNewFilter + +**方法名** +`Request appNewFilter(com.cryptape.cita.protocol.core.methods.request.AppFilter appFilter)` +创建一个新的Event过滤器以用来监听合约中的Event。 + +**参数** +appFilter - 针对于 CITA 智能合约event的过滤器(定义在Request中的appFilter) + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +com.cryptape.cita.protocol.core.methods.request.AppFilter appFilter = new AppFilter(fromBlock, toBlock, addresses); +AppFilter appFilter = service.appNewFilter(txHash).send(); +BigInteger filterId = appFilter.getFilterId(); +``` + +#### appUninstallFilter + +**方法名** +`Request appUninstallFilter(BigInteger filterId)` +移除已部署的过滤器。 + +**参数** +filterId - 过滤器Id + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +BigInteger filterId = {your filter Id }; +AppUninstallFilter uninstallFilter = service.appUninstallFilter(filterId).send(); +``` + +#### appGetFilterChanges + +**方法名** +`Request appGetFilterChanges(BigInteger filterId)` +根据过滤器Id查询log,返回上一次查询之后的所有log。 + +**参数** +filterId - 过滤器Id + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +BigInteger filterId = {your filter Id }; +AppLog logs = service.appGetFilterChanges(filterId).send(); +List results = logs.getLogs(); +``` + +#### appGetFilterLogs + +**方法名** +`Request appGetFilterLogs(BigInteger filterId)` +根据过滤器Id查询log,返回符合输入filter Id的所有log。 + +**参数** +filterId - 过滤器Id + +**返回值** +Request + +**示例** +``` +CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); +BigInteger filterId = {your filter Id }; +AppLog logs = service.appGetFilterLogs(filterId).send(); +List results = logs.getLogs(); +``` + +#### appLogObservable + +**方法名** +`Observable appLogObservable(AppFilter appFilter)` +根据AppFilter来安装一个新的Filter用以获取历史log和监听新的Log,返回一个Observable以交互的模式监听Log。 + +**参数** +AppFilter - 过滤器可以由`appNewFilter`来新建 + +**返回值** +Observable + +**示例** +``` +Observable appLogObservable = service.appLogObservable(filter); + Observable reponse = appLogObservable.map( + (log) -> { + EventValues eventValues = staticExtractEventParameters(event, (Log)log); + return (String) eventValues.getIndexedValues().get(0).getValue();; + } + ); + + reponse.subscribe(x -> { + System.out.println(x); + }); +``` \ No newline at end of file From 3de2ebfa5ba64ef695610f24b59a36810dcb27c5 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 14:54:37 +0800 Subject: [PATCH 3/9] doc: add transaction api document --- .../cita/protocol/account/Account.java | 2 +- .../cita/tx/RawTransactionManager.java | 5 +- docs/{Account.md => account.md} | 0 docs/{CITA_RPC.md => jsonrpc.md} | 0 docs/transaction.md | 202 ++++++++++++++++++ 5 files changed, 206 insertions(+), 3 deletions(-) rename docs/{Account.md => account.md} (100%) rename docs/{CITA_RPC.md => jsonrpc.md} (100%) create mode 100644 docs/transaction.md diff --git a/core/src/main/java/com/cryptape/cita/protocol/account/Account.java b/core/src/main/java/com/cryptape/cita/protocol/account/Account.java index 7c2a6cb8..de3592ab 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/account/Account.java +++ b/core/src/main/java/com/cryptape/cita/protocol/account/Account.java @@ -59,7 +59,7 @@ public AppSendTransaction deploy( version, chainId, value); } - public Future deployAsync( + public Flowable deployAsync( File contractFile, String nonce, long quota, int version, BigInteger chainId, String value) throws IOException, InterruptedException, CompiledContract.ContractCompileError { diff --git a/core/src/main/java/com/cryptape/cita/tx/RawTransactionManager.java b/core/src/main/java/com/cryptape/cita/tx/RawTransactionManager.java index 5c427a19..90ecd99f 100644 --- a/core/src/main/java/com/cryptape/cita/tx/RawTransactionManager.java +++ b/core/src/main/java/com/cryptape/cita/tx/RawTransactionManager.java @@ -14,6 +14,7 @@ import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionCount; import com.cryptape.cita.protocol.core.methods.response.AppSendTransaction; import com.cryptape.cita.utils.Numeric; +import io.reactivex.Flowable; public class RawTransactionManager extends TransactionManager { @@ -108,7 +109,7 @@ public AppSendTransaction sendTransaction( return citaj.appSendRawTransaction(rawTx).send(); } - public Future sendTransactionAsync( + public Flowable sendTransactionAsync( String to, String data, long quota, String nonce, long validUntilBlock, int version, BigInteger chainId, String value) throws IOException { @@ -124,7 +125,7 @@ public Future sendTransactionAsync( } else if (this.signature != null) { rawTx = transaction.sign(this.signature); } - return citaj.appSendRawTransaction(rawTx).sendAsync(); + return citaj.appSendRawTransaction(rawTx).flowable(); } @Override diff --git a/docs/Account.md b/docs/account.md similarity index 100% rename from docs/Account.md rename to docs/account.md diff --git a/docs/CITA_RPC.md b/docs/jsonrpc.md similarity index 100% rename from docs/CITA_RPC.md rename to docs/jsonrpc.md diff --git a/docs/transaction.md b/docs/transaction.md new file mode 100644 index 00000000..9ad06496 --- /dev/null +++ b/docs/transaction.md @@ -0,0 +1,202 @@ +Transction定义在core.request中,用于将交易数据封装并且签名(如果需要),交易数据或者签名后的交易数据被appCall()或者appSendRawTransaction()所使用进行合约的调用或者部署。 + +[Transaction](#transaction) +[createContractTransaction](#createcontracttransaction) +[createFunctionCallTransaction](#createfunctioncalltransaction) +[TransactionManager](#transactionmanager) +[sendTransaction](#sendtransaction) +[sendTransactionAsync](#sendtransactionasync) + +#### Transaction + +**方法名** +`Transaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` +根据参数新建一个交易。 + +**参数** +to - 交易将要的发送地址 +nonce - 随机数用于防止重放攻击 +quota - 用户支付矿工的费用 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 +data - 编码后交易数据(abi) + +**返回值** +Transaction实例 + +**示例** +``` +CITAj service = CITAj.build(new HttpService("127.0.0.1")); +String to = "{address to which the tx is sent}"; +BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong())); +long quota = 9999; +long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88; +int version = 0; +in chainId = 1; +String value = "100000000"; +String init = "{encoded abi}"; +Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_block, version, chainId, value, init); +``` +#### createContractTransaction + +**方法名** +`createContractTransaction(BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String init)` +根据参数新建一个交易。 + +**参数** +nonce - 随机数用于防止重放攻击 +quota - 用户支付矿工的费用 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 +init - 合约编码后数据(abi) + +**返回值** +Transaction实例 + +**示例** +``` +//create new CITAj service +CITAj service = CITAj.build(new HttpService("127.0.0.1")); + +//settings initiation +BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong())); +long quota = 9999; +long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88; +int version = 0; +in chainId = 1; +String value = "100000000"; +String init = "{encoded abi}"; + +//construct transaction +Transaction txToDeployContract = Transction.createContractTransaction(nonce, quota, valid_until_block, version, chainId, value, init); +String signedTx = txToDeployContract.sign(this.config.getPrivateKey(), false, false); +AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); +``` + +#### createFunctionCallTransaction + +**方法名** +`createFunctionCallTransaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` +根据参数新建一个交易。 + +**参数** +to - 交易将要的发送地址 +nonce - 随机数用于防止重放攻击 +quota - 用户支付矿工的费用 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 +data - 编码后交易数据(abi) + +**返回值** +Transaction实例 + +**示例** +``` +//create new CITAj service +CITAj service = CITAj.build(new HttpService("127.0.0.1")); + +//settings initiation +String to = "{smart contract address}"; +BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong())); +long quota = 9999; +long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88; +int version = 0; +in chainId = 1; +String value = "100000000"; +String init = "{encoded abi}"; + +//construct transaction +Transaction txToDeployContract = Transction.createFunctionCallTransaction(to, nonce, quota, valid_until_block, version, chainId, value, init); +String signedTx = txToDeployContract.sign(this.config.getPrivateKey(), false, false); +AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); +``` +#### TransactionManager + +**方法名** +`TransactionManager(CITAj citaj, Credentials credentials)` + +**参数** +citaj - CITAj实例 +credentials - 发起交易账户的credential + +**返回值** +TransactionManager实例 + +**示例** +``` +Credentials credentials = Credentials.create(privateKey); +CITAj service = CITAj.build(new HttpService("127.0.0.1")); +TransactionManager transactionManager = new TransactionManager(service, credentials); +``` + +#### sendTransaction + +**方法名** +`AppSendTransaction sendTransaction(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` +通过TransactionManager发送交易。 + +**参数** +to - 交易将要的发送地址 +data - 编码后交易数据(abi) +quota - 用户支付矿工的费用 +nonce - 随机数用于防止重放攻击 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 + +**返回值** +AppSendTransaction + +**示例** +``` +CitaTransactionManager transactionManager = new CitaTransactionManager(service, credentials); +String to = "{address to which the contract is sent}"; +String contractBin = "{contract bin or function call bin}"; +BigInteger quota = 99999; +BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong())); +long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88; +int version = 0; +int chainId = 1; +String value = "0"; +AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, BigInteger.valueOf(version), chainId, value); +``` + +#### sendTransactionAsync + +**方法名** +`Flowable sendTransactionAsync(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` +通过TransactionManager发送交易。 + +**参数** +to - 交易将要的发送地址 +data - 编码后交易数据(abi) +quota - 用户支付矿工的费用 +nonce - 随机数用于防止重放攻击 +valid_until_block - 超时机制,超过设定块高取消交易 +version - 链的版本信息 +chainId - 链Id +value - 交易中原生token的数量 + +**返回值** +AppSendTransaction + +**示例** +``` +TransactionManager transactionManager = new TransactionManager(service, credentials); +String to = "{address to which the contract is sent}"; +String contractBin = "{contract bin or function call bin}"; +BigInteger quota = 99999; +BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong())); +long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88; +int version = 0; +int chainId = 1; +String value = "0"; +Flowable appSendTransaction = transactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, BigInteger.valueOf(version), chainId, value); +``` \ No newline at end of file From d1bc8ed15c976b163450390575134361e4bdbbd8 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 14:57:06 +0800 Subject: [PATCH 4/9] doc: update markdown format --- docs/account.md | 6 +++--- docs/jsonrpc.md | 44 +++++++++++++++++++++++--------------------- docs/transaction.md | 14 ++++++++------ 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/docs/account.md b/docs/account.md index e1aae316..324d6df2 100644 --- a/docs/account.md +++ b/docs/account.md @@ -8,7 +8,7 @@ Account 使用了 CompiledContract 类,可以直接读取 Solidity 合约文 * [Deploy contract](#deploy-contract) * [Call Contract](#call-contract) -#### New account +### New account **方法名** `Account(String privateKey, CITAj service)` @@ -27,7 +27,7 @@ String privateKey = "{private key}"; CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); Account account = new Account(privateKey, service); ``` -#### Deploy contract +### Deploy contract **方法名** @@ -53,7 +53,7 @@ Account account = new Account(privateKey, service); AppSendTransaction appSendTransaction = account.deploy(new File(path), randomNonce(), quota, version, chainId, value); ``` -#### Call contract +### Call contract **方法名** diff --git a/docs/jsonrpc.md b/docs/jsonrpc.md index 1b4b2266..2945de47 100644 --- a/docs/jsonrpc.md +++ b/docs/jsonrpc.md @@ -1,3 +1,5 @@ +## JSONRPC + CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比如JsonRpc2_0CITAj),提供了方法以发送交易的方式对合约进行部署和函数调用。 [Build CITAj](#build-citaj) @@ -22,7 +24,7 @@ CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比 [appGetFilterLogs](#appgetfilterlogs) [appLogObservable](#applogobservable) -#### Build CITAj +### Build CITAj **方法名** `CITAj build (CITAjService citaj)` @@ -39,7 +41,7 @@ CITAj 实例 CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); ``` -#### netPeer +### netPeer **方法名** `Request netPeer()` @@ -58,7 +60,7 @@ NetPeerCount netPeerCount = service.netPeerCount().send(); BigInteger peerCount = netPeerCount.getQuantity(); ``` -#### appMetaData +### appMetaData **方法名** `Request appMetaData(DefaultBlockParameter defaultBlockParameter)` @@ -79,7 +81,7 @@ int chainId = result.chainId; String chainName = result.chainName; String genesisTS = result.genesisTimestamp; ``` -#### appBlockNumber +### appBlockNumber **方法名** `Request appBlockNumber()` @@ -97,7 +99,7 @@ CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); AppBlockNumber result = service.appBlockNumber().send(); BigInteger blockNumber = result.getBlockNumber(); ``` -#### appGetBalance +### appGetBalance **方法名** `Request appGetBalance(String address, DefaultBlockParameter defaultBlockParameter))` @@ -119,7 +121,7 @@ AppGetBalance getBalance = service.appGetBalance(addr, defaultBlockParamter).sen BigInteger balance = getBalance.getBalance(); ``` -#### appGetAbi +### appGetAbi **方法名** `Request appGetAbi(String contractAddress, DefaultBlockParameter defaultBlockParameter)` @@ -141,7 +143,7 @@ AppGetAbi getAbi = service.appGetAbi(addr, defaultBlockParamter).send(); String abi = getAbi.getAbi(); ``` -#### appGetTransactionCount +### appGetTransactionCount **方法名** `Request appGetTransactionCount(String address, DefaultBlockParameter defaultBlockParameter)` @@ -163,7 +165,7 @@ AppGetTransactionCount getTransactionCount = service.appGetTransactionCount(addr BigInteger txCount = getTransactionCount.getTransactionCount(); ``` -#### appGetCode +### appGetCode **方法名** `Request appGetCode(String address, DefaultBlockParameter defaultBlockParameter)` @@ -185,7 +187,7 @@ AppGetCode getCode = service.appGetCode(addr, defaultBlockParamter).send(); Sring code = getCode.getCode(); ``` -#### appSendRawTransaction +### appSendRawTransaction **方法名** `Request appSendRawTransaction(String signedTransactionData)` @@ -211,7 +213,7 @@ AppSendTransaction sendTransaction = service.appSendRawTransaction(tx).send(); String hash = sendTransaction.getHash(); ``` -#### appCall +### appCall **方法名** `Request appCall(Call call, DefaultBlockParameter defaultBlockParameter)` @@ -232,7 +234,7 @@ AppCall appCall = service.appCall(call, DefaultBlockParameter.valueOf("latest")) String result = call.getValue(); ``` -#### appGetBlockByHash +### appGetBlockByHash **方法名** `Request appGetBlockByHash(String blockHash, boolean returnFullTransactionObjects)` @@ -252,7 +254,7 @@ String blockHash = "{block hash to search}"; AppBlock appBlock = service.appGetBlockByHash(blockHash, false).send(); ``` -#### appGetBlockByNumber +### appGetBlockByNumber **方法名** `Request appGetBlockByNumber(DefaultBlockParameter defaultBlockParameter, boolean returnFullTransactionObjects)` @@ -272,7 +274,7 @@ AppBlock appBlock = service.appGetBlockByHash(DefaultBlockParameter.valueOf("lat ``` -#### appGetTransactionByHash +### appGetTransactionByHash **方法名** `Request appGetTransactionByHash(String transactionHash)` @@ -290,7 +292,7 @@ CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); String txHash = "{hash of transactino to be searched}"; AppTransaction responseTx = service.appGetTransactionByHash(txHash).send(); ``` -#### appGetTransactionReceipt +### appGetTransactionReceipt **方法名** `Request appGetTransactionReceipt(String transactionHash)` @@ -309,7 +311,7 @@ String txHash = "{hash of transactino to be searched}"; AppGetTransactionReceipt txReceipt = service.appGetTransactionReceipt(txHash).send(); ``` -#### appNewBlockFilter +### appNewBlockFilter **方法名** `Request appNewBlockFilter()` @@ -328,7 +330,7 @@ AppFilter appFilter = service.appNewBlockFilter().send(); BigInteger filterId = appFilter.getFilterId(); ``` -#### appBlockHashObservable +### appBlockHashObservable **方法名** `Observable appBlockHashObservable()` @@ -350,7 +352,7 @@ AppLog logs = service.appGetFilterLogs(filterId).send(); }); ``` -#### appNewFilter +### appNewFilter **方法名** `Request appNewFilter(com.cryptape.cita.protocol.core.methods.request.AppFilter appFilter)` @@ -370,7 +372,7 @@ AppFilter appFilter = service.appNewFilter(txHash).send(); BigInteger filterId = appFilter.getFilterId(); ``` -#### appUninstallFilter +### appUninstallFilter **方法名** `Request appUninstallFilter(BigInteger filterId)` @@ -389,7 +391,7 @@ BigInteger filterId = {your filter Id }; AppUninstallFilter uninstallFilter = service.appUninstallFilter(filterId).send(); ``` -#### appGetFilterChanges +### appGetFilterChanges **方法名** `Request appGetFilterChanges(BigInteger filterId)` @@ -409,7 +411,7 @@ AppLog logs = service.appGetFilterChanges(filterId).send(); List results = logs.getLogs(); ``` -#### appGetFilterLogs +### appGetFilterLogs **方法名** `Request appGetFilterLogs(BigInteger filterId)` @@ -429,7 +431,7 @@ AppLog logs = service.appGetFilterLogs(filterId).send(); List results = logs.getLogs(); ``` -#### appLogObservable +### appLogObservable **方法名** `Observable appLogObservable(AppFilter appFilter)` diff --git a/docs/transaction.md b/docs/transaction.md index 9ad06496..79f8025e 100644 --- a/docs/transaction.md +++ b/docs/transaction.md @@ -1,3 +1,5 @@ +## Transaction + Transction定义在core.request中,用于将交易数据封装并且签名(如果需要),交易数据或者签名后的交易数据被appCall()或者appSendRawTransaction()所使用进行合约的调用或者部署。 [Transaction](#transaction) @@ -7,7 +9,7 @@ Transction定义在core.request中,用于将交易数据封装并且签名( [sendTransaction](#sendtransaction) [sendTransactionAsync](#sendtransactionasync) -#### Transaction +### Transaction **方法名** `Transaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` @@ -39,7 +41,7 @@ String value = "100000000"; String init = "{encoded abi}"; Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_block, version, chainId, value, init); ``` -#### createContractTransaction +### createContractTransaction **方法名** `createContractTransaction(BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String init)` @@ -77,7 +79,7 @@ String signedTx = txToDeployContract.sign(this.config.getPrivateKey(), false, fa AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); ``` -#### createFunctionCallTransaction +### createFunctionCallTransaction **方法名** `createFunctionCallTransaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` @@ -116,7 +118,7 @@ Transaction txToDeployContract = Transction.createFunctionCallTransaction(to, no String signedTx = txToDeployContract.sign(this.config.getPrivateKey(), false, false); AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); ``` -#### TransactionManager +### TransactionManager **方法名** `TransactionManager(CITAj citaj, Credentials credentials)` @@ -135,7 +137,7 @@ CITAj service = CITAj.build(new HttpService("127.0.0.1")); TransactionManager transactionManager = new TransactionManager(service, credentials); ``` -#### sendTransaction +### sendTransaction **方法名** `AppSendTransaction sendTransaction(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` @@ -168,7 +170,7 @@ String value = "0"; AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, BigInteger.valueOf(version), chainId, value); ``` -#### sendTransactionAsync +### sendTransactionAsync **方法名** `Flowable sendTransactionAsync(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` From e7e68778ebf0219ca88872afc84aa2ef0af15ca7 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 15:02:37 +0800 Subject: [PATCH 5/9] doc: add cita sdk index documment --- docs/index.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docs/index.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..2ef4a712 --- /dev/null +++ b/docs/index.md @@ -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) \ No newline at end of file From ac88253762ad5a2d0e835b085b5a514bd0ac018c Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 15:06:32 +0800 Subject: [PATCH 6/9] doc: update readme for document link --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index eb406bfa..f58a94a2 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ cita-sdk-java, originally adapted from Ethereum web3j, is a Java library for working with Smart Contract and integrating with clients on CITA. +Here is [detail documentation](docs/index.md) + ## Features - Complete implementation of CITA JSON-RPC API over HTTP. @@ -144,6 +146,9 @@ Please find complete code in [TokenAccountExample](https://github.com/cryptape/c ## 简介 cita-sdk-java 是对以太坊 Web3j 进行改写,适配 CITA 的一个 Java 开发包。cita-sdk-java 集成了与 CITA 客户端交互的功能,可以用来对 CITA 发送交易,系统配置,信息查询。 + +开发请参考[详细文档](docs/index.md) + ## 特性 - 通过 HTTP 协议,实现了 CITA 所定义的所有 JSON-RPC 方法。 - 可以通过 Solidity 智能合约生成该合约的 Java 类。这个智能合约的 Java 类作为 java 对只能合约的包裹层,可以使开发和通过 java 方便地对智能合约进行部署和合约方法的调用(支持Solidity 和 Truffle 的格式)。 From 4321db68b928fa14f53e78f8dbbb997a80a59442 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 15:44:29 +0800 Subject: [PATCH 7/9] doc: update mardown format for jsonrpc and transaction --- docs/jsonrpc.md | 42 +++++++++++++++++++++--------------------- docs/transaction.md | 12 ++++++------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/jsonrpc.md b/docs/jsonrpc.md index 2945de47..f306654e 100644 --- a/docs/jsonrpc.md +++ b/docs/jsonrpc.md @@ -2,27 +2,27 @@ CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比如JsonRpc2_0CITAj),提供了方法以发送交易的方式对合约进行部署和函数调用。 -[Build CITAj](#build-citaj) -[netPeer](#netpeer) -[appMetaData](#appmetadata) -[appBlockNumber](#appblocknumber) -[appGetBalance](#appgetbalance) -[appGetAbi](#appgetabi) -[appGetTransactionCount](#appgettransactioncount) -[appGetCode](#appgetcode) -[appSendRawTransaction](#appsendrawtransaction) -[appCall](#appcall) -[appGetBlockByHash](#appgetblockbyhash) -[appGetBlockByNumber](#appgetblockbynumber) -[appGetTransactionByHash](#appgettransactionbyhash) -[appGetTransactionReceipt](#appgettransactionreceipt) -[appNewBlockFilter](#appnewblockfilter) -[appBlockHashObservable](#appblockhashobservable) -[appNewFilter](#appnewfilter) -[appUninstallFilter](#appuninstallfilter) -[appGetFilterChanges](#appgetfilterchanges) -[appGetFilterLogs](#appgetfilterlogs) -[appLogObservable](#applogobservable) +* [Build CITAj](#build-citaj) +* [netPeer](#netpeer) +* [appMetaData](#appmetadata) +* [appBlockNumber](#appblocknumber) +* [appGetBalance](#appgetbalance) +* [appGetAbi](#appgetabi) +* [appGetTransactionCount](#appgettransactioncount) +* [appGetCode](#appgetcode) +* [appSendRawTransaction](#appsendrawtransaction) +* [appCall](#appcall) +* [appGetBlockByHash](#appgetblockbyhash) +* [appGetBlockByNumber](#appgetblockbynumber) +* [appGetTransactionByHash](#appgettransactionbyhash) +* [appGetTransactionReceipt](#appgettransactionreceipt) +* [appNewBlockFilter](#appnewblockfilter) +* [appBlockHashObservable](#appblockhashobservable) +* [appNewFilter](#appnewfilter) +* [appUninstallFilter](#appuninstallfilter) +* [appGetFilterChanges](#appgetfilterchanges) +* [appGetFilterLogs](#appgetfilterlogs) +* [appLogObservable](#applogobservable) ### Build CITAj diff --git a/docs/transaction.md b/docs/transaction.md index 79f8025e..f6d2671d 100644 --- a/docs/transaction.md +++ b/docs/transaction.md @@ -2,12 +2,12 @@ Transction定义在core.request中,用于将交易数据封装并且签名(如果需要),交易数据或者签名后的交易数据被appCall()或者appSendRawTransaction()所使用进行合约的调用或者部署。 -[Transaction](#transaction) -[createContractTransaction](#createcontracttransaction) -[createFunctionCallTransaction](#createfunctioncalltransaction) -[TransactionManager](#transactionmanager) -[sendTransaction](#sendtransaction) -[sendTransactionAsync](#sendtransactionasync) +* [Transaction](#transaction) +* [createContractTransaction](#createcontracttransaction) +* [createFunctionCallTransaction](#createfunctioncalltransaction) +* [TransactionManager](#transactionmanager) +* [sendTransaction](#sendtransaction) +* [sendTransactionAsync](#sendtransactionasync) ### Transaction From 4bf5000c66dbd64198d93ac3e5d2ab84364aef23 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 15:49:54 +0800 Subject: [PATCH 8/9] doc: update markdown format for method parameters --- docs/account.md | 32 ++++++++--------- docs/jsonrpc.md | 46 ++++++++++++------------- docs/transaction.md | 84 +++++++++++++++++++++++---------------------- 3 files changed, 82 insertions(+), 80 deletions(-) diff --git a/docs/account.md b/docs/account.md index 324d6df2..723088d6 100644 --- a/docs/account.md +++ b/docs/account.md @@ -15,8 +15,8 @@ Account 使用了 CompiledContract 类,可以直接读取 Solidity 合约文 实例化Account对象。 **参数** -privateKey - 发送交易地址的私钥 -service - CITAj 实例 +* privateKey - 发送交易地址的私钥 +* service - CITAj 实例 **返回值** Account @@ -35,12 +35,12 @@ Account account = new Account(privateKey, service); 部署合约。 **参数** -contractFile - solidity智能合约文件 -nonce - 随机数用于防止重放攻击 -quota - 用户支付矿工的费用 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 +* contractFile - solidity智能合约文件 +* nonce - 随机数用于防止重放攻击 +* quota - 用户支付矿工的费用 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 **返回值** AppSendTransaction @@ -61,14 +61,14 @@ AppSendTransaction appSendTransaction = account.deploy(new File(path), randomNon 调用合约方法,根据Abi中对方法的定义判断使用sendRawTransaction还是app_call。 **参数** -to - 交易将要的发送地址 -data - 编码后交易数据(abi) -quota - 用户支付矿工的费用 -nonce - 随机数用于防止重放攻击 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 +* to - 交易将要的发送地址 +* data - 编码后交易数据(abi) +* quota - 用户支付矿工的费用 +* nonce - 随机数用于防止重放攻击 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 **返回值** Object diff --git a/docs/jsonrpc.md b/docs/jsonrpc.md index f306654e..38e8d1fc 100644 --- a/docs/jsonrpc.md +++ b/docs/jsonrpc.md @@ -67,7 +67,7 @@ BigInteger peerCount = netPeerCount.getQuantity(); 获取指定块高的元数据。 **参数** -defaultBlockParameter - 块高度的接口:数字或者关键字 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -106,8 +106,8 @@ BigInteger blockNumber = result.getBlockNumber(); 获取地址余额。 **参数** -address - 所要查询的地址 -defaultBlockParameter - 块高度的接口:数字或者关键字 +* address - 所要查询的地址 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -128,8 +128,8 @@ BigInteger balance = getBalance.getBalance(); 获取合约的Abi。 **参数** -address - 所要查询Abi的合约地址 -defaultBlockParameter - 块高度的接口:数字或者关键字 +* address - 所要查询Abi的合约地址 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -150,8 +150,8 @@ String abi = getAbi.getAbi(); 获取账户发送合约数量。 **参数** -address - 所要查询的地址 -defaultBlockParameter - 块高度的接口:数字或者关键字 +* address - 所要查询的地址 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -172,8 +172,8 @@ BigInteger txCount = getTransactionCount.getTransactionCount(); 获取合约代码。 **参数** -address - 所要查询的地址 -defaultBlockParameter - 块高度的接口:数字或者关键字 +* address - 所要查询的地址 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -194,7 +194,7 @@ Sring code = getCode.getCode(); 向区块链节点发送序列化交易。 **参数** -signedTransaction - 经过签名的交易数据 +* signedTransaction - 经过签名的交易数据 **返回值** Request @@ -220,8 +220,8 @@ String hash = sendTransaction.getHash(); 调用合约接口。 **参数** -call - 合约方法的call的封装 -defaultBlockParameter - 块高度的接口:数字或者关键字 +* call - 合约方法的call的封装 +* defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** Request @@ -241,8 +241,8 @@ String result = call.getValue(); 根据块的哈希值查询块信息。 **参数** -blockHash - 块高度的接口:数字或者关键字 -returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) +* blockHash - 块高度的接口:数字或者关键字 +* returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) **返回值** Request @@ -261,8 +261,8 @@ AppBlock appBlock = service.appGetBlockByHash(blockHash, false).send(); 根据块高度查询块信息。 **参数** -defaultBlockParameter - 块高度的接口:数字或者关键字 -returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) +* defaultBlockParameter - 块高度的接口:数字或者关键字 +* returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) **返回值** Request @@ -281,7 +281,7 @@ AppBlock appBlock = service.appGetBlockByHash(DefaultBlockParameter.valueOf("lat 根据哈希查询交易信息。 **参数** -transactionHash - 交易哈希 +* transactionHash - 交易哈希 **返回值** Request @@ -299,7 +299,7 @@ AppTransaction responseTx = service.appGetTransactionByHash(txHash).send(); 根据交易哈希查询交易回执。 **参数** -transactionHash - 交易哈希 +* transactionHash - 交易哈希 **返回值** Request @@ -359,7 +359,7 @@ AppLog logs = service.appGetFilterLogs(filterId).send(); 创建一个新的Event过滤器以用来监听合约中的Event。 **参数** -appFilter - 针对于 CITA 智能合约event的过滤器(定义在Request中的appFilter) +* appFilter - 针对于 CITA 智能合约event的过滤器(定义在Request中的appFilter) **返回值** Request @@ -379,7 +379,7 @@ BigInteger filterId = appFilter.getFilterId(); 移除已部署的过滤器。 **参数** -filterId - 过滤器Id +* filterId - 过滤器Id **返回值** Request @@ -398,7 +398,7 @@ AppUninstallFilter uninstallFilter = service.appUninstallFilter(filterId).send() 根据过滤器Id查询log,返回上一次查询之后的所有log。 **参数** -filterId - 过滤器Id +* filterId - 过滤器Id **返回值** Request @@ -418,7 +418,7 @@ List results = logs.getLogs(); 根据过滤器Id查询log,返回符合输入filter Id的所有log。 **参数** -filterId - 过滤器Id +* filterId - 过滤器Id **返回值** Request @@ -438,7 +438,7 @@ List results = logs.getLogs(); 根据AppFilter来安装一个新的Filter用以获取历史log和监听新的Log,返回一个Observable以交互的模式监听Log。 **参数** -AppFilter - 过滤器可以由`appNewFilter`来新建 +* AppFilter - 过滤器可以由`appNewFilter`来新建 **返回值** Observable diff --git a/docs/transaction.md b/docs/transaction.md index f6d2671d..151fcf63 100644 --- a/docs/transaction.md +++ b/docs/transaction.md @@ -16,14 +16,14 @@ Transction定义在core.request中,用于将交易数据封装并且签名( 根据参数新建一个交易。 **参数** -to - 交易将要的发送地址 -nonce - 随机数用于防止重放攻击 -quota - 用户支付矿工的费用 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 -data - 编码后交易数据(abi) +* to - 交易将要的发送地址 +* nonce - 随机数用于防止重放攻击 +* quota - 用户支付矿工的费用 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 +* data - 编码后交易数据(abi) **返回值** Transaction实例 @@ -48,13 +48,13 @@ Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_ 根据参数新建一个交易。 **参数** -nonce - 随机数用于防止重放攻击 -quota - 用户支付矿工的费用 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 -init - 合约编码后数据(abi) +* nonce - 随机数用于防止重放攻击 +* quota - 用户支付矿工的费用 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 +* init - 合约编码后数据(abi) **返回值** Transaction实例 @@ -86,14 +86,14 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); 根据参数新建一个交易。 **参数** -to - 交易将要的发送地址 -nonce - 随机数用于防止重放攻击 -quota - 用户支付矿工的费用 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 -data - 编码后交易数据(abi) +* to - 交易将要的发送地址 +* nonce - 随机数用于防止重放攻击 +* quota - 用户支付矿工的费用 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 +* data - 编码后交易数据(abi) **返回值** Transaction实例 @@ -124,8 +124,9 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); `TransactionManager(CITAj citaj, Credentials credentials)` **参数** -citaj - CITAj实例 -credentials - 发起交易账户的credential + +* citaj - CITAj实例 +* credentials - 发起交易账户的credential **返回值** TransactionManager实例 @@ -144,14 +145,15 @@ TransactionManager transactionManager = new TransactionManager(service, credenti 通过TransactionManager发送交易。 **参数** -to - 交易将要的发送地址 -data - 编码后交易数据(abi) -quota - 用户支付矿工的费用 -nonce - 随机数用于防止重放攻击 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 + +* to - 交易将要的发送地址 +* data - 编码后交易数据(abi) +* quota - 用户支付矿工的费用 +* nonce - 随机数用于防止重放攻击 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 **返回值** AppSendTransaction @@ -177,14 +179,14 @@ AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(t 通过TransactionManager发送交易。 **参数** -to - 交易将要的发送地址 -data - 编码后交易数据(abi) -quota - 用户支付矿工的费用 -nonce - 随机数用于防止重放攻击 -valid_until_block - 超时机制,超过设定块高取消交易 -version - 链的版本信息 -chainId - 链Id -value - 交易中原生token的数量 +* to - 交易将要的发送地址 +* data - 编码后交易数据(abi) +* quota - 用户支付矿工的费用 +* nonce - 随机数用于防止重放攻击 +* valid_until_block - 超时机制,超过设定块高取消交易 +* version - 链的版本信息 +* chainId - 链Id +* value - 交易中原生token的数量 **返回值** AppSendTransaction From e6f4bf82024aced4274538f6545257682a5de1ae Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 4 Apr 2019 17:03:46 +0800 Subject: [PATCH 9/9] doc: update method parameters description --- docs/account.md | 20 ++++++-- docs/jsonrpc.md | 111 ++++++++++++++++++++++++++++++++++++++------ docs/transaction.md | 27 ++++++++++- 3 files changed, 139 insertions(+), 19 deletions(-) diff --git a/docs/account.md b/docs/account.md index 723088d6..27b052dd 100644 --- a/docs/account.md +++ b/docs/account.md @@ -11,17 +11,22 @@ Account 使用了 CompiledContract 类,可以直接读取 Solidity 合约文 ### 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")); @@ -32,9 +37,11 @@ Account account = new Account(privateKey, service); **方法名** `AppSendTransaction deploy(File contractFile, BigInteger nonce, long quota, int version, int chainId, String value)` + 部署合约。 **参数** + * contractFile - solidity智能合约文件 * nonce - 随机数用于防止重放攻击 * quota - 用户支付矿工的费用 @@ -43,6 +50,7 @@ Account account = new Account(privateKey, service); * value - 交易中原生token的数量 **返回值** + AppSendTransaction **示例** @@ -58,22 +66,26 @@ AppSendTransaction appSendTransaction = account.deploy(new File(path), randomNon **方法名** `Object callContract(String contractAddress, String funcName, BigInteger nonce, long quota, int version, int chainId, String value, Object... args)` + 调用合约方法,根据Abi中对方法的定义判断使用sendRawTransaction还是app_call。 **参数** -* to - 交易将要的发送地址 -* data - 编码后交易数据(abi) -* quota - 用户支付矿工的费用 + +* contractAddress - 合约地址 +* funcName - 合约方法名称 * nonce - 随机数用于防止重放攻击 -* valid_until_block - 超时机制,超过设定块高取消交易 +* quota - 用户支付矿工的费用 * version - 链的版本信息 * chainId - 链Id * value - 交易中原生token的数量 +* args - 合约方法参数 **返回值** + Object **示例** + ``` String privateKey = "{private key}"; CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); diff --git a/docs/jsonrpc.md b/docs/jsonrpc.md index 38e8d1fc..27b729bf 100644 --- a/docs/jsonrpc.md +++ b/docs/jsonrpc.md @@ -27,13 +27,16 @@ CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比 ### Build CITAj **方法名** + `CITAj build (CITAjService citaj)` 根据 CITAjService 类型实例化 CITAj。 **参数** + citaj - CITAjService 实例 **返回值** + CITAj 实例 **示例** @@ -44,13 +47,16 @@ CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); ### netPeer **方法名** + `Request netPeer()` 获取当前连接节点数。 **参数** + 无 **返回值** + Request **示例** @@ -63,13 +69,16 @@ BigInteger peerCount = netPeerCount.getQuantity(); ### appMetaData **方法名** + `Request appMetaData(DefaultBlockParameter defaultBlockParameter)` 获取指定块高的元数据。 **参数** + * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** @@ -84,16 +93,20 @@ String genesisTS = result.genesisTimestamp; ### appBlockNumber **方法名** + `Request appBlockNumber()` 获取当前块高度。 **参数** + 无 **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); AppBlockNumber result = service.appBlockNumber().send(); @@ -102,17 +115,22 @@ BigInteger blockNumber = result.getBlockNumber(); ### appGetBalance **方法名** + `Request appGetBalance(String address, DefaultBlockParameter defaultBlockParameter))` + 获取地址余额。 **参数** + * address - 所要查询的地址 * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); string addr = "{hex cita address starting with 0x}"; @@ -124,14 +142,17 @@ BigInteger balance = getBalance.getBalance(); ### appGetAbi **方法名** + `Request appGetAbi(String contractAddress, DefaultBlockParameter defaultBlockParameter)` 获取合约的Abi。 **参数** + * address - 所要查询Abi的合约地址 * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** @@ -146,14 +167,18 @@ String abi = getAbi.getAbi(); ### appGetTransactionCount **方法名** + `Request appGetTransactionCount(String address, DefaultBlockParameter defaultBlockParameter)` + 获取账户发送合约数量。 **参数** + * address - 所要查询的地址 * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** @@ -168,14 +193,18 @@ BigInteger txCount = getTransactionCount.getTransactionCount(); ### appGetCode **方法名** + `Request appGetCode(String address, DefaultBlockParameter defaultBlockParameter)` + 获取合约代码。 **参数** + * address - 所要查询的地址 * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** @@ -190,16 +219,21 @@ Sring code = getCode.getCode(); ### appSendRawTransaction **方法名** + `Request appSendRawTransaction(String signedTransactionData)` + 向区块链节点发送序列化交易。 **参数** + * signedTransaction - 经过签名的交易数据 **返回值** + Request **示例** + ``` //create a signed transaction Transaction tx = Transaction.createContractTransaction(BigInteger.valueOf(nonce), this.config.getQuota(), this.currentHeight + 88, 0, chainId, value, this.config.getCode()); @@ -216,14 +250,18 @@ String hash = sendTransaction.getHash(); ### appCall **方法名** + `Request appCall(Call call, DefaultBlockParameter defaultBlockParameter)` + 调用合约接口。 **参数** + * call - 合约方法的call的封装 * defaultBlockParameter - 块高度的接口:数字或者关键字 **返回值** + Request **示例** @@ -237,14 +275,18 @@ String result = call.getValue(); ### appGetBlockByHash **方法名** + `Request appGetBlockByHash(String blockHash, boolean returnFullTransactionObjects)` + 根据块的哈希值查询块信息。 **参数** + * blockHash - 块高度的接口:数字或者关键字 * returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) **返回值** + Request **示例** @@ -257,14 +299,18 @@ AppBlock appBlock = service.appGetBlockByHash(blockHash, false).send(); ### appGetBlockByNumber **方法名** + `Request appGetBlockByNumber(DefaultBlockParameter defaultBlockParameter, boolean returnFullTransactionObjects)` + 根据块高度查询块信息。 **参数** + * defaultBlockParameter - 块高度的接口:数字或者关键字 * returnFullTransactionObjects - 是否返回交易信息 (True: 返回详细交易列表| False: 只返回交易hash) **返回值** + Request **示例** @@ -277,13 +323,17 @@ AppBlock appBlock = service.appGetBlockByHash(DefaultBlockParameter.valueOf("lat ### appGetTransactionByHash **方法名** + `Request appGetTransactionByHash(String transactionHash)` + 根据哈希查询交易信息。 **参数** + * transactionHash - 交易哈希 **返回值** + Request **示例** @@ -295,13 +345,16 @@ AppTransaction responseTx = service.appGetTransactionByHash(txHash).send(); ### appGetTransactionReceipt **方法名** + `Request appGetTransactionReceipt(String transactionHash)` 根据交易哈希查询交易回执。 **参数** + * transactionHash - 交易哈希 **返回值** + Request **示例** @@ -314,16 +367,21 @@ AppGetTransactionReceipt txReceipt = service.appGetTransactionReceipt(txHash).se ### appNewBlockFilter **方法名** + `Request appNewBlockFilter()` + 创建一个新的块过滤器,当有新的块写入时通知。 **参数** + 无 **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); AppFilter appFilter = service.appNewBlockFilter().send(); @@ -333,13 +391,16 @@ BigInteger filterId = appFilter.getFilterId(); ### appBlockHashObservable **方法名** + `Observable appBlockHashObservable()` 新建一个Block Filter来监听新增块的哈希,返回一个Observable,可以用交互的形式来监听块高的变化。 **参数** + 无 **返回值** + Observable **示例** @@ -347,24 +408,29 @@ Observable CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); Observable blockFitlerObservable = service.appBlockHashObservable(); AppLog logs = service.appGetFilterLogs(filterId).send(); - blockFitlerObservable.subscribe(block -> { - System.out.println(block.toString()); - }); +blockFitlerObservable.subscribe(block -> { + System.out.println(block.toString()); +}); ``` ### appNewFilter **方法名** + `Request appNewFilter(com.cryptape.cita.protocol.core.methods.request.AppFilter appFilter)` + 创建一个新的Event过滤器以用来监听合约中的Event。 **参数** + * appFilter - 针对于 CITA 智能合约event的过滤器(定义在Request中的appFilter) **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); com.cryptape.cita.protocol.core.methods.request.AppFilter appFilter = new AppFilter(fromBlock, toBlock, addresses); @@ -375,16 +441,21 @@ BigInteger filterId = appFilter.getFilterId(); ### appUninstallFilter **方法名** + `Request appUninstallFilter(BigInteger filterId)` + 移除已部署的过滤器。 **参数** + * filterId - 过滤器Id **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); BigInteger filterId = {your filter Id }; @@ -394,16 +465,21 @@ AppUninstallFilter uninstallFilter = service.appUninstallFilter(filterId).send() ### appGetFilterChanges **方法名** + `Request appGetFilterChanges(BigInteger filterId)` + 根据过滤器Id查询log,返回上一次查询之后的所有log。 **参数** + * filterId - 过滤器Id **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); BigInteger filterId = {your filter Id }; @@ -414,16 +490,21 @@ List results = logs.getLogs(); ### appGetFilterLogs **方法名** + `Request appGetFilterLogs(BigInteger filterId)` + 根据过滤器Id查询log,返回符合输入filter Id的所有log。 **参数** + * filterId - 过滤器Id **返回值** + Request **示例** + ``` CITAj service = CITAj.build(new HttpService("http://127.0.0.1")); BigInteger filterId = {your filter Id }; @@ -434,26 +515,30 @@ List results = logs.getLogs(); ### appLogObservable **方法名** + `Observable appLogObservable(AppFilter appFilter)` + 根据AppFilter来安装一个新的Filter用以获取历史log和监听新的Log,返回一个Observable以交互的模式监听Log。 **参数** + * AppFilter - 过滤器可以由`appNewFilter`来新建 **返回值** + Observable **示例** ``` Observable appLogObservable = service.appLogObservable(filter); - Observable reponse = appLogObservable.map( - (log) -> { - EventValues eventValues = staticExtractEventParameters(event, (Log)log); - return (String) eventValues.getIndexedValues().get(0).getValue();; - } - ); - - reponse.subscribe(x -> { - System.out.println(x); - }); +Observable reponse = appLogObservable.map( + (log) -> { + EventValues eventValues = staticExtractEventParameters(event, (Log)log); + return (String) eventValues.getIndexedValues().get(0).getValue();; + } +); + +reponse.subscribe(x -> { + System.out.println(x); +}); ``` \ No newline at end of file diff --git a/docs/transaction.md b/docs/transaction.md index 151fcf63..4a45ad89 100644 --- a/docs/transaction.md +++ b/docs/transaction.md @@ -12,10 +12,13 @@ Transction定义在core.request中,用于将交易数据封装并且签名( ### Transaction **方法名** + `Transaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` + 根据参数新建一个交易。 **参数** + * to - 交易将要的发送地址 * nonce - 随机数用于防止重放攻击 * quota - 用户支付矿工的费用 @@ -26,6 +29,7 @@ Transction定义在core.request中,用于将交易数据封装并且签名( * data - 编码后交易数据(abi) **返回值** + Transaction实例 **示例** @@ -44,10 +48,13 @@ Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_ ### createContractTransaction **方法名** + `createContractTransaction(BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String init)` -根据参数新建一个交易。 + +根据参数新建一个部署合约的交易。 **参数** + * nonce - 随机数用于防止重放攻击 * quota - 用户支付矿工的费用 * valid_until_block - 超时机制,超过设定块高取消交易 @@ -57,6 +64,7 @@ Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_ * init - 合约编码后数据(abi) **返回值** + Transaction实例 **示例** @@ -82,10 +90,13 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); ### createFunctionCallTransaction **方法名** + `createFunctionCallTransaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)` -根据参数新建一个交易。 + +根据参数新建一个合约调用的交易。 **参数** + * to - 交易将要的发送地址 * nonce - 随机数用于防止重放攻击 * quota - 用户支付矿工的费用 @@ -96,9 +107,11 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); * data - 编码后交易数据(abi) **返回值** + Transaction实例 **示例** + ``` //create new CITAj service CITAj service = CITAj.build(new HttpService("127.0.0.1")); @@ -121,6 +134,7 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); ### TransactionManager **方法名** + `TransactionManager(CITAj citaj, Credentials credentials)` **参数** @@ -129,6 +143,7 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx); * credentials - 发起交易账户的credential **返回值** + TransactionManager实例 **示例** @@ -141,7 +156,9 @@ TransactionManager transactionManager = new TransactionManager(service, credenti ### sendTransaction **方法名** + `AppSendTransaction sendTransaction(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` + 通过TransactionManager发送交易。 **参数** @@ -156,9 +173,11 @@ TransactionManager transactionManager = new TransactionManager(service, credenti * value - 交易中原生token的数量 **返回值** + AppSendTransaction **示例** + ``` CitaTransactionManager transactionManager = new CitaTransactionManager(service, credentials); String to = "{address to which the contract is sent}"; @@ -175,10 +194,12 @@ AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(t ### sendTransactionAsync **方法名** + `Flowable sendTransactionAsync(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)` 通过TransactionManager发送交易。 **参数** + * to - 交易将要的发送地址 * data - 编码后交易数据(abi) * quota - 用户支付矿工的费用 @@ -189,9 +210,11 @@ AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(t * value - 交易中原生token的数量 **返回值** + AppSendTransaction **示例** + ``` TransactionManager transactionManager = new TransactionManager(service, credentials); String to = "{address to which the contract is sent}";