move correctScriptNumberRepresentation function from ScriptParser to BitcoinScriptUtil

This commit is contained in:
Tom McCabe 2016-09-16 16:23:01 -05:00
parent 6d615b8ee6
commit 0dbb724749
3 changed files with 9 additions and 9 deletions

View File

@ -366,7 +366,7 @@ object CLTVScriptPubKey extends Factory[CLTVScriptPubKey] {
def apply (asm: Seq[ScriptToken]) : CLTVScriptPubKey = fromAsm(asm)
def apply(locktime : ScriptNumber, scriptPubKey : ScriptPubKey) : CLTVScriptPubKey = {
val scriptOp = ScriptParser.correctScriptNumberRepresentation(locktime)
val scriptOp = BitcoinScriptUtil.correctScriptNumberRepresentation(locktime)
val scriptNum : Seq[ScriptToken] = if (scriptOp.isDefined) {
Seq(scriptOp.get)
@ -440,7 +440,7 @@ object CSVScriptPubKey extends Factory[CSVScriptPubKey] {
def apply(asm : Seq[ScriptToken]) : CSVScriptPubKey = fromAsm(asm)
def apply(relativeLockTime : ScriptNumber, scriptPubKey : ScriptPubKey) : CSVScriptPubKey = {
val scriptOp = ScriptParser.correctScriptNumberRepresentation(relativeLockTime)
val scriptOp = BitcoinScriptUtil.correctScriptNumberRepresentation(relativeLockTime)
val scriptNum : Seq[ScriptToken] = if (scriptOp.isDefined) {
Seq(scriptOp.get)

View File

@ -335,12 +335,6 @@ trait ScriptParser extends Factory[List[ScriptToken]] with BitcoinSLogger {
ScriptNumberUtil.toLong(strRemoveHex)
} else str.toLong
}
def correctScriptNumberRepresentation(num : ScriptNumber) : Option[ScriptOperation] = {
val str = num.underlying.toInt.toString
val op = Try(ScriptOperation.fromString(str))
op.get
}
}
object ScriptParser extends ScriptParser

View File

@ -248,7 +248,7 @@ trait BitcoinScriptUtil {
}
/**
* Whenever a script constant is interpreted to a number BIP62 could enforce that number to be encoded
* Whenever a script constant is interpreted to a number BIP62 should enforce that number to be encoded
* in the smallest encoding possible
* https://github.com/bitcoin/bitcoin/blob/a6a860796a44a2805a58391a009ba22752f64e32/src/script/script.h#L220-L237
*
@ -308,6 +308,12 @@ trait BitcoinScriptUtil {
}
return true
}
def correctScriptNumberRepresentation(num : ScriptNumber) : Option[ScriptOperation] = {
val str = num.underlying.toInt.toString
val op = Try(ScriptOperation.fromString(str))
op.get
}
}