use of com.hederahashgraph.api.proto.java.ContractLoginfo in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method assertContractResult.
private void assertContractResult(long consensusTimestamp, ContractFunctionResult result, List<ContractLoginfo> logInfoList, ObjectAssert<ContractResult> contractResult, List<com.hederahashgraph.api.proto.java.ContractStateChange> stateChanges) {
List<Long> createdContractIds = result.getCreatedContractIDsList().stream().map(ContractID::getContractNum).collect(Collectors.toList());
contractResult.returns(result.getBloom().toByteArray(), ContractResult::getBloom).returns(result.getContractCallResult().toByteArray(), ContractResult::getCallResult).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(createdContractIds, ContractResult::getCreatedContractIds).returns(result.getErrorMessage(), ContractResult::getErrorMessage).returns(result.toByteArray(), ContractResult::getFunctionResult).returns(result.getGasUsed(), ContractResult::getGasUsed);
for (int i = 0; i < logInfoList.size(); i++) {
int index = i;
ContractLoginfo logInfo = logInfoList.get(i);
assertThat(contractLogRepository.findById(new ContractLog.Id(consensusTimestamp, index))).isPresent().get().returns(logInfo.getBloom().toByteArray(), ContractLog::getBloom).returns(consensusTimestamp, ContractLog::getConsensusTimestamp).returns(EntityId.of(logInfo.getContractID()), ContractLog::getContractId).returns(logInfo.getData().toByteArray(), ContractLog::getData).returns(index, ContractLog::getIndex).returns(EntityId.of(result.getContractID()), ContractLog::getRootContractId).returns(Utility.getTopic(logInfo, 0), ContractLog::getTopic0).returns(Utility.getTopic(logInfo, 1), ContractLog::getTopic1).returns(Utility.getTopic(logInfo, 2), ContractLog::getTopic2).returns(Utility.getTopic(logInfo, 3), ContractLog::getTopic3);
}
int count = 0;
var contractStateChanges = assertThat(contractStateChangeRepository.findAll());
for (var contractStateChangeInfo : stateChanges) {
EntityId contractId = EntityId.of(contractStateChangeInfo.getContractID());
for (var storageChange : contractStateChangeInfo.getStorageChangesList()) {
byte[] slot = DomainUtils.toBytes(storageChange.getSlot());
byte[] valueWritten = storageChange.hasValueWritten() ? storageChange.getValueWritten().getValue().toByteArray() : null;
contractStateChanges.filteredOn(c -> c.getConsensusTimestamp() == consensusTimestamp && c.getContractId() == contractId.getId() && Arrays.equals(c.getSlot(), slot)).hasSize(1).first().returns(storageChange.getValueRead().toByteArray(), ContractStateChange::getValueRead).returns(valueWritten, ContractStateChange::getValueWritten);
++count;
}
}
contractStateChanges.hasSize(count);
}
use of com.hederahashgraph.api.proto.java.ContractLoginfo 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;
}
use of com.hederahashgraph.api.proto.java.ContractLoginfo in project hedera-mirror-node by hashgraph.
the class ContractResultMigrationTest method migrate.
@SuppressWarnings("deprecation")
@Test
void migrate() throws Exception {
ContractFunctionResult.Builder functionResult = contractFunctionResult();
MigrationContractResult contractResult = contractResult(functionResult);
insert(contractResult);
contractResultMigration.doMigrate();
ContractLoginfo loginfo = functionResult.getLogInfo(0);
assertThat(getContractLogs()).hasSize(1).first().returns(loginfo.getBloom().toByteArray(), MigrationContractLog::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractLog::getConsensusTimestamp).returns(loginfo.getContractID().getContractNum(), MigrationContractLog::getContractId).returns(0, MigrationContractLog::getIndex).returns(Hex.encodeHexString(loginfo.getTopic(0).toByteArray()), MigrationContractLog::getTopic0).returns(Hex.encodeHexString(loginfo.getTopic(1).toByteArray()), MigrationContractLog::getTopic1).returns(Hex.encodeHexString(loginfo.getTopic(2).toByteArray()), MigrationContractLog::getTopic2).returns(Hex.encodeHexString(loginfo.getTopic(3).toByteArray()), MigrationContractLog::getTopic3);
assertThat(getContractResults()).hasSize(1).first().returns(functionResult.getBloom().toByteArray(), MigrationContractResult::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractResult::getConsensusTimestamp).returns(functionResult.getContractCallResult().toByteArray(), MigrationContractResult::getCallResult).returns(functionResult.getContractID().getContractNum(), MigrationContractResult::getContractId).returns(functionResult.getErrorMessage(), MigrationContractResult::getErrorMessage).returns(functionResult.getCreatedContractIDsList().stream().map(EntityId::of).map(EntityId::getId).toArray(Long[]::new), MigrationContractResult::getCreatedContractIds);
}
use of com.hederahashgraph.api.proto.java.ContractLoginfo in project hedera-mirror-node by hashgraph.
the class ContractResultServiceImpl method processContractLogs.
private void processContractLogs(ContractFunctionResult functionResult, ContractResult contractResult) {
for (int index = 0; index < functionResult.getLogInfoCount(); ++index) {
ContractLoginfo contractLoginfo = functionResult.getLogInfo(index);
ContractLog contractLog = new ContractLog();
contractLog.setBloom(DomainUtils.toBytes(contractLoginfo.getBloom()));
contractLog.setConsensusTimestamp(contractResult.getConsensusTimestamp());
contractLog.setContractId(lookup(contractResult.getContractId(), contractLoginfo.getContractID()));
contractLog.setData(DomainUtils.toBytes(contractLoginfo.getData()));
contractLog.setIndex(index);
contractLog.setRootContractId(contractResult.getContractId());
contractLog.setPayerAccountId(contractResult.getPayerAccountId());
contractLog.setTopic0(Utility.getTopic(contractLoginfo, 0));
contractLog.setTopic1(Utility.getTopic(contractLoginfo, 1));
contractLog.setTopic2(Utility.getTopic(contractLoginfo, 2));
contractLog.setTopic3(Utility.getTopic(contractLoginfo, 3));
entityListener.onContractLog(contractLog);
}
}
use of com.hederahashgraph.api.proto.java.ContractLoginfo in project hedera-mirror-node by hashgraph.
the class UtilityTest method getTopic.
@Test
void getTopic() {
ContractLoginfo contractLoginfo = ContractLoginfo.newBuilder().addTopic(ByteString.copyFrom(new byte[] { 0, 0, 0, 0, 0, 0, 1 })).addTopic(ByteString.copyFrom(new byte[] { 0, 127 })).addTopic(ByteString.copyFrom(new byte[] { -1 })).addTopic(ByteString.copyFrom(new byte[] { 0 })).addTopic(ByteString.copyFrom(new byte[] { 0, 0, 0, 0 })).addTopic(ByteString.copyFrom(new byte[0])).build();
assertThat(Utility.getTopic(contractLoginfo, 0)).isEqualTo(new byte[] { 1 });
assertThat(Utility.getTopic(contractLoginfo, 1)).isEqualTo(new byte[] { 127 });
assertThat(Utility.getTopic(contractLoginfo, 2)).isEqualTo(new byte[] { -1 });
assertThat(Utility.getTopic(contractLoginfo, 3)).isEqualTo(new byte[] { 0 });
assertThat(Utility.getTopic(contractLoginfo, 4)).isEqualTo(new byte[] { 0 });
assertThat(Utility.getTopic(contractLoginfo, 5)).isEmpty();
assertThat(Utility.getTopic(contractLoginfo, 999)).isNull();
}
Aggregations