mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 11:35:40 +01:00
core: Change type from Byte
-> LeafVersion
in TapscriptControlBlock
(#5953)
* core: Change type from Byte -> LeafVersion in TapscriptControlBlock constructors * Fix bug with serializing leaf version
This commit is contained in:
parent
32eaf31e48
commit
6287e41281
3 changed files with 5 additions and 6 deletions
|
@ -140,7 +140,7 @@ class TaprootWitnessTest extends BitcoinSUnitTest {
|
|||
}
|
||||
|
||||
it must "have a correct constructor" in {
|
||||
val x = TapscriptControlBlock.apply(controlBlock.bytes.head,
|
||||
val x = TapscriptControlBlock.apply(controlBlock.leafVersion,
|
||||
controlBlock.p,
|
||||
leafHashes = controlBlock.hashes)
|
||||
assert(x.bytes.toHex == controlBlock.bytes.toHex)
|
||||
|
|
|
@ -88,18 +88,18 @@ object TapscriptControlBlock extends Factory[TapscriptControlBlock] {
|
|||
}
|
||||
|
||||
def fromLeaves(
|
||||
leafVersion: Byte,
|
||||
leafVersion: LeafVersion,
|
||||
internalKey: XOnlyPubKey,
|
||||
leafs: Vector[TapLeaf]): TapscriptControlBlock = {
|
||||
TapscriptControlBlock(leafVersion, internalKey, leafs.map(_.sha256))
|
||||
}
|
||||
|
||||
def apply(
|
||||
leafVersion: Byte,
|
||||
leafVersion: LeafVersion,
|
||||
internalKey: XOnlyPubKey,
|
||||
leafHashes: Vector[Sha256Digest]): TapscriptControlBlock = {
|
||||
val bytes =
|
||||
(leafVersion +: internalKey.bytes) ++ ByteVector
|
||||
((leafVersion.toByte | 0x1).toByte +: internalKey.bytes) ++ ByteVector
|
||||
.concat(leafHashes.map(_.bytes))
|
||||
TapscriptControlBlock(bytes)
|
||||
}
|
||||
|
|
|
@ -18,8 +18,7 @@ object LeafVersion {
|
|||
|
||||
case class UnknownLeafVersion(toByte: Byte) extends LeafVersion
|
||||
|
||||
val knownLeafVersions: Vector[LeafVersion] = Vector(
|
||||
Tapscript /*, 0xc1.toByte*/ )
|
||||
val knownLeafVersions: Vector[LeafVersion] = Vector(Tapscript)
|
||||
|
||||
final val TAPROOT_LEAF_MASK: Byte = 0xfe.toByte
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue