From ac112372c0956d879bc587cf3cafa0b80eae1bd8 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Tue, 15 Oct 2024 13:12:46 +0300 Subject: [PATCH] CheckAndGetMethod/CheckAndGetMethodV6, versioned methodById --- .../org/ergoplatform/validation/ValidationRules.scala | 9 +++++++-- data/shared/src/main/scala/sigma/ast/methods.scala | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala b/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala index 9d4de47a99..9cf5828803 100644 --- a/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala +++ b/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala @@ -102,7 +102,7 @@ object ValidationRules { // } } - object CheckAndGetMethod extends ValidationRule(1011, + class CheckAndGetMethodTemplate(ruleId: Short) extends ValidationRule(ruleId, "Check the type has the declared method.") { override protected lazy val settings: SigmaValidationSettings = currentSettings @@ -128,6 +128,9 @@ object ValidationRules { } } + object CheckAndGetMethod extends CheckAndGetMethodTemplate(1011) + object CheckAndGetMethodV6 extends CheckAndGetMethodTemplate(1016) + object CheckHeaderSizeBit extends ValidationRule(1012, "For version greater then 0, size bit should be set.") with SoftForkWhenReplaced { override protected lazy val settings: SigmaValidationSettings = currentSettings @@ -171,7 +174,9 @@ object ValidationRules { CheckHeaderSizeBit, CheckCostFuncOperation, CheckPositionLimit, - CheckLoopLevelInCostFunction + CheckLoopLevelInCostFunction, + // v6 validation rules below + CheckAndGetMethodV6 ) /** Validation settings that correspond to the current version of the ErgoScript implementation. diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index dc85205b37..7fbe2017aa 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -83,7 +83,11 @@ sealed trait MethodsContainer { * @see getMethodById */ def methodById(methodId: Byte): SMethod = { - ValidationRules.CheckAndGetMethod(this, methodId) + if (VersionContext.current.isV6SoftForkActivated) { + ValidationRules.CheckAndGetMethodV6(this, methodId) + } else { + ValidationRules.CheckAndGetMethod(this, methodId) + } } /** Finds a method descriptor [[SMethod]] for the given name. */