コード例 #1
0
 def parse(cls, s):
     # get the length of the entire field
     length = read_varint(s)
     # initialize the cmds array
     cmds = []
     # initialize the number of bytes we've read to 0
     count = 0
     # loop until we've read length bytes
     while count < length:
         # get the current byte
         current = s.read(1)
         # increment the bytes we've read
         count += 1
         # convert the current byte to an integer
         current_byte = current[0]
         # if the current byte is between 1 and 75 inclusive
         if current_byte >= 1 and current_byte <= 75:
             # we have an cmd set n to be the current byte
             n = current_byte
             # add the next n bytes as an cmd
             cmds.append(s.read(n))
             # increase the count by n
             count += n
         else:
             # we have an opcode. set the current byte to op_code
             op_code = current_byte
             # add the op_code to the list of cmds
             cmds.append(op_code)
     if count != length:
         raise SyntaxError('parsing script failed')
     return cls(cmds)
コード例 #2
0
def read_addr_payload(stream):
    r = {}

    # read varint
    count = read_varint(stream)

    # read_address varint times. Return as list.
    r["addresses"] = [read_address(stream) for _ in range(count)]
    return r
コード例 #3
0
def read_addr_payload(stream):
    r = {}
    count = read_varint(stream)
    r['addresses'] = [read_address(stream) for _ in range(count)]
    return r