use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class GetAccountInfoAnswer method responseGiven.
@Override
public Response responseGiven(final Query query, final StateView view, final ResponseCodeEnum validity, final long cost) {
final CryptoGetInfoQuery op = query.getCryptoGetInfo();
CryptoGetInfoResponse.Builder response = CryptoGetInfoResponse.newBuilder();
final ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
response.setHeader(header(validity, type, cost));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
} else {
AccountID id = op.getAccountID();
var optionalInfo = view.infoForAccount(id, aliasManager);
if (optionalInfo.isPresent()) {
response.setHeader(answerOnlyHeader(OK));
response.setAccountInfo(optionalInfo.get());
} else {
response.setHeader(answerOnlyHeader(FAIL_INVALID));
}
}
}
return Response.newBuilder().setCryptoGetInfo(response).build();
}
use of com.hederahashgraph.api.proto.java.AccountID 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.AccountID in project hedera-services by hashgraph.
the class AliasResolver method resolveInternal.
private Result resolveInternal(final AliasManager aliasManager, final AccountID idOrAlias, final Consumer<AccountID> resolvingAction) {
AccountID resolvedId = idOrAlias;
var isEvmAddress = false;
var result = Result.KNOWN_ALIAS;
if (isAlias(idOrAlias)) {
final var alias = idOrAlias.getAlias();
if (alias.size() == EntityIdUtils.EVM_ADDRESS_SIZE) {
final var evmAddress = alias.toByteArray();
if (aliasManager.isMirror(evmAddress)) {
offerMirrorId(evmAddress, resolvingAction);
return Result.KNOWN_ALIAS;
} else {
isEvmAddress = true;
}
}
final var resolution = aliasManager.lookupIdBy(alias);
if (resolution != MISSING_NUM) {
resolvedId = resolution.toGrpcAccountId();
} else {
result = netOf(isEvmAddress, alias);
}
resolutions.put(alias, resolution);
}
resolvingAction.accept(resolvedId);
return result;
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class CryptoCreateTransitionLogic method doStateTransition.
@Override
public void doStateTransition() {
try {
TransactionBody cryptoCreateTxn = txnCtx.accessor().getTxn();
AccountID sponsor = cryptoCreateTxn.getTransactionID().getAccountID();
CryptoCreateTransactionBody op = cryptoCreateTxn.getCryptoCreateAccount();
long balance = op.getInitialBalance();
final var created = ledger.create(sponsor, balance, asCustomizer(op));
sigImpactHistorian.markEntityChanged(created.getAccountNum());
txnCtx.setCreated(created);
txnCtx.setStatus(SUCCESS);
} catch (InsufficientFundsException ife) {
txnCtx.setStatus(INSUFFICIENT_PAYER_BALANCE);
} catch (Exception e) {
log.warn("Avoidable exception!", e);
txnCtx.setStatus(FAIL_INVALID);
}
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class TokenUpdateTransitionLogic method transitionFor.
private void transitionFor(TokenUpdateTransactionBody op) {
var id = store.resolve(op.getToken());
if (id == MISSING_TOKEN) {
txnCtx.setStatus(INVALID_TOKEN_ID);
return;
}
ResponseCodeEnum outcome;
MerkleToken token = store.get(id);
if (op.hasExpiry() && !validator.isValidExpiry(op.getExpiry())) {
txnCtx.setStatus(INVALID_EXPIRATION_TIME);
return;
}
if (token.adminKey().isEmpty() && !affectsExpiryOnly.test(op)) {
txnCtx.setStatus(TOKEN_IS_IMMUTABLE);
return;
}
if (token.isDeleted()) {
txnCtx.setStatus(TOKEN_WAS_DELETED);
return;
}
if (token.isPaused()) {
txnCtx.setStatus(TOKEN_IS_PAUSED);
return;
}
outcome = autoRenewAttachmentCheck(op, token);
if (outcome != OK) {
txnCtx.setStatus(outcome);
return;
}
Optional<AccountID> replacedTreasury = Optional.empty();
if (op.hasTreasury()) {
var newTreasury = op.getTreasury();
if (ledger.isDetached(newTreasury)) {
txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
return;
}
if (!store.associationExists(newTreasury, id)) {
txnCtx.setStatus(INVALID_TREASURY_ACCOUNT_FOR_TOKEN);
return;
}
var existingTreasury = token.treasury().toGrpcAccountId();
if (!allowChangedTreasuryToOwnNfts && token.tokenType() == NON_FUNGIBLE_UNIQUE) {
var existingTreasuryBalance = ledger.getTokenBalance(existingTreasury, id);
if (existingTreasuryBalance > 0L) {
abortWith(CURRENT_TREASURY_STILL_OWNS_NFTS);
return;
}
}
if (!newTreasury.equals(existingTreasury)) {
if (ledger.isDetached(existingTreasury)) {
txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
return;
}
outcome = prepNewTreasury(id, token, newTreasury);
if (outcome != OK) {
abortWith(outcome);
return;
}
replacedTreasury = Optional.of(token.treasury().toGrpcAccountId());
}
}
outcome = store.update(op, txnCtx.consensusTime().getEpochSecond());
if (outcome == OK && replacedTreasury.isPresent()) {
final var oldTreasury = replacedTreasury.get();
long replacedTreasuryBalance = ledger.getTokenBalance(oldTreasury, id);
if (replacedTreasuryBalance > 0) {
if (token.tokenType().equals(TokenType.FUNGIBLE_COMMON)) {
outcome = ledger.doTokenTransfer(id, oldTreasury, op.getTreasury(), replacedTreasuryBalance);
} else {
outcome = store.changeOwnerWildCard(new NftId(id.getShardNum(), id.getRealmNum(), id.getTokenNum(), -1), oldTreasury, op.getTreasury());
}
}
}
if (outcome != OK) {
abortWith(outcome);
return;
}
txnCtx.setStatus(SUCCESS);
sigImpactHistorian.markEntityChanged(id.getTokenNum());
}
Aggregations