diff --git a/ucoinpy/documents/block.py b/ucoinpy/documents/block.py index 031c69f1d3e7da54dde37631930a32bcda4a97cc..873f404d09bc74de170d779aa1145ac6968863f1 100644 --- a/ucoinpy/documents/block.py +++ b/ucoinpy/documents/block.py @@ -11,6 +11,7 @@ from .membership import Membership from .transaction import Transaction import re +import logging class Block(Document): @@ -104,7 +105,7 @@ BOTTOM_SIGNATURE self.transactions = transactions @classmethod - def from_signed_raw(cls, raw, signature=None): + def from_signed_raw(cls, raw): lines = raw.splitlines(True) n = 0 @@ -211,9 +212,19 @@ BOTTOM_SIGNATURE if Block.re_transactions.match(lines[n]): n = n + 1 while not Block.re_signature.match(lines[n]): - transaction = Transaction.from_compact(version, lines[n]) + tx_lines = "" + header_data = Transaction.re_header.match(lines[n]) + version = int(header_data.group(1)) + issuers_num = int(header_data.group(2)) + inputs_num = int(header_data.group(3)) + outputs_num = int(header_data.group(4)) + has_comment = int(header_data.group(5)) + tx_max = n+issuers_num*2+inputs_num+outputs_num+has_comment+1 + for i in range(n, tx_max): + tx_lines += lines[n] + n = n + 1 + transaction = Transaction.from_compact(version, tx_lines) transactions.append(transaction) - n = n + 1 signature = Block.re_signature.match(lines[n]).group(1) diff --git a/ucoinpy/documents/transaction.py b/ucoinpy/documents/transaction.py index 460f1c34dd5d38bca15b00b70ff3b6dc49c3e4b5..cd42c610e78061bd69da10052e883acbbc030c63 100644 --- a/ucoinpy/documents/transaction.py +++ b/ucoinpy/documents/transaction.py @@ -7,7 +7,6 @@ Created on 2 déc. 2014 from . import Document import re - class Transaction(Document): ''' Document format : @@ -45,8 +44,8 @@ SIGNATURE re_issuers = re.compile("Issuers:\n") re_inputs = re.compile("Inputs:\n") re_outputs = re.compile("Outputs:\n") - re_compact_comment = re.compile("-----@@@-----([^\n]+)\n") - re_comment = re.compile("Comment:(?:)?([^\n]*)\n") + re_compact_comment = re.compile("([^\n]+)\n") + re_comment = re.compile("Comment: ([^\n]*)\n") re_pubkey = re.compile("([1-9A-Za-z][^OIl]{42,45})\n") def __init__(self, version, currency, issuers, inputs, outputs, @@ -71,6 +70,7 @@ SIGNATURE issuers_num = int(header_data.group(2)) inputs_num = int(header_data.group(3)) outputs_num = int(header_data.group(4)) + has_comment = int(header_data.group(5)) n = n + 1 issuers = [] @@ -92,8 +92,8 @@ SIGNATURE outputs.append(output_source) n = n + 1 - comment = None - if Transaction.re_comment.match(lines[n]): + comment = "" + if has_comment == 1: comment = Transaction.re_compact_comment.match(lines[n]).group(1) n = n + 1 @@ -175,9 +175,7 @@ Issuers: doc += "{0}\n".format(o.inline()) doc += "Comment: " - if self.comment: - doc += "{0}".format(self.comment) - doc += "\n" + doc += "{0}\n".format(self.comment) return doc @@ -194,19 +192,19 @@ PUBLIC_KEY:AMOUNT ... COMMENT """ - doc = "TX:{0}:{1}:{2}:{3}:{4}".format(self.version, - self.issuers.len, - self.inputs.len, - self.outputs.len, - '1' if self.Comment else '0') + doc = "TX:{0}:{1}:{2}:{3}:{4}\n".format(self.version, + len(self.issuers), + len(self.inputs), + len(self.outputs), + '1' if self.comment != "" else '0') for pubkey in self.issuers: doc += "{0}\n".format(pubkey) for i in self.inputs: doc += "{0}\n".format(i.compact()) for o in self.outputs: doc += "{0}\n".format(o.inline()) - if self.comment: - doc += "-----@@@----- {0}\n".format(self.comment) + if self.comment != "": + doc += "{0}\n".format(self.comment) for s in self.signatures: doc += "{0}\n".format(s)