use of com.jd.blockchain.transaction.TxBuilder in project jdchain-core by blockchain-jd-com.
the class ManagementController method prepareDeActiveTx.
private TransactionRequest prepareDeActiveTx(HashDigest ledgerHash, ParticipantNode node, Properties customProperties) {
int deActiveID = node.getId();
// organize system config properties
Property[] properties = ParticipantContext.context().participantService().createDeactiveProperties(node.getPubKey(), deActiveID, customProperties);
TxBuilder txbuilder = new TxBuilder(ledgerHash, ledgerCryptoSettings.get(ledgerHash).getHashAlgorithm());
// This transaction contains participant state update and settings update two
// ops
txbuilder.states().update(new BlockchainIdentityData(node.getPubKey()), ParticipantNodeState.DEACTIVATED);
txbuilder.consensus().update(properties);
TransactionRequestBuilder reqBuilder = txbuilder.prepareRequest();
reqBuilder.signAsEndpoint(new AsymmetricKeypair(ledgerKeypairs.get(ledgerHash).getPubKey(), ledgerKeypairs.get(ledgerHash).getPrivKey()));
return reqBuilder.buildRequest();
}
use of com.jd.blockchain.transaction.TxBuilder 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;
}
use of com.jd.blockchain.transaction.TxBuilder in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Bft method prepareReconfigTx.
// 在指定的账本上准备一笔reconfig操作交易
private TransactionRequest prepareReconfigTx(String type) {
TransactionRequest reconfigTxRequest;
ParticipantContext context = ParticipantContext.context();
HashDigest ledgerHash = context.ledgerHash();
TxBuilder txbuilder = new TxBuilder(ledgerHash, (Short) context.getProperty(ParticipantContext.HASH_ALG_PROP));
// This transaction contains one reconfig op
txbuilder.consensus().reconfig(type);
TransactionRequestBuilder reqBuilder = txbuilder.prepareRequest();
reqBuilder.signAsEndpoint((AsymmetricKeypair) context.getProperty(ParticipantContext.ENDPOINT_SIGNER_PROP));
reconfigTxRequest = reqBuilder.buildRequest();
DigitalSignature nodeSigner = SignatureUtils.sign((Short) context.getProperty(ParticipantContext.HASH_ALG_PROP), reconfigTxRequest.getTransactionContent(), (AsymmetricKeypair) context.getProperty(ParticipantContext.ENDPOINT_SIGNER_PROP));
((TxRequestMessage) reconfigTxRequest).addNodeSignatures(nodeSigner);
return reconfigTxRequest;
}
Aggregations