@@ -566,12 +566,14 @@ class Commands:
|
|||||||
privkeys = privkey.split()
|
privkeys = privkey.split()
|
||||||
self.nocheck = nocheck
|
self.nocheck = nocheck
|
||||||
#dest = self._resolver(destination)
|
#dest = self._resolver(destination)
|
||||||
tx = sweep(privkeys,
|
tx = await sweep(
|
||||||
network=self.network,
|
privkeys,
|
||||||
config=self.config,
|
network=self.network,
|
||||||
to_address=destination,
|
config=self.config,
|
||||||
fee=tx_fee,
|
to_address=destination,
|
||||||
imax=imax)
|
fee=tx_fee,
|
||||||
|
imax=imax,
|
||||||
|
)
|
||||||
return tx.serialize() if tx else None
|
return tx.serialize() if tx else None
|
||||||
|
|
||||||
@command('wp')
|
@command('wp')
|
||||||
|
|||||||
@@ -1397,9 +1397,6 @@ class TestWalletSending(TestCaseForTestnet):
|
|||||||
|
|
||||||
class NetworkMock:
|
class NetworkMock:
|
||||||
relay_fee = 1000
|
relay_fee = 1000
|
||||||
def run_from_another_thread(self, coro):
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
return loop.run_until_complete(coro)
|
|
||||||
async def listunspent_for_scripthash(self, scripthash):
|
async def listunspent_for_scripthash(self, scripthash):
|
||||||
if scripthash == '460e4fb540b657d775d84ff4955c9b13bd954c2adc26a6b998331343f85b6a45':
|
if scripthash == '460e4fb540b657d775d84ff4955c9b13bd954c2adc26a6b998331343f85b6a45':
|
||||||
return [{'tx_hash': 'ac24de8b58e826f60bd7b9ba31670bdfc3e8aedb2f28d0e91599d741569e3429', 'tx_pos': 1, 'height': 1325785, 'value': 1000000}]
|
return [{'tx_hash': 'ac24de8b58e826f60bd7b9ba31670bdfc3e8aedb2f28d0e91599d741569e3429', 'tx_pos': 1, 'height': 1325785, 'value': 1000000}]
|
||||||
@@ -1414,7 +1411,9 @@ class TestWalletSending(TestCaseForTestnet):
|
|||||||
privkeys = ['93NQ7CFbwTPyKDJLXe97jczw33fiLijam2SCZL3Uinz1NSbHrTu', ]
|
privkeys = ['93NQ7CFbwTPyKDJLXe97jczw33fiLijam2SCZL3Uinz1NSbHrTu', ]
|
||||||
network = NetworkMock()
|
network = NetworkMock()
|
||||||
dest_addr = 'tb1q3ws2p0qjk5vrravv065xqlnkckvzcpclk79eu2'
|
dest_addr = 'tb1q3ws2p0qjk5vrravv065xqlnkckvzcpclk79eu2'
|
||||||
tx = sweep(privkeys, network=network, config=self.config, to_address=dest_addr, fee=5000, locktime=1325785, tx_version=1)
|
sweep_coro = sweep(privkeys, network=network, config=self.config, to_address=dest_addr, fee=5000, locktime=1325785, tx_version=1)
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
tx = loop.run_until_complete(sweep_coro)
|
||||||
|
|
||||||
tx_copy = tx_from_any(tx.serialize())
|
tx_copy = tx_from_any(tx.serialize())
|
||||||
self.assertEqual('010000000129349e5641d79915e9d0282fdbaee8c3df0b6731bab9d70bf626e8588bde24ac010000004847304402206bf0d0a93abae0d5873a62ebf277a5dd2f33837821e8b93e74d04e19d71b578002201a6d729bc159941ef5c4c9e5fe13ece9fc544351ba531b00f68ba549c8b38a9a01fdffffff01b82e0f00000000001600148ba0a0bc12b51831f58c7ea8607e76c5982c071fd93a1400',
|
self.assertEqual('010000000129349e5641d79915e9d0282fdbaee8c3df0b6731bab9d70bf626e8588bde24ac010000004847304402206bf0d0a93abae0d5873a62ebf277a5dd2f33837821e8b93e74d04e19d71b578002201a6d729bc159941ef5c4c9e5fe13ece9fc544351ba531b00f68ba549c8b38a9a01fdffffff01b82e0f00000000001600148ba0a0bc12b51831f58c7ea8607e76c5982c071fd93a1400',
|
||||||
|
|||||||
@@ -164,10 +164,18 @@ async def sweep_preparations(privkeys, network: 'Network', imax=100):
|
|||||||
return inputs, keypairs
|
return inputs, keypairs
|
||||||
|
|
||||||
|
|
||||||
def sweep(privkeys, *, network: 'Network', config: 'SimpleConfig',
|
async def sweep(
|
||||||
to_address: str, fee: int = None, imax=100,
|
privkeys,
|
||||||
locktime=None, tx_version=None) -> PartialTransaction:
|
*,
|
||||||
inputs, keypairs = network.run_from_another_thread(sweep_preparations(privkeys, network, imax))
|
network: 'Network',
|
||||||
|
config: 'SimpleConfig',
|
||||||
|
to_address: str,
|
||||||
|
fee: int = None,
|
||||||
|
imax=100,
|
||||||
|
locktime=None,
|
||||||
|
tx_version=None
|
||||||
|
) -> PartialTransaction:
|
||||||
|
inputs, keypairs = await sweep_preparations(privkeys, network, imax)
|
||||||
total = sum(txin.value_sats() for txin in inputs)
|
total = sum(txin.value_sats() for txin in inputs)
|
||||||
if fee is None:
|
if fee is None:
|
||||||
outputs = [PartialTxOutput(scriptpubkey=bfh(bitcoin.address_to_script(to_address)),
|
outputs = [PartialTxOutput(scriptpubkey=bfh(bitcoin.address_to_script(to_address)),
|
||||||
|
|||||||
@@ -419,6 +419,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
|
|||||||
d.run_daemon()
|
d.run_daemon()
|
||||||
sys_exit(0)
|
sys_exit(0)
|
||||||
else:
|
else:
|
||||||
|
# FIXME this message is lost in detached mode (parent process already exited after forking)
|
||||||
print_msg("Daemon already running")
|
print_msg("Daemon already running")
|
||||||
sys_exit(1)
|
sys_exit(1)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user