Search in sources :

Example 16 with TxBuilder

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();
}
Also used : TxBuilder(com.jd.blockchain.transaction.TxBuilder) Property(utils.Property) ServiceEndpoint(com.jd.httpservice.agent.ServiceEndpoint)

Example 17 with TxBuilder

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;
}
Also used : TransactionRequestBuilder(com.jd.blockchain.ledger.TransactionRequestBuilder) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) TxBuilder(com.jd.blockchain.transaction.TxBuilder) ContractEventSendOperation(com.jd.blockchain.ledger.ContractEventSendOperation) HashAlgorithmUpdateOperation(com.jd.blockchain.ledger.HashAlgorithmUpdateOperation) ConsensusReconfigOperation(com.jd.blockchain.ledger.ConsensusReconfigOperation) ParticipantRegisterOperation(com.jd.blockchain.ledger.ParticipantRegisterOperation) DataAccountKVSetOperation(com.jd.blockchain.ledger.DataAccountKVSetOperation) ParticipantStateUpdateOperation(com.jd.blockchain.ledger.ParticipantStateUpdateOperation) UserRegisterOperation(com.jd.blockchain.ledger.UserRegisterOperation) ContractCodeDeployOperation(com.jd.blockchain.ledger.ContractCodeDeployOperation) Operation(com.jd.blockchain.ledger.Operation) DataAccountRegisterOperation(com.jd.blockchain.ledger.DataAccountRegisterOperation) ConsensusSettingsUpdateOperation(com.jd.blockchain.ledger.ConsensusSettingsUpdateOperation) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest)

Example 18 with TxBuilder

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;
}
Also used : HashDigest(com.jd.blockchain.crypto.HashDigest) TxRequestMessage(com.jd.blockchain.transaction.TxRequestMessage) TxBuilder(com.jd.blockchain.transaction.TxBuilder)

Aggregations

TxBuilder (com.jd.blockchain.transaction.TxBuilder)18 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)6 HashDigest (com.jd.blockchain.crypto.HashDigest)5 LedgerDataSet (com.jd.blockchain.ledger.core.LedgerDataSet)5 TransactionBatchProcessor (com.jd.blockchain.ledger.core.TransactionBatchProcessor)5 TransactionBatchResultHandle (com.jd.blockchain.service.TransactionBatchResultHandle)5 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)4 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)4 DefaultOperationHandleRegisteration (com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration)3 ServiceEndpoint (com.jd.httpservice.agent.ServiceEndpoint)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 TxTestContract (test.com.jd.blockchain.ledger.TxTestContract)3 Bytes (utils.Bytes)3 Property (utils.Property)3 LedgerSecurityManager (com.jd.blockchain.ledger.core.LedgerSecurityManager)2 Ignore (org.junit.Ignore)2 TxTestContractImpl (test.com.jd.blockchain.ledger.TxTestContractImpl)2 BlockchainIdentityData (com.jd.blockchain.ledger.BlockchainIdentityData)1 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)1