mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 14:33:06 +01:00
Implemented the ability to fetch unconfirmed transactions (#3429)
* relay flag in version message made configurable * modified test classes as well * Update configuration.md * reverted few files and cleaned up format * fixed mistake * enabled neutrino node to receive transactions as a callback * added txid to log message * changed txId to txIdBE * unit test added for checking if we're getting transaction as a callback
This commit is contained in:
parent
1032669f21
commit
e2c2798e60
3 changed files with 78 additions and 1 deletions
|
@ -219,6 +219,7 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
|
|||
nodeConf: NodeAppConfig,
|
||||
ec: ExecutionContext): Future[NodeCallbacks] = {
|
||||
lazy val onTx: OnTxReceived = { tx =>
|
||||
logger.info(s"Receiving transaction txid=${tx.txIdBE.hex} as a callback")
|
||||
wallet.processTransaction(tx, blockHashOpt = None).map(_ => ())
|
||||
}
|
||||
lazy val onCompactFilters: OnCompactFiltersReceived = { blockFilters =>
|
||||
|
@ -243,7 +244,8 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
|
|||
onBlockHeadersReceived = Vector(onHeaders)))
|
||||
case NodeType.NeutrinoNode =>
|
||||
Future.successful(
|
||||
NodeCallbacks(onBlockReceived = Vector(onBlock),
|
||||
NodeCallbacks(onTxReceived = Vector(onTx),
|
||||
onBlockReceived = Vector(onBlock),
|
||||
onCompactFiltersReceived = Vector(onCompactFilters),
|
||||
onBlockHeadersReceived = Vector(onHeaders)))
|
||||
case NodeType.FullNode =>
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package org.bitcoins.node.networking.peer
|
||||
|
||||
import org.bitcoins.core.currency.BitcoinsInt
|
||||
import org.bitcoins.core.p2p.TransactionMessage
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.node.OnTxReceived
|
||||
import org.bitcoins.node.NodeCallbacks
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.node.{
|
||||
NeutrinoNodeFundedWalletBitcoind,
|
||||
NodeTestWithCachedBitcoindNewest
|
||||
}
|
||||
import org.scalatest.{FutureOutcome, Outcome}
|
||||
|
||||
import scala.concurrent.{Future, Promise}
|
||||
|
||||
class DataMessageHandlerNeutrinoNodesTest
|
||||
extends NodeTestWithCachedBitcoindNewest {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
||||
|
||||
override type FixtureParam = NeutrinoNodeFundedWalletBitcoind
|
||||
|
||||
def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val outcomeF: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
outcome = withNeutrinoNodeFundedWalletBitcoind(
|
||||
test = test,
|
||||
bip39PasswordOpt = getBIP39PasswordOpt(),
|
||||
bitcoind = bitcoind
|
||||
)(system, getFreshConfig)
|
||||
f <- outcome.toFuture
|
||||
} yield f
|
||||
|
||||
new FutureOutcome(outcomeF)
|
||||
}
|
||||
|
||||
it must "verify OnTxReceived callbacks are executed" in {
|
||||
param: FixtureParam =>
|
||||
val NeutrinoNodeFundedWalletBitcoind(node, _, bitcoind, _) = param
|
||||
|
||||
val resultP: Promise[Transaction] = Promise()
|
||||
|
||||
val callback: OnTxReceived = (tx: Transaction) => {
|
||||
Future {
|
||||
resultP.success(tx)
|
||||
()
|
||||
}
|
||||
}
|
||||
val sender = node.peerMsgSenders(0)
|
||||
|
||||
for {
|
||||
|
||||
txId <- bitcoind.sendToAddress(junkAddress, 1.bitcoin)
|
||||
tx <- bitcoind.getRawTransactionRaw(txId)
|
||||
|
||||
payload = TransactionMessage(tx)
|
||||
|
||||
nodeCallbacks = NodeCallbacks.onTxReceived(callback)
|
||||
_ = node.nodeAppConfig.addCallbacks(nodeCallbacks)
|
||||
|
||||
dataMessageHandler =
|
||||
DataMessageHandler(genesisChainApi)(node.executionContext,
|
||||
node.nodeAppConfig,
|
||||
node.chainConfig)
|
||||
_ <- dataMessageHandler.handleDataPayload(payload, sender)
|
||||
result <- resultP.future
|
||||
} yield assert(result == tx)
|
||||
}
|
||||
}
|
|
@ -86,6 +86,7 @@ object BitcoinSTestAppConfig {
|
|||
|bitcoin-s {
|
||||
| node {
|
||||
| mode = neutrino
|
||||
| relay = true
|
||||
| }
|
||||
| proxy.enabled = ${torEnabled}
|
||||
|}
|
||||
|
@ -103,6 +104,7 @@ object BitcoinSTestAppConfig {
|
|||
|bitcoin-s {
|
||||
| node {
|
||||
| mode = neutrino
|
||||
| relay = true
|
||||
| }
|
||||
| proxy.enabled = ${torEnabled}
|
||||
|}
|
||||
|
|
Loading…
Add table
Reference in a new issue