mirror of
https://github.com/logos-blockchain/logos-blockchain-block-explorer-template.git
synced 2026-02-10 16:13:12 +00:00
28 lines
804 B
Python
28 lines
804 B
Python
|
|
from random import choices, random
|
||
|
|
from typing import List
|
||
|
|
|
||
|
|
from node.api.base import NodeApi
|
||
|
|
from node.models.blocks import Block
|
||
|
|
from node.models.health import Health
|
||
|
|
from node.models.transactions import Transaction
|
||
|
|
|
||
|
|
|
||
|
|
def get_weighted_amount() -> int:
|
||
|
|
items = [1, 2, 3]
|
||
|
|
weights = [0.6, 0.3, 0.1]
|
||
|
|
return choices(items, weights=weights, k=1)[0]
|
||
|
|
|
||
|
|
|
||
|
|
class FakeNodeApi(NodeApi):
|
||
|
|
async def get_health_check(self) -> Health:
|
||
|
|
if random() < 0.1:
|
||
|
|
return Health.from_unhealthy()
|
||
|
|
else:
|
||
|
|
return Health.from_healthy()
|
||
|
|
|
||
|
|
async def get_transactions(self) -> List[Transaction]:
|
||
|
|
return [Transaction.from_random() for _ in range(get_weighted_amount())]
|
||
|
|
|
||
|
|
async def get_blocks(self) -> List[Block]:
|
||
|
|
return [Block.from_random() for _ in range(1)]
|