com.hedera.node.app.service.schedule.impl.handlers.ScheduleVerificationAssistant Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of app-service-schedule-impl Show documentation
Show all versions of app-service-schedule-impl Show documentation
Default Hedera Schedule Service Implementation
The newest version!
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hedera.node.app.service.schedule.impl.handlers;
import com.hedera.hapi.node.base.Key;
import com.hedera.node.app.spi.signatures.SignatureVerification;
import com.hedera.node.app.spi.signatures.VerificationAssistant;
import java.util.Set;
/**
* Verification Assistant that "verifies" keys previously verified via Schedule create or sign transactions.
* This class also observes all primitive keys that are still unverified, and potentially passes those
* on via the side effect of adding them to the sets provided in the constructor, which must be modifiable.
*/
public class ScheduleVerificationAssistant implements VerificationAssistant {
private final Set preValidatedKeys;
private final Set failedPrimitiveKeys;
/**
* Create a new schedule verification assistant.
*
* @param preValidatedKeys a modifiable {@link Set} of primitive keys previously verified.
* @param failedPrimitiveKeys an empty and modifiable {@link Set} to receive a list of
* primitive keys that are still unverified.
*/
public ScheduleVerificationAssistant(final Set preValidatedKeys, Set failedPrimitiveKeys) {
this.preValidatedKeys = preValidatedKeys;
this.failedPrimitiveKeys = failedPrimitiveKeys;
}
@Override
public boolean test(final Key key, final SignatureVerification priorVerify) {
if (key.hasKeyList() || key.hasThresholdKey() || key.hasContractID() || key.hasDelegatableContractId()) {
return priorVerify.passed();
} else {
final boolean isValid = priorVerify.passed() || preValidatedKeys.contains(key);
if (!isValid) {
failedPrimitiveKeys.add(key);
} else if (priorVerify.passed()) {
preValidatedKeys.add(key);
}
return isValid;
}
}
}