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