diff --git a/_ucoinpy_test/documents/test_block.py b/_ucoinpy_test/documents/test_block.py index da3f788ff1131cec6299214713b991f2744d8838..cd8990b9a6e8e013cef8831ebb37ff1534f69afa 100644 --- a/_ucoinpy_test/documents/test_block.py +++ b/_ucoinpy_test/documents/test_block.py @@ -18,6 +18,47 @@ MembersCount: 4\nIdentities:\nJoiners:\nActives:\nLeavers:\n\ Excluded:\nCertifications:\nTransactions:\n" +raw_block_zero = """Version: 1 +Type: Block +Currency: zeta_brouzouf +Nonce: 2125 +Number: 0 +PoWMin: 3 +Time: 1418077277 +MedianTime: 1418077277 +Issuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk +Parameters: 0.01:302400:100:5259600:2629800:3:5:2629800:3:11:600:10:20:0.67 +MembersCount: 4 +Identities: +HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==:1416335620:cgeek +8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:lAW4mCPqA3cnEubHAGpMXR0o8euEdDVeSLplRgdLPf8Bty7R7FqVqwoAlL/4q/7p3O57Cz9z3mvhRSNwt23qBw==:1416378344:inso +RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==:1416428323:vit +9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:ZjlNz2k/7Y38xwzaVEtyteOD12ukRT+x8NBFVTrcZtUHSJdqt7ejBAC0ULu7eCTLlmJk0jS6cuJ3IeVTLfFRDg==:1416436555:ManUtopiK +Joiners: +HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==:0:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709:1416335620:cgeek +8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:43FEO5wwKzo79k+WmZsrUDsNNceStYkrweEntwYGoGn9+YNjyyCbMmKcEU38xzMV2M0ZMgjvlTK30/vWwrD5CQ==:0:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709:1416378344:inso +RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:zPg1kgjVstsaKDBq3Re6Z84hlw0Ja2pjJEORmn7w5ifT6/e45BnEPJaqoVgImzSnytjOpzXN/rhAO4+UDJOUBQ==:0:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709:1416428323:vit +9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:ox/t5um2bbFJfc6NdRDM8DniGxlRB5zmKuW7WK+MiDpE32GUhf/tDcyfBkIpwIFcaY0hqLYW1OQlgbm2qT6xAw==:0:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709:1416436555:ManUtopiK +Actives: +Leavers: +Excluded: +Certifications: +8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ== +RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:xvIlhFdTUwqWx7XIG980xatL0JULOj1Ex15Q9nDcDLVtyFXZZCp1ZeRewkGjkJoGyOFGCJ1iDSB/qFzsPtrsDQ== +9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:0:mNsbLvezg8Zx1NPfs2gdGwmCKtoVWbw64yEHZE7uPkDvF+iexk93O8IT06HKgo1VI5SennwDfh0qp3Ko1OB5BQ== +HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:wIdLq6EYKSLoVXcXoSMLciBPMvJvvP1t5cTCIrvPH4qvo/y02al6vFfQR+wUGwFtoXulUSr8C+U1FRHWfUTCBg== +RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:Gr4EHqCEt+uuLbGPdu1qT/YObkqVthVzmFWCBlKRnRUz3xUt828W25GRtvdVn8hlycvCX/05mMlWeRMBUI/LDA== +9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA== +HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:0:QLaYgLndAqRIk2uRAuxxhNUEQtSLpPqpfKvGBfClpQV0y7YTm1GnEoX9bY3DPhXU8GjUThngkFR0+M4Fx5R6DQ== +8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:0:T+MkH18Eyddq5o93v2tSyBMd/RSkL/mcnE017t/t11QrMmFrXFZeufUhkVfRPi89kLSap4sLV/weEETXX8S7Aw== +9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:0:mWARDngVFmw76JPmHRZHUOh1MFjddNyJ3OMPQHMERFdeev1hKQ3pEUY9lQc6BL524GjIOcvLWufo65Ie0XTDCQ== +8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:0:4vLU/VUE5VxcMnvv4mtJs9bky45o2fddKZCnP0FVGZD3BHC20YMPabTZ2RWcNiCc97zig1Munqj2Ss5RQMBDBA== +RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:0:90w2HrbdsKIc6YJq3Ksa4sSgjpYSMM05+UuowAlYjrk1ixHIyWyg5odyZPRwO50aiIyUsbikoOWsMc3G8ob/Cg== +HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:0:28lv0p8EPHpVgAMiPvXvIe5lMvYJxwko2tv5bPO4voHRHSaDcTz5BR7Oe69S6wjANIEAMfebXiFMqZdj+mWRAA== +Transactions: +""" + + class Test_Block: def test_fromraw(self): block = Block.from_raw(raw_block) @@ -29,9 +70,9 @@ class Test_Block: assert block.time == 1418083330 assert block.mediantime == 1418080208 assert block.issuer == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" - assert block.previoushash == "0000E73C340601ACA1AD5AAA5B5E56B03E178EF8" - assert block.previousissuer == "0000E73C340601ACA1AD5AAA5B5E56B03E178EF8" - assert block.memberscount == 4 + assert block.prev_hash == "0000E73C340601ACA1AD5AAA5B5E56B03E178EF8" + assert block.prev_issuer == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" + assert block.members_count == 4 assert block.identities == [] assert block.joiners == [] assert block.actives == [] @@ -39,3 +80,24 @@ class Test_Block: assert block.excluded == [] assert block.certifications == [] assert block.transactions == [] + + def test_from_raw_block_zero(self): + block = Block.from_raw(raw_block_zero) + assert block.version == 1 + assert block.currency == "zeta_brouzouf" + assert block.noonce == 2125 + assert block.number == 0 + assert block.powmin == 3 + assert block.time == 1418077277 + assert block.mediantime == 1418077277 + assert block.issuer == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" + assert block.parameters == ('0.01','302400','100','5259600','2629800','3','5', + '2629800','3','11','600','10','20','0.67') + assert block.members_count == 4 + assert len(block.identities) == 4 + assert len(block.joiners) == 4 + assert block.actives == [] + assert block.leavers == [] + assert block.excluded == [] + assert len(block.certifications) == 12 + assert block.transactions == [] diff --git a/_ucoinpy_test/documents/test_certification.py b/_ucoinpy_test/documents/test_certification.py index 28cae8d90c17cfbb005e969bcc6212785f3e43ab..968144646eb20f51e8abc244c27392585b2ffd75 100644 --- a/_ucoinpy_test/documents/test_certification.py +++ b/_ucoinpy_test/documents/test_certification.py @@ -5,17 +5,59 @@ Created on 6 déc. 2014 ''' import pytest -from ucoinpy.documents.certification import SelfCertification +from ucoinpy.documents.certification import SelfCertification, Certification from mock import Mock -inline_selfcert = "" +selfcert_inlines = ["HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\ +h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==:\ +1416335620:cgeek\n", "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS:\ +Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==:\ +1416428323:vit\n" ] +cert_inlines = [ +"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\ +0:TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==\n", +"9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y:8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:0:\ +qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==\n" +] class Test_SelfCertification: ''' classdocs ''' - def test_certification(self): + def test_selfcertification(self): version = 1 - selfcert = SelfCertification.from_inline(version, inline_selfcert) + currency = "zeta_brousouf" + selfcert = SelfCertification.from_inline(version, currency, selfcert_inlines[0]) + assert selfcert.pubkey == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" + assert selfcert.signatures[0] == "h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==" + assert selfcert.timestamp == 1416335620 + assert selfcert.identifier == "cgeek" + + selfcert = SelfCertification.from_inline(version, currency, selfcert_inlines[1]) + assert selfcert.pubkey == "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS" + assert selfcert.signatures[0] == "Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==" + assert selfcert.timestamp == 1416428323 + assert selfcert.identifier == "vit" + + def test_certifications(self): + version = 1 + currency = "zeta_brousouf" + blockhash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" + cert = Certification.from_inline(version, currency, blockhash, cert_inlines[0]) + assert cert.pubkey_from == "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" + assert cert.pubkey_to == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" + assert cert.blocknumber == 0 + assert cert.blockhash == blockhash + assert cert.signatures[0] == "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==" + + cert = Certification.from_inline(version, currency, blockhash, cert_inlines[1]) + assert cert.pubkey_from == "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y" + assert cert.pubkey_to == "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" + assert cert.blocknumber == 0 + assert cert.blockhash == blockhash + assert cert.signatures[0] == "qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==" + + + diff --git a/_ucoinpy_test/documents/test_membership.py b/_ucoinpy_test/documents/test_membership.py index b9bb639cd8b080075d76738c5bbfb3c9f12972b0..2881952a601c9729bd5f9547112c8d297fd7e85d 100644 --- a/_ucoinpy_test/documents/test_membership.py +++ b/_ucoinpy_test/documents/test_membership.py @@ -7,10 +7,12 @@ import pytest from ucoinpy.documents.membership import Membership from mock import Mock -inline_membership = "" +inline_membership = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:\ +dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==:\ +0:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709:1416335620:cgeek\n" class Test_Membership: def test_frominline(self): - membership = Membership.from_inline(inline_membership) + membership = Membership.from_inline(1, "zeta_brousouf", 'IN', inline_membership) diff --git a/_ucoinpy_test/documents/test_transaction.py b/_ucoinpy_test/documents/test_transaction.py index 97a66823542b8ed64c416f3a7cf2e883d45ea3e7..f24cac9a5d264a71a1166b8fcf522637889c426d 100644 --- a/_ucoinpy_test/documents/test_transaction.py +++ b/_ucoinpy_test/documents/test_transaction.py @@ -20,29 +20,31 @@ BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30 class Test_Transaction: def test_fromraw(self): - tx = Transaction.from_compact(compact_transaction) + tx = Transaction.from_compact("zeta_brousouf", 2, compact_transaction) assert tx.version == 1 - assert tx.issuers.len == 1 - assert tx.inputs.len == 1 - assert tx.outputs.len == 3 + assert len(tx.issuers) == 1 + assert len(tx.inputs) == 3 + assert len(tx.outputs) == 1 + + assert tx.issuers[0] == "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY" assert tx.inputs[0].index == 0 assert tx.inputs[0].source == 'T' assert tx.inputs[0].number == 65 - assert tx.inputs[0].pubkey == "D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8" + assert tx.inputs[0].txhash == "D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8" assert tx.inputs[0].amount == 4 assert tx.inputs[1].index == 0 assert tx.inputs[1].source == 'T' assert tx.inputs[1].number == 77 - assert tx.inputs[1].pubkey == "F80993776FB55154A60B3E58910C942A347964AD" + assert tx.inputs[1].txhash == "F80993776FB55154A60B3E58910C942A347964AD" assert tx.inputs[1].amount == 15 assert tx.inputs[2].index == 0 assert tx.inputs[2].source == 'D' assert tx.inputs[2].number == 88 - assert tx.inputs[2].pubkey == "F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B" + assert tx.inputs[2].txhash == "F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B" assert tx.inputs[2].amount == 11 assert tx.outputs[0].pubkey == "BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g" - assert tx.outputs[1].amount == 30 + assert tx.outputs[0].amount == 30 diff --git a/ucoinpy/documents/block.py b/ucoinpy/documents/block.py index 34db3545eb92570df3b67ccb16e6bda1b63f7946..cbf7c13372f0790c94088ca6137911086d7f339e 100644 --- a/ucoinpy/documents/block.py +++ b/ucoinpy/documents/block.py @@ -60,10 +60,12 @@ BOTTOM_SIGNATURE re_time = re.compile("Time: ([0-9]+)\n") re_mediantime = re.compile("MedianTime: ([0-9]+)\n") re_universaldividend = re.compile("UniversalDividend: ([0-9]+)\n") - re_issuer = re.compile("Issuer: ([1-9A-Za-z][^OIl]{43,45})\n") + re_issuer = re.compile("Issuer: ([1-9A-Za-z][^OIl]{42,45})\n") re_previoushash = re.compile("PreviousHash: ([0-9a-fA-F]{5,40})\n") - re_previousissuer = re.compile("PreviousIssuer: ([1-9A-Za-z][^OIl]{43,45})\n") - re_parameters = re.compile("Parameters: ([0-9]+\.[0-9]+)(:[0-9]+){10}\n") + re_previousissuer = re.compile("PreviousIssuer: ([1-9A-Za-z][^OIl]{42,45})\n") + re_parameters = re.compile("Parameters: ([0-9]+\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):\ +([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):\ +([0-9]+\.[0-9]+)\n") re_memberscount = re.compile("MembersCount: ([0-9]+)\n") re_identities = re.compile("Identities:\n") re_joiners = re.compile("Joiners:\n") @@ -82,7 +84,7 @@ BOTTOM_SIGNATURE ''' Constructor ''' - super(version, currency, [signature]) + super(Block, self).__init__(version, currency, [signature]) self.noonce = noonce self.number = number self.powmin = powmin @@ -107,49 +109,53 @@ BOTTOM_SIGNATURE lines = raw.splitlines(True) n = 0 - version = Block.re_version.match(lines[n]).group(1) + version = int(Block.re_version.match(lines[n]).group(1)) n = n + 1 - type = Block.re_type.match(lines[n]).group(1) + doctype = Block.re_type.match(lines[n]).group(1) n = n + 1 currency = Block.re_currency.match(lines[n]).group(1) n = n + 1 - noonce = int(Block.re_noonce.match(lines[n])).group(1) + noonce = int(Block.re_noonce.match(lines[n]).group(1)) n = n + 1 - number = int(Block.re_number.match(lines[n])).group(1) + number = int(Block.re_number.match(lines[n]).group(1)) n = n + 1 - powmin = int(Block.re_powmin.match(lines[n])).group(1) + powmin = int(Block.re_powmin.match(lines[n]).group(1)) n = n + 1 - time = int(Block.re_time.match(lines[n])).group(1) + time = int(Block.re_time.match(lines[n]).group(1)) n = n + 1 - mediantime = int(Block.re_mediantime.match(lines[n])).group(1) + mediantime = int(Block.re_mediantime.match(lines[n]).group(1)) n = n + 1 - ud = Block.re_universaldividend.match(lines[n]).group(1) + ud = Block.re_universaldividend.match(lines[n]) if ud is not None: - ud = int(ud) + ud = int(ud.group(1)) n = n + 1 issuer = Block.re_issuer.match(lines[n]).group(1) n = n + 1 - prev_hash = Block.re_previoushash.match(lines[n]).group(1) - n = n + 1() + prev_hash = None + prev_issuer = None + if number > 0: + prev_hash = Block.re_previoushash.match(lines[n]).group(1) + n = n + 1 - prev_issuer = Block.re_previousissuer.match(lines[n]).group(1) - n = n + 1 + prev_issuer = Block.re_previousissuer.match(lines[n]).group(1) + n = n + 1 + parameters = None if number == 0: - parameters = Block.re_parameters.match(lines[n]).group(1) + parameters = Block.re_parameters.match(lines[n]).groups() n = n + 1 - members_count = int(Block.re_memberscount.match(lines[n])).group(1) + members_count = int(Block.re_memberscount.match(lines[n]).group(1)) n = n + 1 identities = [] @@ -161,54 +167,59 @@ BOTTOM_SIGNATURE transactions = [] if Block.re_identities.match(lines[n]) is not None: + n = n + 1 while Block.re_joiners.match(lines[n]) is None: - selfcert = SelfCertification.from_inline(version, lines[n]) + selfcert = SelfCertification.from_inline(version, currency, lines[n]) identities.append(selfcert) - lines = lines + 1 + n = n + 1 if Block.re_joiners.match(lines[n]): - lines = lines + 1 + n = n + 1 while Block.re_actives.match(lines[n]) is None: membership = Membership.from_inline(version, currency, "IN", lines[n]) joiners.append(membership) - lines = lines + 1 + n = n + 1 if Block.re_actives.match(lines[n]): - lines = lines + 1 + n = n + 1 while Block.re_leavers.match(lines[n]) is None: membership = Membership.from_inline(version, currency, "IN", lines[n]) actives.append(membership) - lines = lines + 1 + n = n + 1 if Block.re_leavers.match(lines[n]): - lines = lines + 1 + n = n + 1 while Block.re_excluded.match(lines[n]) is None: membership = Membership.from_inline(version, currency, "OUT", lines[n]) leavers.append(membership) - lines = lines + 1 + n = n + 1 if Block.re_excluded.match(lines[n]): - lines = lines + 1 + n = n + 1 while Block.re_certifications.match(lines[n]) is None: membership = Membership.from_inline(version, currency, "OUT", lines[n]) excluded.append(membership) - lines = lines + 1 + n = n + 1 if Block.re_certifications.match(lines[n]): - lines = lines + 1 + n = n + 1 while Block.re_transactions.match(lines[n]) is None: - certification = Certification.from_inline(version, lines[n]) + certification = Certification.from_inline(version, currency, + prev_hash, lines[n]) certifications.append(certification) - lines = lines + 1 + n = n + 1 if Block.re_transactions.match(lines[n]): - lines = lines + 1 - while Block.re_sign.match(lines[n]) is None: + n = n + 1 + while n < len(lines) and not Block.re_sign.match(lines[n]): transaction = Transaction.from_compact(version, lines[n]) transactions.append(transaction) - lines = lines + 1 + n = n + 1 + + signature = None + if n < len(lines): + signature = Block.re_sign.match(lines[n]) - signature = Block.re_sign.match(lines[n]) n = n + 1 return cls(version, currency, noonce, number, powmin, time, diff --git a/ucoinpy/documents/certification.py b/ucoinpy/documents/certification.py index 66c9331ee4f4cf561d48401d02509f708255b9e2..e7df7abd2cab37d5a4a62a682005d313b39ff1ad 100644 --- a/ucoinpy/documents/certification.py +++ b/ucoinpy/documents/certification.py @@ -13,22 +13,22 @@ class SelfCertification(Document): A document discribing a self certification. ''' - re_inline = re.compile("([1-9A-Za-z][^OIl]{43,45}):([A-Za-z0-9+/]+):([0-9]+):([^\n]+)\n") + re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):([0-9]+):([^\n]+)\n") def __init__(self, version, currency, pubkey, ts, identifier, signature): - super(version, currency, [signature]) + super().__init__(version, currency, [signature]) self.pubkey = pubkey self.timestamp = ts self.identifier = identifier @classmethod - def from_inline(cls, version, inline): + def from_inline(cls, version, currency, inline): selfcert_data = SelfCertification.re_inline.match(inline) pubkey = selfcert_data.group(1) signature = selfcert_data.group(2) - ts = selfcert_data.group(3) + ts = int(selfcert_data.group(3)) identifier = selfcert_data.group(4) - return cls(version, pubkey, ts, identifier, signature) + return cls(version, currency, pubkey, ts, identifier, signature) @classmethod def from_raw(cls, raw): @@ -50,29 +50,30 @@ class Certification(Document): A document describing a certification. ''' - re_inline = re.compile("([1-9A-Za-z][^OIl]{43,45}):\ - ([A-Za-z0-9+/]+)(==)?:([0-9]+):([0-9a-fA-F]{5,40}):\ - ([0-9]+):([^\n]+)\n") + re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):\ +([1-9A-Za-z][^OIl]{42,45}):([0-9]+):([A-Za-z0-9+/]+(?:=|==)?)\n") def __init__(self, version, currency, pubkey_from, pubkey_to, blockhash, blocknumber, signature): ''' Constructor ''' - super(version, currency, signature) + super().__init__(version, currency, [signature]) self.pubkey_from = pubkey_from self.pubkey_to = pubkey_to self.blockhash = blockhash self.blocknumber = blocknumber @classmethod - def from_inline(cls, version, blockhash, inline): + def from_inline(cls, version, currency, blockhash, inline): cert_data = Certification.re_inline.match(inline) pubkey_from = cert_data.group(1) pubkey_to = cert_data.group(2) - blocknumber = cert_data.group(3) + blocknumber = int(cert_data.group(3)) + if blocknumber == 0: + blockhash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" signature = cert_data.group(4) - return cls(version, pubkey_from, pubkey_to, + return cls(version, currency, pubkey_from, pubkey_to, blockhash, blocknumber, signature) def ts(self): diff --git a/ucoinpy/documents/membership.py b/ucoinpy/documents/membership.py index 392ae9f9c13de9185686d708869d65afe6afb5fb..cd355262af4470e378a7c714b172a180ca21f3ad 100644 --- a/ucoinpy/documents/membership.py +++ b/ucoinpy/documents/membership.py @@ -23,15 +23,15 @@ class Membership(Document): ''' # PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID - re_inline = re.compile("([1-9A-Za-z][^OIl]{43,45}):([A-Za-z0-9+/]+):\ - ([0-9]+):([0-9a-fA-F]{5,40}):([0-9]+):([^\n]+)\n") + re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):\ +([0-9]+):([0-9a-fA-F]{5,40}):([0-9]+):([^\n]+)\n") def __init__(self, version, currency, issuer, block_number, block_hash, membership_type, userid, cert_ts, signature): ''' Constructor ''' - super(version, currency, [signature]) + super().__init__(version, currency, [signature]) self.issuer = issuer self.block_number = block_number self.block_hash = block_hash @@ -40,7 +40,7 @@ class Membership(Document): self.cert_ts = cert_ts @classmethod - def from_inline(cls, version, currency, type, inline): + def from_inline(cls, version, currency, membership_type, inline): data = Membership.re_inline.match(inline) issuer = data.group(1) signature = data.group(2) @@ -49,7 +49,7 @@ class Membership(Document): cert_ts = data.group(5) userid = data.group(6) return cls(version, currency, issuer, block_number, - block_hash, type, userid, cert_ts, signature) + block_hash, membership_type, userid, cert_ts, signature) @classmethod def from_raw(cls, raw): diff --git a/ucoinpy/documents/peer.py b/ucoinpy/documents/peer.py index 6d4c50ca2ede69909d6d7f18bc4e3640a08e7e72..e315a5f929d7f378af5b2c2e7514364a2007bf24 100644 --- a/ucoinpy/documents/peer.py +++ b/ucoinpy/documents/peer.py @@ -25,7 +25,7 @@ class Peer(Document): """ def __init__(self, version, currency, pubkey, blockid, endpoints, signature): - super(version, currency, [signature]) + super().__init__(version, currency, [signature]) self.pubkey = pubkey self.blockid = blockid self.endpoints = endpoints diff --git a/ucoinpy/documents/status.py b/ucoinpy/documents/status.py index a05c083ad4b0705f8754fa3cf7d63e2ec4feb732..e12a6b3e120040144bf1af7b9923e179692452e2 100644 --- a/ucoinpy/documents/status.py +++ b/ucoinpy/documents/status.py @@ -19,11 +19,12 @@ class Status(Document): To: RECIPIENT ''' - def __init__(self, version, currency, status, blockid, sender, recipient, signature): + def __init__(self, version, currency, status, blockid, sender, + recipient, signature): ''' Constructor ''' - super(version, currency, [signature]) + super().__init__(version, currency, [signature]) self.status = status self.blockid = blockid self.sender = sender diff --git a/ucoinpy/documents/transaction.py b/ucoinpy/documents/transaction.py index d73d4e60b52b52279b232eb7f3c17f3bb9d5747a..6040f1863cb396672ddd30c179abb0f0968f243a 100644 --- a/ucoinpy/documents/transaction.py +++ b/ucoinpy/documents/transaction.py @@ -45,14 +45,14 @@ SIGNATURE re_issuers = re.compile("Issuers:\n") re_inputs = re.compile("Inputs:\n") re_outputs = re.compile("Outputs:\n") - re_pubkey = re.compile("([1-9A-Za-z][^OIl]{43,45})\n") + re_pubkey = re.compile("([1-9A-Za-z][^OIl]{42,45})\n") def __init__(self, version, currency, issuers, inputs, outputs, comment, signatures): ''' Constructor ''' - super(version, currency, signatures) + super().__init__(version, currency, signatures) self.issuers = issuers self.inputs = inputs self.outputs = outputs @@ -64,10 +64,10 @@ SIGNATURE n = 0 header_data = Transaction.re_header.match(lines[n]) - version = header_data.group(2) - issuers_num = int(header_data.group(3)) + 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(3)) + outputs_num = int(header_data.group(4)) n = n + 1 issuers = [] @@ -81,17 +81,16 @@ SIGNATURE n = n + 1 for i in range(0, inputs_num): - input = InputSource.from_compact(lines[n]) - inputs.append(issuer) + input_source = InputSource.from_inline(lines[n]) + inputs.append(input_source) n = n + 1 for i in range(0, outputs_num): - output = OutputSource.from_inline(lines[n]) - outputs.append(output) + output_source = OutputSource.from_inline(lines[n]) + outputs.append(output_source) n = n + 1 - return cls(version, currency, issuers, inputs, outputs, signatures) - + return cls(version, currency, issuers, inputs, outputs, None, signatures) @classmethod def from_raw(cls, raw): @@ -211,7 +210,7 @@ As transaction class, but for only one issuer. ''' Constructor ''' - super(version, currency, [issuer], [single_input], + super().__init__(version, currency, [issuer], [single_input], outputs, comment, [signature]) @@ -223,8 +222,8 @@ class InputSource(): INDEX:SOURCE:FINGERPRINT:AMOUNT ''' re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\ - ([0-9a-fA-F]{5,40}):([0-9]+)") - re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)") +([0-9a-fA-F]{5,40}):([0-9]+)\n") + re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)\n") def __init__(self, index, source, number, txhash, amount): self.index = index @@ -236,21 +235,21 @@ class InputSource(): @classmethod def from_inline(cls, inline): data = InputSource.re_inline.match(inline) - index = data.group(1) + index = int(data.group(1)) source = data.group(2) - number = data.group(3) + number = int(data.group(3)) txhash = data.group(4) - amount = data.group(5) - return cls(data, index, source, number, txhash, amount) + amount = int(data.group(5)) + return cls(index, source, number, txhash, amount) @classmethod def from_compact(cls, number, compact): data = InputSource.re_compact.match(compact) - index = data.group(1) + index = int(data.group(1)) source = data.group(2) txhash = data.group(3) - amount = data.group(4) - return cls(data, index, source, number, txhash, amount) + amount = int(data.group(4)) + return cls(index, source, number, txhash, amount) def inline(self): return "{0}:{1}:{2}:{3}:{4}".format(self.index, @@ -270,7 +269,7 @@ class OutputSource(): ''' A Transaction OUTPUT ''' - re_inline = "([1-9A-Za-z][^OIl]{43,45}):([0-9]+)" + re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([0-9]+)") def __init__(self, pubkey, amount): self.pubkey = pubkey @@ -280,7 +279,7 @@ class OutputSource(): def from_inline(cls, inline): data = OutputSource.re_inline.match(inline) pubkey = data.group(1) - amount = data.group(2) + amount = int(data.group(2)) return cls(pubkey, amount) def inline(self):