use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiTopicUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
if (!spec.registry().hasTopicMeta(topic)) {
return spec.fees().maxFeeTinyBars();
} else {
/* Lookup topic metadata saved during creation. */
long oldExpiry = spec.registry().getTopicExpiry(topic);
ConsensusCreateTopicTransactionBody oldMeta = spec.registry().getTopicMeta(topic);
/* Computed the increase in RBS due to this update. */
long tentativeRbsIncrease = 0;
try {
TransactionBody updateTxn = CommonUtils.extractTransactionBody(txn);
tentativeRbsIncrease = ConsensusServiceFeeBuilder.getUpdateTopicRbsIncrease(updateTxn.getTransactionID().getTransactionValidStart(), oldMeta.getAdminKey(), oldMeta.getSubmitKey(), oldMeta.getMemo(), oldMeta.hasAutoRenewAccount(), Timestamp.newBuilder().setSeconds(oldExpiry).build(), updateTxn.getConsensusUpdateTopic());
} catch (Exception impossible) {
throw new IllegalStateException(impossible);
}
/* Create a custom activity metrics calculator based on the rbsIncrease. */
final long rbsIncrease = tentativeRbsIncrease;
FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> ConsensusServiceFeeBuilder.getConsensusUpdateTopicFee(txBody, rbsIncrease, sigUsage);
/* Return the net fee. */
return spec.fees().forActivityBasedOp(ConsensusUpdateTopic, metricsCalc, txn, numPayerKeys);
}
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiContractCall method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (details.isPresent()) {
ActionableContractCall actionable = spec.registry().getActionableCall(details.get());
contract = actionable.getContract();
abi = actionable.getDetails().getAbi();
params = actionable.getDetails().getExampleArgs();
} else if (paramsFn.isPresent()) {
params = paramsFn.get().apply(spec);
}
byte[] callData;
if (explicitHexedParams.isPresent()) {
callData = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex).get();
} else {
final var paramsList = Arrays.asList(params);
final var tupleExist = paramsList.stream().anyMatch(p -> p instanceof Tuple || p instanceof Tuple[]);
if (tupleExist) {
callData = encodeParametersWithTuple(params);
} else {
callData = (!abi.equals(FALLBACK_ABI)) ? CallTransaction.Function.fromJsonInterface(abi).encode(params) : new byte[] {};
}
}
ContractCallTransactionBody opBody = spec.txns().<ContractCallTransactionBody, ContractCallTransactionBody.Builder>body(ContractCallTransactionBody.class, builder -> {
if (!tryAsHexedAddressIfLenMatches) {
builder.setContractID(spec.registry().getContractId(contract));
} else {
builder.setContractID(TxnUtils.asContractId(contract, spec));
}
builder.setFunctionParameters(ByteString.copyFrom(callData));
sentTinyHbars.ifPresent(builder::setAmount);
gas.ifPresent(builder::setGas);
});
return b -> b.setContractCall(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiContractDelete method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
ContractDeleteTransactionBody opBody = spec.txns().<ContractDeleteTransactionBody, ContractDeleteTransactionBody.Builder>body(ContractDeleteTransactionBody.class, builder -> {
builder.setContractID(TxnUtils.asContractId(contract, spec));
transferContract.ifPresent(c -> builder.setTransferContractID(TxnUtils.asContractId(c, spec)));
transferAccount.ifPresent(a -> builder.setTransferAccountID(spec.registry().getAccountID(a)));
});
return builder -> builder.setContractDeleteInstance(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec 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.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiContractUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
Timestamp newExpiry = TxnFactory.expiryGiven(newExpirySecs.orElse(spec.setup().defaultExpirationSecs()));
Timestamp oldExpiry = TxnUtils.currContractExpiry(contract, spec);
final Timestamp expiry = TxnUtils.inConsensusOrder(oldExpiry, newExpiry) ? newExpiry : oldExpiry;
FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> scFees.getContractUpdateTxFeeMatrices(txBody, expiry, sigUsage);
return spec.fees().forActivityBasedOp(HederaFunctionality.ContractUpdate, metricsCalc, txn, numPayerKeys);
}
Aggregations