mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-18 21:22:04 +01:00
Remove WalletSync.sync() -> WalletSync.syncFullBlocks() (#2522)
This commit is contained in:
parent
a1a2524b56
commit
f3e81d027d
4 changed files with 23 additions and 14 deletions
|
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue