use of com.jd.blockchain.ledger.Operation in project jdchain-core by blockchain-jd-com.
the class TransactionDecorator method initTxContent.
private TransactionContent initTxContent(TransactionContent txContent) {
TxContentBlob txContentBlob = new TxContentBlob(txContent.getLedgerHash());
txContentBlob.setTime(txContent.getTimestamp());
Operation[] operations = txContent.getOperations();
if (operations != null && operations.length > 0) {
for (Operation op : operations) {
Operation opDecorator = initOperation(op);
if (opDecorator != null) {
txContentBlob.addOperation(opDecorator);
}
}
}
return txContentBlob;
}
use of com.jd.blockchain.ledger.Operation in project jdchain-core by blockchain-jd-com.
the class TransactionSetTest method buildTransactionRequest_RandomOperation.
/**
* 创建交易请求;以随机生成的数据作为交易的操作参数;
*
* @param ledgerHash
* @param defCryptoSetting
* @return
*/
private TransactionRequest buildTransactionRequest_RandomOperation(HashDigest ledgerHash, CryptoSetting defCryptoSetting) {
// Build transaction request;
TxBuilder txBuilder = new TxBuilder(ledgerHash, defCryptoSetting.getHashAlgorithm());
Operation[] operations = new Operation[5];
// register user;
BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate();
operations[0] = txBuilder.users().register(userKey.getIdentity());
// register data account;
BlockchainKeypair dataKey = BlockchainKeyGenerator.getInstance().generate();
operations[1] = txBuilder.dataAccounts().register(dataKey.getIdentity());
// set data after registering data account immediately;
operations[2] = txBuilder.dataAccount(dataKey.getAddress()).setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1).getOperation();
// generate random bytes as the bytes of ChainCode to deploy as a smart
// contract;
byte[] chainCode = new byte[128];
rand.nextBytes(chainCode);
BlockchainKeypair contractKey = BlockchainKeyGenerator.getInstance().generate();
operations[3] = txBuilder.contracts().deploy(contractKey.getIdentity(), chainCode);
// invoke smart contract;
operations[4] = txBuilder.contract(contractKey.getAddress()).invoke("test", BytesDataList.singleText("TestContractArgs"));
// build transaction request;
TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest();
BlockchainKeypair sponsorKey = BlockchainKeyGenerator.getInstance().generate();
txReqBuilder.signAsEndpoint(sponsorKey);
BlockchainKeypair gatewayKey = BlockchainKeyGenerator.getInstance().generate();
txReqBuilder.signAsNode(gatewayKey);
TransactionRequest txReq = txReqBuilder.buildRequest();
return txReq;
}
Aggregations