use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiTokenUnpause method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(final HapiApiSpec spec) throws Throwable {
var tId = TxnUtils.asTokenId(token, spec);
TokenUnpauseTransactionBody opBody = spec.txns().<TokenUnpauseTransactionBody, TokenUnpauseTransactionBody.Builder>body(TokenUnpauseTransactionBody.class, b -> {
b.setToken(tId);
});
return b -> b.setTokenUnpause(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiTokenUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final TokenInfo info = HapiTokenFeeScheduleUpdate.lookupInfo(spec, token, log, loggingOff);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
var estimate = TokenUpdateUsage.newEstimate(_txn, suFrom(svo));
estimate.givenCurrentExpiry(info.getExpiry().getSeconds()).givenCurrentMemo(info.getMemo()).givenCurrentName(info.getName()).givenCurrentSymbol(info.getSymbol());
if (info.hasFreezeKey()) {
estimate.givenCurrentFreezeKey(Optional.of(info.getFreezeKey()));
}
if (info.hasAdminKey()) {
estimate.givenCurrentAdminKey(Optional.of(info.getAdminKey()));
}
if (info.hasSupplyKey()) {
estimate.givenCurrentSupplyKey(Optional.of(info.getSupplyKey()));
}
if (info.hasKycKey()) {
estimate.givenCurrentKycKey(Optional.of(info.getKycKey()));
}
if (info.hasWipeKey()) {
estimate.givenCurrentWipeKey(Optional.of(info.getWipeKey()));
}
if (info.hasFeeScheduleKey()) {
estimate.givenCurrentFeeScheduleKey(Optional.of(info.getFeeScheduleKey()));
}
if (info.hasPauseKey()) {
estimate.givenCurrentPauseKey(Optional.of(info.getPauseKey()));
}
if (info.hasAutoRenewAccount()) {
estimate.givenCurrentlyUsingAutoRenewAccount();
}
return estimate.get();
};
return spec.fees().forActivityBasedOp(HederaFunctionality.TokenUpdate, metricsCalc, txn, numPayerKeys);
} catch (Throwable t) {
log.warn("Couldn't estimate usage", t);
return HapiApiSuite.ONE_HBAR;
}
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiTokenUpdate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
var id = TxnUtils.asTokenId(token, spec);
if (newSymbolFn.isPresent()) {
newSymbol = Optional.of(newSymbolFn.get().apply(spec));
}
if (newNameFn.isPresent()) {
newName = Optional.of(newNameFn.get().apply(spec));
}
TokenUpdateTransactionBody opBody = spec.txns().<TokenUpdateTransactionBody, TokenUpdateTransactionBody.Builder>body(TokenUpdateTransactionBody.class, b -> {
b.setToken(id);
newSymbol.ifPresent(b::setSymbol);
newName.ifPresent(b::setName);
newMemo.ifPresent(s -> b.setMemo(StringValue.newBuilder().setValue(s).build()));
if (useImproperEmptyKey) {
b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
} else if (useEmptyAdminKeyList) {
b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
} else {
newAdminKey.ifPresent(a -> b.setAdminKey(spec.registry().getKey(a)));
}
newTreasury.ifPresent(a -> b.setTreasury(spec.registry().getAccountID(a)));
newSupplyKey.ifPresent(k -> b.setSupplyKey(spec.registry().getKey(k)));
newSupplyKeySupplier.ifPresent(s -> b.setSupplyKey(s.get()));
newWipeKey.ifPresent(k -> b.setWipeKey(spec.registry().getKey(k)));
newKycKey.ifPresent(k -> b.setKycKey(spec.registry().getKey(k)));
if (useInvalidFeeScheduleKey) {
b.setFeeScheduleKey(TxnUtils.EMPTY_THRESHOLD_KEY);
} else {
newFeeScheduleKey.ifPresent(k -> b.setFeeScheduleKey(spec.registry().getKey(k)));
}
newFreezeKey.ifPresent(k -> b.setFreezeKey(spec.registry().getKey(k)));
newPauseKey.ifPresent(k -> b.setPauseKey(spec.registry().getKey(k)));
if (autoRenewAccount.isPresent()) {
var autoRenewId = TxnUtils.asId(autoRenewAccount.get(), spec);
b.setAutoRenewAccount(autoRenewId);
}
expiry.ifPresent(t -> b.setExpiry(Timestamp.newBuilder().setSeconds(t).build()));
autoRenewPeriod.ifPresent(secs -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(secs).build()));
});
return b -> b.setTokenUpdate(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiSysDelete method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (file.isPresent() && contract.isPresent()) {
Assertions.fail("Ambiguous SystemDelete---both file and contract present!");
}
SystemDeleteTransactionBody opBody = spec.txns().<SystemDeleteTransactionBody, SystemDeleteTransactionBody.Builder>body(SystemDeleteTransactionBody.class, b -> {
newExpiry.ifPresent(l -> b.setExpirationTime(TimestampSeconds.newBuilder().setSeconds(l)));
file.ifPresent(n -> b.setFileID(asFileId(n, spec)));
contract.ifPresent(n -> b.setContractID(asContractId(n, spec)));
});
return b -> b.setSystemDelete(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiTokenAssociate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
var aId = TxnUtils.asId(account, spec);
TokenAssociateTransactionBody opBody = spec.txns().<TokenAssociateTransactionBody, TokenAssociateTransactionBody.Builder>body(TokenAssociateTransactionBody.class, b -> {
b.setAccount(aId);
b.addAllTokens(tokens.stream().map(lit -> TxnUtils.asTokenId(lit, spec)).collect(toList()));
});
return b -> b.setTokenAssociate(opBody);
}
Aggregations