use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemUndelete.
/**
* System account undoes the deletion marker on a smart contract that has been deleted but
* not yet removed.
*
* @param txBody
* API reuest to undelete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract undeletion result
*/
public TransactionRecord systemUndelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemUndeleteTransactionBody op = txBody.getSystemUndelete();
ContractID cid = op.getContractID();
var entity = EntityId.fromGrpcContractId(cid);
TransactionReceipt receipt = getTransactionReceipt(SUCCESS, exchange.activeRates());
long oldExpiry = 0;
try {
if (entityExpiries.containsKey(entity)) {
oldExpiry = entityExpiries.get(entity);
} else {
receipt = getTransactionReceipt(INVALID_FILE_ID, exchange.activeRates());
}
if (oldExpiry > 0) {
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(oldExpiry);
ledger.customizePotentiallyDeleted(asAccount(cid), customizer);
}
if (receipt.getStatus() == SUCCESS) {
try {
receipt = updateDeleteFlag(cid, false);
} catch (Exception e) {
receipt = getTransactionReceipt(FAIL_INVALID, exchange.activeRates());
if (log.isDebugEnabled()) {
log.debug("systemUndelete exception: can't serialize or deserialize! tx= {} {}", txBody, e);
}
}
}
entityExpiries.remove(entity);
} catch (Exception e) {
log.warn("Unhandled exception in SystemUndelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemDelete.
/**
* System account deletes any contract. This simply marks the contract as deleted.
*
* @param txBody
* API request to delete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract deletion result
*/
public TransactionRecord systemDelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemDeleteTransactionBody op = txBody.getSystemDelete();
ContractID cid = op.getContractID();
long newExpiry = op.getExpirationTime().getSeconds();
TransactionReceipt receipt;
receipt = updateDeleteFlag(cid, true);
try {
if (receipt.getStatus().equals(ResponseCodeEnum.SUCCESS)) {
AccountID id = asAccount(cid);
long oldExpiry = ledger.expiry(id);
var entity = EntityId.fromGrpcContractId(cid);
entityExpiries.put(entity, oldExpiry);
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(newExpiry);
ledger.customizePotentiallyDeleted(id, customizer);
}
} catch (Exception e) {
log.warn("Unhandled exception in SystemDelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(ResponseCodeEnum.FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class HapiGetContractRecords method submitWith.
@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws Throwable {
Query query = getContractRecordsQuery(spec, payment, false);
response = spec.clients().getScSvcStub(targetNodeFor(spec), useTls).getTxRecordByContractID(query);
List<TransactionRecord> records = response.getContractGetRecordsResponse().getRecordsList();
if (verboseLoggingOn) {
if (customLog.isPresent()) {
customLog.get().accept(log, records);
} else {
log.info(records);
}
}
if (snapshotDirPath.isPresent()) {
saveSnapshots(spec, records);
}
if (saveRecordNum.isPresent()) {
spec.registry().saveIntValue(saveRecordNum.get(), records.size());
}
if (expectationsDirPath.isPresent()) {
checkExpectations(spec, records);
}
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class HapiGetContractRecords method checkExpectations.
private void checkExpectations(HapiApiSpec spec, List<TransactionRecord> records) throws Throwable {
String specExpectationsDir = specScopedDir(spec, expectationsDirPath);
try {
String expectationsDir = specExpectationsDir + "/" + contract;
File countFile = new File(expectationsDir + "/n.txt");
CharSource charSource = Files.asCharSource(countFile, Charset.forName("UTF-8"));
int n = Integer.parseInt(charSource.readFirstLine());
Assertions.assertEquals(n, records.size(), "Bad number of records!");
for (int i = 0; i < n; i++) {
File recordFile = new File(expectationsDir + "/record" + i + ".bin");
ByteSource byteSource = Files.asByteSource(recordFile);
TransactionRecord expected = TransactionRecord.parseFrom(byteSource.read());
Assertions.assertEquals(expected, records.get(i), "Wrong record #" + i);
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.error("Something amiss with the expected records...", e);
} else {
log.error("Something amiss with the expected records {}", records);
}
throw new HapiQueryCheckStateException("Impossible to meet expectations (on records)!");
}
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.
the class HapiGetAccountRecords method submitWith.
@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) {
Query query = getRecordsQuery(spec, payment, false);
response = spec.clients().getCryptoSvcStub(targetNodeFor(spec), useTls).getAccountRecords(query);
List<TransactionRecord> records = response.getCryptoGetAccountRecords().getRecordsList();
if (verboseLoggingOn) {
if (customLog.isPresent()) {
customLog.get().accept(log, records);
} else {
log.info(records);
}
}
if (snapshotDirPath.isPresent()) {
saveSnapshots(spec, records);
}
if (expectationsDirPath.isPresent()) {
checkExpectations(spec, records);
}
}
Aggregations