示例#1
0
 def unfollow(cls, user_address, sender):
     memo = Memo()
     memo.sender = sender
     memo.prefix = PRIFIX_BY_ACTION_NAME['Unfollow user']
     memo.address = address_to_public_key_hash(user_address).hex()
     memo.__create_values()
     return memo
示例#2
0
def construct_output_block(outputs):

    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:
            script = (OP_RETURN + len(dest).to_bytes(1, byteorder='little') +
                      dest)

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

        output_block += int_to_unknown_bytes(len(script), byteorder='little')
        output_block += script

    return output_block
示例#3
0
def test_address_to_public_key_hash():
    assert address_to_public_key_hash(BITCOIN_CASHADDRESS) == PUBKEY_HASH
    assert address_to_public_key_hash(BITCOIN_CASHADDRESS_TEST) == PUBKEY_HASH
    assert address_to_public_key_hash(
        BITCOIN_CASHADDRESS_COMPRESSED) == PUBKEY_HASH_COMPRESSED
    assert address_to_public_key_hash(
        BITCOIN_CASHADDRESS_TEST_COMPRESSED) == PUBKEY_HASH_COMPRESSED
    with pytest.raises(ValueError):
        address_to_public_key_hash(BITCOIN_CASHADDRESS_PAY2SH)
    with pytest.raises(ValueError):
        address_to_public_key_hash(BITCOIN_CASHADDRESS_TEST_PAY2SH)
示例#4
0
def construct_output_block(outputs):
    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:
            values_bytes = b''
            split_length = 10
            info = [
                dest[i:i + split_length]
                for i in range(0, len(dest), split_length)
            ]
            for message in info:
                messagebytes = message.encode('utf-8')
                len_message_bytes = len(messagebytes).to_bytes(
                    1, byteorder='little')
                _values = (len_message_bytes + messagebytes).hex()
                values_bytes += bytes.fromhex(_values)

            data_bytes = values_bytes

            script = (OP_RETURN + data_bytes)

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

        output_block += int_to_unknown_bytes(len(script), byteorder='little')

        output_block += script

    return output_block
示例#5
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_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_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"
        # CVarInt is what I believe we have here - No changes made. If incorrect - only breaks if 220 byte limit is increased.
        output_block += int_to_unknown_bytes(len(script), byteorder="little")
        output_block += script

    return output_block
示例#6
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