Пример #1
0
def test_address_to_public_key_hash():
    assert address_to_public_key_hash(BITCOIN_ADDRESS) == PUBKEY_HASH
    assert address_to_public_key_hash(
        BITCOIN_ADDRESS_COMPRESSED) == PUBKEY_HASH_COMPRESSED
    with pytest.raises(ValueError):
        address_to_public_key_hash(BITCOIN_ADDRESS_PAY2SH)
    with pytest.raises(ValueError):
        address_to_public_key_hash(BITCOIN_ADDRESS_TEST_PAY2SH)
Пример #2
0
def construct_output_block(outputs, custom_pushdata=False):

    output_block = b''

    for data in outputs:
        dest, amount = data

        # Real recipient
        if amount:
            script = (OP_DUP + OP_HASH160 + OP_PUSH_20 +
                      address_to_public_key_hash(dest) + OP_EQUALVERIFY +
                      OP_CHECKSIG)

            output_block += amount.to_bytes(8, byteorder='little')

        # Blockchain storage
        else:
            if custom_pushdata is False:
                script = OP_FALSE + OP_RETURN + get_op_pushdata_code(
                    dest) + dest

                output_block += b'\x00\x00\x00\x00\x00\x00\x00\x00'

            elif custom_pushdata is True:
                # manual control over number of bytes in each batch of pushdata
                if type(dest) != bytes:
                    raise TypeError("custom pushdata must be of type: bytes")
                else:
                    script = (OP_FALSE + OP_RETURN + dest)

                output_block += b'\x00\x00\x00\x00\x00\x00\x00\x00'

        # Script length in wiki is "Var_int" but there's a note of "modern BitcoinQT" using a more compact "CVarInt"
        output_block += int_to_varint(len(script))
        output_block += script

    return output_block
Пример #3
0
 def scriptcode(self):
     self._scriptcode = (OP_DUP + OP_HASH160 + OP_PUSH_20 +
                         address_to_public_key_hash(self.address) +
                         OP_EQUALVERIFY + OP_CHECKSIG)
     return self._scriptcode