mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-15 12:20:06 +01:00
Implement Wallet.listTransactions() (#1744)
This commit is contained in:
parent
576d455924
commit
b044b6400d
12 changed files with 46 additions and 29 deletions
|
@ -19,12 +19,13 @@ class ImplicitsTest extends BitcoinSUnitTest {
|
|||
List(succeed, assert(4 + 4 == 7), assert(true))
|
||||
assertions.toAssertion
|
||||
} catch {
|
||||
case e: TestFailedException =>
|
||||
case _: TestFailedException =>
|
||||
succeed
|
||||
case e: Throwable => fail
|
||||
case _: Throwable => fail
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO fix the deprecation warning here
|
||||
it should "fail to flatten a lazy sequence of assertions where one has failed" in {
|
||||
try {
|
||||
val assertions: Stream[org.scalatest.Assertion] =
|
||||
|
@ -34,11 +35,12 @@ class ImplicitsTest extends BitcoinSUnitTest {
|
|||
|
||||
assertions.toAssertion
|
||||
} catch {
|
||||
case e: TestFailedException =>
|
||||
case _: TestFailedException =>
|
||||
succeed
|
||||
case e: Throwable => fail
|
||||
case _: Throwable => fail
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
it should "fail to flatten an empty list" in {
|
||||
intercept[TestFailedException] {
|
||||
|
|
|
@ -23,10 +23,12 @@ class ProcessTransactionTest extends BitcoinSWalletTest {
|
|||
private def checkUtxosAndBalance(wallet: WalletApi)(
|
||||
action: => Future[_]): Future[Assertion] =
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
oldUtxos <- wallet.listUtxos()
|
||||
oldUnconfirmed <- wallet.getUnconfirmedBalance()
|
||||
oldConfirmed <- wallet.getBalance()
|
||||
_ <- action // by name
|
||||
newTransactions <- wallet.listTransactions()
|
||||
newUtxos <- wallet.listUtxos()
|
||||
newUnconfirmed <- wallet.getUnconfirmedBalance()
|
||||
newConfirmed <- wallet.getBalance()
|
||||
|
@ -35,6 +37,7 @@ class ProcessTransactionTest extends BitcoinSWalletTest {
|
|||
assert(oldConfirmed == newConfirmed)
|
||||
assert(oldUnconfirmed == newUnconfirmed)
|
||||
assert(oldUtxos == newUtxos)
|
||||
assert(oldTransactions == newTransactions)
|
||||
}
|
||||
|
||||
it must "change state when processing a transaction with a block hash" in {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bitcoins.wallet
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.{Config, ConfigFactory}
|
||||
import org.bitcoins.commons.serializers.JsonSerializers._
|
||||
import org.bitcoins.core.crypto.{ExtPublicKey, MnemonicCode}
|
||||
|
|
|
@ -32,13 +32,17 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
val WalletWithBitcoindRpc(wallet, _) = param
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
tx <- wallet.sendToAddress(testAddr,
|
||||
Satoshis(3000),
|
||||
Some(SatoshisPerByte(Satoshis(3))))
|
||||
|
||||
updatedCoins <- wallet.spendingInfoDAO.findOutputsBeingSpent(tx)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(updatedCoins.forall(_.state == TxoState.PendingConfirmationsSpent))
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +50,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
val WalletWithBitcoindRpc(wallet, bitcoind) = param
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
addr <- wallet.getNewAddress()
|
||||
|
||||
txId <- bitcoind.sendToAddress(addr, Satoshis(3000))
|
||||
|
@ -59,9 +64,12 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
|
||||
updatedCoin <-
|
||||
wallet.spendingInfoDAO.findByScriptPubKey(addr.scriptPubKey)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(
|
||||
updatedCoin.forall(_.state == TxoState.PendingConfirmationsReceived))
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +79,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
val dummyOutput = TransactionOutput(Satoshis(3000), EmptyScriptPubKey)
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
tx <- wallet.fundRawTransaction(Vector(dummyOutput),
|
||||
SatoshisPerVirtualByte.one,
|
||||
fromTagOpt = None,
|
||||
|
@ -78,9 +87,12 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
|
||||
updatedCoins <- wallet.spendingInfoDAO.findOutputsBeingSpent(tx)
|
||||
reserved <- wallet.listUtxos(TxoState.Reserved)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(updatedCoins.forall(_.state == TxoState.Reserved))
|
||||
assert(updatedCoins.forall(reserved.contains))
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(!newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +103,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
val dummyOutput = TransactionOutput(Satoshis(3000), EmptyScriptPubKey)
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
tx <- wallet.fundRawTransaction(Vector(dummyOutput),
|
||||
SatoshisPerVirtualByte.one,
|
||||
fromTagOpt = None,
|
||||
|
@ -102,8 +115,11 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
_ = assert(reservedUtxos.forall(allReserved.contains))
|
||||
|
||||
unreservedUtxos <- wallet.unmarkUTXOsAsReserved(reservedUtxos.toVector)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(unreservedUtxos.forall(_.state != TxoState.Reserved))
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(!newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +130,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
val dummyOutput = TransactionOutput(Satoshis(3000), EmptyScriptPubKey)
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
tx <- wallet.fundRawTransaction(Vector(dummyOutput),
|
||||
SatoshisPerVirtualByte.one,
|
||||
fromTagOpt = None,
|
||||
|
@ -125,8 +142,11 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
.forall(allReserved.map(_.outPoint).contains))
|
||||
|
||||
unreservedUtxos <- wallet.unmarkUTXOsAsReserved(tx)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(unreservedUtxos.forall(_.state != TxoState.Reserved))
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(!newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,6 +159,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
P2PKHScriptPubKey(ECPublicKey.freshPublicKey))
|
||||
|
||||
for {
|
||||
oldTransactions <- wallet.listTransactions()
|
||||
tx <- wallet.sendToOutputs(Vector(dummyOutput),
|
||||
Some(SatoshisPerVirtualByte.one))
|
||||
_ <- wallet.processTransaction(tx, None)
|
||||
|
@ -160,8 +181,11 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest {
|
|||
_ <- wallet.processBlock(block)
|
||||
|
||||
newReserved <- wallet.listUtxos(TxoState.Reserved)
|
||||
newTransactions <- wallet.listTransactions()
|
||||
} yield {
|
||||
assert(newReserved.isEmpty)
|
||||
assert(!oldTransactions.map(_.transaction).contains(tx))
|
||||
assert(newTransactions.map(_.transaction).contains(tx))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
package org.bitcoins.wallet
|
||||
|
||||
import org.bitcoins.testkit.util.{BitcoinSAsyncTest, BitcoinSUnitTest}
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
import org.bitcoins.testkit.util.{BitcoinSAsyncTest}
|
||||
import org.bitcoins.core.config.TestNet3
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.bitcoins.core.config.RegTest
|
||||
import org.bitcoins.core.config.MainNet
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
import java.nio.file.Paths
|
||||
|
||||
import org.bitcoins.core.hd.HDPurposes
|
||||
import java.nio.file.Files
|
||||
|
||||
import ch.qos.logback.classic.Level
|
||||
import java.nio.file.Path
|
||||
|
||||
import scala.util.Properties
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class WalletBloomTest extends BitcoinSWalletTest {
|
|||
|
||||
it should "generate a bloom filter that matches the outpoints in our wallet" in {
|
||||
param =>
|
||||
val WalletWithBitcoindRpc(walletApi, bitcoind) = param
|
||||
val WalletWithBitcoindRpc(walletApi, _) = param
|
||||
val wallet = walletApi.asInstanceOf[Wallet]
|
||||
|
||||
for {
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
package org.bitcoins.wallet
|
||||
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.script.P2PKHScriptPubKey
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
EmptyTransaction,
|
||||
Transaction,
|
||||
TransactionOutput
|
||||
}
|
||||
import org.bitcoins.crypto.ECPublicKey
|
||||
import org.bitcoins.core.protocol.transaction.{EmptyTransaction, Transaction}
|
||||
import org.bitcoins.testkit.wallet.BitcoinSWalletTest
|
||||
import org.bitcoins.testkit.wallet.FundWalletUtil.FundedWallet
|
||||
import org.bitcoins.wallet.models.SpendingInfoDb
|
||||
|
@ -96,10 +89,6 @@ class WalletCallbackTest extends BitcoinSWalletTest {
|
|||
} yield assert(result == EmptyTransaction)
|
||||
}
|
||||
|
||||
private val dummyOutput = TransactionOutput(
|
||||
10000.satoshis,
|
||||
P2PKHScriptPubKey(ECPublicKey.freshPublicKey))
|
||||
|
||||
it must "verify OnReservedUtxos callbacks are executed when reserving" in {
|
||||
fundedWallet: FundedWallet =>
|
||||
val resultP: Promise[Vector[SpendingInfoDb]] = Promise()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bitcoins.wallet.models
|
||||
|
||||
import org.bitcoins.core.currency.Satoshis
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerByte
|
||||
import org.bitcoins.testkit.fixtures.WalletDAOFixture
|
||||
import org.bitcoins.testkit.wallet.{BitcoinSWalletTest, WalletTestUtil}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ class SpendingInfoDAOTest extends BitcoinSWalletTest with WalletDAOFixture {
|
|||
val spendingInfoDAO = daos.utxoDAO
|
||||
for {
|
||||
utxo <- WalletTestUtil.insertSegWitUTXO(daos)
|
||||
updated <- spendingInfoDAO.update(
|
||||
_ <- spendingInfoDAO.update(
|
||||
utxo.copy(state = TxoState.PendingConfirmationsReceived))
|
||||
unspent <- spendingInfoDAO.findAllUnspent()
|
||||
updated <-
|
||||
|
@ -135,7 +135,7 @@ class SpendingInfoDAOTest extends BitcoinSWalletTest with WalletDAOFixture {
|
|||
for {
|
||||
utxo <- WalletTestUtil.insertLegacyUTXO(daos)
|
||||
state = utxo.copy(state = TxoState.PendingConfirmationsSpent)
|
||||
updated <- spendingInfoDAO.update(state)
|
||||
_ <- spendingInfoDAO.update(state)
|
||||
unspent <- spendingInfoDAO.findAllUnspent()
|
||||
} yield assert(unspent.isEmpty)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.bitcoins.core.wallet.utxo.{AddressTag, TxoState}
|
|||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.keymanager._
|
||||
import org.bitcoins.wallet.WalletLogger
|
||||
import org.bitcoins.wallet.models.{AddressDb, SpendingInfoDb}
|
||||
import org.bitcoins.wallet.models.{AddressDb, SpendingInfoDb, TransactionDb}
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.{Failure, Success}
|
||||
|
@ -65,6 +65,8 @@ trait WalletApi extends WalletLogger {
|
|||
}
|
||||
}
|
||||
|
||||
def listTransactions(): Future[Vector[TransactionDb]]
|
||||
|
||||
/**
|
||||
* Takes in a block header and updates our TxoStates to the new chain tip
|
||||
* @param blockHeader Block header we are processing
|
||||
|
|
|
@ -63,6 +63,9 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
|
|||
res
|
||||
}
|
||||
|
||||
override def listTransactions(): Future[Vector[TransactionDb]] =
|
||||
transactionDAO.findAll()
|
||||
|
||||
private[wallet] case class ProcessTxResult(
|
||||
updatedIncoming: List[SpendingInfoDb],
|
||||
updatedOutgoing: List[SpendingInfoDb])
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.net.InetSocketAddress
|
|||
import org.bitcoins.core.util.BytesUtil
|
||||
import org.scalatest.flatspec.AsyncFlatSpec
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.zeromq.{ZFrame, ZMQ, ZMsg}
|
||||
import org.zeromq.{SocketType, ZFrame, ZMQ, ZMsg}
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
import scala.concurrent.Promise
|
||||
|
@ -38,7 +38,7 @@ class ZMQSubscriberTest extends AsyncFlatSpec {
|
|||
val socket = new InetSocketAddress("tcp://127.0.0.1", port)
|
||||
|
||||
val context = ZMQ.context(1)
|
||||
val publisher = context.socket(ZMQ.PUB)
|
||||
val publisher = context.socket(SocketType.PUB)
|
||||
|
||||
val uri = socket.getHostString + ":" + socket.getPort
|
||||
publisher.bind(uri)
|
||||
|
|
Loading…
Add table
Reference in a new issue