use of com.hedera.services.bdd.spec.HapiApiSpec 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.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiScheduleCreate method defaultSigners.
@Override
protected List<Function<HapiApiSpec, Key>> defaultSigners() {
List<Function<HapiApiSpec, Key>> signers = new ArrayList<>(List.of(spec -> spec.registry().getKey(effectivePayer(spec))));
adminKey.ifPresent(k -> signers.add(spec -> spec.registry().getKey(k)));
for (String added : initialSigners) {
signers.add(spec -> spec.registry().getKey(added));
}
return signers;
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiScheduleCreate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
var subOp = scheduled.signedTxnFor(spec);
ScheduleCreateTransactionBody opBody = spec.txns().<ScheduleCreateTransactionBody, ScheduleCreateTransactionBody.Builder>body(ScheduleCreateTransactionBody.class, b -> {
if (scheduleNoFunction) {
b.setScheduledTransactionBody(SchedulableTransactionBody.getDefaultInstance());
} else {
try {
var deserializedTxn = TransactionBody.parseFrom(subOp.getBodyBytes());
scheduledTxn.set(ScheduleUtils.fromOrdinary(deserializedTxn));
b.setScheduledTransactionBody(scheduledTxn.get());
} catch (InvalidProtocolBufferException fatal) {
throw new IllegalStateException("Couldn't deserialize serialized TransactionBody!");
}
}
if (useSentinelKeyListForAdminKey) {
b.setAdminKey(Key.newBuilder().setKeyList(KeyList.getDefaultInstance()));
} else {
adminKey.ifPresent(k -> b.setAdminKey(spec.registry().getKey(k)));
}
entityMemo.ifPresent(b::setMemo);
payerAccountID.ifPresent(a -> {
var payer = TxnUtils.asId(a, spec);
b.setPayerAccountID(payer);
});
});
return b -> b.setScheduleCreate(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiScheduleSign method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
ScheduleSignTransactionBody opBody = spec.txns().<ScheduleSignTransactionBody, ScheduleSignTransactionBody.Builder>body(ScheduleSignTransactionBody.class, b -> {
ScheduleID id;
try {
id = asScheduleId(schedule, spec);
b.setScheduleID(id);
} catch (RegistryNotFound e) {
if (!ignoreMissing) {
throw e;
}
}
});
return b -> b.setScheduleSign(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiScheduleSign method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final ScheduleInfo info = ScheduleFeeUtils.lookupInfo(spec, schedule, loggingOff);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> scheduleOpsUsage.scheduleSignUsage(_txn, suFrom(svo), info.getExpirationTime().getSeconds());
return spec.fees().forActivityBasedOp(HederaFunctionality.ScheduleSign, metricsCalc, txn, numPayerKeys);
} catch (Throwable ignore) {
return HapiApiSuite.ONE_HBAR;
}
}
Aggregations