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);
}
}
Aggregations