wallet server: dont fail to start on segwit txs

This commit is contained in:
Victor Shyba 2019-08-14 10:26:02 -03:00
parent 4d741bd200
commit ab6944b7b0
5 changed files with 24 additions and 6 deletions

View file

@ -102,7 +102,7 @@ class LBC(Coin):
''' '''
Overrides electrumx hashX from script by extracting addresses from claim scripts. Overrides electrumx hashX from script by extracting addresses from claim scripts.
''' '''
if script and script[0] == OpCodes.OP_RETURN: if script and script[0] == OpCodes.OP_RETURN or not script:
return None return None
if script[0] in [ if script[0] in [
OutputScript.OP_CLAIM_NAME, OutputScript.OP_CLAIM_NAME,

View file

@ -33,6 +33,14 @@ class TestSessionBloat(IntegrationTestCase):
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0) self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)
class TestSegwitServer(IntegrationTestCase):
LEDGER = lbry.wallet
ENABLE_SEGWIT = True
async def test_at_least_it_starts(self):
await asyncio.wait_for(self.ledger.network.get_headers(0, 1), 1.0)
class TestHeadersComponent(CommandTestCase): class TestHeadersComponent(CommandTestCase):
LEDGER = lbry.wallet LEDGER = lbry.wallet

View file

@ -255,7 +255,7 @@ class Template:
self.opcodes = opcodes self.opcodes = opcodes
def parse(self, tokens): def parse(self, tokens):
return Parser(self.opcodes, tokens).parse().values return Parser(self.opcodes, tokens).parse().values if self.opcodes else {}
def generate(self, values): def generate(self, values):
source = BCDataStream() source = BCDataStream()
@ -288,6 +288,8 @@ class Script:
templates: List[Template] = [] templates: List[Template] = []
NO_SCRIPT = Template('no_script', None) # special case
def __init__(self, source=None, template=None, values=None, template_hint=None): def __init__(self, source=None, template=None, values=None, template_hint=None):
self.source = source self.source = source
self._template = template self._template = template
@ -318,6 +320,8 @@ class Script:
def parse(self, template_hint=None): def parse(self, template_hint=None):
tokens = self.tokens tokens = self.tokens
if not tokens and not template_hint:
template_hint = self.NO_SCRIPT
for template in chain((template_hint,), self.templates): for template in chain((template_hint,), self.templates):
if not template: if not template:
continue continue

View file

@ -67,12 +67,14 @@ def set_logging(ledger_module, level, handler=None):
class Conductor: class Conductor:
def __init__(self, ledger_module=None, manager_module=None, verbosity=logging.WARNING): def __init__(self, ledger_module=None, manager_module=None, verbosity=logging.WARNING,
enable_segwit=False):
self.ledger_module = ledger_module or get_ledger_from_environment() self.ledger_module = ledger_module or get_ledger_from_environment()
self.manager_module = manager_module or get_manager_from_environment() self.manager_module = manager_module or get_manager_from_environment()
self.spv_module = get_spvserver_from_ledger(self.ledger_module) self.spv_module = get_spvserver_from_ledger(self.ledger_module)
self.blockchain_node = get_blockchain_node_from_ledger(self.ledger_module) self.blockchain_node = get_blockchain_node_from_ledger(self.ledger_module)
self.blockchain_node.segwit_enabled = enable_segwit
self.spv_node = SPVNode(self.spv_module) self.spv_node = SPVNode(self.spv_module)
self.wallet_node = WalletNode(self.manager_module, self.ledger_module.RegTestLedger) self.wallet_node = WalletNode(self.manager_module, self.ledger_module.RegTestLedger)
@ -326,12 +328,14 @@ class BlockchainNode:
self.data_path = tempfile.mkdtemp() self.data_path = tempfile.mkdtemp()
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
asyncio.get_child_watcher().attach_loop(loop) asyncio.get_child_watcher().attach_loop(loop)
command = ( command = [
self.daemon_bin, self.daemon_bin,
f'-datadir={self.data_path}', '-printtoconsole', '-regtest', '-server', '-txindex', f'-datadir={self.data_path}', '-printtoconsole', '-regtest', '-server', '-txindex',
f'-rpcuser={self.rpcuser}', f'-rpcpassword={self.rpcpassword}', f'-rpcport={self.rpcport}', f'-rpcuser={self.rpcuser}', f'-rpcpassword={self.rpcpassword}', f'-rpcport={self.rpcport}',
f'-port={self.peerport}' f'-port={self.peerport}'
) + () if self.segwit_enabled else ('-addresstype=legacy', '-vbparams=segwit:0:999999999999') ]
if not self.segwit_enabled:
command.extend(['-addresstype=legacy', '-vbparams=segwit:0:999999999999'])
self.log.info(' '.join(command)) self.log.info(' '.join(command))
self.transport, self.protocol = await loop.subprocess_exec( self.transport, self.protocol = await loop.subprocess_exec(
BlockchainProcess, *command BlockchainProcess, *command

View file

@ -185,6 +185,7 @@ class IntegrationTestCase(AsyncioTestCase):
LEDGER = None LEDGER = None
MANAGER = None MANAGER = None
ENABLE_SEGWIT = False
VERBOSITY = logging.WARN VERBOSITY = logging.WARN
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -199,7 +200,8 @@ class IntegrationTestCase(AsyncioTestCase):
async def asyncSetUp(self): async def asyncSetUp(self):
self.conductor = Conductor( self.conductor = Conductor(
ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY,
enable_segwit=self.ENABLE_SEGWIT
) )
await self.conductor.start_blockchain() await self.conductor.start_blockchain()
self.addCleanup(self.conductor.stop_blockchain) self.addCleanup(self.conductor.stop_blockchain)