mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
Add address type to createmultisig
bitcoind rpc (#4828)
* Add address type to createmultisig rpc * Fix tests * Fix UtilRpcTests
This commit is contained in:
parent
994ee25733
commit
9f53b4e572
@ -348,6 +348,7 @@ class MultiWalletRpcTest extends BitcoindFixturesCachedPairV19 {
|
||||
client
|
||||
.createMultiSig(2,
|
||||
Vector(privKey1.publicKey, privKey2.publicKey),
|
||||
AddressType.Bech32,
|
||||
walletNameOpt = Some(walletName))
|
||||
address2 = firstResult.address
|
||||
|
||||
|
@ -30,7 +30,9 @@ class MultisigRpcTest extends BitcoindRpcTest {
|
||||
|
||||
for {
|
||||
client <- clientF
|
||||
_ <- client.createMultiSig(2, Vector(pubKey1, pubKey2))
|
||||
_ <- client.createMultiSig(2,
|
||||
Vector(pubKey1, pubKey2),
|
||||
AddressType.Bech32)
|
||||
} yield succeed
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import org.bitcoins.commons.jsonmodels.bitcoind.{
|
||||
DecodeScriptResultV22
|
||||
}
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.AddressType
|
||||
import org.bitcoins.core.protocol.P2PKHAddress
|
||||
import org.bitcoins.core.script.ScriptType
|
||||
import org.bitcoins.crypto.ECPrivateKey
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
@ -17,7 +16,7 @@ import scala.concurrent.Future
|
||||
class UtilRpcTest extends BitcoindRpcTest {
|
||||
|
||||
lazy val clientsF: Future[(BitcoindRpcClient, BitcoindRpcClient)] =
|
||||
BitcoindRpcTestUtil.createNodePairV21(clientAccum = clientAccum)
|
||||
BitcoindRpcTestUtil.createNodePair(clientAccum = clientAccum)
|
||||
|
||||
behavior of "RpcUtilTest"
|
||||
|
||||
@ -31,22 +30,22 @@ class UtilRpcTest extends BitcoindRpcTest {
|
||||
|
||||
it should "be able to decode a reedem script" in {
|
||||
val ecPrivKey1 = ECPrivateKey.freshPrivateKey
|
||||
val ecPrivKey2 = ECPrivateKey.freshPrivateKey
|
||||
val pubKey1 = ecPrivKey1.publicKey
|
||||
val pubKey2 = ecPrivKey2.publicKey
|
||||
for {
|
||||
(client, _) <- clientsF
|
||||
address <- client.getNewAddress(addressType = AddressType.Legacy)
|
||||
multisig <-
|
||||
client
|
||||
.addMultiSigAddress(
|
||||
2,
|
||||
Vector(Left(pubKey1), Right(address.asInstanceOf[P2PKHAddress])))
|
||||
.createMultiSig(2, Vector(pubKey1, pubKey2), AddressType.Legacy)
|
||||
decoded <- client.decodeScript(multisig.redeemScript)
|
||||
} yield {
|
||||
decoded match {
|
||||
case decodedPreV22: DecodeScriptResultPreV22 =>
|
||||
assert(decodedPreV22.reqSigs.contains(2))
|
||||
assert(decoded.typeOfScript.contains(ScriptType.MULTISIG))
|
||||
assert(decodedPreV22.addresses.get.contains(address))
|
||||
assert(decodedPreV22.reqSigs.exists(_ == 2))
|
||||
assert(decoded.typeOfScript.exists(_ == ScriptType.MULTISIG))
|
||||
assert(decodedPreV22.addresses.get.exists(_ == address))
|
||||
case decodedV22: DecodeScriptResultV22 =>
|
||||
assert(decodedV22.typeOfScript.contains(ScriptType.MULTISIG))
|
||||
}
|
||||
|
@ -477,7 +477,9 @@ class WalletRpcTest extends BitcoindFixturesCachedPairV21 {
|
||||
for {
|
||||
firstResult <-
|
||||
client
|
||||
.createMultiSig(2, Vector(privKey1.publicKey, privKey2.publicKey))
|
||||
.createMultiSig(2,
|
||||
Vector(privKey1.publicKey, privKey2.publicKey),
|
||||
AddressType.Bech32)
|
||||
address2 = firstResult.address
|
||||
|
||||
secondResult <-
|
||||
|
@ -1,6 +1,9 @@
|
||||
package org.bitcoins.rpc.v20
|
||||
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.WalletFlag
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{
|
||||
AddressType,
|
||||
WalletFlag
|
||||
}
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind._
|
||||
import org.bitcoins.core.config.RegTest
|
||||
import org.bitcoins.core.gcs.{BlockFilter, FilterType}
|
||||
@ -129,13 +132,15 @@ class BitcoindV20RpcClientTest extends BitcoindFixturesFundedCachedV20 {
|
||||
val pubKey2 = ECPublicKey.freshPublicKey
|
||||
|
||||
for {
|
||||
multiSigResult <- client.createMultiSig(2, Vector(pubKey1, pubKey2))
|
||||
multiSigResult <- client.createMultiSig(2,
|
||||
Vector(pubKey1, pubKey2),
|
||||
AddressType.Bech32)
|
||||
} yield {
|
||||
// just validate we are able to receive a sane descriptor
|
||||
// no need to check checksum
|
||||
assert(
|
||||
multiSigResult.descriptor.startsWith(
|
||||
s"sh(multi(2,${pubKey1.hex},${pubKey2.hex}))#"))
|
||||
s"wsh(multi(2,${pubKey1.hex},${pubKey2.hex}))#"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
package org.bitcoins.rpc.v21
|
||||
|
||||
import org.bitcoins.asyncutil.AsyncUtil
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.WalletFlag
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.{
|
||||
AddressType,
|
||||
WalletFlag
|
||||
}
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind._
|
||||
import org.bitcoins.core.config.RegTest
|
||||
import org.bitcoins.core.gcs.{BlockFilter, FilterType}
|
||||
@ -169,13 +172,15 @@ class BitcoindV21RpcClientTest extends BitcoindFixturesFundedCachedV21 {
|
||||
val pubKey2 = ECPublicKey.freshPublicKey
|
||||
|
||||
for {
|
||||
multiSigResult <- client.createMultiSig(2, Vector(pubKey1, pubKey2))
|
||||
multiSigResult <- client.createMultiSig(2,
|
||||
Vector(pubKey1, pubKey2),
|
||||
AddressType.Bech32)
|
||||
} yield {
|
||||
// just validate we are able to receive a sane descriptor
|
||||
// no need to check checksum
|
||||
assert(
|
||||
multiSigResult.descriptor.startsWith(
|
||||
s"sh(multi(2,${pubKey1.hex},${pubKey2.hex}))#"))
|
||||
s"wsh(multi(2,${pubKey1.hex},${pubKey2.hex}))#"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,13 +81,17 @@ trait MultisigRpc { self: Client =>
|
||||
def createMultiSig(
|
||||
minSignatures: Int,
|
||||
keys: Vector[ECPublicKey],
|
||||
addressType: AddressType,
|
||||
walletNameOpt: Option[String] = None): Future[MultiSigResult] = {
|
||||
self.version.flatMap {
|
||||
case V23 | V22 | V21 | V20 | Unknown =>
|
||||
bitcoindCall[MultiSigResultPostV20](
|
||||
"createmultisig",
|
||||
List(JsNumber(minSignatures), Json.toJson(keys.map(_.hex))),
|
||||
uriExtensionOpt = walletNameOpt.map(walletExtension))
|
||||
List(JsNumber(minSignatures),
|
||||
Json.toJson(keys.map(_.hex)),
|
||||
Json.toJson(addressType)),
|
||||
uriExtensionOpt = walletNameOpt.map(walletExtension)
|
||||
)
|
||||
case V17 | V18 | V19 =>
|
||||
bitcoindCall[MultiSigResultPreV20](
|
||||
"createmultisig",
|
||||
|
@ -73,13 +73,17 @@ trait V20MultisigRpc extends MultisigRpc { self: Client =>
|
||||
override def createMultiSig(
|
||||
minSignatures: Int,
|
||||
keys: Vector[ECPublicKey],
|
||||
addressType: AddressType,
|
||||
walletNameOpt: Option[String] = None): Future[MultiSigResultPostV20] = {
|
||||
self.version.flatMap {
|
||||
case V20 | V21 | V22 | V23 | Unknown =>
|
||||
bitcoindCall[MultiSigResultPostV20](
|
||||
"createmultisig",
|
||||
List(JsNumber(minSignatures), Json.toJson(keys.map(_.hex))),
|
||||
uriExtensionOpt = walletNameOpt.map(walletExtension))
|
||||
List(JsNumber(minSignatures),
|
||||
Json.toJson(keys.map(_.hex)),
|
||||
Json.toJson(addressType)),
|
||||
uriExtensionOpt = walletNameOpt.map(walletExtension)
|
||||
)
|
||||
case version @ (V17 | V18 | V19) =>
|
||||
throw new RuntimeException(
|
||||
s"Cannot use v20MultisigRpc on an older version, got $version")
|
||||
|
Loading…
Reference in New Issue
Block a user