Remove unneeded CoreApi (#3599)

This commit is contained in:
benthecarman 2021-08-24 14:17:04 -05:00 committed by GitHub
parent 6ef30b4996
commit 479f8e249c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 200 deletions

View File

@ -3,7 +3,6 @@ package org.bitcoins.server
import akka.http.scaladsl.model.ContentTypes._
import akka.http.scaladsl.server.ValidationRejection
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import org.bitcoins.core.Core
import org.bitcoins.core.api.chain.ChainApi
import org.bitcoins.core.api.chain.db._
import org.bitcoins.core.api.wallet.db._
@ -79,7 +78,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
val walletRoutes: WalletRoutes = WalletRoutes(mockWalletApi)
val coreRoutes: CoreRoutes = CoreRoutes(Core)
val coreRoutes: CoreRoutes = CoreRoutes()
"The server" should {

View File

@ -7,7 +7,6 @@ import org.bitcoins.chain.blockchain.ChainHandler
import org.bitcoins.chain.config.ChainAppConfig
import org.bitcoins.chain.models._
import org.bitcoins.commons.util.{DatadirParser, ServerArgParser}
import org.bitcoins.core.Core
import org.bitcoins.core.api.chain.ChainApi
import org.bitcoins.core.api.feeprovider.FeeRateApi
import org.bitcoins.core.api.node.NodeApi
@ -332,7 +331,7 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
val walletRoutes = WalletRoutes(wallet)
val nodeRoutes = NodeRoutes(nodeApi)
val chainRoutes = ChainRoutes(chainApi, nodeConf.network)
val coreRoutes = CoreRoutes(Core)
val coreRoutes = CoreRoutes()
val dlcRoutes = DLCRoutes(dlcNode)
val handlers =

View File

@ -4,7 +4,6 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import org.bitcoins.commons.jsonmodels.{SerializedPSBT, SerializedTransaction}
import org.bitcoins.core.api.core.CoreApi
import org.bitcoins.core.hd.AddressType
import org.bitcoins.core.protocol.script.{
MultiSignatureScriptPubKey,
@ -12,15 +11,15 @@ import org.bitcoins.core.protocol.script.{
P2WSHWitnessSPKV0
}
import org.bitcoins.core.protocol.{Bech32Address, P2SHAddress}
import org.bitcoins.core.psbt.PSBT
import org.bitcoins.server.BitcoinSAppConfig.toChainConf
import org.bitcoins.server.routes.{Server, ServerCommand, ServerRoute}
import ujson._
import scala.collection.mutable
import scala.concurrent.Future
case class CoreRoutes(core: CoreApi)(implicit
system: ActorSystem,
config: BitcoinSAppConfig)
case class CoreRoutes()(implicit system: ActorSystem, config: BitcoinSAppConfig)
extends ServerRoute {
import system.dispatcher
@ -29,8 +28,7 @@ case class CoreRoutes(core: CoreApi)(implicit
withValidServerCommand(FinalizePSBT.fromJsArr(arr)) {
case FinalizePSBT(psbt) =>
complete {
core
.finalizePSBT(psbt)
psbt.finalizePSBT
.map(finalized => Server.httpSuccess(finalized.base64))
}
}
@ -39,8 +37,7 @@ case class CoreRoutes(core: CoreApi)(implicit
withValidServerCommand(ExtractFromPSBT.fromJsArr(arr)) {
case ExtractFromPSBT(psbt) =>
complete {
core
.extractFromPSBT(psbt)
psbt.extractTransactionAndValidate
.map(tx => Server.httpSuccess(tx.hex))
}
}
@ -49,9 +46,9 @@ case class CoreRoutes(core: CoreApi)(implicit
withValidServerCommand(ConvertToPSBT.fromJsArr(arr)) {
case ConvertToPSBT(tx) =>
complete {
core
.convertToPSBT(tx)
.map(psbt => Server.httpSuccess(psbt.base64))
val psbt = PSBT.fromUnsignedTx(tx)
Server.httpSuccess(psbt.base64)
}
}
@ -59,8 +56,7 @@ case class CoreRoutes(core: CoreApi)(implicit
withValidServerCommand(CombinePSBTs.fromJsArr(arr)) {
case CombinePSBTs(psbts) =>
complete {
core
.combinePSBTs(psbts)
combinePSBTs(psbts.toVector)
.map(psbt => Server.httpSuccess(psbt.base64))
}
}
@ -69,8 +65,7 @@ case class CoreRoutes(core: CoreApi)(implicit
withValidServerCommand(JoinPSBTs.fromJsArr(arr)) {
case JoinPSBTs(psbts) =>
complete {
core
.joinPSBTs(psbts)
combinePSBTs(psbts.toVector)
.map(psbt => Server.httpSuccess(psbt.base64))
}
}
@ -187,4 +182,21 @@ case class CoreRoutes(core: CoreApi)(implicit
}
}
}
def combinePSBTs(psbts: Vector[PSBT]): Future[PSBT] = {
if (psbts.isEmpty) {
Future.failed(new IllegalArgumentException("No PSBTs given"))
} else {
try {
val empty = PSBT.fromUnsignedTx(psbts.head.transaction)
val combined =
psbts.foldLeft(empty)((accum, psbt) => accum.combinePSBT(psbt))
Future.successful(combined)
} catch {
case err: IllegalArgumentException =>
Future.failed(err)
}
}
}
}

View File

@ -1,106 +0,0 @@
package org.bitcoins.core.api
import org.bitcoins.core.Core
import org.bitcoins.core.protocol.transaction._
import org.bitcoins.core.psbt.PSBT
import org.bitcoins.testkitcore.util.BitcoinSJvmTest
class CoreApiTest extends BitcoinSJvmTest {
behavior of "CoreApi"
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
generatorDrivenConfigNewCode
it must "successfully combine two PSBTs with unknown types" in {
val psbt1 = PSBT(
"70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f00")
val psbt2 = PSBT(
"70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000a0f0102030405060708100f0102030405060708090a0b0c0d0e0f000a0f0102030405060708100f0102030405060708090a0b0c0d0e0f000a0f0102030405060708100f0102030405060708090a0b0c0d0e0f00")
val expected = PSBT(
"70736274ff01003f0200000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000ffffffff010000000000000000036a0100000000000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f0a0f0102030405060708100f0102030405060708090a0b0c0d0e0f000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f0a0f0102030405060708100f0102030405060708090a0b0c0d0e0f000a0f0102030405060708090f0102030405060708090a0b0c0d0e0f0a0f0102030405060708100f0102030405060708090a0b0c0d0e0f00")
Core.joinPSBTs(Seq(psbt1, psbt2)).map(psbt => assert(psbt == expected))
Core.combinePSBTs(Seq(psbt1, psbt2)).map(psbt => assert(psbt == expected))
}
it must "fail to combine when given an empty seq" in {
Core
.joinPSBTs(Seq.empty)
.failed
.map(err => assertThrows[IllegalArgumentException](throw err))
}
it must "catch errors when combining PSBTs" in {
val psbt0 = PSBT.fromUnsignedTx(Transaction(
"020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000"))
val psbt1 = PSBT.fromUnsignedTx(Transaction(
"02000000019dfc6628c26c5899fe1bd3dc338665bfd55d7ada10f6220973df2d386dec12760100000000ffffffff01f03dcd1d000000001600147b3a00bfdc14d27795c2b74901d09da6ef13357900000000"))
Core
.joinPSBTs(Seq(psbt0, psbt1))
.failed
.map(err => assertThrows[IllegalArgumentException](throw err))
}
it must "successfully finalize a PSBT" in {
val psbt = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000002202029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01220202dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f000000800000008001000080000100f80200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f79650000002202023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d201220203089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f010103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000")
val expected = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae000100f80200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f79650000000107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000")
Core.finalizePSBT(psbt).map(finalized => assert(finalized == expected))
}
it must "catch errors when finalizing a PSBT" in {
val psbt = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000")
Core
.finalizePSBT(psbt)
.failed
.map(err => assertThrows[IllegalStateException](throw err))
}
it must "successfully extract a transaction from a finalized PSBT" in {
val psbt = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000")
val expected = Transaction.fromHex(
"0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7500000000da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752aeffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d01000000232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00000000")
Core
.extractFromPSBT(psbt)
.map(tx => assert(tx == expected))
}
it must "catch errors when extracting a transaction from a finalized PSBT" in {
val psbt = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000")
Core
.extractFromPSBT(psbt)
.failed
.map(err => assertThrows[IllegalStateException](throw err))
}
it must "convert a tx to a PSBT" in {
val tx = Transaction(
"020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000")
val expected = PSBT(
"70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000")
Core.convertToPSBT(tx).map(psbt => assert(psbt == expected))
}
it must "catch errors when converting a tx to a PSBT" in {
val tx = Transaction(
"0200000002cffe265210b42971f9642adcf88f6e6aaa40e6baec30037ce0088383b47c4f28031e306ffd2403004730450220259683be7d97e0a0f611926057bbd3fc8c5f886a06d39ec5ce330a87bcb33fa9022100ae6eb066c89dee2b5e4fefaa03450cfa6960508c2dc1c82f206bd66b9e8d3913463044022030d398ef4a69646ae40a84af9634e0608f4882269b92777f239c146555a3d4b602200ff23130697bca6bb7be3b69962387d6caeb25e198dc59969328d993119f9b5147304502206c0abf639640f56ab85c9800a2555be92569682a96bde261cfd9f1254578ee90022100c4b42232041d5f228ff832d1615151949d320eaf85bef9389463744f996e46b9473045022058d8a8ac02b5bd7139a99787dd42067e2de3a4e613f0878318aefcac4f13768f022100f620e66d3cc96230a0602e803a3f790861e1f66f72028e2ed79dc0ec3c24b98e4d01025f2103a2ae334a00a2a8b0191b41829b72eac3d4f207f87ea5b102383ed58716a43d452102351e70b50c30827ff18fde7b7458c991f74a938878f94c5f1384840b0775be2b210210c5d0c5528f61def05d0893e7b3145c5c5c58c4771c74de74470c69c8d86da121032999f0c7acd64f80b318beae5be7cedb4a72b0f370dcaa8ab9a0be1190df001821034afa6da2e9a4fbf84b33e5c35c81b0396542b4bf5eddaef0fb7e760833047fca21022875fe400ea9200ca013447c9dfe68e72d09e39a14c2b80f5beba35db00eb3a621031969406b809d0413d156fd2eb449cdc7b4b6fd431a3179abbd73cc2dd8a675bc21022f017723760552871039ba59678db384a1d195f2bcb6207a4514d1b86af0d6f42102a2d346e46656e5070433874521aaf24423f78438ec644c975ce8e2a32f35ef1d21027138384fcde2ae4aee8052f576227c3a158a09be5e8ee9df5145a39a06b5f6f32103d30805f2a4fc3d816b0f37b5500ffa7f59603ef45680c7f75991342d53af30d02103a27ef20b51281a98dcf55afdf53182d6a07c0d48afa511fa52d352faf79169b52102c50b2f80b12f0bbd304802916f906e366d017083d381cd45d64074fdb04b1b3d2103e3a5a4df1fc467589ed98d94f90cc1d41a2ac5a40b68a6c489cc1e4af04c5bb421039af4e1b6903db40e9cfe2c14cdd490c385d1339b0b7386719e277bbd5492378d5fae0f25e5bbcffe265210b42971f9642adcf88f6e6aaa40e6baec30037ce0088383b47c4f28031e306ffd2403004730450220259683be7d97e0a0f611926057bbd3fc8c5f886a06d39ec5ce330a87bcb33fa9022100ae6eb066c89dee2b5e4fefaa03450cfa6960508c2dc1c82f206bd66b9e8d3913463044022030d398ef4a69646ae40a84af9634e0608f4882269b92777f239c146555a3d4b602200ff23130697bca6bb7be3b69962387d6caeb25e198dc59969328d993119f9b5147304502206c0abf639640f56ab85c9800a2555be92569682a96bde261cfd9f1254578ee90022100c4b42232041d5f228ff832d1615151949d320eaf85bef9389463744f996e46b9473045022058d8a8ac02b5bd7139a99787dd42067e2de3a4e613f0878318aefcac4f13768f022100f620e66d3cc96230a0602e803a3f790861e1f66f72028e2ed79dc0ec3c24b98e4d01025f2103a2ae334a00a2a8b0191b41829b72eac3d4f207f87ea5b102383ed58716a43d452102351e70b50c30827ff18fde7b7458c991f74a938878f94c5f1384840b0775be2b210210c5d0c5528f61def05d0893e7b3145c5c5c58c4771c74de74470c69c8d86da121032999f0c7acd64f80b318beae5be7cedb4a72b0f370dcaa8ab9a0be1190df001821034afa6da2e9a4fbf84b33e5c35c81b0396542b4bf5eddaef0fb7e760833047fca21022875fe400ea9200ca013447c9dfe68e72d09e39a14c2b80f5beba35db00eb3a621031969406b809d0413d156fd2eb449cdc7b4b6fd431a3179abbd73cc2dd8a675bc21022f017723760552871039ba59678db384a1d195f2bcb6207a4514d1b86af0d6f42102a2d346e46656e5070433874521aaf24423f78438ec644c975ce8e2a32f35ef1d21027138384fcde2ae4aee8052f576227c3a158a09be5e8ee9df5145a39a06b5f6f32103d30805f2a4fc3d816b0f37b5500ffa7f59603ef45680c7f75991342d53af30d02103a27ef20b51281a98dcf55afdf53182d6a07c0d48afa511fa52d352faf79169b52102c50b2f80b12f0bbd304802916f906e366d017083d381cd45d64074fdb04b1b3d2103e3a5a4df1fc467589ed98d94f90cc1d41a2ac5a40b68a6c489cc1e4af04c5bb421039af4e1b6903db40e9cfe2c14cdd490c385d1339b0b7386719e277bbd5492378d5fae0f25e5bb0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000")
Core
.convertToPSBT(tx)
.failed
.map(err => assertThrows[IllegalArgumentException](throw err))
}
}

View File

@ -1,57 +0,0 @@
package org.bitcoins.core
import org.bitcoins.core.api.core.CoreApi
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.psbt.PSBT
import scala.concurrent.Future
import scala.util.{Failure, Success}
object Core extends CoreApi {
override def combinePSBTs(psbts: Seq[PSBT]): Future[PSBT] = {
if (psbts.isEmpty) {
Future.failed(new IllegalArgumentException("No PSBTs given"))
} else {
try {
val empty = PSBT.fromUnsignedTx(psbts.head.transaction)
val combined =
psbts.foldLeft(empty)((accum, psbt) => accum.combinePSBT(psbt))
Future.successful(combined)
} catch {
case err: IllegalArgumentException =>
Future.failed(err)
}
}
}
override def finalizePSBT(psbt: PSBT): Future[PSBT] = {
psbt.finalizePSBT match {
case Success(finalized) =>
Future.successful(finalized)
case Failure(err) =>
Future.failed(err)
}
}
override def extractFromPSBT(psbt: PSBT): Future[Transaction] = {
psbt.extractTransactionAndValidate match {
case Success(extracted) =>
Future.successful(extracted)
case Failure(err) =>
Future.failed(err)
}
}
override def convertToPSBT(transaction: Transaction): Future[PSBT] = {
try {
val psbt = PSBT.fromUnsignedTx(transaction)
Future.successful(psbt)
} catch {
case err: IllegalArgumentException =>
Future.failed(err)
}
}
}

View File

@ -1,18 +0,0 @@
package org.bitcoins.core.api.core
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.psbt.PSBT
import scala.concurrent.Future
trait CoreApi {
def combinePSBTs(psbts: Seq[PSBT]): Future[PSBT]
def joinPSBTs(psbts: Seq[PSBT]): Future[PSBT] = combinePSBTs(psbts)
def finalizePSBT(psbt: PSBT): Future[PSBT]
def extractFromPSBT(psbt: PSBT): Future[Transaction]
def convertToPSBT(transaction: Transaction): Future[PSBT]
}