use of com.hedera.services.bdd.spec.HapiApiSpec 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);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiCryptoDelete method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
AccountID target;
if (referenceType == ReferenceType.REGISTRY_NAME) {
target = TxnUtils.asId(account, spec);
} else {
account = lookUpAccountWithAlias(spec, aliasKeySource);
target = asAccount(account);
}
CryptoDeleteTransactionBody opBody = spec.txns().<CryptoDeleteTransactionBody, CryptoDeleteTransactionBody.Builder>body(CryptoDeleteTransactionBody.class, b -> {
transferAccount.ifPresent(a -> b.setTransferAccountID(spec.registry().getAccountID(a)));
b.setDeleteAccountID(target);
});
return b -> b.setCryptoDelete(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiCryptoUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
try {
updKey = updKeyName.map(spec.registry()::getKey);
} catch (Exception ignore) {
}
AccountID id;
if (referenceType == ReferenceType.REGISTRY_NAME) {
id = TxnUtils.asId(account, spec);
} else {
id = asIdForKeyLookUp(aliasKeySource, spec);
account = asAccountString(id);
}
CryptoUpdateTransactionBody opBody = spec.txns().<CryptoUpdateTransactionBody, CryptoUpdateTransactionBody.Builder>body(CryptoUpdateTransactionBody.class, builder -> {
builder.setAccountIDToUpdate(id);
newProxy.ifPresent(p -> {
var proxyId = TxnUtils.asId(p, spec);
builder.setProxyAccountID(proxyId);
});
updSigRequired.ifPresent(u -> builder.setReceiverSigRequiredWrapper(BoolValue.of(u)));
if (useContractKey) {
builder.setKey(Key.newBuilder().setContractID(HapiPropertySource.asContract("0.0.1234")));
} else {
updKey.ifPresent(builder::setKey);
}
newAutoRenewPeriod.ifPresent(p -> builder.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p)));
entityMemo.ifPresent(m -> builder.setMemo(StringValue.newBuilder().setValue(m).build()));
sendThreshold.ifPresent(v -> builder.setSendRecordThresholdWrapper(UInt64Value.newBuilder().setValue(v).build()));
newExpiry.ifPresent(l -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(l).build()));
newMaxAutomaticAssociations.ifPresent(p -> builder.setMaxAutomaticTokenAssociations(Int32Value.of(p)));
});
return builder -> builder.setCryptoUpdateAccount(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiFileAppend method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (contentsSupplier.isPresent()) {
contents = Optional.of(contentsSupplier.get().get());
} else if (path.isPresent()) {
contents = Optional.of(Files.toByteArray(new File(path.get())));
}
var fid = TxnUtils.asFileId(file, spec);
FileAppendTransactionBody opBody = spec.txns().<FileAppendTransactionBody, FileAppendTransactionBody.Builder>body(FileAppendTransactionBody.class, builder -> {
builder.setFileID(fid);
contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
});
preAppendCb.ifPresent(cb -> cb.accept(fid));
return b -> b.setFileAppend(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiFileCreate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (!immutable) {
generateWaclKey(spec);
}
if (contentsPathFn.isPresent()) {
var loc = contentsPathFn.get().apply(spec);
contents = Optional.of(Files.toByteArray(new File(loc)));
}
FileCreateTransactionBody opBody = spec.txns().<FileCreateTransactionBody, FileCreateTransactionBody.Builder>body(FileCreateTransactionBody.class, builder -> {
if (!immutable) {
builder.setKeys(waclKey.getKeyList());
}
memo.ifPresent(builder::setMemo);
contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
lifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
expiry.ifPresent(t -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
});
return b -> {
expiryUsed.set(opBody.getExpirationTime());
b.setFileCreate(opBody);
};
}
Aggregations