Simplify queueentry

This commit is contained in:
lash 2022-03-11 21:49:23 +00:00
parent 790c9ddf13
commit b763d11eff
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 31 additions and 36 deletions

View File

@ -11,15 +11,6 @@ from hexathon import (
logg = logging.getLogger(__name__)
def to_key(k, v):
return '{:>010s}_{}'.format(k, v)
def from_key(k):
(seq_str, tx_hash) = k.split('_')
return (int(seq_str), tx_hash,)
def normalize_hex(k):
k = strip_0x(k)
return uniform(k)
@ -39,16 +30,12 @@ class QueueEntry:
def create(self, seq, signed_tx):
n = str(seq)
signed_tx = normalize_hex(signed_tx)
self.k = to_key(n, self.tx_hash)
self.store.put(self.k, signed_tx)
self.store.put_seq(self.tx_hash, n)
self.k = self.store.put(self.tx_hash, n, signed_tx)
self.synced = True
def load(self):
seq = self.store.get_seq(self.tx_hash)
self.k = to_key(seq, self.tx_hash)
self.signed_tx = self.store.get(self.k)
(self.k, self.signed_tx) = self.store.get(self.tx_hash)
self.synced = True

View File

@ -2,12 +2,19 @@
import logging
import re
# local imports
from .entry import from_key
logg = logging.getLogger(__name__)
def to_key(k, v):
return '{:>010s}_{}'.format(k, v)
def from_key(k):
(seq_str, tx_hash) = k.split('_')
return (int(seq_str), tx_hash,)
re_u = r'^[^_][_A-Z]+$'
class Store:
@ -19,35 +26,36 @@ class Store:
continue
v = self.state_store.from_name(s)
setattr(self, s, v)
for v in ['put', 'get', 'state', 'change', 'set', 'unset']:
for v in ['state', 'change', 'set', 'unset']:
setattr(self, v, getattr(self.state_store, v))
def put(self, k, v):
def put(self, k, n, v):
self.index_store.put(k, n)
k = to_key(n, k)
self.state_store.put(k, v)
def get(self, k, v):
return self.state_store.get(k)
def put_seq(self, k, seq):
self.index_store.put(k, seq)
def get_seq(self, k):
return self.index_store.get(k)
def get(self, k):
n = self.index_store.get(k)
k = to_key(n, k)
return (k, self.state_store.get(k))
def list(self, state=0, limit=4096, strict=False):
hashes = []
i = 0
for k in self.state_store.list(state):
item_state = self.state_store.state(k)
if strict:
hashes_state = self.state_store.list(state)
if strict:
for k in hashes_state:
item_state = self.state_store.state(k)
if item_state & state != item_state:
continue
hashes.append(k)
hashes.append(k)
else:
hashes = hashes_state
hashes.sort()
hashes_out = []
for h in hashes:

View File

@ -23,13 +23,13 @@ class MockTranslator:
class TestShep(TestShepBase):
def test_entry_get(self):
tx_hash_one = add_0x(os.urandom(20).hex())
tx_hash_one = add_0x(os.urandom(32).hex())
signed_tx = add_0x(os.urandom(128).hex())
nonce = 42
entry = QueueEntry(self.store, tx_hash_one)
entry.create(nonce, signed_tx)
tx_hash_two = add_0x(os.urandom(20).hex())
tx_hash_two = add_0x(os.urandom(32).hex())
signed_tx = add_0x(os.urandom(128).hex())
nonce = 42
entry = QueueEntry(self.store, tx_hash_two)