Moving duplicate dataStructures in cli and app-server into app-commons (#4541)

* duplicate data structures in (ConsoleCli.scala) and (ServerJsonModels.scala) moved to (Command.scala)

* removed unused imports

* rebase for merge conflitcts

* change output type for Accept DLC

* more error fixes

* error fixes

* fixed destintaion error

* scala reformatting

* send from outpoints test runs and passes

* removed unnecessary braces, removed incorrect extensions on objects

* scala reformatting

* removed commented out code
This commit is contained in:
GreyMcCarthy 2022-08-02 12:55:43 -04:00 committed by GitHub
parent ba396f2fb3
commit b7c7cb8fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1787 additions and 1646 deletions

View file

@ -3,14 +3,7 @@ package org.bitcoins.cli
import org.bitcoins.cli.CliCommand._
import org.bitcoins.cli.CliReaders._
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts.LockUnspentOutputParameter
import org.bitcoins.commons.rpc.{
AppServerCliCommand,
ContactAdd,
ContactRemove,
ContactsList,
OracleServerCliCommand,
ServerlessCliCommand
}
import org.bitcoins.commons.rpc._
import org.bitcoins.commons.serializers.Picklers._
import org.bitcoins.core.api.wallet.CoinSelectionAlgo
import org.bitcoins.core.config.NetworkParameters
@ -112,14 +105,14 @@ object ConsoleCli {
.action((tx, conf) =>
conf.copy(command = conf.command match {
case decode: DecodeRawTransaction =>
decode.copy(transaction = tx)
decode.copy(tx = tx)
case other => other
}))),
note(sys.props("line.separator") + "=== Wallet ==="),
cmd("rescan")
.action((_, conf) =>
conf.copy(
command = Rescan(addressBatchSize = Option.empty,
command = Rescan(batchSize = Option.empty,
startBlock = Option.empty,
endBlock = Option.empty,
force = false,
@ -141,7 +134,7 @@ object ConsoleCli {
.action((batchSize, conf) =>
conf.copy(command = conf.command match {
case rescan: Rescan =>
rescan.copy(addressBatchSize = Option(batchSize))
rescan.copy(batchSize = Option(batchSize))
case other => other
})),
opt[BlockStamp]("start")
@ -666,10 +659,10 @@ object ConsoleCli {
arg[Vector[LockUnspentOutputParameter]]("transactions")
.text("The transaction outpoints to unlock/lock, empty to apply to all utxos")
.optional()
.action((outPoints, conf) =>
.action((outputParam, conf) =>
conf.copy(command = conf.command match {
case lockUnspent: LockUnspent =>
lockUnspent.copy(outPoints = outPoints)
lockUnspent.copy(outputParam = outputParam)
case other => other
}))
),
@ -863,7 +856,7 @@ object ConsoleCli {
.action((_, conf) => conf.copy(command = DecodeOffer(null)))
.text("Decodes an offer message into json")
.children(
arg[LnMessage[DLCOfferTLV]]("offer")
arg[DLCOfferTLV]("offer")
.text("Hex encoded dlc offer message")
.required()
.action((offer, conf) =>
@ -907,7 +900,10 @@ object ConsoleCli {
command = CreateDLCOffer(ContractInfoV0TLV.dummy,
Satoshis.zero,
None,
None,
UInt32.zero,
None,
None,
None)))
.text("Creates a DLC offer that another party can accept")
.children(
@ -917,7 +913,7 @@ object ConsoleCli {
.action((info, conf) =>
conf.copy(command = conf.command match {
case offer: CreateDLCOffer =>
offer.copy(contractInfo = info)
offer.copy(contractInfoTLV = info)
case other => other
})),
arg[Satoshis]("collateral")
@ -941,10 +937,10 @@ object ConsoleCli {
arg[UInt32]("refundlocktime")
.text("Locktime of the refund transaction")
.required()
.action((refundLT, conf) =>
.action((refundLocktime, conf) =>
conf.copy(command = conf.command match {
case offer: CreateDLCOffer =>
offer.copy(refundLT = refundLT)
offer.copy(refundLocktime = refundLocktime)
case other => other
})),
opt[UInt32]("cetlocktime")
@ -953,7 +949,7 @@ object ConsoleCli {
.action((locktime, conf) =>
conf.copy(command = conf.command match {
case offer: CreateDLCOffer =>
offer.copy(cetLocktimeOpt = Some(locktime))
offer.copy(locktimeOpt = Some(locktime))
case other => other
}))
),
@ -961,7 +957,9 @@ object ConsoleCli {
.action((_, conf) =>
conf.copy(command =
AcceptDLC(null,
InetSocketAddress.createUnresolved("localhost", 0))))
InetSocketAddress.createUnresolved("localhost", 0),
None,
None)))
.text("Accepts a DLC offer given from another party")
.children(
arg[LnMessage[DLCOfferTLV]]("offer")
@ -984,7 +982,8 @@ object ConsoleCli {
}))
),
cmd("acceptdlcoffer")
.action((_, conf) => conf.copy(command = AcceptDLCOffer(null)))
.action((_, conf) =>
conf.copy(command = AcceptDLCOffer(null, None, None, None)))
.text("Accepts a DLC offer given from another party")
.children(
arg[LnMessage[DLCOfferTLV]]("offer")
@ -1293,8 +1292,8 @@ object ConsoleCli {
.required()
.action((ann, conf) =>
conf.copy(command = conf.command match {
case create: CreateContractInfo =>
create.copy(announcementTLV = ann)
case createContractInfo: CreateContractInfo =>
createContractInfo.copy(announcementTLV = ann)
case other => other
})),
arg[Satoshis]("totalCollateral")
@ -1306,7 +1305,7 @@ object ConsoleCli {
create.copy(totalCollateral = totalCollateral)
case other => other
})),
arg[ujson.Value]("contractDescriptor")
arg[ContractDescriptorTLV]("contractDescriptor")
.text("The contract descriptor in the DLC. This is expected to be of format [[outcome1, payout1], [outcome2, payout2], ...]")
.required()
.action((contractDescriptor, conf) =>
@ -1479,7 +1478,7 @@ object ConsoleCli {
.action((tx, conf) =>
conf.copy(command = conf.command match {
case convertToPSBT: ConvertToPSBT =>
convertToPSBT.copy(transaction = tx)
convertToPSBT.copy(tx = tx)
case other => other
}))
),
@ -1953,25 +1952,45 @@ object ConsoleCli {
case GetDLCs => RequestParam("getdlcs")
case GetDLC(dlcId) =>
RequestParam("getdlc", Seq(up.writeJs(dlcId)))
case CreateDLCOffer(contractInfo,
case CreateDLCOffer(contractInfoTLV,
collateral,
feeRateOpt,
refundLT,
cetLocktimeOpt) =>
locktimeOpt,
refundLocktime,
externalPayoutAddressOpt,
externalChangeAddressOpt,
peerAddressOpt) =>
RequestParam(
"createdlcoffer",
Seq(
up.writeJs(contractInfo),
up.writeJs(contractInfoTLV),
up.writeJs(collateral),
up.writeJs(feeRateOpt),
up.writeJs(cetLocktimeOpt),
up.writeJs(refundLT)
up.writeJs(locktimeOpt),
up.writeJs(refundLocktime),
up.writeJs(externalPayoutAddressOpt),
up.writeJs(externalChangeAddressOpt),
up.writeJs(peerAddressOpt)
)
)
case AcceptDLC(offer, address) =>
RequestParam("acceptdlc", Seq(up.writeJs(offer), up.writeJs(address)))
case AcceptDLCOffer(offer) =>
RequestParam("acceptdlcoffer", Seq(up.writeJs(offer)))
case AcceptDLC(offer,
peerAddr,
externalPayoutAddressOpt,
externalChangeAddressOpt) =>
RequestParam("acceptdlc",
Seq(up.writeJs(offer),
up.writeJs(peerAddr),
up.writeJs(externalPayoutAddressOpt),
up.writeJs(externalChangeAddressOpt)))
case AcceptDLCOffer(offer,
peerAddr,
externalPayoutAddressOpt,
externalChangeAddressOpt) =>
RequestParam("acceptdlcoffer",
Seq(up.writeJs(offer),
up.writeJs(peerAddr),
up.writeJs(externalPayoutAddressOpt),
up.writeJs(externalChangeAddressOpt)))
case AcceptDLCOfferFromFile(path, dest) =>
RequestParam("acceptdlcofferfromfile",
Seq(up.writeJs(path), up.writeJs(dest)))
@ -2248,7 +2267,7 @@ object ConsoleCli {
RequestParam("offer-remove", args)
case cmd @ (_: ServerlessCliCommand | _: AppServerCliCommand |
_: OracleServerCliCommand) =>
_: Broadcastable | _: OracleServerCliCommand) =>
sys.error(s"Command $cmd unsupported")
case org.bitcoins.commons.rpc.CliCommand.NoCommand => ???
}
@ -2359,10 +2378,6 @@ object Config {
object CliCommand {
trait Broadcastable {
def noBroadcast: Boolean
}
case object GetVersion extends ServerlessCliCommand
case object GetInfo extends AppServerCliCommand
@ -2370,51 +2385,18 @@ object CliCommand {
// DLC
case object GetDLCHostAddress extends AppServerCliCommand
case class DecodeContractInfo(contractInfo: ContractInfoV0TLV)
extends AppServerCliCommand
case class DecodeOffer(offer: LnMessage[DLCOfferTLV])
extends AppServerCliCommand
case class DecodeAnnouncement(announcement: OracleAnnouncementV0TLV)
extends AppServerCliCommand
case class DecodeAttestments(sigs: OracleAttestmentV0TLV)
extends AppServerCliCommand
case class CreateDLCOffer(
contractInfo: ContractInfoV0TLV,
collateral: Satoshis,
feeRateOpt: Option[SatoshisPerVirtualByte],
refundLT: UInt32,
cetLocktimeOpt: Option[UInt32])
extends AppServerCliCommand
sealed trait AcceptDLCCliCommand extends AppServerCliCommand
case class AcceptDLC(
offer: LnMessage[DLCOfferTLV],
peerAddr: InetSocketAddress)
extends AcceptDLCCliCommand
case class AcceptDLCOffer(offer: LnMessage[DLCOfferTLV])
extends AcceptDLCCliCommand
case class AcceptDLCOfferFromFile(path: Path, destination: Option[Path])
extends AcceptDLCCliCommand
sealed trait SignDLCCliCommand extends AppServerCliCommand
case class SignDLC(accept: LnMessage[DLCAcceptTLV]) extends SignDLCCliCommand
case class SignDLCFromFile(path: Path, destination: Option[Path])
extends SignDLCCliCommand
sealed trait AddDLCSigsCliCommand extends AppServerCliCommand
case class AddDLCSigs(sigs: LnMessage[DLCSignTLV])
extends AddDLCSigsCliCommand
case class AddDLCSigsFromFile(path: Path) extends AddDLCSigsCliCommand
sealed trait AddDLCSigsAndBroadcastCliCommand extends AddDLCSigsCliCommand
@ -2425,42 +2407,8 @@ object CliCommand {
case class AddDLCSigsAndBroadcastFromFile(path: Path)
extends AddDLCSigsAndBroadcastCliCommand
case class GetDLCFundingTx(contractId: ByteVector) extends AppServerCliCommand
case class BroadcastDLCFundingTx(contractId: ByteVector)
extends AppServerCliCommand
case class ExecuteDLC(
contractId: ByteVector,
oracleSigs: Vector[OracleAttestmentTLV],
noBroadcast: Boolean)
extends AppServerCliCommand
with Broadcastable
case class ExecuteDLCRefund(contractId: ByteVector, noBroadcast: Boolean)
extends AppServerCliCommand
with Broadcastable
case class CancelDLC(dlcId: Sha256Digest) extends AppServerCliCommand
case object GetDLCs extends AppServerCliCommand
case class GetDLC(dlcId: Sha256Digest) extends AppServerCliCommand
case class CreateContractInfo(
announcementTLV: OracleAnnouncementTLV,
totalCollateral: Satoshis,
contractDescriptor: ujson.Value)
extends AppServerCliCommand
object CreateContractInfo {
lazy val empty: CreateContractInfo = {
CreateContractInfo(announcementTLV = OracleAnnouncementV0TLV.dummy,
totalCollateral = Satoshis.zero,
contractDescriptor = ujson.Null)
}
}
case class AddDLCOffer(
offer: LnMessage[DLCOfferTLV],
peer: String,
@ -2469,79 +2417,9 @@ object CliCommand {
case class RemoveDLCOffer(offerHash: Sha256Digest) extends AppServerCliCommand
sealed trait SendCliCommand extends AppServerCliCommand {
def destination: BitcoinAddress
}
// Wallet
case class SendToAddress(
destination: BitcoinAddress,
amount: Bitcoins,
satoshisPerVirtualByte: Option[SatoshisPerVirtualByte],
noBroadcast: Boolean)
extends SendCliCommand
with Broadcastable
case class SendFromOutPoints(
outPoints: Vector[TransactionOutPoint],
destination: BitcoinAddress,
amount: Bitcoins,
feeRateOpt: Option[SatoshisPerVirtualByte])
extends SendCliCommand
case class SweepWallet(
destination: BitcoinAddress,
feeRateOpt: Option[SatoshisPerVirtualByte])
extends SendCliCommand
case class SendWithAlgo(
destination: BitcoinAddress,
amount: Bitcoins,
feeRateOpt: Option[SatoshisPerVirtualByte],
algo: CoinSelectionAlgo)
extends SendCliCommand
case class OpReturnCommit(
message: String,
hashMessage: Boolean,
feeRateOpt: Option[SatoshisPerVirtualByte])
extends AppServerCliCommand
case class BumpFeeCPFP(
txId: DoubleSha256DigestBE,
feeRate: SatoshisPerVirtualByte)
extends AppServerCliCommand
case class BumpFeeRBF(
txId: DoubleSha256DigestBE,
feeRate: SatoshisPerVirtualByte)
extends AppServerCliCommand
case class SignPSBT(psbt: PSBT) extends AppServerCliCommand
case class LockUnspent(
unlock: Boolean,
outPoints: Vector[LockUnspentOutputParameter])
extends AppServerCliCommand
case class LabelAddress(address: BitcoinAddress, label: AddressLabelTag)
extends AppServerCliCommand
case class GetAddressTags(address: BitcoinAddress) extends AppServerCliCommand
case class GetAddressLabel(address: BitcoinAddress)
extends AppServerCliCommand
case object GetAddressLabels extends AppServerCliCommand
case class DropAddressLabel(address: BitcoinAddress, label: String)
extends AppServerCliCommand
case class DropAddressLabels(address: BitcoinAddress)
extends AppServerCliCommand
case class GetNewAddress(labelOpt: Option[AddressLabelTag])
extends AppServerCliCommand
case object GetUtxos extends AppServerCliCommand
case object ListReservedUtxos extends AppServerCliCommand
case object GetAddresses extends AppServerCliCommand
@ -2552,55 +2430,14 @@ object CliCommand {
case object CreateNewAccount extends AppServerCliCommand
case object IsEmpty extends AppServerCliCommand
case object WalletInfo extends AppServerCliCommand
case class GetBalance(isSats: Boolean) extends AppServerCliCommand
case class GetConfirmedBalance(isSats: Boolean) extends AppServerCliCommand
case class GetUnconfirmedBalance(isSats: Boolean) extends AppServerCliCommand
case class GetBalances(isSats: Boolean) extends AppServerCliCommand
case class GetAddressInfo(address: BitcoinAddress) extends AppServerCliCommand
case object GetDLCWalletAccounting extends AppServerCliCommand
case class GetTransaction(txId: DoubleSha256DigestBE)
extends AppServerCliCommand
case class KeyManagerPassphraseChange(
oldPassword: AesPassword,
newPassword: AesPassword)
extends AppServerCliCommand
case class KeyManagerPassphraseSet(password: AesPassword)
extends AppServerCliCommand
case class ImportSeed(
walletNameOpt: Option[String],
mnemonic: MnemonicCode,
passwordOpt: Option[AesPassword])
extends AppServerCliCommand
case class ExportSeed(
walletNameOpt: Option[String],
passwordOpt: Option[AesPassword])
extends AppServerCliCommand
case class MarkSeedAsBackedUp(
walletNameOpt: Option[String],
passwordOpt: Option[AesPassword])
extends AppServerCliCommand
case class GetSeedBackupTime(
walletNameOpt: Option[String],
passwordOpt: Option[AesPassword])
extends AppServerCliCommand
case class ImportXprv(
walletNameOpt: Option[String],
xprv: ExtPrivateKey,
passwordOpt: Option[AesPassword])
extends AppServerCliCommand
// Node
case object GetPeers extends AppServerCliCommand
case object Stop extends AppServerCliCommand
case class SendRawTransaction(tx: Transaction) extends AppServerCliCommand
// Chain
case object GetBestBlockHash extends AppServerCliCommand
@ -2608,37 +2445,11 @@ object CliCommand {
case object GetFilterCount extends AppServerCliCommand
case object GetFilterHeaderCount extends AppServerCliCommand
case class GetBlockHeader(hash: DoubleSha256DigestBE)
extends AppServerCliCommand
case object GetMedianTimePast extends AppServerCliCommand
case class DecodeRawTransaction(transaction: Transaction)
extends AppServerCliCommand
case class Rescan(
addressBatchSize: Option[Int],
startBlock: Option[BlockStamp],
endBlock: Option[BlockStamp],
force: Boolean,
ignoreCreationTime: Boolean)
extends AppServerCliCommand
// PSBT
case class DecodePSBT(psbt: PSBT) extends AppServerCliCommand
case class CombinePSBTs(psbts: Seq[PSBT]) extends AppServerCliCommand
case class JoinPSBTs(psbts: Seq[PSBT]) extends AppServerCliCommand
case class FinalizePSBT(psbt: PSBT) extends AppServerCliCommand
case class ExtractFromPSBT(psbt: PSBT) extends AppServerCliCommand
case class ConvertToPSBT(transaction: Transaction) extends AppServerCliCommand
case class AnalyzePSBT(psbt: PSBT) extends AppServerCliCommand
// Util
case class CreateMultisig(
requiredKeys: Int,
keys: Vector[ECPublicKey],
addressType: AddressType)
extends AppServerCliCommand
case class ZipDataDir(path: Path) extends AppServerCliCommand

View file

@ -1,44 +1,21 @@
package org.bitcoins.gui
import org.bitcoins.cli.CliCommand.{
import org.bitcoins.cli.CliCommand.AddDLCSigsAndBroadcastCliCommand
import org.bitcoins.commons.rpc.{
AcceptDLCCliCommand,
AddDLCSigsAndBroadcastCliCommand,
CreateDLCOffer,
SignDLCCliCommand
}
import org.bitcoins.core.protocol.dlc.models.DLCStatus
import org.bitcoins.core.protocol.tlv.{
ContractInfoV0TLV,
DLCAcceptTLV,
DLCOfferTLV,
DLCSignTLV,
LnMessageFactory,
OracleAnnouncementV0TLV
}
import org.bitcoins.core.protocol.tlv._
import org.bitcoins.gui.contract.GlobalContractData
import org.bitcoins.gui.dlc.DLCPaneModel
import org.bitcoins.gui.dlc.dialog.{
AcceptOfferDialog,
BroadcastDLCDialog,
CreateDLCOfferDialog,
DLCDialogContainer,
SignDLCDialog,
ViewDLCDialog
}
import org.bitcoins.gui.dlc.dialog._
import org.bitcoins.gui.util.GUIUtil
import scalafx.beans.property.StringProperty
import scalafx.geometry._
import scalafx.scene.Parent
import scalafx.scene.control.{
ContextMenu,
Hyperlink,
Label,
MenuItem,
TableColumn,
TableView,
TextArea,
TextField
}
import scalafx.scene.control._
import scalafx.scene.layout._
import java.io.File

View file

@ -4,6 +4,8 @@ import akka.actor.{ActorSystem, Cancellable}
import grizzled.slf4j.Logging
import org.bitcoins.cli.CliCommand._
import org.bitcoins.cli.ConsoleCli
import org.bitcoins.cli.ConsoleCli.exec
import org.bitcoins.commons.rpc.GetNewAddress
import org.bitcoins.core.config.DLC
import org.bitcoins.core.dlc.accounting.RateOfReturnUtil
import org.bitcoins.core.serializers.PicklerKeys
@ -60,8 +62,7 @@ class WalletGUIModel(dlcModel: DLCPaneModel)(implicit system: ActorSystem)
taskRunner.run(
caption = "Get New Address",
op = {
ConsoleCli.exec(GetNewAddress(None),
GlobalData.consoleCliConfig) match {
exec(GetNewAddress(None), GlobalData.consoleCliConfig) match {
case Success(commandReturn) => addressP.success(commandReturn)
case Failure(err) =>
addressP.failure(err)

View file

@ -1,8 +1,8 @@
package org.bitcoins.gui.dialog
import grizzled.slf4j.Logging
import org.bitcoins.cli.CliCommand.{LockUnspent, Rescan}
import org.bitcoins.cli.ConsoleCli
import org.bitcoins.commons.rpc.{LockUnspent, Rescan}
import org.bitcoins.gui.{GlobalData, TaskRunner}
import scalafx.Includes._
import scalafx.geometry.Pos
@ -56,7 +56,7 @@ object DebugDialog extends Logging {
unreserveAllUTXOsButton.onAction = _ => {
taskRunner.run(
"Unreserve All UTXOs", {
ConsoleCli.exec(LockUnspent(true, Vector.empty),
ConsoleCli.exec(LockUnspent(unlock = true, Vector.empty),
GlobalData.consoleCliConfig) match {
case Success(_) => ()
case Failure(err) =>
@ -107,7 +107,7 @@ object DebugDialog extends Logging {
private def setRescanAction(taskRunner: TaskRunner, button: Button): Unit = {
val rescanCmd = {
Rescan(addressBatchSize = Some(200),
Rescan(batchSize = Some(200),
startBlock = None,
endBlock = None,
force = true,

View file

@ -1,6 +1,6 @@
package org.bitcoins.gui.dialog
import org.bitcoins.cli.CliCommand.{SendCliCommand, SendToAddress, SweepWallet}
import org.bitcoins.commons.rpc.{SendCliCommand, SendToAddress, SweepWallet}
import org.bitcoins.core.currency._
import org.bitcoins.core.protocol.BitcoinAddress
import org.bitcoins.core.wallet.fee.{FeeUnit, SatoshisPerVirtualByte}

View file

@ -3,7 +3,14 @@ package org.bitcoins.gui.dlc
import grizzled.slf4j.Logging
import org.bitcoins.cli.CliCommand._
import org.bitcoins.cli.ConsoleCli
import org.bitcoins.commons.rpc.CliCommand
import org.bitcoins.commons.rpc.{
BroadcastDLCFundingTx,
CliCommand,
GetDLC,
GetDLCs,
GetTransaction,
SendRawTransaction
}
import org.bitcoins.commons.serializers.Picklers._
import org.bitcoins.core.protocol.dlc.models._
import org.bitcoins.core.protocol.transaction.Transaction

View file

@ -1,6 +1,6 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.cli.CliCommand._
import org.bitcoins.commons.rpc.{AcceptDLC, AcceptDLCCliCommand, AcceptDLCOffer}
import org.bitcoins.core.config.DLC
import org.bitcoins.core.protocol.dlc.models._
import org.bitcoins.core.protocol.tlv._
@ -25,10 +25,9 @@ class AcceptOfferDialog extends CliCommandProducer[AcceptDLCCliCommand] {
val text = peerAddressTF.text.value.trim
if (text.nonEmpty) {
val peer = NetworkUtil.parseInetSocketAddress(text, DLC.DefaultPort)
AcceptDLC(offer, peer)
AcceptDLC(offer = offer, peerAddr = peer, None, None)
} else {
AcceptDLCOffer(offer)
AcceptDLCOffer(offer = offer, None, None, None)
}
}

View file

@ -1,7 +1,7 @@
package org.bitcoins.gui.dlc.dialog
import grizzled.slf4j.Logging
import org.bitcoins.cli.CliCommand.CreateDLCOffer
import org.bitcoins.commons.rpc.CreateDLCOffer
import org.bitcoins.core.currency._
import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.dlc.models._
@ -573,7 +573,7 @@ class CreateDLCOfferDialog(feeRate: FeeUnit)
} else None
}
val contractInfo = oracleInfo match {
val contractInfoTLV = oracleInfo match {
case oracleInfo: EnumOracleInfo =>
val missingOutcomes = fields.values.filter(_._2.text.value.isEmpty)
if (missingOutcomes.nonEmpty) {
@ -606,11 +606,14 @@ class CreateDLCOfferDialog(feeRate: FeeUnit)
}
CreateDLCOffer(
contractInfo = contractInfo,
contractInfoTLV = contractInfoTLV,
collateral = collateral,
feeRateOpt = feeRateOpt,
refundLT = refundLocktime,
cetLocktimeOpt = None
refundLocktime = refundLocktime,
locktimeOpt = None,
externalPayoutAddressOpt = None,
externalChangeAddressOpt = None,
peerAddressOpt = None
)
}
}

View file

@ -1,6 +1,6 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.cli.CliCommand.ExecuteDLC
import org.bitcoins.commons.rpc.ExecuteDLC
import org.bitcoins.core.protocol.tlv.OracleAttestmentTLV
import scalafx.scene.Node
import scalafx.scene.control.TextField

View file

@ -1,6 +1,6 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.cli.CliCommand.ExecuteDLCRefund
import org.bitcoins.commons.rpc.ExecuteDLCRefund
import scalafx.scene.Node
import scalafx.scene.control.TextField
import scodec.bits.ByteVector

View file

@ -1,7 +1,7 @@
package org.bitcoins.gui.dlc.dialog
import grizzled.slf4j.Logging
import org.bitcoins.cli.CliCommand._
import org.bitcoins.commons.rpc.{SignDLC, SignDLCCliCommand, SignDLCFromFile}
import org.bitcoins.core.protocol.dlc.models._
import org.bitcoins.core.protocol.tlv._
import org.bitcoins.gui.GlobalData

View file

@ -1,6 +1,8 @@
package org.bitcoins.server
import org.bitcoins.asyncutil.AsyncUtil
import org.bitcoins.cli.ConsoleCli.exec
import org.bitcoins.commons.rpc.{GetBalance, GetNewAddress}
import org.bitcoins.cli.{CliCommand, Config, ConsoleCli}
import org.bitcoins.commons.util.ServerArgParser
import org.bitcoins.testkit.fixtures.BitcoinSAppConfigBitcoinFixtureNotStarted
@ -24,10 +26,8 @@ class BitcoinSServerMainBitcoindTest
_ <- server.start()
info = ConsoleCli.exec(CliCommand.WalletInfo, cliConfig)
balance = ConsoleCli.exec(CliCommand.GetBalance(isSats = true),
cliConfig)
addr = ConsoleCli.exec(CliCommand.GetNewAddress(labelOpt = None),
cliConfig)
balance = exec(GetBalance(isSats = true), cliConfig)
addr = exec(GetNewAddress(labelOpt = None), cliConfig)
blockHash = ConsoleCli.exec(CliCommand.GetBestBlockHash, cliConfig)
_ <- AsyncUtil.nonBlockingSleep(1.second)
_ <- server.stop() //stop to free all resources

View file

@ -1,7 +1,9 @@
package org.bitcoins.server
import org.bitcoins.asyncutil.AsyncUtil
import org.bitcoins.cli.ConsoleCli.exec
import org.bitcoins.cli.{CliCommand, Config, ConsoleCli}
import org.bitcoins.commons.rpc.{GetBalance, GetNewAddress}
import org.bitcoins.commons.util.ServerArgParser
import org.bitcoins.testkit.fixtures.BitcoinSAppConfigBitcoinFixtureNotStarted
import org.bitcoins.testkit.tor.CachedTor
@ -27,10 +29,8 @@ class BitcoinSServerMainBitcoindTorTest
_ <- server.start()
info = ConsoleCli.exec(CliCommand.WalletInfo, cliConfig)
balance = ConsoleCli.exec(CliCommand.GetBalance(isSats = true),
cliConfig)
addr = ConsoleCli.exec(CliCommand.GetNewAddress(labelOpt = None),
cliConfig)
balance = exec(GetBalance(isSats = true), cliConfig)
addr = exec(GetNewAddress(labelOpt = None), cliConfig)
blockHash = ConsoleCli.exec(CliCommand.GetBestBlockHash, cliConfig)
_ <- AsyncUtil.nonBlockingSleep(1.second)
_ <- server.stop() //stop to free all resources

View file

@ -59,18 +59,18 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
// the genesis address
val testAddressStr = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
val testAddress = BitcoinAddress.fromString(testAddressStr)
val testAddress: BitcoinAddress = BitcoinAddress.fromString(testAddressStr)
val testLabel: AddressLabelTag = AddressLabelTag("test")
val mockWalletApi = mock[MockWalletApi]
val mockWalletApi: MockWalletApi = mock[MockWalletApi]
val mockChainApi = mock[ChainApi]
val mockChainApi: ChainApi = mock[ChainApi]
val mockNode = mock[Node]
val mockNode: Node = mock[Node]
val chainRoutes = ChainRoutes(mockChainApi, RegTest, Future.unit)
val chainRoutes: ChainRoutes = ChainRoutes(mockChainApi, RegTest, Future.unit)
val nodeRoutes = NodeRoutes(mockNode)
val nodeRoutes: NodeRoutes = NodeRoutes(mockNode)
val walletRoutes: WalletRoutes =
WalletRoutes(mockWalletApi)(system, conf.walletConf)

View file

@ -10,6 +10,7 @@ import akka.http.scaladsl.model.ws.{
}
import akka.http.scaladsl.model.{HttpHeader, StatusCodes}
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import org.bitcoins.cli.ConsoleCli.exec
import org.bitcoins.cli.{CliCommand, Config, ConsoleCli}
import org.bitcoins.commons.jsonmodels.ws.ChainNotification.{
BlockProcessedNotification,
@ -22,6 +23,14 @@ import org.bitcoins.commons.jsonmodels.ws.{
WalletWsType,
WsNotification
}
import org.bitcoins.commons.rpc.{
GetBlockHeader,
GetNewAddress,
GetTransaction,
LockUnspent,
Rescan,
SendToAddress
}
import org.bitcoins.commons.serializers.{Picklers, WsPicklers}
import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.protocol.BitcoinAddress
@ -94,8 +103,7 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
val cliConfig = Config(rpcPortOpt = Some(server.conf.rpcPort),
rpcPassword = "wrong password")
val cliResponse =
ConsoleCli.exec(CliCommand.GetNewAddress(labelOpt = None), cliConfig)
val cliResponse = exec(GetNewAddress(labelOpt = None), cliConfig)
assert(cliResponse.isFailure)
assert(
@ -121,9 +129,8 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
notificationsF._2._1
val promise: Promise[Option[Message]] = notificationsF._2._2
val expectedAddressStr = ConsoleCli
.exec(CliCommand.GetNewAddress(labelOpt = None), cliConfig)
.get
val expectedAddressStr =
exec(GetNewAddress(labelOpt = None), cliConfig).get
val expectedAddress = BitcoinAddress.fromString(expectedAddressStr)
for {
@ -157,14 +164,14 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
for {
address <- addressF
cmd = CliCommand.SendToAddress(destination = address,
amount = Bitcoins.one,
satoshisPerVirtualByte =
Some(SatoshisPerVirtualByte.one),
noBroadcast = false)
cmd = SendToAddress(destination = address,
amount = Bitcoins.one,
satoshisPerVirtualByte =
Some(SatoshisPerVirtualByte.one),
noBroadcast = false)
txIdStr = ConsoleCli.exec(cmd, cliConfig)
expectedTxId = DoubleSha256DigestBE.fromHex(txIdStr.get)
getTxCmd = CliCommand.GetTransaction(expectedTxId)
getTxCmd = GetTransaction(expectedTxId)
expectedTxStr = ConsoleCli.exec(getTxCmd, cliConfig)
expectedTx = Transaction.fromHex(expectedTxStr.get)
_ <- AkkaUtil.nonBlockingSleep(500.millis)
@ -196,14 +203,14 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
for {
address <- addressF
cmd = CliCommand.SendToAddress(destination = address,
amount = Bitcoins.one,
satoshisPerVirtualByte =
Some(SatoshisPerVirtualByte.one),
noBroadcast = false)
cmd = SendToAddress(destination = address,
amount = Bitcoins.one,
satoshisPerVirtualByte =
Some(SatoshisPerVirtualByte.one),
noBroadcast = false)
txIdStr = ConsoleCli.exec(cmd, cliConfig)
expectedTxId = DoubleSha256DigestBE.fromHex(txIdStr.get)
getTxCmd = CliCommand.GetTransaction(expectedTxId)
getTxCmd = GetTransaction(expectedTxId)
expectedTxStr = ConsoleCli.exec(getTxCmd, cliConfig)
expectedTx = Transaction.fromHex(expectedTxStr.get)
_ <- AkkaUtil.nonBlockingSleep(500.millis)
@ -236,7 +243,7 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
for {
address <- addressF
hashes <- bitcoind.generateToAddress(1, address)
cmd = CliCommand.GetBlockHeader(hash = hashes.head)
cmd = GetBlockHeader(hash = hashes.head)
getBlockHeaderResultStr = ConsoleCli.exec(cmd, cliConfig)
getBlockHeaderResult = upickle.default.read(getBlockHeaderResultStr.get)(
Picklers.getBlockHeaderResultPickler)
@ -268,11 +275,11 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
val promise = tuple._2._2
//lock all utxos
val lockCmd = CliCommand.LockUnspent(unlock = false, Vector.empty)
val lockCmd = LockUnspent(unlock = false, Vector.empty)
ConsoleCli.exec(lockCmd, cliConfig)
//unlock all utxos
val unlockCmd = CliCommand.LockUnspent(unlock = true, Vector.empty)
val unlockCmd = LockUnspent(unlock = true, Vector.empty)
ConsoleCli.exec(unlockCmd, cliConfig)
for {
@ -387,11 +394,11 @@ class WebsocketTests extends BitcoinSServerMainBitcoindFixture {
}
val notificationsF = tuple._2._1
val promise = tuple._2._2
val cmd = CliCommand.Rescan(addressBatchSize = None,
startBlock = None,
endBlock = None,
force = true,
ignoreCreationTime = false)
val cmd = Rescan(batchSize = None,
startBlock = None,
endBlock = None,
force = true,
ignoreCreationTime = false)
val _ = ConsoleCli.exec(cmd, cliConfig)
for {
_ <- AkkaUtil.nonBlockingSleep(5000.millis)

View file

@ -4,6 +4,7 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import org.bitcoins.commons.jsonmodels.BitcoinSServerInfo
import org.bitcoins.commons.rpc.GetBlockHeader
import org.bitcoins.commons.serializers.Picklers
import org.bitcoins.commons.serializers.Picklers._
import org.bitcoins.core.api.chain.ChainApi

View file

@ -11,6 +11,7 @@ import org.bitcoins.core.protocol.script.{
P2SHScriptPubKey,
P2WSHWitnessSPKV0
}
import org.bitcoins.commons.rpc._
import org.bitcoins.core.protocol.{Bech32Address, P2SHAddress}
import org.bitcoins.core.psbt.PSBT
import org.bitcoins.server.routes.{Server, ServerCommand, ServerRoute}

View file

@ -62,7 +62,7 @@ case class DLCRoutes(dlcNode: DLCNodeApi)(implicit system: ActorSystem)
EnumSingleOracleInfo(create.announcementTLV)
}
val contractInfo = SingleContractInfo(create.totalCollateral,
create.contractDescriptor,
create.ContractDescriptorTLV,
oracleInfo)
Server.httpSuccess(contractInfo.hex)
}

View file

@ -6,6 +6,7 @@ import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import akka.stream.Materializer
import grizzled.slf4j.Logging
import org.bitcoins.commons.rpc._
import org.bitcoins.commons.serializers.Picklers._
import org.bitcoins.core.api.dlc.wallet.DLCNeutrinoHDWalletApi
import org.bitcoins.core.api.wallet.db.SpendingInfoDb
@ -630,10 +631,9 @@ case class WalletRoutes(wallet: DLCNeutrinoHDWalletApi)(implicit
}
}
}
case ServerCommand("sendfromoutpoints", arr) =>
withValidServerCommand(SendFromOutpoints.fromJsArr(arr)) {
case SendFromOutpoints(outPoints,
withValidServerCommand(SendFromOutPoints.fromJsArr(arr)) {
case SendFromOutPoints(outPoints,
address,
bitcoins,
satoshisPerVirtualByteOpt) =>