Exemplo n.º 1
0
    async def make_raw_block(self, b):
        '''Construct a raw block'''

        header = await self.make_raw_header(b)

        transactions = []
        if b.get('height') > 0:
            transactions = await self.getrawtransactions(b.get('tx'), False)

        raw_block = header
        num_txs = len(transactions)
        if num_txs > 0:
            raw_block += int_to_varint(num_txs)
            raw_block += b''.join(transactions)
        else:
            raw_block += b'\x00'

        return raw_block
Exemplo n.º 2
0
def test_int_to_varint():
    with pytest.raises(ValueError):
        util.int_to_varint(-1)
    assert util.int_to_varint(0) == b'\0'
    assert util.int_to_varint(5) == b'\5'
    assert util.int_to_varint(252) == b'\xfc'
    assert util.int_to_varint(253) == b'\xfd\xfd\0'
    assert util.int_to_varint(65535) == b'\xfd\xff\xff'
    assert util.int_to_varint(65536) == b'\xfe\0\0\1\0'
    assert util.int_to_varint(2**32-1) == b'\xfe\xff\xff\xff\xff'
    assert util.int_to_varint(2**32) == b'\xff\0\0\0\0\1\0\0\0'
    assert util.int_to_varint(2**64-1) \
        == b'\xff\xff\xff\xff\xff\xff\xff\xff\xff'