Search in sources :

Example 1 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class RecordStreamFileParsingTest method setUp.

@BeforeAll
public static void setUp() throws ConstructableRegistryException {
    // this register is needed so that the Hash objects can be de-serialized
    ConstructableRegistry.registerConstructables("com.swirlds.common");
    // this register is needed so that RecordStreamObject can be de-serialized
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(RecordStreamObject.class, RecordStreamObject::new));
    // the following settings are needed for de-serializing Transaction
    SettingsCommon.maxTransactionCountPerEvent = 245760;
    SettingsCommon.maxTransactionBytesPerEvent = 245760;
    SettingsCommon.transactionMaxBytes = 6144;
}
Also used : ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class AccountsReader method from.

public static MerkleMap<EntityNum, MerkleAccount> from(String loc) throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleMap.class, MerkleMap::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    try (MerkleDataInputStream in = new MerkleDataInputStream(Files.newInputStream(Path.of(loc)))) {
        MerkleMap<EntityNum, MerkleAccount> fcm = in.readMerkleTree(Integer.MAX_VALUE);
        return fcm;
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) MerkleDataInputStream(com.swirlds.common.merkle.io.MerkleDataInputStream) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) EntityNum(com.hedera.services.utils.EntityNum) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) MerkleMap(com.swirlds.merkle.map.MerkleMap) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Example 3 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class FcmToJsonUtil method convertStorageToJson.

@Test
void convertStorageToJson() throws Exception {
    String[] round60Locs = { // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n0-storage-round60.fcm",
    "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n1-storage-round60.fcm" // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n2-storage-round60.fcm",
    // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n3-storage-round60.fcm",
    };
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleBlobMeta.class, MerkleBlobMeta::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleOptionalBlob.class, MerkleOptionalBlob::new));
    for (String dumpLoc : round60Locs) {
        System.out.println("Reading " + dumpLoc);
        PojoFs.fromDisk(dumpLoc).asJsonTo(jsonSuffixed(dumpLoc));
    }
}
Also used : MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleBlobMeta(com.hedera.services.state.merkle.MerkleBlobMeta) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 4 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class FcmToJsonUtil method convertAccountsToJson.

@Test
void convertAccountsToJson() throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    for (String dumpLoc : accountsLocs) {
        PojoLedger.fromDisk(dumpLoc).asJsonTo(jsonSuffixed(dumpLoc));
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 5 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class SignedStateBalancesExporterTest method setUp.

@BeforeEach
void setUp() throws ConstructableRegistryException {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    thisNodeAccount = MerkleAccountFactory.newAccount().balance(thisNodeBalance).get();
    anotherNodeAccount = MerkleAccountFactory.newAccount().balance(anotherNodeBalance).get();
    firstNonNodeAccount = MerkleAccountFactory.newAccount().balance(firstNonNodeAccountBalance).get();
    secondNonNodeAccount = MerkleAccountFactory.newAccount().balance(secondNonNodeAccountBalance).tokens(theToken, theDeletedToken, theMissingToken).get();
    deletedAccount = MerkleAccountFactory.newAccount().deleted(true).get();
    accounts.put(fromAccountId(thisNode), thisNodeAccount);
    accounts.put(fromAccountId(anotherNode), anotherNodeAccount);
    accounts.put(fromAccountId(firstNonNode), firstNonNodeAccount);
    accounts.put(fromAccountId(secondNonNode), secondNonNodeAccount);
    accounts.put(fromAccountId(deleted), deletedAccount);
    token = mock(MerkleToken.class);
    given(token.isDeleted()).willReturn(false);
    deletedToken = mock(MerkleToken.class);
    given(deletedToken.isDeleted()).willReturn(true);
    tokens.put(fromTokenId(theToken), token);
    tokens.put(fromTokenId(theDeletedToken), deletedToken);
    tokenRels.put(fromAccountTokenRel(secondNonNode, theToken), new MerkleTokenRelStatus(secondNonNodeTokenBalance, false, true, false));
    tokenRels.put(fromAccountTokenRel(secondNonNode, theDeletedToken), new MerkleTokenRelStatus(secondNonNodeDeletedTokenBalance, false, true, false));
    assurance = mock(DirectoryAssurance.class);
    properties = mock(PropertySource.class);
    given(properties.getLongProperty("ledger.totalTinyBarFloat")).willReturn(ledgerFloat);
    var firstNodeAddress = mock(Address.class);
    given(firstNodeAddress.getMemo()).willReturn("0.0.3");
    var secondNodeAddress = mock(Address.class);
    given(secondNodeAddress.getMemo()).willReturn("0.0.4");
    var book = mock(AddressBook.class);
    given(book.getSize()).willReturn(2);
    given(book.getAddress(0)).willReturn(firstNodeAddress);
    given(book.getAddress(1)).willReturn(secondNodeAddress);
    state = mock(ServicesState.class);
    given(state.getAccountFromNodeId(nodeId)).willReturn(thisNode);
    given(state.tokens()).willReturn(tokens);
    given(state.accounts()).willReturn(accounts);
    given(state.tokenAssociations()).willReturn(tokenRels);
    given(state.addressBook()).willReturn(book);
    signer = mock(UnaryOperator.class);
    given(signer.apply(fileHash)).willReturn(sig);
    systemExits = mock(SystemExits.class);
    subject = new SignedStateBalancesExporter(systemExits, properties, signer, dynamicProperties);
    sigFileWriter = mock(SigFileWriter.class);
    hashReader = mock(FileHashReader.class);
    subject.sigFileWriter = sigFileWriter;
    subject.hashReader = hashReader;
}
Also used : MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) PropertySource(com.hedera.services.context.properties.PropertySource) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) ServicesState(com.hedera.services.ServicesState) SystemExits(com.hedera.services.utils.SystemExits) UnaryOperator(java.util.function.UnaryOperator) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)19 Test (org.junit.jupiter.api.Test)13 SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)9 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 EntityId (com.hedera.services.state.submerkle.EntityId)5 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)4 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)3 MerkleLong (com.swirlds.common.merkle.utility.MerkleLong)3 FCQueue (com.swirlds.fcqueue.FCQueue)3 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)2 EvmFnResult (com.hedera.services.state.submerkle.EvmFnResult)2 TxnId (com.hedera.services.state.submerkle.TxnId)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ServicesState (com.hedera.services.ServicesState)1