Package com.privatechain.core.spi
Interface TransactionValidator
public interface TransactionValidator
Service Provider Interface (SPI) for pluggable transaction validation logic.
Built-in implementations (in
A TransactionValidator is called before a transaction enters the
Blockchain mempool and again before it is
included in a mined block. Multiple validators are composable in a
chain-of-responsibility pattern via the built-in CompositeValidator
(FR-TX-03).
Built-in implementations (in blockchain-core)
SignatureTransactionValidator— verifies ECDSA signature (FR-TX-04)BalanceValidator— checks sender has sufficient fundsCompositeValidator— chains multiple validators
Writing a custom validator
public class KycValidator implements TransactionValidator {
\@Override
public ValidationResult validate(Transaction tx, Blockchain chain) {
if (!kycService.isApproved(tx.getSenderAddress())) {
return ValidationResult.failure(
ValidationStatus.CUSTOM_REJECTION,
"Sender has not completed KYC verification");
}
return ValidationResult.success();
}
}
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvalidate(Transaction tx, Blockchain chain) Validates a single transaction against the current chain state.
-
Method Details
-
validate
Validates a single transaction against the current chain state.Implementations should be stateless and idempotent: calling this method twice with the same arguments must return the same result. Side effects (e.g., network calls) are permitted but must not mutate the chain.
The method receives the full
Blockchainsnapshot so that balance-checking validators can scan confirmed transactions without additional infrastructure.- Parameters:
tx- the transaction to validate (non-null)chain- the current chain state used for balance and duplicate checks (non-null)- Returns:
- a
ValidationResultindicating success or the first encountered failure
-