mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 20:30:17 +01:00
Nicer Satoshis.apply (#899)
* Replaced Satoshis(Int64(_)) with Satoshis(_) * Fixed SignerTest
This commit is contained in:
parent
804f18f47f
commit
15ec7b89b6
26 changed files with 138 additions and 147 deletions
|
@ -31,8 +31,8 @@ import scala.async.Async.{async, await}
|
|||
import scala.concurrent.Future
|
||||
|
||||
class WalletRpcTest extends BitcoindRpcTest {
|
||||
lazy val clientsF: Future[
|
||||
(BitcoindRpcClient, BitcoindRpcClient, BitcoindRpcClient)] =
|
||||
lazy val clientsF
|
||||
: Future[(BitcoindRpcClient, BitcoindRpcClient, BitcoindRpcClient)] =
|
||||
BitcoindRpcTestUtil.createNodeTripleV17(clientAccum = clientAccum)
|
||||
|
||||
// This client's wallet is encrypted
|
||||
|
@ -487,7 +487,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
|||
info <- client.getWalletInfo
|
||||
} yield {
|
||||
assert(success)
|
||||
assert(info.paytxfee == SatoshisPerByte(Satoshis(Int64(1000))))
|
||||
assert(info.paytxfee == SatoshisPerByte(Satoshis(1000)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.time.ZoneOffset
|
|||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.{Bitcoins, Satoshis}
|
||||
import org.bitcoins.core.number.{Int32, Int64, UInt32, UInt64}
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
|
||||
import org.bitcoins.core.protocol.script.{
|
||||
ScriptPubKey,
|
||||
|
@ -115,8 +115,8 @@ object JsonReaders {
|
|||
|
||||
implicit object SatoshisReads extends Reads[Satoshis] {
|
||||
override def reads(json: JsValue): JsResult[Satoshis] =
|
||||
SerializerUtil.processJsNumber[Satoshis](num =>
|
||||
Satoshis(Int64(num.toBigInt)))(json)
|
||||
SerializerUtil.processJsNumber[Satoshis](num => Satoshis(num.toBigInt))(
|
||||
json)
|
||||
}
|
||||
|
||||
implicit object BlockHeaderReads extends Reads[BlockHeader] {
|
||||
|
@ -522,7 +522,7 @@ object JsonReaders {
|
|||
implicit object BitcoinFeeUnitReads extends Reads[BitcoinFeeUnit] {
|
||||
override def reads(json: JsValue): JsResult[BitcoinFeeUnit] =
|
||||
SerializerUtil.processJsNumber[BitcoinFeeUnit](num =>
|
||||
SatoshisPerByte(Satoshis(Int64((num * 100000).toBigInt))))(json)
|
||||
SatoshisPerByte(Satoshis((num * 100000).toBigInt)))(json)
|
||||
}
|
||||
|
||||
implicit object FileReads extends Reads[File] {
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.net.{InetAddress, URI}
|
|||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.{Bitcoins, Satoshis}
|
||||
import org.bitcoins.core.hd.BIP32Path
|
||||
import org.bitcoins.core.number.{Int32, Int64, UInt32, UInt64}
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
|
||||
import org.bitcoins.core.protocol.script.{ScriptPubKey, ScriptSignature}
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
|
@ -153,7 +153,7 @@ object JsonSerializers {
|
|||
|
||||
def reads(json: JsValue): JsResult[SatoshisPerKiloByte] =
|
||||
SerializerUtil.processJsNumber(num =>
|
||||
SatoshisPerKiloByte(Satoshis(Int64(num.toBigInt))))(json)
|
||||
SatoshisPerKiloByte(Satoshis(num.toBigInt)))(json)
|
||||
}
|
||||
|
||||
implicit val peerNetworkInfoReads: Reads[PeerNetworkInfo] =
|
||||
|
@ -182,7 +182,8 @@ object JsonSerializers {
|
|||
Json.reads[GetBlockResult]
|
||||
|
||||
implicit val getBlockWithTransactionsResultReads: Reads[
|
||||
GetBlockWithTransactionsResult] = Json.reads[GetBlockWithTransactionsResult]
|
||||
GetBlockWithTransactionsResult] =
|
||||
Json.reads[GetBlockWithTransactionsResult]
|
||||
|
||||
implicit val softforkProgressReads: Reads[SoftforkProgress] =
|
||||
Json.reads[SoftforkProgress]
|
||||
|
@ -430,7 +431,8 @@ object JsonSerializers {
|
|||
Json.reads[GetDescriptorInfoResult]
|
||||
|
||||
implicit val walletCreateFundedPsbtResultReads: Reads[
|
||||
WalletCreateFundedPsbtResult] = Json.reads[WalletCreateFundedPsbtResult]
|
||||
WalletCreateFundedPsbtResult] =
|
||||
Json.reads[WalletCreateFundedPsbtResult]
|
||||
|
||||
implicit val scriptTypeReads: Reads[ScriptType] = ScriptTypeReads
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers {
|
|||
val wtx = WitnessTransaction(rawTx)
|
||||
val witScriptPubKey =
|
||||
P2WPKHWitnessSPKV0("1600144c9c3dfac4207d5d8cb89df5722cb3d712385e3f")
|
||||
val amount = Satoshis(Int64(2000))
|
||||
val amount = Satoshis(2000)
|
||||
val txSigComponent =
|
||||
WitnessTxSigComponentRaw(wtx,
|
||||
inputIndex,
|
||||
|
@ -358,7 +358,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers {
|
|||
|
||||
val p2wsh = P2WSHWitnessSPKV0.fromAsmHex(
|
||||
"00209e1be07558ea5cc8e02ed1d80c0911048afad949affa36d5c3951e3159dbea19")
|
||||
val amount = Satoshis(Int64(200000))
|
||||
val amount = Satoshis(200000)
|
||||
val output = TransactionOutput(amount, p2wsh)
|
||||
|
||||
//OP_CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>
|
||||
|
|
|
@ -27,10 +27,10 @@ class CurrencyUnitTest extends BitcoinSUnitTest {
|
|||
assert(num.bitcoin == Bitcoins(num))
|
||||
assert(num.BTC == Bitcoins(num))
|
||||
|
||||
assert(num.satoshis == Satoshis(Int64(num)))
|
||||
assert(num.satoshi == Satoshis(Int64(num)))
|
||||
assert(num.sats == Satoshis(Int64(num)))
|
||||
assert(num.sat == Satoshis(Int64(num)))
|
||||
assert(num.satoshis == Satoshis(num))
|
||||
assert(num.satoshi == Satoshis(num))
|
||||
assert(num.sats == Satoshis(num))
|
||||
assert(num.sat == Satoshis(num))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,10 @@ class CurrencyUnitTest extends BitcoinSUnitTest {
|
|||
}
|
||||
|
||||
forAll(Gen.choose(0, Satoshis.max.toLong)) { num =>
|
||||
assert(num.satoshis == Satoshis(Int64(num)))
|
||||
assert(num.satoshi == Satoshis(Int64(num)))
|
||||
assert(num.sats == Satoshis(Int64(num)))
|
||||
assert(num.sat == Satoshis(Int64(num)))
|
||||
assert(num.satoshis == Satoshis(num))
|
||||
assert(num.satoshi == Satoshis(num))
|
||||
assert(num.sats == Satoshis(num))
|
||||
assert(num.sat == Satoshis(num))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ class CurrencyUnitTest extends BitcoinSUnitTest {
|
|||
forAll(CurrencyUnitGenerator.satoshis, CurrencyUnitGenerator.bitcoins) {
|
||||
(sats: Satoshis, btc: Bitcoins) =>
|
||||
val result =
|
||||
Try(Satoshis(Int64(sats.toBigInt + btc.satoshis.toBigInt)))
|
||||
Try(Satoshis(sats.toBigInt + btc.satoshis.toBigInt))
|
||||
val expected = result.map(Bitcoins(_))
|
||||
val actual: Try[CurrencyUnit] = Try(sats + btc)
|
||||
if (actual.isSuccess && expected.isSuccess) actual.get == expected.get
|
||||
|
|
|
@ -31,7 +31,7 @@ class ChainParamsTest extends BitcoinSUnitTest {
|
|||
"434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC".toLowerCase)
|
||||
|
||||
val expectedGenesisOutput =
|
||||
TransactionOutput(Satoshis(Int64(5000000000L)), expectedGenesisScriptPubKey)
|
||||
TransactionOutput(Satoshis(5000000000L), expectedGenesisScriptPubKey)
|
||||
"ChainParams" must "generate correct block hex for genesis block" in {
|
||||
val hex = "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e6" +
|
||||
"7768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c010100000001000000000000000000000000000" +
|
||||
|
@ -66,7 +66,7 @@ class ChainParamsTest extends BitcoinSUnitTest {
|
|||
|
||||
it must "generate the output correctly for the genesis transaction's output" in {
|
||||
val output = genesisTransaction.outputs.head
|
||||
output.value must be(Satoshis(Int64(5000000000L)))
|
||||
output.value must be(Satoshis(5000000000L))
|
||||
output.scriptPubKey.hex must be(expectedGenesisScriptPubKey.hex)
|
||||
output.hex must be(
|
||||
"00F2052A01000000".toLowerCase + expectedGenesisScriptPubKey.hex)
|
||||
|
|
|
@ -31,8 +31,8 @@ object CoreTransactionTestCaseProtocol extends DefaultJsonProtocol {
|
|||
|
||||
if (elements.size < 3) None
|
||||
else {
|
||||
val creditingTxsInfo: Seq[
|
||||
(TransactionOutPoint, ScriptPubKey, Option[CurrencyUnit])] =
|
||||
val creditingTxsInfo
|
||||
: Seq[(TransactionOutPoint, ScriptPubKey, Option[CurrencyUnit])] =
|
||||
elements.head match {
|
||||
case array: JsArray => parseOutPointsScriptPubKeysAmount(array)
|
||||
case _: JsValue =>
|
||||
|
@ -58,8 +58,8 @@ object CoreTransactionTestCaseProtocol extends DefaultJsonProtocol {
|
|||
* These are in the following format
|
||||
* [[prevout hash, prevout index, prevout scriptPubKey, amount], [input 2], ...]
|
||||
*/
|
||||
def parseOutPointsScriptPubKeysAmount(array: JsArray): Seq[
|
||||
(TransactionOutPoint, ScriptPubKey, Option[CurrencyUnit])] = {
|
||||
def parseOutPointsScriptPubKeysAmount(array: JsArray)
|
||||
: Seq[(TransactionOutPoint, ScriptPubKey, Option[CurrencyUnit])] = {
|
||||
val result = array.elements.map {
|
||||
case array: JsArray =>
|
||||
val prevoutHashHex =
|
||||
|
@ -75,7 +75,7 @@ object CoreTransactionTestCaseProtocol extends DefaultJsonProtocol {
|
|||
|
||||
val amount =
|
||||
if (array.elements.size == 4)
|
||||
Some(Satoshis(Int64(array.elements(3).convertTo[Long])))
|
||||
Some(Satoshis(array.elements(3).convertTo[Long]))
|
||||
else None
|
||||
|
||||
//val prevoutIndex = UInt32(array.elements(1).convertTo[Int])
|
||||
|
|
|
@ -54,8 +54,7 @@ object CoreTestCaseProtocol extends DefaultJsonProtocol {
|
|||
//means we have a witness as the first item in our array
|
||||
val witnessArray = elements.head.asInstanceOf[JsArray]
|
||||
val amount = Satoshis(
|
||||
Int64(
|
||||
(witnessArray.elements.last.convertTo[Double] * 100000000L).toLong))
|
||||
(witnessArray.elements.last.convertTo[Double] * 100000000L).toLong)
|
||||
val stack = witnessArray.elements
|
||||
.slice(0, witnessArray.elements.size - 1)
|
||||
.map(c => BitcoinSUtil.decodeHex(c.convertTo[String]))
|
||||
|
@ -96,8 +95,7 @@ object CoreTestCaseProtocol extends DefaultJsonProtocol {
|
|||
} else if (elements.size == 6 && elements.head.isInstanceOf[JsArray]) {
|
||||
val witnessArray = elements.head.asInstanceOf[JsArray]
|
||||
val amount = Satoshis(
|
||||
Int64(
|
||||
(witnessArray.elements.last.convertTo[Double] * 100000000L).toLong))
|
||||
(witnessArray.elements.last.convertTo[Double] * 100000000L).toLong)
|
||||
val stack = witnessArray.elements
|
||||
.slice(0, witnessArray.elements.size - 1)
|
||||
.map(c => BitcoinSUtil.decodeHex(c.convertTo[String]))
|
||||
|
|
|
@ -27,7 +27,7 @@ class RawTransactionOutputParserTest extends BitcoinSUnitTest {
|
|||
|
||||
val txOutput: TransactionOutput =
|
||||
RawTransactionOutputParser.read(rawTxOutput)
|
||||
txOutput.value must be(Satoshis(Int64(20000)))
|
||||
txOutput.value must be(Satoshis(20000))
|
||||
txOutput.scriptPubKey.asm must be(
|
||||
Seq(OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
|
@ -51,7 +51,7 @@ class RawTransactionOutputParserTest extends BitcoinSUnitTest {
|
|||
val txOutput =
|
||||
"00f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"
|
||||
val output = RawTransactionOutputParser.read(txOutput)
|
||||
output.value must be(Satoshis(Int64(5000000000L)))
|
||||
output.value must be(Satoshis(5000000000L))
|
||||
}
|
||||
|
||||
it must "serialize the empty transaction output correctly" in {
|
||||
|
|
|
@ -44,7 +44,7 @@ class BitcoinTxBuilderSpec extends Properties("TxBuilderSpec") {
|
|||
ScriptGenerators.scriptPubKey,
|
||||
ChainParamsGenerator.bitcoinNetworkParams) {
|
||||
case (destinations: Seq[TransactionOutput], changeSPK, network) =>
|
||||
val fee = SatoshisPerVirtualByte(Satoshis(Int64(1000)))
|
||||
val fee = SatoshisPerVirtualByte(Satoshis(1000))
|
||||
val outpointsWithKeys =
|
||||
buildCreditingTxInfo(creditingTxsInfo.toList)
|
||||
val builder = BitcoinTxBuilder(destinations,
|
||||
|
@ -68,7 +68,7 @@ class BitcoinTxBuilderSpec extends Properties("TxBuilderSpec") {
|
|||
ScriptGenerators.scriptPubKey,
|
||||
ChainParamsGenerator.bitcoinNetworkParams) {
|
||||
case (destinations: Seq[TransactionOutput], changeSPK, network) =>
|
||||
val fee = SatoshisPerByte(Satoshis(Int64(1000)))
|
||||
val fee = SatoshisPerByte(Satoshis(1000))
|
||||
val outpointsWithKeys =
|
||||
buildCreditingTxInfo(creditingTxsInfo.toList)
|
||||
val builder = BitcoinTxBuilder(destinations,
|
||||
|
@ -110,28 +110,28 @@ class BitcoinTxBuilderSpec extends Properties("TxBuilderSpec") {
|
|||
private def buildCreditingTxInfo(
|
||||
info: List[BitcoinUTXOSpendingInfo]): BitcoinTxBuilder.UTXOMap = {
|
||||
@tailrec
|
||||
def loop(
|
||||
rem: List[BitcoinUTXOSpendingInfo],
|
||||
accum: BitcoinTxBuilder.UTXOMap): BitcoinTxBuilder.UTXOMap = rem match {
|
||||
case Nil => accum
|
||||
case BitcoinUTXOSpendingInfo(txOutPoint,
|
||||
txOutput,
|
||||
signers,
|
||||
redeemScriptOpt,
|
||||
scriptWitOpt,
|
||||
hashType,
|
||||
conditionalPath) :: t =>
|
||||
val o = txOutPoint
|
||||
val output = txOutput
|
||||
val outPointsSpendingInfo = BitcoinUTXOSpendingInfo(o,
|
||||
output,
|
||||
signers,
|
||||
redeemScriptOpt,
|
||||
scriptWitOpt,
|
||||
hashType,
|
||||
conditionalPath)
|
||||
loop(t, accum.updated(o, outPointsSpendingInfo))
|
||||
}
|
||||
def loop(rem: List[BitcoinUTXOSpendingInfo],
|
||||
accum: BitcoinTxBuilder.UTXOMap): BitcoinTxBuilder.UTXOMap =
|
||||
rem match {
|
||||
case Nil => accum
|
||||
case BitcoinUTXOSpendingInfo(txOutPoint,
|
||||
txOutput,
|
||||
signers,
|
||||
redeemScriptOpt,
|
||||
scriptWitOpt,
|
||||
hashType,
|
||||
conditionalPath) :: t =>
|
||||
val o = txOutPoint
|
||||
val output = txOutput
|
||||
val outPointsSpendingInfo = BitcoinUTXOSpendingInfo(o,
|
||||
output,
|
||||
signers,
|
||||
redeemScriptOpt,
|
||||
scriptWitOpt,
|
||||
hashType,
|
||||
conditionalPath)
|
||||
loop(t, accum.updated(o, outPointsSpendingInfo))
|
||||
}
|
||||
loop(info, Map.empty)
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ class BitcoinTxBuilderTest extends AsyncFlatSpec with MustMatchers {
|
|||
conditionalPath = ConditionalPath.NoConditionsLeft
|
||||
)
|
||||
val utxoMap: BitcoinTxBuilder.UTXOMap = Map(outPoint -> utxo)
|
||||
val feeUnit = SatoshisPerVirtualByte(Satoshis(Int64(-1)))
|
||||
val feeUnit = SatoshisPerVirtualByte(Satoshis(-1))
|
||||
val txBuilder = BitcoinTxBuilder(destinations = destinations,
|
||||
utxos = utxoMap,
|
||||
feeRate = feeUnit,
|
||||
|
@ -145,7 +145,7 @@ class BitcoinTxBuilderTest extends AsyncFlatSpec with MustMatchers {
|
|||
conditionalPath =
|
||||
ConditionalPath.NoConditionsLeft)
|
||||
val utxoMap: BitcoinTxBuilder.UTXOMap = Map(outPoint -> utxo)
|
||||
val feeUnit = SatoshisPerVirtualByte(currencyUnit = Satoshis(Int64(1)))
|
||||
val feeUnit = SatoshisPerVirtualByte(currencyUnit = Satoshis(1))
|
||||
val txBuilder = BitcoinTxBuilder(destinations = destinations,
|
||||
utxos = utxoMap,
|
||||
feeRate = feeUnit,
|
||||
|
|
|
@ -45,11 +45,11 @@ class SignerTest extends BitcoinSAsyncTest {
|
|||
}
|
||||
|
||||
it should "fail if there are inconsistent P2WPKH spending infos" in {
|
||||
val dumbSpendingInfo = CreditingTxGen.output.sample.get
|
||||
val dumbSpendingInfo = GenUtil.sample(CreditingTxGen.output)
|
||||
val p2wpkh = GenUtil
|
||||
.sample(CreditingTxGen.p2wpkhOutput)
|
||||
.asInstanceOf[P2WPKHV0SpendingInfo]
|
||||
val tx = TransactionGenerators.baseTransaction.sample.get
|
||||
val tx = GenUtil.sample(TransactionGenerators.baseTransaction)
|
||||
recoverToSucceededIf[IllegalArgumentException] {
|
||||
P2WPKHSigner.sign(dumbSpendingInfo, tx, isDummySignature = false, p2wpkh)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class SignerTest extends BitcoinSAsyncTest {
|
|||
val p2wsh = GenUtil
|
||||
.sample(CreditingTxGen.p2wshOutput)
|
||||
.asInstanceOf[P2WSHV0SpendingInfo]
|
||||
val tx = TransactionGenerators.baseTransaction.sample.get
|
||||
val tx = GenUtil.sample(TransactionGenerators.baseTransaction)
|
||||
recoverToSucceededIf[IllegalArgumentException] {
|
||||
P2WSHSigner.sign(dumbSpendingInfo, tx, isDummySignature = false, p2wsh)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bitcoins.core.consensus
|
||||
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.number.Int64
|
||||
|
||||
/**
|
||||
* Created by chris on 5/13/16.
|
||||
|
@ -20,7 +19,7 @@ sealed abstract class Consensus {
|
|||
*/
|
||||
def maxSigOps = 80000
|
||||
|
||||
def maxMoney: CurrencyUnit = Satoshis(Int64(2100000000000000L))
|
||||
def maxMoney: CurrencyUnit = Satoshis(2100000000000000L)
|
||||
|
||||
/**
|
||||
* A integer representing the maximum number of public keys you can have in a
|
||||
|
|
|
@ -84,6 +84,8 @@ object Satoshis
|
|||
override def fromBytes(bytes: ByteVector): Satoshis =
|
||||
RawSatoshisSerializer.read(bytes)
|
||||
def apply(int64: Int64): Satoshis = SatoshisImpl(int64)
|
||||
def apply(satoshis: Long): Satoshis = SatoshisImpl(Int64(satoshis))
|
||||
def apply(satoshis: BigInt): Satoshis = SatoshisImpl(Int64(satoshis))
|
||||
|
||||
private case class SatoshisImpl(underlying: Int64) extends Satoshis
|
||||
}
|
||||
|
@ -99,7 +101,7 @@ sealed abstract class Bitcoins extends CurrencyUnit {
|
|||
|
||||
override def satoshis: Satoshis = {
|
||||
val sat = underlying * CurrencyUnits.btcToSatoshiScalar
|
||||
Satoshis(Int64(sat.toLongExact))
|
||||
Satoshis(sat.toLongExact)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,10 +126,10 @@ object CurrencyUnits {
|
|||
/** The number you need to multiply BTC by to get it's satoshis */
|
||||
val btcToSatoshiScalar: Long = 100000000
|
||||
val satoshisToBTCScalar: BigDecimal = BigDecimal(1.0) / btcToSatoshiScalar
|
||||
val oneBTC: CurrencyUnit = Satoshis(Int64(btcToSatoshiScalar))
|
||||
val oneMBTC: CurrencyUnit = Satoshis(Int64(btcToSatoshiScalar / 1000))
|
||||
val oneBTC: CurrencyUnit = Satoshis(btcToSatoshiScalar)
|
||||
val oneMBTC: CurrencyUnit = Satoshis(btcToSatoshiScalar / 1000)
|
||||
val zero: CurrencyUnit = Satoshis.zero
|
||||
val negativeSatoshi = Satoshis(Int64(-1))
|
||||
val negativeSatoshi = Satoshis(-1)
|
||||
|
||||
def toSatoshis(unit: CurrencyUnit): Satoshis = unit match {
|
||||
case b: Bitcoins => b.satoshis
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.bitcoins.core
|
||||
|
||||
import org.bitcoins.core.number.Int64
|
||||
|
||||
// We extend AnyVal to avoid runtime allocation of new
|
||||
// objects. See the Scala documentation on value classes
|
||||
// and universal traits for more:
|
||||
|
@ -24,7 +22,7 @@ package object currency {
|
|||
|
||||
/** Provides natural language syntax for satoshis */
|
||||
implicit class SatoshisInt(private val i: Int) extends AnyVal {
|
||||
def satoshis: Satoshis = Satoshis(Int64(i))
|
||||
def satoshis: Satoshis = Satoshis(i)
|
||||
def satoshi: Satoshis = satoshis
|
||||
def sats: Satoshis = satoshis
|
||||
def sat: Satoshis = satoshis
|
||||
|
@ -32,7 +30,7 @@ package object currency {
|
|||
|
||||
/** Provides natural language syntax for satoshis */
|
||||
implicit class SatoshisLong(private val i: Long) extends AnyVal {
|
||||
def satoshis: Satoshis = Satoshis(Int64(i))
|
||||
def satoshis: Satoshis = Satoshis(i)
|
||||
def satoshi: Satoshis = satoshis
|
||||
def sats: Satoshis = satoshis
|
||||
def sat: Satoshis = satoshis
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bitcoins.core.policy
|
||||
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits, Satoshis}
|
||||
import org.bitcoins.core.number.Int64
|
||||
import org.bitcoins.core.script.flag._
|
||||
|
||||
/**
|
||||
|
@ -59,13 +58,13 @@ sealed abstract class Policy {
|
|||
def minChannelAmount: CurrencyUnit = CurrencyUnits.oneMBTC
|
||||
|
||||
/** The minimum amount of satoshis we can spend to an output */
|
||||
def dustThreshold: CurrencyUnit = Satoshis(Int64(1000))
|
||||
def dustThreshold: CurrencyUnit = Satoshis(1000)
|
||||
|
||||
/** A default fee to use per byte on the bitcoin network */
|
||||
def defaultFee: CurrencyUnit = Satoshis(Int64(50))
|
||||
def defaultFee: CurrencyUnit = Satoshis(50)
|
||||
|
||||
/** Max fee for a transaction is set to 10 mBTC right now */
|
||||
def maxFee: CurrencyUnit = Satoshis(Int64(10)) * CurrencyUnits.oneMBTC
|
||||
def maxFee: CurrencyUnit = Satoshis(10) * CurrencyUnits.oneMBTC
|
||||
|
||||
def isRBFEnabled: Boolean = true
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.bitcoins.core.config.{
|
|||
import org.bitcoins.core.consensus.Merkle
|
||||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.number.{Int32, Int64, UInt32}
|
||||
import org.bitcoins.core.number.{Int32, UInt32}
|
||||
import org.bitcoins.core.protocol.script.{ScriptPubKey, ScriptSignature}
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.constant.{BytesToPushOntoStack, ScriptConstant}
|
||||
|
@ -247,7 +247,7 @@ object MainNetChainParams extends BitcoinChainParams {
|
|||
UInt32(2083236893),
|
||||
UInt32(0x1d00ffff),
|
||||
Int32.one,
|
||||
Satoshis(Int64(5000000000L)))
|
||||
Satoshis(5000000000L))
|
||||
|
||||
override lazy val base58Prefixes: Map[Base58Type, ByteVector] =
|
||||
Map(
|
||||
|
@ -308,7 +308,7 @@ object TestNetChainParams extends BitcoinChainParams {
|
|||
UInt32(414098458),
|
||||
UInt32(0x1d00ffff),
|
||||
Int32.one,
|
||||
Satoshis(Int64(5000000000L)))
|
||||
Satoshis(5000000000L))
|
||||
|
||||
override lazy val base58Prefixes: Map[Base58Type, ByteVector] =
|
||||
Map(
|
||||
|
@ -359,7 +359,7 @@ object RegTestNetChainParams extends BitcoinChainParams {
|
|||
UInt32(2),
|
||||
UInt32(0x207fffff),
|
||||
Int32.one,
|
||||
Satoshis(Int64(5000000000L)))
|
||||
Satoshis(5000000000L))
|
||||
override lazy val base58Prefixes: Map[Base58Type, ByteVector] =
|
||||
TestNetChainParams.base58Prefixes
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ object LnCurrencyUnits {
|
|||
def toSatoshi(lnCurrencyUnits: LnCurrencyUnit): Satoshis = {
|
||||
val pico = lnCurrencyUnits.toPicoBitcoins
|
||||
val sat = pico.toBigInt / PICO_TO_SATOSHIS
|
||||
Satoshis(Int64(sat))
|
||||
Satoshis(sat)
|
||||
}
|
||||
|
||||
def fromMSat(msat: MilliSatoshis): PicoBitcoins = {
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.crypto.{
|
|||
WitnessTxSigComponentP2SH
|
||||
}
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits, Satoshis}
|
||||
import org.bitcoins.core.number.{Int64, UInt32}
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.policy.Policy
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
|
@ -465,41 +465,42 @@ sealed abstract class BitcoinTxBuilder extends TxBuilder {
|
|||
@tailrec
|
||||
def loop(
|
||||
remaining: Seq[UTXOSpendingInfo],
|
||||
accum: Seq[TransactionInput]): Seq[TransactionInput] = remaining match {
|
||||
case Nil => accum.reverse
|
||||
case spendingInfo +: newRemaining =>
|
||||
spendingInfo match {
|
||||
case lockTime: LockTimeSpendingInfo =>
|
||||
val sequence = lockTime.scriptPubKey match {
|
||||
case csv: CSVScriptPubKey => solveSequenceForCSV(csv.locktime)
|
||||
case _: CLTVScriptPubKey => UInt32.zero
|
||||
}
|
||||
val input = TransactionInput(lockTime.outPoint,
|
||||
EmptyScriptSignature,
|
||||
sequence)
|
||||
loop(newRemaining, input +: accum)
|
||||
case p2sh: P2SHSpendingInfo =>
|
||||
loop(p2sh.nestedSpendingInfo +: newRemaining, accum)
|
||||
case p2wsh: P2WSHV0SpendingInfo =>
|
||||
loop(p2wsh.nestedSpendingInfo +: newRemaining, accum)
|
||||
case conditional: ConditionalSpendingInfo =>
|
||||
loop(conditional.nestedSpendingInfo +: newRemaining, accum)
|
||||
case _: P2WPKHV0SpendingInfo |
|
||||
_: UnassignedSegwitNativeUTXOSpendingInfo | _: P2PKSpendingInfo |
|
||||
_: P2PKHSpendingInfo | _: MultiSignatureSpendingInfo |
|
||||
_: EmptySpendingInfo =>
|
||||
//none of these script types affect the sequence number of a tx
|
||||
//the sequence only needs to be adjustd if we have replace by fee (RBF) enabled
|
||||
//see BIP125 for more information
|
||||
val sequence =
|
||||
if (isRBFEnabled) UInt32.zero else TransactionConstants.sequence
|
||||
val input =
|
||||
TransactionInput(spendingInfo.outPoint,
|
||||
EmptyScriptSignature,
|
||||
sequence)
|
||||
loop(newRemaining, input +: accum)
|
||||
}
|
||||
}
|
||||
accum: Seq[TransactionInput]): Seq[TransactionInput] =
|
||||
remaining match {
|
||||
case Nil => accum.reverse
|
||||
case spendingInfo +: newRemaining =>
|
||||
spendingInfo match {
|
||||
case lockTime: LockTimeSpendingInfo =>
|
||||
val sequence = lockTime.scriptPubKey match {
|
||||
case csv: CSVScriptPubKey => solveSequenceForCSV(csv.locktime)
|
||||
case _: CLTVScriptPubKey => UInt32.zero
|
||||
}
|
||||
val input = TransactionInput(lockTime.outPoint,
|
||||
EmptyScriptSignature,
|
||||
sequence)
|
||||
loop(newRemaining, input +: accum)
|
||||
case p2sh: P2SHSpendingInfo =>
|
||||
loop(p2sh.nestedSpendingInfo +: newRemaining, accum)
|
||||
case p2wsh: P2WSHV0SpendingInfo =>
|
||||
loop(p2wsh.nestedSpendingInfo +: newRemaining, accum)
|
||||
case conditional: ConditionalSpendingInfo =>
|
||||
loop(conditional.nestedSpendingInfo +: newRemaining, accum)
|
||||
case _: P2WPKHV0SpendingInfo |
|
||||
_: UnassignedSegwitNativeUTXOSpendingInfo |
|
||||
_: P2PKSpendingInfo | _: P2PKHSpendingInfo |
|
||||
_: MultiSignatureSpendingInfo | _: EmptySpendingInfo =>
|
||||
//none of these script types affect the sequence number of a tx
|
||||
//the sequence only needs to be adjustd if we have replace by fee (RBF) enabled
|
||||
//see BIP125 for more information
|
||||
val sequence =
|
||||
if (isRBFEnabled) UInt32.zero else TransactionConstants.sequence
|
||||
val input =
|
||||
TransactionInput(spendingInfo.outPoint,
|
||||
EmptyScriptSignature,
|
||||
sequence)
|
||||
loop(newRemaining, input +: accum)
|
||||
}
|
||||
}
|
||||
|
||||
loop(utxos, Nil)
|
||||
}
|
||||
|
@ -667,8 +668,8 @@ object TxBuilder {
|
|||
//https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
|
||||
|
||||
val acceptableVariance = 40 * feeRate.toLong
|
||||
val min = Satoshis(Int64(-acceptableVariance))
|
||||
val max = Satoshis(Int64(acceptableVariance))
|
||||
val min = Satoshis(-acceptableVariance)
|
||||
val max = Satoshis(acceptableVariance)
|
||||
val difference = estimatedFee - actualFee
|
||||
if (difference <= min) {
|
||||
logger.error(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bitcoins.core.wallet.fee
|
||||
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.number.Int64
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
|
||||
/**
|
||||
|
@ -11,7 +10,7 @@ import org.bitcoins.core.protocol.transaction.Transaction
|
|||
sealed abstract class FeeUnit {
|
||||
def currencyUnit: CurrencyUnit
|
||||
def *(tx: Transaction): CurrencyUnit = calc(tx)
|
||||
def calc(tx: Transaction): CurrencyUnit = Satoshis(Int64(tx.vsize * toLong))
|
||||
def calc(tx: Transaction): CurrencyUnit = Satoshis(tx.vsize * toLong)
|
||||
def toLong: Long = currencyUnit.satoshis.toLong
|
||||
}
|
||||
|
||||
|
@ -24,7 +23,7 @@ sealed abstract class BitcoinFeeUnit extends FeeUnit
|
|||
case class SatoshisPerByte(currencyUnit: CurrencyUnit) extends BitcoinFeeUnit {
|
||||
|
||||
def toSatPerKb: SatoshisPerKiloByte = {
|
||||
SatoshisPerKiloByte(currencyUnit.satoshis * Satoshis(Int64(1000)))
|
||||
SatoshisPerKiloByte(currencyUnit.satoshis * Satoshis(1000))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +34,7 @@ case class SatoshisPerKiloByte(currencyUnit: CurrencyUnit)
|
|||
val conversionOpt = (currencyUnit.toBigDecimal * 0.001).toBigIntExact
|
||||
conversionOpt match {
|
||||
case Some(conversion) =>
|
||||
val sat = Satoshis(Int64(conversion))
|
||||
val sat = Satoshis(conversion)
|
||||
SatoshisPerByte(sat)
|
||||
|
||||
case None =>
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.bitcoins.core.crypto._
|
|||
import org.bitcoins.core.currency.{CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.gcs.FilterType
|
||||
import org.bitcoins.core.hd._
|
||||
import org.bitcoins.core.number.{Int32, Int64, UInt32, UInt64}
|
||||
import org.bitcoins.core.number.{Int32, UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.script.{ScriptPubKey, ScriptWitness}
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
|
@ -155,7 +155,7 @@ abstract class DbCommonsColumnMappers {
|
|||
|
||||
implicit val currencyUnitMapper: BaseColumnType[CurrencyUnit] =
|
||||
MappedColumnType
|
||||
.base[CurrencyUnit, Long](_.satoshis.toLong, l => Satoshis(Int64(l)))
|
||||
.base[CurrencyUnit, Long](_.satoshis.toLong, l => Satoshis(l))
|
||||
|
||||
implicit val filterTypeMapper: BaseColumnType[FilterType] =
|
||||
MappedColumnType
|
||||
|
|
|
@ -375,7 +375,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
val getChannelId =
|
||||
(client: EclairRpcClient, otherClient: EclairRpcClient) => {
|
||||
otherClient.getInfo.flatMap { info =>
|
||||
val amt = Satoshis(Int64(100000))
|
||||
val amt = Satoshis(100000)
|
||||
val openedChanF = clientF.flatMap(_.open(info.nodeId, amt))
|
||||
|
||||
openedChanF.flatMap { channelId =>
|
||||
|
@ -844,11 +844,10 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
}
|
||||
}
|
||||
|
||||
def openChannel(
|
||||
c1: EclairRpcClient,
|
||||
c2: EclairRpcClient): Future[FundedChannelId] = {
|
||||
def openChannel(c1: EclairRpcClient,
|
||||
c2: EclairRpcClient): Future[FundedChannelId] = {
|
||||
EclairRpcTestUtil
|
||||
.openChannel(c1, c2, Satoshis(Int64(500000)), MilliSatoshis(500000))
|
||||
.openChannel(c1, c2, Satoshis(500000), MilliSatoshis(500000))
|
||||
}
|
||||
|
||||
val openedChannelsF: Future[(ChannelId, ChannelId)] = {
|
||||
|
@ -1050,7 +1049,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
ourUpdates.flatMap(our =>
|
||||
allUpdates.map { all =>
|
||||
our != all
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
AsyncUtil
|
||||
|
@ -1146,9 +1145,8 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
}
|
||||
}
|
||||
|
||||
private def hasConnection(
|
||||
client: Future[EclairRpcClient],
|
||||
nodeId: NodeId): Future[Assertion] = {
|
||||
private def hasConnection(client: Future[EclairRpcClient],
|
||||
nodeId: NodeId): Future[Assertion] = {
|
||||
|
||||
val hasPeersF = client.flatMap(_.getPeers.map(_.nonEmpty))
|
||||
|
||||
|
@ -1163,9 +1161,8 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
}
|
||||
|
||||
/** Checks that the given [[org.bitcoins.eclair.rpc.client.EclairRpcClient]] has the given chanId */
|
||||
private def hasChannel(
|
||||
client: EclairRpcClient,
|
||||
chanId: ChannelId): Future[Assertion] = {
|
||||
private def hasChannel(client: EclairRpcClient,
|
||||
chanId: ChannelId): Future[Assertion] = {
|
||||
val recognizedOpenChannel: Future[Assertion] = {
|
||||
|
||||
val chanResultF: Future[ChannelResult] = client.channel(chanId)
|
||||
|
@ -1180,7 +1177,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
|
|||
private def openAndConfirmChannel(
|
||||
client1F: Future[EclairRpcClient],
|
||||
client2F: Future[EclairRpcClient],
|
||||
amount: CurrencyUnit = Satoshis(Int64(1000000))): Future[ChannelId] = {
|
||||
amount: CurrencyUnit = Satoshis(1000000)): Future[ChannelId] = {
|
||||
|
||||
val bitcoindRpcF = client1F.map(EclairRpcTestUtil.getBitcoindRpc(_))
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.bitcoins.core.protocol.transaction.Transaction
|
|||
import org.bitcoins.node.P2PLogger
|
||||
import org.bitcoins.core.crypto.HashDigest
|
||||
import org.bitcoins.core.bloom.BloomFilter
|
||||
import org.bitcoins.core.protocol.blockchain.BlockHeader
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
|
||||
import scala.concurrent.duration.DurationInt
|
||||
|
|
|
@ -13,8 +13,6 @@ import org.bitcoins.core.wallet.utxo.{
|
|||
}
|
||||
import org.scalacheck.Gen
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
sealed abstract class CreditingTxGen {
|
||||
|
||||
/** Minimum amount of outputs to generate */
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.bitcoins.core.currency.{
|
|||
CurrencyUnits,
|
||||
Satoshis
|
||||
}
|
||||
import org.bitcoins.core.number.Int64
|
||||
import org.bitcoins.core.protocol.ln.currency._
|
||||
import org.scalacheck.Gen
|
||||
import org.bitcoins.core.wallet.fee.FeeUnit
|
||||
|
@ -58,7 +57,7 @@ trait CurrencyUnitGenerator {
|
|||
*/
|
||||
def positiveRealistic: Gen[Satoshis] =
|
||||
Gen.choose(0, Bitcoins(1000000).satoshis.toLong).map { n =>
|
||||
Satoshis(Int64(n))
|
||||
Satoshis(n)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bitcoins.testkit.core.gen
|
|||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.core.number.{Int32, Int64, UInt32}
|
||||
import org.bitcoins.core.number.{Int32, UInt32}
|
||||
import org.bitcoins.core.policy.Policy
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
|
@ -76,7 +76,7 @@ object TransactionGenerators extends BitcoinSLogger {
|
|||
} else {
|
||||
val amt = Gen
|
||||
.choose(100, remainingAmount.toBigDecimal.toLongExact)
|
||||
.map(n => Satoshis(Int64(n)))
|
||||
.map(n => Satoshis(n))
|
||||
.sampleSome
|
||||
loop(remaining - 1, remainingAmount - amt, amt +: accum)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue