forked from LBRYCommunity/lbry-sdk
wallet server: dont fail to start on segwit txs
This commit is contained in:
parent
4d741bd200
commit
ab6944b7b0
5 changed files with 24 additions and 6 deletions
|
@ -102,7 +102,7 @@ class LBC(Coin):
|
|||
'''
|
||||
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
|
||||
if script[0] in [
|
||||
OutputScript.OP_CLAIM_NAME,
|
||||
|
|
|
@ -33,6 +33,14 @@ class TestSessionBloat(IntegrationTestCase):
|
|||
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):
|
||||
|
||||
LEDGER = lbry.wallet
|
||||
|
|
|
@ -255,7 +255,7 @@ class Template:
|
|||
self.opcodes = opcodes
|
||||
|
||||
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):
|
||||
source = BCDataStream()
|
||||
|
@ -288,6 +288,8 @@ class Script:
|
|||
|
||||
templates: List[Template] = []
|
||||
|
||||
NO_SCRIPT = Template('no_script', None) # special case
|
||||
|
||||
def __init__(self, source=None, template=None, values=None, template_hint=None):
|
||||
self.source = source
|
||||
self._template = template
|
||||
|
@ -318,6 +320,8 @@ class Script:
|
|||
|
||||
def parse(self, template_hint=None):
|
||||
tokens = self.tokens
|
||||
if not tokens and not template_hint:
|
||||
template_hint = self.NO_SCRIPT
|
||||
for template in chain((template_hint,), self.templates):
|
||||
if not template:
|
||||
continue
|
||||
|
|
|
@ -67,12 +67,14 @@ def set_logging(ledger_module, level, handler=None):
|
|||
|
||||
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.manager_module = manager_module or get_manager_from_environment()
|
||||
self.spv_module = get_spvserver_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.wallet_node = WalletNode(self.manager_module, self.ledger_module.RegTestLedger)
|
||||
|
||||
|
@ -326,12 +328,14 @@ class BlockchainNode:
|
|||
self.data_path = tempfile.mkdtemp()
|
||||
loop = asyncio.get_event_loop()
|
||||
asyncio.get_child_watcher().attach_loop(loop)
|
||||
command = (
|
||||
command = [
|
||||
self.daemon_bin,
|
||||
f'-datadir={self.data_path}', '-printtoconsole', '-regtest', '-server', '-txindex',
|
||||
f'-rpcuser={self.rpcuser}', f'-rpcpassword={self.rpcpassword}', f'-rpcport={self.rpcport}',
|
||||
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.transport, self.protocol = await loop.subprocess_exec(
|
||||
BlockchainProcess, *command
|
||||
|
|
|
@ -185,6 +185,7 @@ class IntegrationTestCase(AsyncioTestCase):
|
|||
|
||||
LEDGER = None
|
||||
MANAGER = None
|
||||
ENABLE_SEGWIT = False
|
||||
VERBOSITY = logging.WARN
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -199,7 +200,8 @@ class IntegrationTestCase(AsyncioTestCase):
|
|||
|
||||
async def asyncSetUp(self):
|
||||
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()
|
||||
self.addCleanup(self.conductor.stop_blockchain)
|
||||
|
|
Loading…
Reference in a new issue