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);
}
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();
}
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;
}
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 ------");
}
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;
}
Aggregations