use of com.hederahashgraph.api.proto.java.ContractCreateTransactionBody in project hedera-services by hashgraph.
the class SmartContractFeeBuilder method getContractCreateTransactionBodySize.
/**
* This method returns total bytes in Contract Create Transaction body
*/
private int getContractCreateTransactionBodySize(TransactionBody txBody) {
/*
* FileID fileID - BASIC_ENTITY_ID_SIZE Key adminKey - calculated value int64 gas - LONG_SIZE uint64
* initialBalance - LONG_SIZE AccountID proxyAccountID - BASIC_ENTITY_ID_SIZE bytes
* constructorParameters - calculated value Duration autoRenewPeriod - (LONG_SIZE + INT_SIZE)
* ShardID shardID - LONG_SIZE RealmID realmID - LONG_SIZE Key newRealmAdminKey - calculated
* value string memo - calculated value
*
*/
ContractCreateTransactionBody contractCreate = txBody.getContractCreateInstance();
int adminKeySize = 0;
int proxyAcctID = 0;
if (contractCreate.hasAdminKey()) {
adminKeySize = getAccountKeyStorageSize(contractCreate.getAdminKey());
}
int newRealmAdminKeySize = 0;
if (contractCreate.hasNewRealmAdminKey()) {
newRealmAdminKeySize = getAccountKeyStorageSize(contractCreate.getNewRealmAdminKey());
}
int constructParamSize = 0;
if (contractCreate.getConstructorParameters() != null) {
constructParamSize = contractCreate.getConstructorParameters().size();
}
if (contractCreate.hasProxyAccountID()) {
proxyAcctID = BASIC_ENTITY_ID_SIZE;
}
int memoSize = 0;
if (contractCreate.getMemo() != null) {
memoSize = contractCreate.getMemoBytes().size();
}
return BASIC_CONTRACT_CREATE_SIZE + adminKeySize + proxyAcctID + constructParamSize + newRealmAdminKeySize + memoSize;
}
use of com.hederahashgraph.api.proto.java.ContractCreateTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method assertContractCreateResult.
private void assertContractCreateResult(ContractCreateTransactionBody transactionBody, TransactionRecord record) {
long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
TransactionReceipt receipt = record.getReceipt();
ContractFunctionResult result = record.getContractCreateResult();
ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getInitialBalance(), ContractResult::getAmount).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId).returns(toBytes(transactionBody.getConstructorParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
if (receipt.getStatus() == ResponseCodeEnum.SUCCESS) {
contractResult.returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId);
}
assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
use of com.hederahashgraph.api.proto.java.ContractCreateTransactionBody in project hedera-services by hashgraph.
the class HapiContractCreate method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (!omitAdminKey && !useDeprecatedAdminKey) {
generateAdminKey(spec);
}
if (bytecodeFileFn.isPresent()) {
bytecodeFile = Optional.of(bytecodeFileFn.get().get());
}
if (!bytecodeFile.isPresent()) {
setBytecodeToDefaultContract(spec);
}
Optional<byte[]> params;
if (explicitHexedParams.isPresent()) {
params = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex);
} else {
params = abi.isPresent() ? Optional.of(CallTransaction.Function.fromJsonInterface(abi.get()).encodeArguments(args.get())) : Optional.empty();
}
FileID bytecodeFileId = TxnUtils.asFileId(bytecodeFile.get(), spec);
ContractCreateTransactionBody opBody = spec.txns().<ContractCreateTransactionBody, ContractCreateTransactionBody.Builder>body(ContractCreateTransactionBody.class, b -> {
if (useDeprecatedAdminKey) {
b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
} else if (!omitAdminKey) {
b.setAdminKey(adminKey);
}
b.setFileID(bytecodeFileId);
autoRenewPeriodSecs.ifPresent(p -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p).build()));
balance.ifPresent(b::setInitialBalance);
memo.ifPresent(b::setMemo);
gas.ifPresent(b::setGas);
proxy.ifPresent(p -> b.setProxyAccountID(asId(p, spec)));
params.ifPresent(bytes -> b.setConstructorParameters(ByteString.copyFrom(bytes)));
});
return b -> b.setContractCreateInstance(opBody);
}
Aggregations