mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
move correctScriptNumberRepresentation function from ScriptParser to BitcoinScriptUtil
This commit is contained in:
parent
6d615b8ee6
commit
0dbb724749
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user