diff --git a/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala index 97857c8769..0525062fc7 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/chain/SyncUtil.scala @@ -168,13 +168,16 @@ abstract class SyncUtil extends BitcoinSLogger { node.NodeChainQueryApi(nodeApi, chainQuery) } - def syncWallet(wallet: Wallet, bitcoind: BitcoindRpcClient)(implicit + /** Syncs a wallet against bitcoind by retrieving full blocks and then calling + * [[Wallet.processBlock()]] + */ + def syncWalletFullBlocks(wallet: Wallet, bitcoind: BitcoindRpcClient)(implicit ec: ExecutionContext): Future[Wallet] = { - WalletSync.sync( + WalletSync.syncFullBlocks( wallet = wallet, getBlockHeaderFunc = SyncUtil.getBlockHeaderFunc(bitcoind), getBestBlockHashFunc = SyncUtil.getBestBlockHashFunc(bitcoind), - getBlock = SyncUtil.getBlockFunc(bitcoind) + getBlockFunc = SyncUtil.getBlockFunc(bitcoind) ) } } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala index 2eda61d52c..ff8a268b02 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala @@ -274,8 +274,8 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg { bitcoind = bitcoind, bip39PasswordOpt = bip39PasswordOpt) fundedWallet <- fundWalletWithBitcoind(walletWithBitcoind) - _ <- - SyncUtil.syncWallet(wallet = fundedWallet.wallet, bitcoind = bitcoind) + _ <- SyncUtil.syncWalletFullBlocks(wallet = fundedWallet.wallet, + bitcoind = bitcoind) _ <- BitcoinSWalletTest.awaitWalletBalances(fundedWallet) } yield fundedWallet } @@ -294,8 +294,8 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg { .map(_.asInstanceOf[BitcoindV19RpcClient]) wallet <- createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt) fundedWallet <- fundWalletWithBitcoind(wallet) - _ <- - SyncUtil.syncWallet(wallet = fundedWallet.wallet, bitcoind = bitcoind) + _ <- SyncUtil.syncWalletFullBlocks(wallet = fundedWallet.wallet, + bitcoind = bitcoind) _ <- BitcoinSWalletTest.awaitWalletBalances(fundedWallet) } yield { WalletWithBitcoindV19(fundedWallet.wallet, bitcoind) diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/sync/WalletSyncTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/sync/WalletSyncTest.scala index 0b1468fdda..3ba2102db9 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/sync/WalletSyncTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/sync/WalletSyncTest.scala @@ -22,10 +22,10 @@ class WalletSyncTest extends BitcoinSWalletTest { val getBlockHeaderFunc = SyncUtil.getBlockHeaderFunc(bitcoind) val getBlockFunc = SyncUtil.getBlockFunc(bitcoind) - val syncedWalletF = WalletSync.sync(wallet, - getBlockHeaderFunc, - getBestBlockHashFunc, - getBlockFunc) + val syncedWalletF = WalletSync.syncFullBlocks(wallet, + getBlockHeaderFunc, + getBestBlockHashFunc, + getBlockFunc) val bitcoindBestHeaderF = bitcoind.getBestBlockHeader() for { diff --git a/wallet/src/main/scala/org/bitcoins/wallet/sync/WalletSync.scala b/wallet/src/main/scala/org/bitcoins/wallet/sync/WalletSync.scala index 38e6e1610d..65aba0b064 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/sync/WalletSync.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/sync/WalletSync.scala @@ -9,11 +9,17 @@ import scala.concurrent.{ExecutionContext, Future} trait WalletSync extends BitcoinSLogger { - def sync( + /** Synchronizes the bitcoin-s' wallet by retrieving each block and then calling + * [[Wallet.processBlock()]] on the block retrieved + * + * WARNING: This should not be used on resource constrained devices + * as fetching full blocks will use a lot of bandwidth on live networks + */ + def syncFullBlocks( wallet: Wallet, getBlockHeaderFunc: DoubleSha256DigestBE => Future[BlockHeader], getBestBlockHashFunc: () => Future[DoubleSha256DigestBE], - getBlock: DoubleSha256DigestBE => Future[Block])(implicit + getBlockFunc: DoubleSha256DigestBE => Future[Block])(implicit ec: ExecutionContext): Future[Wallet] = { val bestBlockHashF = getBestBlockHashFunc() val bestBlockHeaderF = for { @@ -26,7 +32,7 @@ trait WalletSync extends BitcoinSLogger { blocksToSync <- getBlocksToSync(wallet = wallet, currentTipBlockHashBE = bestHeader.hashBE, accum = Vector.empty, - getBlock = getBlock) + getBlock = getBlockFunc) } yield blocksToSync val syncedWalletF = for {