improve frontend, no reloading. types in views_api, formatting
This commit is contained in:
parent
802d01cc4b
commit
bb1941445d
19 changed files with 134 additions and 119 deletions
11
nostr/pow.py
11
nostr/pow.py
|
|
@ -1,7 +1,9 @@
|
|||
import time
|
||||
|
||||
from .event import Event
|
||||
from .key import PrivateKey
|
||||
|
||||
|
||||
def zero_bits(b: int) -> int:
|
||||
n = 0
|
||||
|
||||
|
|
@ -14,10 +16,11 @@ def zero_bits(b: int) -> int:
|
|||
|
||||
return 7 - n
|
||||
|
||||
|
||||
def count_leading_zero_bits(hex_str: str) -> int:
|
||||
total = 0
|
||||
for i in range(0, len(hex_str) - 2, 2):
|
||||
bits = zero_bits(int(hex_str[i:i+2], 16))
|
||||
bits = zero_bits(int(hex_str[i : i + 2], 16))
|
||||
total += bits
|
||||
|
||||
if bits != 8:
|
||||
|
|
@ -25,7 +28,10 @@ def count_leading_zero_bits(hex_str: str) -> int:
|
|||
|
||||
return total
|
||||
|
||||
def mine_event(content: str, difficulty: int, public_key: str, kind: int, tags: list=[]) -> Event:
|
||||
|
||||
def mine_event(
|
||||
content: str, difficulty: int, public_key: str, kind: int, tags: list = []
|
||||
) -> Event:
|
||||
all_tags = [["nonce", "1", str(difficulty)]]
|
||||
all_tags.extend(tags)
|
||||
|
||||
|
|
@ -43,6 +49,7 @@ def mine_event(content: str, difficulty: int, public_key: str, kind: int, tags:
|
|||
|
||||
return Event(public_key, content, created_at, kind, all_tags, event_id)
|
||||
|
||||
|
||||
def mine_key(difficulty: int) -> PrivateKey:
|
||||
sk = PrivateKey()
|
||||
num_leading_zero_bits = count_leading_zero_bits(sk.public_key.hex())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue