use of com.hederahashgraph.api.proto.java.ServicesConfigurationList in project hedera-services by hashgraph.
the class HapiFileUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
Optional<Key> wacl = useBadlyEncodedWacl ? Optional.of(badlyEncodedWacl()) : (useEmptyWacl ? Optional.of(emptyWacl()) : newWaclKey.map(spec.registry()::getKey));
if (newContentsPath.isPresent()) {
newContents = Optional.of(ByteString.copyFrom(Files.toByteArray(new File(newContentsPath.get()))));
} else if (contentFn.isPresent()) {
newContents = Optional.of(contentFn.get().apply(spec));
} else if (propOverrides.isPresent() || propDeletions.isPresent()) {
if (propOverrides.isEmpty()) {
propOverrides = Optional.of(Collections.emptyMap());
}
ServicesConfigurationList defaults = readBaseProps(spec);
ServicesConfigurationList.Builder list = ServicesConfigurationList.newBuilder();
Map<String, String> overrides = propOverrides.get();
Map<String, String> defaultPairs = defaults.getNameValueList().stream().collect(Collectors.toMap(Setting::getName, Setting::getValue));
Set<String> keys = new HashSet<>();
defaults.getNameValueList().stream().map(Setting::getName).filter(key -> !propDeletions.orElse(EMPTY_SET).contains(key)).forEach(keys::add);
overrides.keySet().stream().forEach(keys::add);
keys.forEach(key -> {
if (overrides.containsKey(key)) {
list.addNameValue(asSetting(key, overrides.get(key)));
} else {
list.addNameValue(asSetting(key, defaultPairs.get(key)));
}
});
newContents = Optional.of(list.build().toByteString());
}
long nl = -1;
if (expiryExtension.isPresent()) {
try {
var oldExpiry = spec.registry().getTimestamp(file).getSeconds();
nl = oldExpiry - Instant.now().getEpochSecond() + expiryExtension.getAsLong();
} catch (Exception ignore) {
}
} else if (lifetimeSecs.isPresent()) {
nl = lifetimeSecs.get();
}
final OptionalLong newLifetime = (nl == -1) ? OptionalLong.empty() : OptionalLong.of(nl);
var fid = TxnUtils.asFileId(file, spec);
FileUpdateTransactionBody opBody = spec.txns().<FileUpdateTransactionBody, FileUpdateTransactionBody.Builder>body(FileUpdateTransactionBody.class, builder -> {
builder.setFileID(fid);
newMemo.ifPresent(s -> builder.setMemo(StringValue.newBuilder().setValue(s).build()));
wacl.ifPresent(k -> builder.setKeys(k.getKeyList()));
newContents.ifPresent(b -> builder.setContents(b));
newLifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
});
preUpdateCb.ifPresent(cb -> cb.accept(fid));
return builder -> builder.setFileUpdate(opBody);
}
use of com.hederahashgraph.api.proto.java.ServicesConfigurationList in project hedera-services by hashgraph.
the class HapiFileUpdate method readBaseProps.
private ServicesConfigurationList readBaseProps(HapiApiSpec spec) {
if (dropUnmentionedProperties) {
return ServicesConfigurationList.getDefaultInstance();
}
if (!basePropsFile.isPresent()) {
if (!file.equals(HapiApiSuite.API_PERMISSIONS) && !file.equals(HapiApiSuite.APP_PROPERTIES)) {
throw new IllegalStateException("Property overrides make no sense for file '" + file + "'!");
}
int getsRemaining = 10;
var gotFileContents = false;
HapiGetFileContents subOp = null;
while (!gotFileContents) {
try {
var candSubOp = getFileContents(file);
payer.ifPresent(name -> candSubOp.payingWith(payerToUse(name, spec)));
allRunFor(spec, candSubOp);
gotFileContents = true;
subOp = candSubOp;
} catch (Throwable ignore) {
getsRemaining--;
}
if (getsRemaining == 0) {
break;
}
}
if (!gotFileContents) {
Assertions.fail("Unable to use 'overridingProps', couldn't get existing file contents!");
}
try {
byte[] bytes = subOp.getResponse().getFileGetContents().getFileContents().getContents().toByteArray();
ServicesConfigurationList defaults = ServicesConfigurationList.parseFrom(bytes);
return defaults;
} catch (Exception e) {
log.error("No available defaults for " + file + " --- aborting!", e);
throw new IllegalStateException("Property overrides via fileUpdate must have available defaults!");
}
} else {
String defaultsPath = basePropsFile.get();
try {
byte[] bytes = java.nio.file.Files.readAllBytes(new File(defaultsPath).toPath());
ServicesConfigurationList defaults = ServicesConfigurationList.parseFrom(bytes);
return defaults;
} catch (Exception e) {
log.error("No available defaults for " + file + " --- aborting!", e);
throw new IllegalStateException("Property overrides via fileUpdate must have available defaults!");
}
}
}
Aggregations