Merge pull request #68 from ethereum/vbuterin-patch-6

Add bool to simple serialize
This commit is contained in:
vbuterin 2018-10-11 20:21:04 -04:00 committed by GitHub
commit b9c922ce4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -81,6 +81,20 @@ buffer_size = int_size / 8
return value.to_bytes(buffer_size, 'big')
```
#### bool
Convert directly to a single 0x00 or 0x01 byte.
| Check to perform | Code |
|:------------------|:---------------------------|
| Value is boolean | ``value in (True, False)`` |
```python
assert(value in (True, False))
return b'\x01' if value is True else b'\x00'
```
#### Address
The address should already come as a hash/byte format. Ensure that length is
@ -237,6 +251,15 @@ new_index = current_index + int_size
return int.from_bytes(rawbytes[current_index:current_index+int_size], 'big'), new_index
```
#### Bool
Return True if 0x01, False if 0x00.
```python
assert rawbytes in (b'\x00', b'\x01')
return True if rawbytes == b'\x01' else False
```
#### Address
Return the 20 bytes.