Search in sources :

Example 11 with ContractFunctionResult

use of com.hederahashgraph.api.proto.java.ContractFunctionResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigration method process.

private boolean process(MigrationContractResult contractResult) {
    long consensusTimestamp = contractResult.getConsensusTimestamp();
    try {
        byte[] functionResult = contractResult.getFunctionResult();
        if (functionResult == null || functionResult.length == 0) {
            return false;
        }
        ContractFunctionResult contractFunctionResult = ContractFunctionResult.parseFrom(functionResult);
        Long[] createdContractIds = new Long[contractFunctionResult.getCreatedContractIDsCount()];
        for (int i = 0; i < createdContractIds.length; ++i) {
            createdContractIds[i] = getContractId(contractFunctionResult.getCreatedContractIDs(i));
        }
        contractResult.setBloom(DomainUtils.toBytes(contractFunctionResult.getBloom()));
        contractResult.setCallResult(DomainUtils.toBytes(contractFunctionResult.getContractCallResult()));
        contractResult.setContractId(getContractId(contractFunctionResult.getContractID()));
        contractResult.setCreatedContractIds(createdContractIds);
        contractResult.setErrorMessage(contractFunctionResult.getErrorMessage());
        update(contractResult);
        for (int index = 0; index < contractFunctionResult.getLogInfoCount(); ++index) {
            ContractLoginfo contractLoginfo = contractFunctionResult.getLogInfo(index);
            MigrationContractLog migrationContractLog = new MigrationContractLog();
            migrationContractLog.setBloom(DomainUtils.toBytes(contractLoginfo.getBloom()));
            migrationContractLog.setConsensusTimestamp(consensusTimestamp);
            migrationContractLog.setContractId(getContractId(contractLoginfo.getContractID()));
            migrationContractLog.setData(DomainUtils.toBytes(contractLoginfo.getData()));
            migrationContractLog.setIndex(index);
            migrationContractLog.setTopic0(DomainUtils.bytesToHex(Utility.getTopic(contractLoginfo, 0)));
            migrationContractLog.setTopic1(DomainUtils.bytesToHex(Utility.getTopic(contractLoginfo, 1)));
            migrationContractLog.setTopic2(DomainUtils.bytesToHex(Utility.getTopic(contractLoginfo, 2)));
            migrationContractLog.setTopic3(DomainUtils.bytesToHex(Utility.getTopic(contractLoginfo, 3)));
            insert(migrationContractLog);
        }
        return true;
    } catch (Exception e) {
        log.warn("Unable to parse {} as ContractFunctionResult", consensusTimestamp, e);
    }
    return false;
}
Also used : ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicLong(java.util.concurrent.atomic.AtomicLong) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) IOException(java.io.IOException)

Example 12 with ContractFunctionResult

use of com.hederahashgraph.api.proto.java.ContractFunctionResult in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImplIntegrationTest method contractCallResultOnFailure.

@Test
void contractCallResultOnFailure() {
    RecordItem recordItem = recordItemBuilder.contractCall().record(x -> x.clearContractCallResult()).receipt(r -> r.clearContractID().setStatus(ResponseCodeEnum.CONTRACT_EXECUTION_EXCEPTION)).build();
    ContractFunctionResult contractFunctionResult = recordItem.getRecord().getContractCreateResult();
    contractResultsTest(recordItem, contractFunctionResult);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) RecordStreamFileListener(com.hedera.mirror.importer.parser.record.RecordStreamFileListener) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) TokenType(com.hederahashgraph.api.proto.java.TokenType) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 13 with ContractFunctionResult

use of com.hederahashgraph.api.proto.java.ContractFunctionResult in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImplIntegrationTest method getContractResultOnCreate.

@Test
void getContractResultOnCreate() {
    RecordItem recordItem = recordItemBuilder.contractCreate(CONTRACT_ID).build();
    ContractFunctionResult contractFunctionResult = recordItem.getRecord().getContractCreateResult();
    contractResultsTest(recordItem, contractFunctionResult);
}
Also used : ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 14 with ContractFunctionResult

use of com.hederahashgraph.api.proto.java.ContractFunctionResult in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImplIntegrationTest method contractResultZeroStateChanges.

@Test
void contractResultZeroStateChanges() {
    RecordItem recordItem = recordItemBuilder.contractCreate().record(x -> x.setContractCreateResult(recordItemBuilder.contractFunctionResult(CONTRACT_ID).clearStateChanges())).receipt(r -> r.setContractID(CONTRACT_ID)).build();
    ContractFunctionResult contractFunctionResult = recordItem.getRecord().getContractCreateResult();
    contractResultsTest(recordItem, contractFunctionResult);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) RecordStreamFileListener(com.hedera.mirror.importer.parser.record.RecordStreamFileListener) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) TokenType(com.hederahashgraph.api.proto.java.TokenType) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 15 with ContractFunctionResult

use of com.hederahashgraph.api.proto.java.ContractFunctionResult in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImplIntegrationTest method getContractResultOnTokenMintFT.

@Test
void getContractResultOnTokenMintFT() {
    RecordItem recordItem = recordItemBuilder.tokenMint(TokenType.FUNGIBLE_COMMON).record(x -> x.setContractCallResult(recordItemBuilder.contractFunctionResult(CONTRACT_ID))).build();
    ContractFunctionResult contractFunctionResult = recordItem.getRecord().getContractCallResult();
    contractResultsTest(recordItem, contractFunctionResult);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) RecordStreamFileListener(com.hedera.mirror.importer.parser.record.RecordStreamFileListener) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) TokenType(com.hederahashgraph.api.proto.java.TokenType) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)30 Test (org.junit.jupiter.api.Test)20 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)13 ByteString (com.google.protobuf.ByteString)12 EntityId (com.hedera.mirror.common.domain.entity.EntityId)12 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)12 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)11 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)11 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)11 DomainUtils (com.hedera.mirror.common.util.DomainUtils)11 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)11 ContractLogRepository (com.hedera.mirror.importer.repository.ContractLogRepository)11 ContractStateChangeRepository (com.hedera.mirror.importer.repository.ContractStateChangeRepository)11 ContractID (com.hederahashgraph.api.proto.java.ContractID)11 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)11 TokenType (com.hederahashgraph.api.proto.java.TokenType)11 Collectors (java.util.stream.Collectors)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 ObjectAssert (org.assertj.core.api.ObjectAssert)11