Search in sources :

Example 6 with Payment

use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.

the class ValidationScenarios method appendToFeesCsv.

private static void appendToFeesCsv(String loc, List<Payment> payments, FeeSnapshotsScenario scenario) {
    List<String> lines = null;
    int numExistingPayments = -1;
    try {
        lines = Files.readAllLines(Paths.get(loc));
        numExistingPayments = lines.size() - 1;
    } catch (IOException e) {
        log.warn("Unable to read fees CSV, skipping it!", e);
        return;
    }
    if (scenario.getIgnoreCostAnswer()) {
        payments = payments.stream().filter(p -> p.reason != Payment.Reason.COST_ANSWER_QUERY_COST).collect(toList());
    }
    if (numExistingPayments != payments.size()) {
        log.error(String.format("Existing CSV has %d payments, scenario resulted in %d payments, skipping!", numExistingPayments, payments.size()));
    }
    int i = 1;
    try (BufferedWriter fout = Files.newBufferedWriter(Paths.get(loc))) {
        fout.write(lines.get(0) + "," + asColumnHeader(scenario.getScheduleDesc()) + "\n");
        for (Payment p : payments) {
            fout.write(String.format("%s,%s\n", lines.get(i++), p.tinyBars));
        }
    } catch (IOException e) {
        log.warn("Unable to create fees CSV, skipping it!", e);
        throw new IllegalStateException(e);
    }
}
Also used : Payment(com.hedera.services.bdd.spec.fees.Payment) Files.readString(java.nio.file.Files.readString) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

Payment (com.hedera.services.bdd.spec.fees.Payment)6 IOException (java.io.IOException)3 File (java.io.File)2 Properties (java.util.Properties)2 ByteSource (com.google.common.io.ByteSource)1 CharSink (com.google.common.io.CharSink)1 ByteString (com.google.protobuf.ByteString)1 HapiQueryPrecheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException)1 TxnUtils.txnToString (com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 BufferedWriter (java.io.BufferedWriter)1 InputStream (java.io.InputStream)1 Files.readString (java.nio.file.Files.readString)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1