Search in sources :

Example 66 with TransactionRecord

use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.

the class ContractSysDelTransitionLogicTest method followsHappyPathWithOverrides.

@Test
void followsHappyPathWithOverrides() {
    // setup:
    TransactionRecord updateRec = TransactionRecord.newBuilder().setReceipt(TransactionReceipt.newBuilder().setStatus(SUCCESS).build()).build();
    givenValidTxnCtx();
    // and:
    given(delegate.perform(contractSysDelTxn, consensusTime)).willReturn(updateRec);
    // when:
    subject.doStateTransition();
    // then:
    verify(sigImpactHistorian).markEntityChanged(target.getContractNum());
    verify(txnCtx).setStatus(SUCCESS);
}
Also used : TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Test(org.junit.jupiter.api.Test)

Example 67 with TransactionRecord

use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.

the class ContractSysUndelTransitionLogicTest method capturesBadUndelete.

@Test
void capturesBadUndelete() {
    // setup:
    TransactionRecord sysUndelRec = TransactionRecord.newBuilder().setReceipt(TransactionReceipt.newBuilder().setStatus(INVALID_CONTRACT_ID).build()).build();
    givenValidTxnCtx();
    // and:
    given(delegate.perform(contractSysUndelTxn, consensusTime)).willReturn(sysUndelRec);
    // when:
    subject.doStateTransition();
    // then:
    verify(txnCtx).setStatus(INVALID_CONTRACT_ID);
}
Also used : TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Test(org.junit.jupiter.api.Test)

Example 68 with TransactionRecord

use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.

the class HapiGetAccountRecords method checkExpectations.

private void checkExpectations(HapiApiSpec spec, List<TransactionRecord> records) {
    String specExpectationsDir = specScopedDir(spec, expectationsDirPath);
    try {
        String expectationsDir = specExpectationsDir + "/" + account;
        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) {
        log.error("Something amiss with the expected records...", e);
        Assertions.fail("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)

Example 69 with TransactionRecord

use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.

the class HapiGetTxnRecord method submitWith.

@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws InvalidProtocolBufferException {
    Query query = getRecordQuery(spec, payment, false);
    response = spec.clients().getCryptoSvcStub(targetNodeFor(spec), useTls).getTxRecordByTxID(query);
    final TransactionRecord record = response.getTransactionGetRecord().getTransactionRecord();
    if (contractResultAbi != null) {
        exposeRequestedEventsFrom(record);
    }
    observer.ifPresent(obs -> obs.accept(record));
    childRecords = response.getTransactionGetRecord().getChildTransactionRecordsList();
    childRecordsCount.ifPresent(count -> assertEquals(count, childRecords.size()));
    for (var rec : childRecords) {
        spec.registry().saveAccountId(rec.getAlias().toStringUtf8(), rec.getReceipt().getAccountID());
        spec.registry().saveKey(rec.getAlias().toStringUtf8(), Key.parseFrom(rec.getAlias()));
        log.info(spec.logPrefix() + "  Saving alias {} to registry for Account ID {}", rec.getAlias().toStringUtf8(), rec.getReceipt().getAccountID());
    }
    if (verboseLoggingOn) {
        if (format.isPresent()) {
            format.get().accept(record, log);
        } else {
            var fee = record.getTransactionFee();
            var rates = spec.ratesProvider();
            var priceInUsd = sdec(rates.toUsdWithActiveRates(fee), 5);
            log.info(spec.logPrefix() + "Record (charged ${}): {}", priceInUsd, record);
            log.info(spec.logPrefix() + "  And {} child record{}: {}", childRecords.size(), childRecords.size() > 1 ? "s" : "", childRecords);
            log.info("Duplicates: {}", response.getTransactionGetRecord().getDuplicateTransactionRecordsList());
        }
    }
    if (response.getTransactionGetRecord().getHeader().getNodeTransactionPrecheckCode() == OK) {
        priceConsumer.ifPresent(pc -> pc.accept(record.getTransactionFee()));
        debitsConsumer.ifPresent(dc -> dc.accept(asDebits(record.getTransferList())));
    }
    if (registryEntry.isPresent()) {
        spec.registry().saveContractList(registryEntry.get() + "CreateResult", record.getContractCreateResult().getCreatedContractIDsList());
        spec.registry().saveContractList(registryEntry.get() + "CallResult", record.getContractCallResult().getCreatedContractIDsList());
    }
    if (saveTxnRecordToRegistry.isPresent()) {
        spec.registry().saveTransactionRecord(saveTxnRecordToRegistry.get(), record);
    }
}
Also used : TransactionGetRecordQuery(com.hederahashgraph.api.proto.java.TransactionGetRecordQuery) Query(com.hederahashgraph.api.proto.java.Query) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 70 with TransactionRecord

use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-services by hashgraph.

the class RecordParser method parseFrom.

public static RecordFile parseFrom(File file) {
    FileInputStream stream = null;
    List<TxnHistory> histories = new LinkedList<>();
    byte[] prevHash = null;
    if (!file.exists()) {
        throw new IllegalArgumentException("No such file - " + file);
    }
    try {
        stream = new FileInputStream(file);
        DataInputStream dis = new DataInputStream(stream);
        prevHash = new byte[48];
        int record_format_version = dis.readInt();
        int version = dis.readInt();
        log.debug("File '{}' is: ", file);
        log.debug("  -> Record format v{}", record_format_version);
        log.debug("  -> HAPI protocol v{}", version);
        while (dis.available() != 0) {
            try {
                byte typeDelimiter = dis.readByte();
                switch(typeDelimiter) {
                    case TYPE_PREV_HASH:
                        dis.read(prevHash);
                        break;
                    case TYPE_RECORD:
                        int n = dis.readInt();
                        byte[] buffer = new byte[n];
                        dis.readFully(buffer);
                        Transaction signedTxn = Transaction.parseFrom(buffer);
                        n = dis.readInt();
                        buffer = new byte[n];
                        dis.readFully(buffer);
                        TransactionRecord record = TransactionRecord.parseFrom(buffer);
                        histories.add(new TxnHistory(signedTxn, record));
                        break;
                    default:
                        log.warn("Record file '{}' contained unrecognized delimiter |{}|", file, typeDelimiter);
                }
            } catch (Exception e) {
                log.warn("Problem parsing record file '{}'", file);
                break;
            }
        }
        metaDigest.reset();
        contentDigest.reset();
        byte[] everything = Files.readAllBytes(file.toPath());
        byte[] preface = Arrays.copyOfRange(everything, 0, 57);
        byte[] bodyHash = contentDigest.digest(Arrays.copyOfRange(everything, 57, everything.length));
        metaDigest.update(ArrayUtils.addAll(preface, bodyHash));
    } catch (FileNotFoundException e) {
        throw new IllegalStateException();
    } catch (IOException e) {
        log.error("Problem reading record file '{}'!", file, e);
    } catch (Exception e) {
        log.error("Problem parsing record file '{}'!", file, e);
    } finally {
        try {
            if (stream != null) {
                stream.close();
            }
        } catch (IOException ex) {
            log.error("Exception in closing stream for '{}'!", file, ex);
        }
    }
    return new RecordFile(prevHash, metaDigest.digest(), histories);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Transaction(com.hederahashgraph.api.proto.java.Transaction) 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