Added create_block RPC endpoint

This commit is contained in:
Kevin F 2023-01-10 22:08:08 -06:00
parent 7895442b51
commit 2b224cae84

View File

@ -1,9 +1,11 @@
from secrets import randbits
import base64
from base64 import b85decode
from onionrblocks import Block
import onionrblocks
from jsonrpc import dispatcher
import ujson
from base64 import b85decode
from gossip.blockqueues import gossip_block_queues
from blockdb import get_blocks_after_timestamp
@ -14,6 +16,14 @@ def get_blocks(timestamp):
return [block.raw for block in get_blocks_after_timestamp(timestamp)]
@dispatcher.add_method
def create_block(
block_data: 'base64', block_type: str, ttl: int, metadata: dict):
# Wrapper for onionrblocks.create_block (take base64 to be compatible with RPC)
bl = onionrblocks.create_anonvdf_block(
base64.b64decode(block_data), block_type, ttl, **metadata)
return base64.b85encode(bl.raw).decode('utf-8')
queue_to_use = randbits(1)
@dispatcher.add_method
def insert_block(block):