mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 19:37:30 +01:00
Replace Bitcoins params in RPC client with CurrencyUnit (#618)
* implemented currency unit and wrote a writer * Convert more Bitcoins parameters to CurrencyUnit
This commit is contained in:
parent
1b3a964027
commit
87dabed2b1
4 changed files with 37 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.rpc.client.common
|
||||
|
||||
import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE}
|
||||
import org.bitcoins.core.currency.{Bitcoins, Satoshis}
|
||||
import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.blockchain.MerkleBlock
|
||||
import org.bitcoins.rpc.client.common.RpcOpts.{AddressType, FeeEstimationMode}
|
||||
|
@ -133,29 +133,31 @@ trait TransactionRpc { self: Client =>
|
|||
}
|
||||
|
||||
def sendMany(
|
||||
amounts: Map[BitcoinAddress, Bitcoins],
|
||||
amounts: Map[BitcoinAddress, CurrencyUnit],
|
||||
minconf: Int = 1,
|
||||
comment: String = "",
|
||||
subtractFeeFrom: Vector[BitcoinAddress] = Vector.empty): Future[
|
||||
DoubleSha256DigestBE] = {
|
||||
bitcoindCall[DoubleSha256DigestBE]("sendmany",
|
||||
bitcoindCall[DoubleSha256DigestBE](
|
||||
"sendmany",
|
||||
List(JsString(""),
|
||||
Json.toJson(amounts),
|
||||
Json.toJson(amounts.mapValues(curr => Bitcoins(curr.satoshis))),
|
||||
JsNumber(minconf),
|
||||
JsString(comment),
|
||||
Json.toJson(subtractFeeFrom)))
|
||||
Json.toJson(subtractFeeFrom))
|
||||
)
|
||||
}
|
||||
|
||||
def sendToAddress(
|
||||
address: BitcoinAddress,
|
||||
amount: Bitcoins,
|
||||
amount: CurrencyUnit,
|
||||
localComment: String = "",
|
||||
toComment: String = "",
|
||||
subractFeeFromAmount: Boolean = false): Future[DoubleSha256DigestBE] = {
|
||||
bitcoindCall[DoubleSha256DigestBE](
|
||||
"sendtoaddress",
|
||||
List(Json.toJson(address),
|
||||
Json.toJson(amount),
|
||||
Json.toJson(Bitcoins(amount.satoshis)),
|
||||
JsString(localComment),
|
||||
JsString(toComment),
|
||||
JsBoolean(subractFeeFromAmount))
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.bitcoins.rpc.serializers.JsonSerializers._
|
|||
import play.api.libs.json.{JsNumber, JsString}
|
||||
|
||||
import scala.concurrent.Future
|
||||
import org.bitcoins.core.currency.CurrencyUnit
|
||||
import play.api.libs.json.Json
|
||||
|
||||
/**
|
||||
* RPC calls related to transaction sending
|
||||
|
@ -19,12 +21,12 @@ trait V16SendRpc { self: Client =>
|
|||
def move(
|
||||
fromAccount: String,
|
||||
toAccount: String,
|
||||
amount: Bitcoins,
|
||||
amount: CurrencyUnit,
|
||||
comment: String = ""): Future[Boolean] = {
|
||||
bitcoindCall[Boolean]("move",
|
||||
List(JsString(fromAccount),
|
||||
JsString(toAccount),
|
||||
JsNumber(amount.toBigDecimal),
|
||||
Json.toJson(Bitcoins(amount.satoshis)),
|
||||
JsNumber(6),
|
||||
JsString(comment)))
|
||||
}
|
||||
|
@ -32,15 +34,15 @@ trait V16SendRpc { self: Client =>
|
|||
def sendFrom(
|
||||
fromAccount: String,
|
||||
toAddress: BitcoinAddress,
|
||||
amount: Bitcoins,
|
||||
amount: CurrencyUnit,
|
||||
confirmations: Int = 1,
|
||||
comment: String = "",
|
||||
toComment: String = ""): Future[DoubleSha256DigestBE] = {
|
||||
bitcoindCall[DoubleSha256DigestBE](
|
||||
"sendfrom",
|
||||
List(JsString(fromAccount),
|
||||
JsString(toAddress.value),
|
||||
JsNumber(amount.toBigDecimal),
|
||||
Json.toJson(toAddress),
|
||||
Json.toJson(Bitcoins(amount.satoshis)),
|
||||
JsNumber(confirmations),
|
||||
JsString(comment),
|
||||
JsString(toComment))
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.bitcoins.rpc.serializers.JsonSerializers._
|
|||
import play.api.libs.json._
|
||||
|
||||
import scala.concurrent.Future
|
||||
import org.bitcoins.core.currency.CurrencyUnit
|
||||
|
||||
/**
|
||||
* RPC calls related to PSBT (partially signed bitcoin transactions)
|
||||
|
@ -43,12 +44,13 @@ trait V17PsbtRpc { self: Client =>
|
|||
|
||||
def createPsbt(
|
||||
inputs: Vector[TransactionInput],
|
||||
outputs: Map[BitcoinAddress, Bitcoins],
|
||||
outputs: Map[BitcoinAddress, CurrencyUnit],
|
||||
locktime: Int = 0,
|
||||
replacable: Boolean = false): Future[String] = {
|
||||
bitcoindCall[String]("createpsbt",
|
||||
bitcoindCall[String](
|
||||
"createpsbt",
|
||||
List(Json.toJson(inputs),
|
||||
Json.toJson(outputs),
|
||||
Json.toJson(outputs.mapValues(curr => Bitcoins(curr.satoshis))),
|
||||
JsNumber(locktime),
|
||||
JsBoolean(replacable)))
|
||||
}
|
||||
|
@ -66,17 +68,19 @@ trait V17PsbtRpc { self: Client =>
|
|||
|
||||
def walletCreateFundedPsbt(
|
||||
inputs: Vector[TransactionInput],
|
||||
outputs: Map[BitcoinAddress, Bitcoins],
|
||||
outputs: Map[BitcoinAddress, CurrencyUnit],
|
||||
locktime: Int = 0,
|
||||
options: WalletCreateFundedPsbtOptions = WalletCreateFundedPsbtOptions(),
|
||||
bip32derivs: Boolean = false
|
||||
): Future[WalletCreateFundedPsbtResult] =
|
||||
bitcoindCall[WalletCreateFundedPsbtResult]("walletcreatefundedpsbt",
|
||||
bitcoindCall[WalletCreateFundedPsbtResult](
|
||||
"walletcreatefundedpsbt",
|
||||
List(Json.toJson(inputs),
|
||||
Json.toJson(outputs),
|
||||
Json.toJson(outputs.mapValues(curr => Bitcoins(curr.satoshis))),
|
||||
JsNumber(locktime),
|
||||
Json.toJson(options),
|
||||
Json.toJson(bip32derivs)))
|
||||
Json.toJson(bip32derivs))
|
||||
)
|
||||
|
||||
def walletProcessPsbt(
|
||||
psbt: String,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.rpc.serializers
|
||||
|
||||
import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE}
|
||||
import org.bitcoins.core.currency.Bitcoins
|
||||
import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit}
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.ln.currency.MilliSatoshis
|
||||
|
|
Loading…
Add table
Reference in a new issue