Example #1
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version,), bytes) = parse(bytes, UINT32_FMT)
     (num_hashes, bytes) = parse_varint(bytes)
     hashes = []
     for _ in xrange(num_hashes):
         ((hash,), bytes) = parse(bytes, cls.HASH_FMT)
         hashes.append(hash)
     ((hash_stop,), bytes) = parse(bytes, cls.HASH_FMT)
     return (cls(version, hashes, hash_stop, header=header), bytes)
Example #2
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version, services, timestamp), bytes) = parse(bytes, cls.BITS[0])
     (addr_recv, bytes) = parse_addr_bare(bytes)
     (addr_from, bytes) = parse_addr_bare(bytes)
     ((nonce, ), bytes) = parse(bytes, cls.BITS[1])
     (user_agent, bytes) = parse_varstr(bytes)
     ((start_height, relay), bytes) = parse(bytes, cls.BITS[2])
     return (cls(version, addr_recv, addr_from, nonce, user_agent,
                 start_height, relay, services, timestamp, header), bytes)
Example #3
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version, ), bytes) = parse(bytes, UINT32_FMT)
     (num_hashes, bytes) = parse_varint(bytes)
     hashes = []
     for _ in xrange(num_hashes):
         ((hash, ), bytes) = parse(bytes, cls.HASH_FMT)
         hashes.append(hash)
     ((hash_stop, ), bytes) = parse(bytes, cls.HASH_FMT)
     return (cls(version, hashes, hash_stop, header=header), bytes)
Example #4
0
 def parse(cls, bytes):
     ((version, ), bytes) = parse(bytes, UINT32_FMT)
     (num_tx_in, bytes) = parse_varint(bytes)
     tx_in = []
     for _ in xrange(num_tx_in):
         (tx, bytes) = TxIn.parse(bytes)
         tx_in.append(tx)
     (num_tx_out, bytes) = parse_varint(bytes)
     tx_out = []
     for _ in xrange(num_tx_out):
         (tx, bytes) = TxOut.parse(bytes)
         tx_out.append(tx)
     ((lock_time, ), bytes) = parse(bytes, UINT32_FMT)
     return (cls(version, tx_in, tx_out, lock_time), bytes)
Example #5
0
 def parse(cls, bytes):
     ((version,), bytes) = parse(bytes, UINT32_FMT)
     (num_tx_in, bytes) = parse_varint(bytes)
     tx_in = []
     for _ in xrange(num_tx_in):
         (tx, bytes) = TxIn.parse(bytes)
         tx_in.append(tx)
     (num_tx_out, bytes) = parse_varint(bytes)
     tx_out = []
     for _ in xrange(num_tx_out):
         (tx, bytes) = TxOut.parse(bytes)
         tx_out.append(tx)
     ((lock_time,), bytes) = parse(bytes, UINT32_FMT)
     return (cls(version, tx_in, tx_out, lock_time), bytes)
Example #6
0
 def parse(cls, bytes):
     ((magic, command, payload_length, checksum),
      bytes) = parse(bytes, cls.HEADER_FMT)
     if magic != MAGIC:
         raise ParseError('Magic does not match: %r' % (magic, ))
     command = command.rstrip('\x00')
     return (cls(command, payload_length, checksum), bytes)
Example #7
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     (count, bytes) = parse_varint(bytes)
     hashes = []
     for _ in xrange(count):
         (item, bytes) = parse(bytes, cls.HASH_FMT)
         hashes.append(item)
     return (cls(hashes, header), bytes)
Example #8
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     (count, bytes) = parse_varint(bytes)
     hashes = []
     for _ in xrange(count):
         (item, bytes) = parse(bytes, cls.HASH_FMT)
         hashes.append(item)
     return (cls(hashes, header), bytes)
Example #9
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version, services, timestamp), bytes) = parse(bytes, cls.BITS[0])
     (addr_recv, bytes) = parse_addr_bare(bytes)
     (addr_from, bytes) = parse_addr_bare(bytes)
     ((nonce,), bytes) = parse(bytes, cls.BITS[1])
     (user_agent, bytes) = parse_varstr(bytes)
     ((start_height, relay), bytes) = parse(bytes, cls.BITS[2])
     return (cls(version,
                 addr_recv,
                 addr_from,
                 nonce,
                 user_agent,
                 start_height,
                 relay,
                 services,
                 timestamp,
                 header),
             bytes)
Example #10
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version, prev_block_hash, merkle_root, timestamp, bits, nonce),
      bytes) = parse(bytes, cls.HDR_FMT)
     (num_tx, bytes) = parse_varint(bytes)
     txns = []
     for _ in xrange(num_tx):
         (tx, bytes) = Transaction.parse(bytes)
         txns.append(tx)
     return (cls(version, prev_block_hash, merkle_root, timestamp, bits, nonce, txns), bytes)
Example #11
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((version, prev_block_hash, merkle_root, timestamp, bits, nonce),
      bytes) = parse(bytes, cls.HDR_FMT)
     (num_tx, bytes) = parse_varint(bytes)
     txns = []
     for _ in xrange(num_tx):
         (tx, bytes) = Transaction.parse(bytes)
         txns.append(tx)
     return (cls(version, prev_block_hash, merkle_root, timestamp, bits,
                 nonce, txns), bytes)
Example #12
0
def parse_addr(bytes):
    ((ts,), bytes) = parse(bytes, ADDR_FMT)
    (addr, bytes) = parse_addr_bare(bytes)
    return (ts, addr, bytes)
Example #13
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((nonce,), bytes) = parse(bytes, cls.PAYLOAD)
     return (cls(nonce, header), bytes)
Example #14
0
 def parse(cls, bytes):
     ((value, ), bytes) = parse(bytes, INT64_FMT)
     (script_len, bytes) = parse_varint(bytes)
     (pk_script, bytes) = splitn(bytes, script_len)
     return (cls(value, PubKeyScript(pk_script)), bytes)
Example #15
0
 def parse(cls, bytes):
     (previous_output, bytes) = parse(bytes, cls.OUTPOINT_FMT)
     (script_len, bytes) = parse_varint(bytes)
     (signature_script, bytes) = splitn(bytes, script_len)
     ((sequence, ), bytes) = parse(bytes, UINT32_FMT)
     return (cls(previous_output, signature_script, sequence), bytes)
Example #16
0
 def parse(cls, bytes, header=None):
     if header is None:
         (header, bytes) = MessageHeader.parse(bytes)
     ((nonce, ), bytes) = parse(bytes, cls.PAYLOAD)
     return (cls(nonce, header), bytes)
Example #17
0
def parse_addr_bare(bytes):
    ((services, ), bytes) = parse(bytes, ADDR_SVCS_FMT)
    ((_, _, _, ipbytes, port), bytes) = parse(bytes, ADDR_BARE_FMT)
    ip = '.'.join(str(ord(o)) for o in ipbytes)
    return ((services, ip, port), bytes)
Example #18
0
def parse_addr_bare(bytes):
    ((services,), bytes) = parse(bytes, ADDR_SVCS_FMT)
    ((_, _, _, ipbytes, port), bytes) = parse(bytes, ADDR_BARE_FMT)
    ip = '.'.join(str(ord(o)) for o in ipbytes)
    return ((services, ip, port), bytes)
Example #19
0
 def parse(cls, bytes):
     (previous_output, bytes) = parse(bytes, cls.OUTPOINT_FMT)
     (script_len, bytes) = parse_varint(bytes)
     (signature_script, bytes) = splitn(bytes, script_len)
     ((sequence,), bytes) = parse(bytes, UINT32_FMT)
     return (cls(previous_output, signature_script, sequence), bytes)
Example #20
0
 def parse(cls, bytes):
     ((value,), bytes) = parse(bytes, INT64_FMT)
     (script_len, bytes) = parse_varint(bytes)
     (pk_script, bytes) = splitn(bytes, script_len)
     return (cls(value, PubKeyScript(pk_script)), bytes)
Example #21
0
def parse_addr(bytes):
    ((ts, ), bytes) = parse(bytes, ADDR_FMT)
    (addr, bytes) = parse_addr_bare(bytes)
    return (ts, addr, bytes)
Example #22
0
 def parse(cls, bytes):
     ((magic, command, payload_length, checksum), bytes) = parse(bytes, cls.HEADER_FMT)
     if magic != MAGIC:
         raise ParseError('Magic does not match: %r' % (magic,))
     command = command.rstrip('\x00')
     return (cls(command, payload_length, checksum), bytes)