Ejemplo n.º 1
0
    def test_multisig(self, unsigned_pair, signed1_pair, fully_signed_pair,
                      signed2_pair):
        unsigned_hex, unsigned_json = unsigned_pair
        signed1_hex, signed1_json = signed1_pair
        fully_signed_hex, fully_signed_json = fully_signed_pair
        signed2_hex, signed2_json = signed2_pair

        tx = Transaction.from_extended_bytes(bytes.fromhex(unsigned_hex))

        keystore1, keystore2 = self.multisig_keystores()

        assert json.dumps(tx.to_dict()) == unsigned_json

        # Sign with keystore 1, then 2
        keystore1.sign_transaction(tx, "OLD")
        assert json.dumps(tx.to_dict()) == signed1_json

        keystore2.sign_transaction(tx, "BIP32")
        assert tx.serialize() == fully_signed_hex

        # Sign with keystore 2, then 1
        tx = Transaction.from_extended_bytes(bytes.fromhex(unsigned_hex))

        keystore2.sign_transaction(tx, "BIP32")
        assert json.dumps(tx.to_dict()) == signed2_json

        keystore1.sign_transaction(tx, "OLD")
        assert tx.serialize() == fully_signed_hex
        assert json.dumps(tx.to_dict()) == fully_signed_json
Ejemplo n.º 2
0
    def test_tx_unsigned(self):
        tx = Transaction.from_extended_bytes(bytes.fromhex(unsigned_blob))
        assert tx.version == 1
        assert len(tx.inputs) == 1
        txin = tx.inputs[0]
        assert txin.prev_hash.hex(
        ) == '49f35e43fefd22d8bb9e4b3ff294c6286154c25712baf6ab77b646e5074d6aed'
        assert txin.prev_idx == 1
        assert txin.script_sig.to_hex(
        ) == '01ff4c53ff0488b21e0000000000000000004f130d773e678a58366711837ec2e33ea601858262f8eaef246a7ebd19909c9a03c3b30e38ca7d797fee1223df1c9827b2a9f3379768f520910260220e0560014600002300'
        assert txin.sequence == 4294967294
        assert txin.value == 20112600
        assert txin.signatures == [NO_SIGNATURE]
        assert txin.x_pubkeys == [
            XPublicKey.from_hex(
                'ff0488b21e0000000000000000004f130d773e678a58366711837ec2e33ea601858262f8eaef246a7ebd19909c9a03c3b30e38ca7d797fee1223df1c9827b2a9f3379768f520910260220e0560014600002300'
            )
        ]
        assert txin.threshold == 1
        assert (tx.outputs[0].value == 20112408 and tx.outputs[0].script_pubkey == \
            address_from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK').to_script())
        assert tx.locktime == 507231

        assert json.dumps(
            tx.to_dict()
        ) == '{"version": 1, "hex": "010000000149f35e43fefd22d8bb9e4b3ff294c6286154c25712baf6ab77b646e5074d6aed010000002401ff2103b5bbebceeb33c1b61f649596b9c3611c6b2853a1f6b48bce05dd54f667fa2166feffffff0118e43201000000001976a914e158fb15c888037fdc40fb9133b4c1c3c688706488ac5fbd0700", "complete": false, "inputs": [{"script_type": 2, "threshold": 1, "value": 20112600, "signatures": ["ff"], "x_pubkeys": [{"bip32_xpub": "xpub661MyMwAqRbcFL6WFqND2XM2w1EfpBwFfhsSUcw9xDR3nH8eYLv4z4HAhxv5zkqjHojWsPYK1ZSK7yCr8fZ9iWU6D361G2ryv5UgsKjbeDq", "derivation_path": [0, 35]}]}]}'
Ejemplo n.º 3
0
 def test_update_signatures(self):
     signed_tx = Tx.from_hex(signed_tx_3)
     sigs = [next(input.script_sig.ops())[:-1] for input in signed_tx.inputs]
     tx = Transaction.from_extended_bytes(bytes.fromhex(unsigned_tx))
     tx.update_signatures(sigs)
     assert tx.is_complete()
     assert tx.txid() == "b83acf939a92c420d0cb8d45d5d4dfad4e90369ebce0f49a45808dc1b41259b0"
Ejemplo n.º 4
0
 def sign_tx(self, unsigned_tx_hex, priv_keys):
     keypairs = {XPublicKey.from_hex(priv_key.public_key.to_hex()):
                 (priv_key.to_bytes(), priv_key.is_compressed())
                 for priv_key in priv_keys}
     tx = Transaction.from_extended_bytes(bytes.fromhex(unsigned_tx_hex))
     tx.sign(keypairs)
     return tx
Ejemplo n.º 5
0
 def test_fd_read_write(self):
     tx_hex = ('010000000111111111111111111111111111111111111111111111111111111111111111111b'
         '000000ec0001ff483045022100ae42f172f722ac2392ef3e5958d78bbca1ebedbce47eff27ba66345b'
         'e781c46f02207c9ab6ff496791bf2e56300ff4621beaec6ccdd3639e460612569c6e0407e09a414c9e'
         '5245fe84717a26df3332b129e59faaab25c11752277bc55c07d8724e1660e63b862d00b41d3db01e29'
         'ed54ca83300eb73d82b5381536298f40fdad8c1e307b66cf39a9000000004c53ff0488b21e00000000'
         '0000000000f79d7a4d3ea07099f09fbf35c3103908cbb4b1f30e8602a06ffbdbb213d0025602e9aa22'
         'cc7106abab85e4c41f18f030c370213769c18d6754f3d0584e69a7fa120000000052aeffffffffb414'
         '0000000000000188130000000000001976a914000000000000000000000000000000000000000088ac'
         '00000000')
     tx = Transaction.from_extended_bytes(bytes.fromhex(tx_hex))
     # We do not serialize the old extended byte format anymore.
     assert tx.serialize() != tx_hex
Ejemplo n.º 6
0
    def test_tx_signed(self):
        # This is testing the extended parsing for a signed transaction.
        tx = Transaction.from_extended_bytes(bytes.fromhex(signed_blob))
        assert tx.version == 1
        assert len(tx.inputs) == 1
        txin = tx.inputs[0]
        assert txin.prev_hash.hex() == '49f35e43fefd22d8bb9e4b3ff294c6286154c25712baf6ab77b646e5074d6aed'
        assert txin.prev_idx == 1
        assert txin.script_sig.to_hex() == '473044022025bdc804c6fe30966f6822dc25086bc6bb0366016e68e880cf6efd2468921f3202200e665db0404f6d6d9f86f73838306ac55bb0d0f6040ac6047d4e820f24f46885412103b5bbebceeb33c1b61f649596b9c3611c6b2853a1f6b48bce05dd54f667fa2166'
        assert txin.sequence == 4294967294
        assert txin.signatures == [bytes.fromhex('3044022025bdc804c6fe30966f6822dc25086bc6bb0366016e68e880cf6efd2468921f3202200e665db0404f6d6d9f86f73838306ac55bb0d0f6040ac6047d4e820f24f4688541')]
        assert txin.x_pubkeys == [XPublicKey.from_hex('03b5bbebceeb33c1b61f649596b9c3611c6b2853a1f6b48bce05dd54f667fa2166')]
        assert txin.threshold == 1
        assert (tx.outputs[0].value == 20112408 and tx.outputs[0].script_pubkey == \
            address_from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK').to_script())
        assert tx.locktime == 507231
        assert tx.to_dict() == {'hex': signed_blob, 'complete': True, 'version': 1}
        assert tx.serialize() == signed_blob

        tx.update_signatures(signed_blob)

        assert tx.estimated_size() == 192