mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
Merge pull request #38 from Christewart/master
Adding helper function to P2PKHScriptPubKey
This commit is contained in:
commit
3114b0a2c5
@ -50,6 +50,10 @@ object P2PKHScriptPubKey extends Factory[P2PKHScriptPubKey] {
|
||||
|
||||
def apply(pubKey : ECPublicKey) : P2PKHScriptPubKey = {
|
||||
val hash = CryptoUtil.sha256Hash160(pubKey.bytes)
|
||||
P2PKHScriptPubKey(hash)
|
||||
}
|
||||
|
||||
def apply(hash: Sha256Hash160Digest): P2PKHScriptPubKey = {
|
||||
val pushOps = BitcoinScriptUtil.calculatePushOp(hash.bytes)
|
||||
val asm = Seq(OP_DUP, OP_HASH160) ++ pushOps ++ Seq(ScriptConstant(hash.bytes), OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
P2PKHScriptPubKey(asm)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.core.gen.{CryptoGenerators, ScriptGenerators}
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
@ -11,6 +11,11 @@ class P2PKHScriptPubKeySpec extends Properties("P2PKHScriptPubKeySpec") {
|
||||
property("Serialization symmetry") =
|
||||
Prop.forAll(ScriptGenerators.p2pkhScriptPubKey) { case (p2pkhScriptPubKey, _) =>
|
||||
P2PKHScriptPubKey(p2pkhScriptPubKey.hex) == p2pkhScriptPubKey
|
||||
}
|
||||
|
||||
property("find pubkeyhash in scriptPubKey") =
|
||||
Prop.forAll(CryptoGenerators.sha256Hash160Digest) { hash =>
|
||||
val scriptPubKey = P2PKHScriptPubKey(hash)
|
||||
scriptPubKey.pubKeyHash == hash
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
|
||||
/**
|
||||
* Created by chris on 9/22/16.
|
||||
*/
|
||||
class P2PKHScriptPubKeyTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"P2PKHScriptPubKey" must "return the pubkeyhash" in {
|
||||
val hash = CryptoGenerators.sha256Hash160Digest.sample.get
|
||||
val p2pkhScriptPubKey = P2PKHScriptPubKey(hash)
|
||||
p2pkhScriptPubKey.pubKeyHash must be (hash)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user