CITA文档中,对于交易首先进行了建立:
long currentHeight = currentBlockNumber();
long validUntilBlock = currentHeight + 80;
Random random = new Random(System.currentTimeMillis());
String nonce = String.valueOf(Math.abs(random.nextLong()));
long quota = 1000000;
Transaction tx = Transaction.createContractTransaction(nonce, quota, validUntilBlock, contractCode);
然后对交易进行了签名:
String rawTx = tx.sign(privateKey);
//TODO,第一个问题,我想获取此时tx的hash值,要通过调用sdk中哪个方法可以获取到?
CITAj service = CITAj.build(new HttpService(ipAddr + ":" + port));
AppSendTransaction result = service.appSendRawTransaction(rawTx).send();
第二个问题,若第一个问题能获取到hash,这个hash和下面代码中链上及时返回的txHash是否一致?
//得到回执和回执中的合约部署地址
String txHash = result.getSendTransactionResult().getHash();
TransactionReceipt txReceipt = service.appGetTransactionReceipt(txHash).send().getTransactionReceipt();
String contractAddress = txReceipt.getContractAddress();
//对交易签名并且发送
Transaction tx = Transaction.createFunctionCallTransaction(contractAddress, nonce, quota, validUntilBlock, functionCallData);
String rawTx = tx.sign(privateKey);
String txHash = service.appSendRawTransaction(rawTx).send().getSendTransactionResult().getHash();