use of com.hedera.services.bdd.spec.transactions.file.HapiFileUpdate in project hedera-services by hashgraph.
the class UtilVerbs method updateLargeFile.
public static HapiSpecOperation updateLargeFile(String payer, String fileName, ByteString byteString, boolean signOnlyWithPayer, OptionalLong tinyBarsToOffer, Consumer<HapiFileUpdate> updateCustomizer, ObjIntConsumer<HapiFileAppend> appendCustomizer) {
return withOpContext((spec, ctxLog) -> {
List<HapiSpecOperation> opsList = new ArrayList<>();
int fileSize = byteString.size();
int position = Math.min(BYTES_4K, fileSize);
HapiFileUpdate updateSubOp = fileUpdate(fileName).contents(byteString.substring(0, position)).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED).noLogging().payingWith(payer);
updateCustomizer.accept(updateSubOp);
if (tinyBarsToOffer.isPresent()) {
updateSubOp = updateSubOp.fee(tinyBarsToOffer.getAsLong());
}
if (signOnlyWithPayer) {
updateSubOp = updateSubOp.signedBy(payer);
}
opsList.add(updateSubOp);
final int bytesLeft = fileSize - position;
final int totalAppendsRequired = bytesLeft / BYTES_4K + Math.min(1, bytesLeft % BYTES_4K);
int numAppends = 0;
while (position < fileSize) {
int newPosition = Math.min(fileSize, position + BYTES_4K);
var appendSubOp = fileAppend(fileName).content(byteString.substring(position, newPosition).toByteArray()).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED).noLogging().payingWith(payer);
appendCustomizer.accept(appendSubOp, totalAppendsRequired - numAppends);
if (tinyBarsToOffer.isPresent()) {
appendSubOp = appendSubOp.fee(tinyBarsToOffer.getAsLong());
}
if (signOnlyWithPayer) {
appendSubOp = appendSubOp.signedBy(payer);
}
opsList.add(appendSubOp);
position = newPosition;
numAppends++;
}
CustomSpecAssert.allRunFor(spec, opsList);
});
}
Aggregations