Onionr/static-data/official-plugins/wot/wot/blockprocessingevent.py

33 lines
879 B
Python
Raw Normal View History

2022-08-31 05:30:28 +00:00
from typing import TYPE_CHECKING
2022-10-01 04:25:46 +00:00
from .identityprocessing import process_identity_announce
2022-08-31 05:30:28 +00:00
if TYPE_CHECKING:
from onionrblocks import Block
2022-09-17 05:02:49 +00:00
from wot.exceptions import InvalidWotBlock
2022-10-01 04:25:46 +00:00
from wot.wotcommand import WotCommand
2022-08-31 05:30:28 +00:00
2022-08-31 05:30:28 +00:00
class WotPayload:
def __init__(self, block_data: bytes):
wot_command = WotCommand(
int.from_bytes(block_data[0], byteorder='big'))
match wot_command(WotCommand):
case WotCommand.TRUST:
pass
2022-10-01 04:25:46 +00:00
case WotCommand.REVOKE_TRUST:
pass
case WotCommand.ANNOUNCE:
process_identity_announce(block_data[1:])
case WotCommand.REVOKE:
pass
case _:
raise InvalidWotBlock('Invalid WOT command')
2022-08-31 05:30:28 +00:00
def process_block(bl: 'Block'):
assert bl.type == 'iden'
wot_command = WotCommand(bl.data)