Search in sources :

Example 1 with TransactionRecord

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();
}
Also used : SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 2 with TransactionRecord

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();
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) RequestBuilder.getTransactionReceipt(com.hederahashgraph.builder.RequestBuilder.getTransactionReceipt) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ContractID(com.hederahashgraph.api.proto.java.ContractID) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RequestBuilder.getTransactionRecord(com.hederahashgraph.builder.RequestBuilder.getTransactionRecord) HederaAccountCustomizer(com.hedera.services.ledger.accounts.HederaAccountCustomizer)

Example 3 with TransactionRecord

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);
    }
}
Also used : ContractGetRecordsQuery(com.hederahashgraph.api.proto.java.ContractGetRecordsQuery) Query(com.hederahashgraph.api.proto.java.Query) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 4 with TransactionRecord

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)!");
    }
}
Also used : CharSource(com.google.common.io.CharSource) ByteSource(com.google.common.io.ByteSource) File(java.io.File) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException)

Example 5 with TransactionRecord

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);
    }
}
Also used : Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountRecordsQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountRecordsQuery) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Aggregations

TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)107 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)86 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)84 Transaction (com.hederahashgraph.api.proto.java.Transaction)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)74 Test (org.junit.jupiter.api.Test)69 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)30 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)30 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)28 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)26 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)26 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)26 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)23 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)19 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)19 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)19 Entity (com.hedera.mirror.common.domain.entity.Entity)17 EnumSource (org.junit.jupiter.params.provider.EnumSource)13