(vch)
| 494 | |
| 495 | @staticmethod |
| 496 | def decode(vch): |
| 497 | result = 0 |
| 498 | # We assume valid push_size and minimal encoding |
| 499 | value = vch[1:] |
| 500 | if len(value) == 0: |
| 501 | return result |
| 502 | for i, byte in enumerate(value): |
| 503 | result |= int(byte) << 8 * i |
| 504 | if value[-1] >= 0x80: |
| 505 | # Mask for all but the highest result bit |
| 506 | num_mask = (2**(len(value) * 8) - 1) >> 1 |
| 507 | result &= num_mask |
| 508 | result *= -1 |
| 509 | return result |
| 510 | |
| 511 | class CScript(bytes): |
| 512 | """Serialized script |