use of com.hederahashgraph.api.proto.java.ResponseCodeEnum 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());
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class TokenListChecks method checkKeys.
public static ResponseCodeEnum checkKeys(final boolean hasAdminKey, final Key adminKey, final boolean hasKycKey, final Key kycKey, final boolean hasWipeKey, final Key wipeKey, final boolean hasSupplyKey, final Key supplyKey, final boolean hasFreezeKey, final Key freezeKey, final boolean hasFeeScheduleKey, final Key feeScheduleKey, final boolean hasPauseKey, final Key pauseKey) {
ResponseCodeEnum validity = checkAdminKey(hasAdminKey, adminKey);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasKycKey, kycKey, INVALID_KYC_KEY);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasWipeKey, wipeKey, INVALID_WIPE_KEY);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasSupplyKey, supplyKey, INVALID_SUPPLY_KEY);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasFreezeKey, freezeKey, INVALID_FREEZE_KEY);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasFeeScheduleKey, feeScheduleKey, INVALID_CUSTOM_FEE_SCHEDULE_KEY);
if (validity != OK) {
return validity;
}
validity = checkKeyOfType(hasPauseKey, pauseKey, INVALID_PAUSE_KEY);
return validity;
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class FileAppendTransitionLogic method doStateTransition.
@Override
public void doStateTransition() {
var op = txnCtx.accessor().getTxn().getFileAppend();
try {
var target = op.getFileID();
var data = op.getContents().toByteArray();
ResponseCodeEnum validity;
if (fileNumbers.isSoftwareUpdateFile(target.getFileNum())) {
validity = hfs.exists(target) ? OK : INVALID_FILE_ID;
} else {
Optional<HFileMeta> attr = hfs.exists(target) ? Optional.of(hfs.getattr(target)) : Optional.empty();
validity = classify(attr);
}
if (validity != OK) {
txnCtx.setStatus(validity);
return;
}
if (networkCtx.get().getPreparedUpdateFileNum() == target.getFileNum()) {
txnCtx.setStatus(PREPARED_UPDATE_FILE_IS_IMMUTABLE);
return;
}
final var result = hfs.append(target, data);
final var status = result.outcome();
txnCtx.setStatus(status);
} catch (IllegalArgumentException iae) {
mapToStatus(iae, txnCtx);
} catch (Exception unknown) {
log.warn("Unrecognized failure handling {}!", txnCtx.accessor().getSignedTxnWrapper(), unknown);
txnCtx.setStatus(FAIL_INVALID);
}
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class SigOpsRegressionTest method setupFor.
private void setupFor(TxnHandlingScenario scenario) throws Throwable {
hfs = scenario.hfs();
aliasManager = mock(AliasManager.class);
runningAvgs = mock(MiscRunningAvgs.class);
speedometers = mock(MiscSpeedometers.class);
accounts = scenario.accounts();
platformTxn = scenario.platformTxn();
expectedErrorStatus = null;
final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
signingOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
final var payerKeys = signingOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
expectedSigs = new ArrayList<>();
if (payerKeys.hasErrorReport()) {
expectedErrorStatus = payerKeys.getErrorReport();
} else {
PlatformSigsCreationResult payerResult = PlatformSigOps.createCryptoSigsFrom(payerKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
expectedSigs.addAll(payerResult.getPlatformSigs());
SigningOrderResult<ResponseCodeEnum> otherKeys = signingOrder.keysForOtherParties(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
if (otherKeys.hasErrorReport()) {
expectedErrorStatus = otherKeys.getErrorReport();
} else {
PlatformSigsCreationResult otherResult = PlatformSigOps.createCryptoSigsFrom(otherKeys.getOrderedKeys(), new PojoSigMapPubKeyToSigBytes(platformTxn.getSigMap()), new ReusableBodySigningFactory(platformTxn));
if (!otherResult.hasFailed()) {
expectedSigs.addAll(otherResult.getPlatformSigs());
}
}
}
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class GetFileContentsAnswerTest method usesValidator.
@Test
void usesValidator() throws Throwable {
// setup:
Query query = validQuery(COST_ANSWER, fee, target);
given(optionValidator.queryableFileStatus(asFile(target), view)).willReturn(FILE_DELETED);
// when:
ResponseCodeEnum validity = subject.checkValidity(query, view);
// then:
assertEquals(FILE_DELETED, validity);
// and:
verify(optionValidator).queryableFileStatus(any(), any());
}
Aggregations