(vch)
| 410 | |
| 411 | @staticmethod |
| 412 | def decode(vch): |
| 413 | result = 0 |
| 414 | # We assume valid push_size and minimal encoding |
| 415 | value = vch[1:] |
| 416 | if len(value) == 0: |
| 417 | return result |
| 418 | for i, byte in enumerate(value): |
| 419 | result |= int(byte) << 8 * i |
| 420 | if value[-1] >= 0x80: |
| 421 | # Mask for all but the highest result bit |
| 422 | num_mask = (2**(len(value) * 8) - 1) >> 1 |
| 423 | result &= num_mask |
| 424 | result *= -1 |
| 425 | return result |
| 426 | |
| 427 | |
| 428 | class CScript(bytes): |