Search in sources :

Example 1 with TransactionRequest

use of com.jd.blockchain.ledger.TransactionRequest in project jdchain-core by blockchain-jd-com.

the class TransactionSetEditor method getTransaction.

@Override
public LedgerTransaction getTransaction(long txSeq) {
    TransactionRequest txRequest = loadRequestKv(txSeq);
    if (null == txRequest) {
        return null;
    }
    TransactionResult txResult = loadResultKv(txSeq);
    if (null == txResult) {
        return null;
    }
    return new LedgerTransactionData(txRequest, txResult);
}
Also used : TransactionResult(com.jd.blockchain.ledger.TransactionResult) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest)

Example 2 with TransactionRequest

use of com.jd.blockchain.ledger.TransactionRequest in project jdchain-core by blockchain-jd-com.

the class LedgerEditorTest method testGennesisBlockCreation.

/**
 * 测试创建账本;
 */
@Test
public void testGennesisBlockCreation() {
    LedgerEditor ldgEdt = createLedgerInitEditor();
    LedgerTransactionContext genisisTxCtx = createGenisisTx(ldgEdt, participants);
    LedgerDataSetEditor ldgDS = (LedgerDataSetEditor) genisisTxCtx.getDataset();
    AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair();
    BlockchainKeypair userKP = new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey());
    UserAccount userAccount = ldgDS.getUserAccountSet().register(userKP.getAddress(), userKP.getPubKey());
    userAccount.setProperty("Name", "孙悟空", -1);
    userAccount.setProperty("Age", "10000", -1);
    TransactionResult tx = genisisTxCtx.commit(TransactionState.SUCCESS);
    TransactionRequest genesisTxReq = genisisTxCtx.getTransactionRequest();
    assertEquals(genesisTxReq.getTransactionHash(), tx.getTransactionHash());
    assertEquals(0, tx.getBlockHeight());
    LedgerBlock block = ldgEdt.prepare();
    assertEquals(0, block.getHeight());
    assertNotNull(block.getHash());
    assertNull(block.getLedgerHash());
    assertNull(block.getPreviousHash());
    // 提交数据,写入存储;
    ldgEdt.commit();
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) AsymmetricKeypair(com.jd.blockchain.crypto.AsymmetricKeypair) TransactionResult(com.jd.blockchain.ledger.TransactionResult) LedgerDataSetEditor(com.jd.blockchain.ledger.core.LedgerDataSetEditor) LedgerEditor(com.jd.blockchain.ledger.core.LedgerEditor) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) LedgerTransactionContext(com.jd.blockchain.ledger.core.LedgerTransactionContext) UserAccount(com.jd.blockchain.ledger.core.UserAccount) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest) Test(org.junit.Test)

Example 3 with TransactionRequest

use of com.jd.blockchain.ledger.TransactionRequest in project jdchain-core by blockchain-jd-com.

the class LedgerEditorTest method createGenisisTx.

private LedgerTransactionContext createGenisisTx(LedgerEditor ldgEdt, BlockchainKeypair[] partis) {
    TransactionRequest genesisTxReq = LedgerTestUtils.createLedgerInitTxRequest_SHA256(partis);
    LedgerTransactionContext txCtx = ldgEdt.newTransaction(genesisTxReq);
    return txCtx;
}
Also used : LedgerTransactionContext(com.jd.blockchain.ledger.core.LedgerTransactionContext) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest)

Example 4 with TransactionRequest

use of com.jd.blockchain.ledger.TransactionRequest in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionDataTest method testSerialize_TransactionRequest.

@Test
public void testSerialize_TransactionRequest() throws Exception {
    byte[] serialBytes = BinaryProtocol.encode(txRequest, TransactionRequest.class);
    TransactionRequest resolvedData = BinaryProtocol.decode(serialBytes);
    System.out.println("------Assert start ------");
    Assert_TransactionRequest(resolvedData);
    System.out.println("------Assert OK ------");
}
Also used : TransactionRequest(com.jd.blockchain.ledger.TransactionRequest) Test(org.junit.Test)

Example 5 with TransactionRequest

use of com.jd.blockchain.ledger.TransactionRequest in project jdchain-core by blockchain-jd-com.

the class BlockFullRollBackTest method initLedger.

private HashDigest initLedger(MemoryKVStorage storage, BlockchainKeypair... partiKeys) {
    // 创建初始化配置;
    LedgerInitSetting initSetting = LedgerTestUtils.createLedgerInitSetting(partiKeys);
    // 创建账本;
    LedgerEditor ldgEdt = LedgerTransactionalEditor.createEditor(initSetting, LEDGER_KEY_PREFIX, storage, storage, LedgerDataStructure.MERKLE_TREE);
    TransactionRequest genesisTxReq = LedgerTestUtils.createLedgerInitTxRequest_SHA256(partiKeys);
    LedgerTransactionContext genisisTxCtx = ldgEdt.newTransaction(genesisTxReq);
    LedgerDataSetEditor ldgDS = (LedgerDataSetEditor) genisisTxCtx.getDataset();
    for (int i = 0; i < partiKeys.length; i++) {
        UserAccount userAccount = ldgDS.getUserAccountSet().register(partiKeys[i].getAddress(), partiKeys[i].getPubKey());
        userAccount.setProperty("Name", "参与方-" + i, -1);
        userAccount.setProperty("Share", "" + (10 + i), -1);
    }
    TransactionResult tx = genisisTxCtx.commit(TransactionState.SUCCESS);
    assertEquals(genesisTxReq.getTransactionHash(), tx.getTransactionHash());
    assertEquals(0, tx.getBlockHeight());
    LedgerBlock block = ldgEdt.prepare();
    assertEquals(0, block.getHeight());
    assertNotNull(block.getHash());
    assertNull(block.getPreviousHash());
    // 创世区块的账本哈希为 null;
    assertNull(block.getLedgerHash());
    assertNotNull(block.getHash());
    // 提交数据,写入存储;
    ldgEdt.commit();
    HashDigest ledgerHash = block.getHash();
    return ledgerHash;
}
Also used : LedgerBlock(com.jd.blockchain.ledger.LedgerBlock) TransactionResult(com.jd.blockchain.ledger.TransactionResult) LedgerDataSetEditor(com.jd.blockchain.ledger.core.LedgerDataSetEditor) HashDigest(com.jd.blockchain.crypto.HashDigest) LedgerInitSetting(com.jd.blockchain.ledger.LedgerInitSetting) LedgerEditor(com.jd.blockchain.ledger.core.LedgerEditor) LedgerTransactionContext(com.jd.blockchain.ledger.core.LedgerTransactionContext) UserAccount(com.jd.blockchain.ledger.core.UserAccount) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest)

Aggregations

TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)20 HashDigest (com.jd.blockchain.crypto.HashDigest)10 Test (org.junit.Test)10 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)9 TransactionResult (com.jd.blockchain.ledger.TransactionResult)9 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)9 LedgerBlock (com.jd.blockchain.ledger.LedgerBlock)8 LedgerEditor (com.jd.blockchain.ledger.core.LedgerEditor)8 TransactionResponse (com.jd.blockchain.ledger.TransactionResponse)6 LedgerManager (com.jd.blockchain.ledger.core.LedgerManager)6 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)6 UserAccount (com.jd.blockchain.ledger.core.UserAccount)6 DefaultOperationHandleRegisteration (com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration)5 LedgerDataSet (com.jd.blockchain.ledger.core.LedgerDataSet)5 LedgerSecurityManager (com.jd.blockchain.ledger.core.LedgerSecurityManager)5 OperationHandleRegisteration (com.jd.blockchain.ledger.core.OperationHandleRegisteration)5 TransactionBatchProcessor (com.jd.blockchain.ledger.core.TransactionBatchProcessor)5 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)4 LedgerTransactionContext (com.jd.blockchain.ledger.core.LedgerTransactionContext)4 TransactionSetEditor (com.jd.blockchain.ledger.core.TransactionSetEditor)4