Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for witness transactions #2613

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lbry/lbry/wallet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
__node_bin__ = ''
__node_url__ = (
'https://github.com/lbryio/lbrycrd/releases/download/v0.17.2.1/lbrycrd-linux.zip'
# 'https://github.com/lbryio/lbrycrd/releases/download/v0.17.3.1/lbrycrd-linux-1731.zip'
)
__spvserver__ = 'lbry.wallet.server.coin.LBCRegTest'

Expand Down
10 changes: 10 additions & 0 deletions torba/torba/client/basetransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,23 @@ def _deserialize(self):
stream = BCDataStream(self._raw)
self.version = stream.read_uint32()
input_count = stream.read_compact_size()
flag = 0
if input_count == 0:
flag = stream.read_uint8()
input_count = stream.read_compact_size()
self._add(self._inputs, [
self.input_class.deserialize_from(stream) for _ in range(input_count)
])
output_count = stream.read_compact_size()
self._add(self._outputs, [
self.output_class.deserialize_from(stream) for _ in range(output_count)
])
if flag == 1:
# drain witness portion of transaction
# too many witnesses for no crime
for _ in range(input_count):
for _ in range(stream.read_compact_size()):
stream.read(stream.read_compact_size())
self.locktime = stream.read_uint32()

@classmethod
Expand Down
26 changes: 21 additions & 5 deletions torba/torba/server/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,26 @@ def __init__(self, binary, start=0):
self.binary = binary
self.binary_length = len(binary)
self.cursor = start
self.flags = 0

def read_tx(self):
"""Return a deserialized transaction."""
version = self._read_le_int32()
inputs = self._read_inputs()
outputs = self._read_outputs()
if self.flags == 1:
# drain witness portion of transaction
# too many witnesses for no crime
for i in range(len(inputs)):
for v in range(self._read_varint()):
self._read_varbytes()
self.flags = 0
locktime = self._read_le_uint32()
return Tx(
self._read_le_int32(), # version
self._read_inputs(), # inputs
self._read_outputs(), # outputs
self._read_le_uint32() # locktime
version,
inputs,
outputs,
locktime
)

def read_tx_and_hash(self):
Expand All @@ -132,7 +144,11 @@ def read_tx_block(self):

def _read_inputs(self):
read_input = self._read_input
return [read_input() for i in range(self._read_varint())]
num_inputs = self._read_varint()
if num_inputs == 0:
self.flags = self._read_byte()
num_inputs = self._read_varint()
return [read_input() for i in range(num_inputs)]

def _read_input(self):
return TxInput(
Expand Down