Search in sources :

Example 1 with TransactionStagedSnapshot

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

the class LedgerTestUtils method generateRandomSnapshot.

public static TransactionStagedSnapshot generateRandomSnapshot() {
    TransactionStagedSnapshot txDataSnapshot = new TransactionStagedSnapshot();
    txDataSnapshot.setAdminAccountHash(generateRandomHash());
    txDataSnapshot.setContractAccountSetHash(generateRandomHash());
    txDataSnapshot.setDataAccountSetHash(generateRandomHash());
    txDataSnapshot.setUserAccountSetHash(generateRandomHash());
    return txDataSnapshot;
}
Also used : TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot)

Example 2 with TransactionStagedSnapshot

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

the class LedgerTransactionDataTest method initLedgerTransactionImpl.

@Before
public void initLedgerTransactionImpl() throws Exception {
    DataContractRegistry.register(LedgerTransaction.class);
    DataContractRegistry.register(LedgerDataSnapshot.class);
    DataContractRegistry.register(HashObject.class);
    DataContractRegistry.register(DataAccountKVSetOperation.class);
    txRequest = initTxRequestMessage(ClassicAlgorithm.SHA256);
    long blockHeight = 9986L;
    TransactionStagedSnapshot snapshot = initTransactionStagedSnapshot();
    data = new TransactionResultData(txRequest.getTransactionHash(), blockHeight, TransactionState.SUCCESS, snapshot, null);
    HashDigest hash = ClassicCryptoService.SHA256.hash("zhangsan".getBytes());
    HashDigest adminAccountHash = ClassicCryptoService.SHA256.hash("lisi".getBytes());
    HashDigest userAccountSetHash = ClassicCryptoService.SHA256.hash("wangwu".getBytes());
    HashDigest dataAccountSetHash = ClassicCryptoService.SHA256.hash("zhaoliu".getBytes());
    HashDigest contractAccountSetHash = ClassicCryptoService.SHA256.hash("sunqi".getBytes());
    snapshot.setAdminAccountHash(adminAccountHash);
    snapshot.setUserAccountSetHash(userAccountSetHash);
    snapshot.setDataAccountSetHash(dataAccountSetHash);
    snapshot.setContractAccountSetHash(contractAccountSetHash);
    ledgerTransactionData = new LedgerTransactionData(txRequest, data);
}
Also used : LedgerTransactionData(com.jd.blockchain.ledger.core.LedgerTransactionData) TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot) HashDigest(com.jd.blockchain.crypto.HashDigest) TransactionResultData(com.jd.blockchain.ledger.core.TransactionResultData) Before(org.junit.Before)

Example 3 with TransactionStagedSnapshot

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

the class TransactionStagedSnapshotTest method initTransactionStagedSnapshot.

@Before
public void initTransactionStagedSnapshot() {
    DataContractRegistry.register(LedgerDataSnapshot.class);
    data = new TransactionStagedSnapshot();
    data.setAdminAccountHash(ClassicCryptoService.SHA256.hash("zhangsan".getBytes()));
    data.setContractAccountSetHash(ClassicCryptoService.SHA256.hash("lisi".getBytes()));
    data.setDataAccountSetHash(ClassicCryptoService.SHA256.hash("wangwu".getBytes()));
    data.setUserAccountSetHash(ClassicCryptoService.SHA256.hash("zhaoliu".getBytes()));
}
Also used : TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot) Before(org.junit.Before)

Example 4 with TransactionStagedSnapshot

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

the class TransactionDecorator method initTransactionStagedSnapshot.

private TransactionStagedSnapshot initTransactionStagedSnapshot(LedgerDataSnapshot ledgerDataSnapshot) {
    TransactionStagedSnapshot transactionStagedSnapshot = new TransactionStagedSnapshot();
    transactionStagedSnapshot.setAdminAccountHash(ledgerDataSnapshot.getAdminAccountHash());
    transactionStagedSnapshot.setUserAccountSetHash(ledgerDataSnapshot.getUserAccountSetHash());
    transactionStagedSnapshot.setContractAccountSetHash(ledgerDataSnapshot.getContractAccountSetHash());
    transactionStagedSnapshot.setDataAccountSetHash(ledgerDataSnapshot.getDataAccountSetHash());
    transactionStagedSnapshot.setSystemEventSetHash(ledgerDataSnapshot.getSystemEventSetHash());
    transactionStagedSnapshot.setUserEventSetHash(ledgerDataSnapshot.getUserEventSetHash());
    return transactionStagedSnapshot;
}
Also used : TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot)

Example 5 with TransactionStagedSnapshot

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

the class LedgerBlockImplTest method testSerialize_LedgerDataSnapshot.

// notice: LedgerBlock interface has more field info than LedgerDataSnapshot
// interface, so cannot deserialize LedgerBlock
// with LedgerDataSnapshot encode
// @Test
// public void testSerialize_LedgerDataSnapshot() throws Exception {
// byte[] serialBytes = BinaryEncodingUtils.encode(data,
// LedgerDataSnapshot.class);
// LedgerDataSnapshot resolvedData = BinaryEncodingUtils.decode(serialBytes,
// null,
// LedgerBlockData.class);
// System.out.println("------Assert start ------");
// assertEquals(resolvedData.getAdminAccountHash(), data.getAdminAccountHash());
// assertEquals(resolvedData.getAdminAccountHash(), data.getAdminAccountHash());
// assertEquals(resolvedData.getContractAccountSetHash(),
// data.getContractAccountSetHash());
// assertEquals(resolvedData.getDataAccountSetHash(),
// data.getDataAccountSetHash());
// assertEquals(resolvedData.getUserAccountSetHash(),
// data.getUserAccountSetHash());
// System.out.println("------Assert OK ------");
// }
@Test
public void testSerialize_LedgerDataSnapshot() throws Exception {
    TransactionStagedSnapshot transactionStagedSnapshot = new TransactionStagedSnapshot();
    HashDigest admin = ClassicCryptoService.SHA256.hash("alice".getBytes());
    HashDigest contract = ClassicCryptoService.SHA256.hash("bob".getBytes());
    HashDigest data = ClassicCryptoService.SHA256.hash("jerry".getBytes());
    HashDigest user = ClassicCryptoService.SHA256.hash("tom".getBytes());
    transactionStagedSnapshot.setAdminAccountHash(admin);
    transactionStagedSnapshot.setContractAccountSetHash(contract);
    transactionStagedSnapshot.setDataAccountSetHash(data);
    transactionStagedSnapshot.setUserAccountSetHash(user);
    byte[] serialBytes = BinaryProtocol.encode(transactionStagedSnapshot, LedgerDataSnapshot.class);
    LedgerDataSnapshot resolvedData = BinaryProtocol.decode(serialBytes);
    // verify start
    assertEquals(resolvedData.getAdminAccountHash(), transactionStagedSnapshot.getAdminAccountHash());
    assertEquals(resolvedData.getContractAccountSetHash(), transactionStagedSnapshot.getContractAccountSetHash());
    assertEquals(resolvedData.getDataAccountSetHash(), transactionStagedSnapshot.getDataAccountSetHash());
    assertEquals(resolvedData.getUserAccountSetHash(), transactionStagedSnapshot.getUserAccountSetHash());
// verify succeed
}
Also used : TransactionStagedSnapshot(com.jd.blockchain.ledger.core.TransactionStagedSnapshot) HashDigest(com.jd.blockchain.crypto.HashDigest) LedgerDataSnapshot(com.jd.blockchain.ledger.LedgerDataSnapshot) Test(org.junit.Test)

Aggregations

TransactionStagedSnapshot (com.jd.blockchain.ledger.core.TransactionStagedSnapshot)8 HashDigest (com.jd.blockchain.crypto.HashDigest)4 TransactionResultData (com.jd.blockchain.ledger.core.TransactionResultData)3 Before (org.junit.Before)2 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)1 CryptoSetting (com.jd.blockchain.ledger.CryptoSetting)1 LedgerDataSnapshot (com.jd.blockchain.ledger.LedgerDataSnapshot)1 LedgerTransaction (com.jd.blockchain.ledger.LedgerTransaction)1 OperationResult (com.jd.blockchain.ledger.OperationResult)1 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)1 TransactionResult (com.jd.blockchain.ledger.TransactionResult)1 TransactionState (com.jd.blockchain.ledger.TransactionState)1 LedgerTransactionData (com.jd.blockchain.ledger.core.LedgerTransactionData)1 TransactionSetEditor (com.jd.blockchain.ledger.core.TransactionSetEditor)1 BufferedKVStorage (com.jd.blockchain.storage.service.utils.BufferedKVStorage)1 MemoryKVStorage (com.jd.blockchain.storage.service.utils.MemoryKVStorage)1 Test (org.junit.Test)1