use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.
the class BaseHederaLedgerTestHelper method commonSetup.
protected void commonSetup() {
sideEffectsTracker = mock(SideEffectsTracker.class);
creator = mock(ExpiringCreations.class);
historian = mock(AccountRecordsHistorian.class);
ids = new EntityIdSource() {
long nextId = NEXT_ID;
@Override
public TopicID newTopicId(final AccountID sponsor) {
return TopicID.newBuilder().setTopicNum(nextId++).build();
}
@Override
public AccountID newAccountId(AccountID newAccountSponsor) {
return AccountID.newBuilder().setAccountNum(nextId++).build();
}
@Override
public ContractID newContractId(AccountID newContractSponsor) {
return ContractID.newBuilder().setContractNum(nextId++).build();
}
@Override
public FileID newFileId(AccountID newFileSponsor) {
return FileID.newBuilder().setFileNum(nextId++).build();
}
@Override
public TokenID newTokenId(AccountID sponsor) {
return TokenID.newBuilder().setTokenNum(nextId++).build();
}
@Override
public ScheduleID newScheduleId(AccountID sponsor) {
return ScheduleID.newBuilder().setScheduleNum(nextId++).build();
}
@Override
public void reclaimLastId() {
nextId--;
}
@Override
public void reclaimProvisionalIds() {
}
@Override
public void resetProvisionalIds() {
}
};
}
use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemUndelete.
/**
* System account undoes the deletion marker on a smart contract that has been deleted but
* not yet removed.
*
* @param txBody
* API reuest to undelete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract undeletion result
*/
public TransactionRecord systemUndelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemUndeleteTransactionBody op = txBody.getSystemUndelete();
ContractID cid = op.getContractID();
var entity = EntityId.fromGrpcContractId(cid);
TransactionReceipt receipt = getTransactionReceipt(SUCCESS, exchange.activeRates());
long oldExpiry = 0;
try {
if (entityExpiries.containsKey(entity)) {
oldExpiry = entityExpiries.get(entity);
} else {
receipt = getTransactionReceipt(INVALID_FILE_ID, exchange.activeRates());
}
if (oldExpiry > 0) {
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(oldExpiry);
ledger.customizePotentiallyDeleted(asAccount(cid), customizer);
}
if (receipt.getStatus() == SUCCESS) {
try {
receipt = updateDeleteFlag(cid, false);
} catch (Exception e) {
receipt = getTransactionReceipt(FAIL_INVALID, exchange.activeRates());
if (log.isDebugEnabled()) {
log.debug("systemUndelete exception: can't serialize or deserialize! tx= {} {}", txBody, e);
}
}
}
entityExpiries.remove(entity);
} catch (Exception e) {
log.warn("Unhandled exception in SystemUndelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.
the class SmartContractRequestHandler method systemDelete.
/**
* System account deletes any contract. This simply marks the contract as deleted.
*
* @param txBody
* API request to delete the contract
* @param consensusTimestamp
* Platform consensus time
* @return Details of contract deletion result
*/
public TransactionRecord systemDelete(TransactionBody txBody, Instant consensusTimestamp) {
SystemDeleteTransactionBody op = txBody.getSystemDelete();
ContractID cid = op.getContractID();
long newExpiry = op.getExpirationTime().getSeconds();
TransactionReceipt receipt;
receipt = updateDeleteFlag(cid, true);
try {
if (receipt.getStatus().equals(ResponseCodeEnum.SUCCESS)) {
AccountID id = asAccount(cid);
long oldExpiry = ledger.expiry(id);
var entity = EntityId.fromGrpcContractId(cid);
entityExpiries.put(entity, oldExpiry);
HederaAccountCustomizer customizer = new HederaAccountCustomizer().expiry(newExpiry);
ledger.customizePotentiallyDeleted(id, customizer);
}
} catch (Exception e) {
log.warn("Unhandled exception in SystemDelete", e);
log.debug("File System Exception {} tx= {}", () -> e, () -> TextFormat.shortDebugString(op));
receipt = getTransactionReceipt(ResponseCodeEnum.FILE_SYSTEM_EXCEPTION, exchange.activeRates());
}
TransactionRecord.Builder transactionRecord = getTransactionRecord(txBody.getTransactionFee(), txBody.getMemo(), txBody.getTransactionID(), getTimestamp(consensusTimestamp), receipt);
return transactionRecord.build();
}
use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.
the class HapiGetContractBytecode method getContractBytecodeQuery.
private Query getContractBytecodeQuery(HapiApiSpec spec, Transaction payment, boolean costOnly) {
final ContractID resolvedTarget;
if (contract.length() == HEXED_EVM_ADDRESS_LEN) {
resolvedTarget = ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(unhex(contract))).build();
} else {
resolvedTarget = TxnUtils.asContractId(contract, spec);
}
ContractGetBytecodeQuery query = ContractGetBytecodeQuery.newBuilder().setHeader(costOnly ? answerCostHeader(payment) : answerHeader(payment)).setContractID(resolvedTarget).build();
return Query.newBuilder().setContractGetBytecode(query).build();
}
use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.
the class HapiGetContractInfo method readContractID.
private ContractID readContractID(HapiApiSpec spec) {
String specExpectationsDir = specScopedDir(spec, validateDirPath);
try {
String expectationsDir = specExpectationsDir + "/" + contract;
File contractIdFile = new File(expectationsDir + "/contractId.txt");
ByteSource contractIdByteSource = Files.asByteSource(contractIdFile);
ContractID contractID = ContractID.parseFrom(contractIdByteSource.read());
return contractID;
} catch (Exception e) {
log.error("Something wrong with the expected ContractInfo file", e);
return null;
}
}
Aggregations