use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class ContractCreateTransitionLogicTest method rejectSerializationFailed.
@Test
void rejectSerializationFailed() {
Key key = Key.getDefaultInstance();
var op = ContractCreateTransactionBody.newBuilder().setFileID(bytecodeSrc).setInitialBalance(balance).setGas(gas).setAdminKey(key).setProxyAccountID(proxy);
var txn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setContractCreateInstance(op);
contractCreateTxn = txn.build();
given(accessor.getTxn()).willReturn(contractCreateTxn);
given(txnCtx.accessor()).willReturn(accessor);
given(validator.attemptToDecodeOrThrow(key, SERIALIZATION_FAILED)).willThrow(new InvalidTransactionException(SERIALIZATION_FAILED));
// when:
Exception exception = assertThrows(InvalidTransactionException.class, () -> subject.doStateTransition());
// then:
assertEquals("SERIALIZATION_FAILED", exception.getMessage());
}
use of com.hederahashgraph.api.proto.java.Key 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.Key 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.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class HapiContractUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
Optional<Key> key = newKey.map(spec.registry()::getKey);
ContractUpdateTransactionBody opBody = spec.txns().<ContractUpdateTransactionBody, ContractUpdateTransactionBody.Builder>body(ContractUpdateTransactionBody.class, b -> {
if (contract.length() == HEXED_EVM_ADDRESS_LEN) {
b.setContractID(ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(CommonUtils.unhex(contract))));
} else {
b.setContractID(TxnUtils.asContractId(contract, spec));
}
if (useDeprecatedAdminKey) {
b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
} else if (wipeToThresholdKey) {
b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
} else if (useEmptyAdminKeyList) {
b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
} else {
key.ifPresent(b::setAdminKey);
}
newExpirySecs.ifPresent(t -> b.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
newMemo.ifPresent(s -> {
if (useDeprecatedMemoField) {
b.setMemo(s);
} else {
b.setMemoWrapper(StringValue.newBuilder().setValue(s).build());
}
});
newAutoRenew.ifPresent(autoRenew -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(autoRenew).build()));
bytecode.ifPresent(f -> b.setFileID(TxnUtils.asFileId(bytecode.get(), spec)).build());
});
return builder -> builder.setContractUpdateInstance(opBody);
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class HapiCryptoCreate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
key = key != null ? key : netOf(spec, keyName, keyShape, keyType, Optional.of(this::effectiveKeyGen));
long amount = balanceFn.map(fn -> fn.apply(spec)).orElse(initialBalance.orElse(-1L));
initialBalance = (amount >= 0) ? Optional.of(amount) : Optional.empty();
CryptoCreateTransactionBody opBody = spec.txns().<CryptoCreateTransactionBody, CryptoCreateTransactionBody.Builder>body(CryptoCreateTransactionBody.class, b -> {
b.setKey(key);
proxy.ifPresent(b::setProxyAccountID);
entityMemo.ifPresent(b::setMemo);
sendThresh.ifPresent(b::setSendRecordThreshold);
receiveThresh.ifPresent(b::setReceiveRecordThreshold);
initialBalance.ifPresent(b::setInitialBalance);
receiverSigRequired.ifPresent(b::setReceiverSigRequired);
autoRenewDurationSecs.ifPresent(s -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(s).build()));
maxAutomaticTokenAssociations.ifPresent(b::setMaxAutomaticTokenAssociations);
});
return b -> b.setCryptoCreateAccount(opBody);
}
Aggregations