(self)
| 116 | return cls(cmds) |
| 117 | |
| 118 | def raw_serialize(self): |
| 119 | # initialize what we'll send back |
| 120 | result = b'' |
| 121 | # go through each cmd |
| 122 | for cmd in self.cmds: |
| 123 | # if the cmd is an integer, it's an opcode |
| 124 | if type(cmd) == int: |
| 125 | # turn the cmd into a single byte integer using int_to_little_endian |
| 126 | result += int_to_little_endian(cmd, 1) |
| 127 | else: |
| 128 | # otherwise, this is an element |
| 129 | # get the length in bytes |
| 130 | length = len(cmd) |
| 131 | # for large lengths, we have to use a pushdata opcode |
| 132 | if length < 75: |
| 133 | # turn the length into a single byte integer |
| 134 | result += int_to_little_endian(length, 1) |
| 135 | elif length > 75 and length < 0x100: |
| 136 | # 76 is pushdata1 |
| 137 | result += int_to_little_endian(76, 1) |
| 138 | result += int_to_little_endian(length, 1) |
| 139 | elif length >= 0x100 and length <= 520: |
| 140 | # 77 is pushdata2 |
| 141 | result += int_to_little_endian(77, 1) |
| 142 | result += int_to_little_endian(length, 2) |
| 143 | else: |
| 144 | raise ValueError('too long an cmd') |
| 145 | result += cmd |
| 146 | return result |
| 147 | |
| 148 | def serialize(self): |
| 149 | # get the raw serialization (no prepended length) |
no test coverage detected