WIP Implement transition setters on shep
This commit is contained in:
parent
0682dd8ed3
commit
38aae6f8c0
@ -13,7 +13,7 @@ class Verify:
|
||||
to_state_name = state_store.name(to_state)
|
||||
m = None
|
||||
try:
|
||||
m = getattr(self, 'verify_' + to_state_name)
|
||||
m = getattr(self, to_state_name)
|
||||
except AttributeError:
|
||||
logg.debug('foo {}'.format(to_state_name))
|
||||
return None
|
||||
@ -26,13 +26,56 @@ class Verify:
|
||||
return r
|
||||
|
||||
|
||||
def verify_INSUFFICIENT_FUNDS(self, state_store, from_state):
|
||||
def INSUFFICIENT_FUNDS(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
if from_state & state_store.INSUFFICIENT_FUNDS:
|
||||
if from_state & state_store.IN_NETWORK:
|
||||
return 'already in network'
|
||||
|
||||
|
||||
def UNKNOWN_ERROR(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
if from_state & state_store.RESERVED:
|
||||
return 'not reserved'
|
||||
if from_state & state_store.mask_error:
|
||||
return 'already finalized'
|
||||
|
||||
|
||||
def NODE_ERROR(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
if from_state & state_store.IN_NETWORK:
|
||||
return 'already in network'
|
||||
if from_state & state_store.RESERVED:
|
||||
return 'not reserved'
|
||||
if from_state & state_store.mask_error:
|
||||
return 'already finalized'
|
||||
|
||||
|
||||
def OBSOLETE(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
if from_state & state_store.IN_NETWORK:
|
||||
return 'already in network'
|
||||
if from_state & state_store.OBSOLETE:
|
||||
return 'already obsolete'
|
||||
|
||||
|
||||
def MANUAL(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
|
||||
|
||||
def QUEUED(self, state_store, from_state):
|
||||
if from_state & state_store.FINAL:
|
||||
return 'already finalized'
|
||||
if from_state & state_store.IN_NETWORK:
|
||||
if not from_state & state_store.mask_error:
|
||||
return 'not in error state'
|
||||
elif from_state & state_store.mask_error:
|
||||
return 'no first send on error state'
|
||||
|
||||
|
||||
class Status(shep.persist.PersistedState):
|
||||
|
||||
@ -62,3 +105,5 @@ class Status(shep.persist.PersistedState):
|
||||
self.alias('REJECTED', self.NODE_ERROR | self.FINAL)
|
||||
self.alias('REVERTED', self.IN_NETWORK | self.FINAL, self.NETWORK_ERROR)
|
||||
self.alias('SUCCESS', self.IN_NETWORK | self.FINAL)
|
||||
|
||||
self.mask_error = self.LOCAL_ERROR | self.NODE_ERROR | self.NETWORK_ERROR | self.UNKNOWN_ERROR
|
||||
|
@ -1,3 +1,9 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Tx:
|
||||
|
||||
def __init__(self, store, seq, tx_hash, signed_tx, cache=None):
|
||||
@ -6,6 +12,7 @@ class Tx:
|
||||
self.tx_hash = tx_hash
|
||||
self.signed_tx = signed_tx
|
||||
self.cache = cache
|
||||
self.k = self.__to_key(str(seq), tx_hash)
|
||||
|
||||
|
||||
def __to_key(self, k, v):
|
||||
@ -13,9 +20,47 @@ class Tx:
|
||||
|
||||
|
||||
def create(self):
|
||||
k = self.__to_key(str(self.seq), self.tx_hash)
|
||||
self.store.put(k, self.signed_tx)
|
||||
self.store.put(self.k, self.signed_tx)
|
||||
|
||||
|
||||
def waitforgas(self):
|
||||
pass
|
||||
def __match_state(self, state):
|
||||
return bool(self.store.state(self.k) & state)
|
||||
|
||||
|
||||
def waitforfunds(self):
|
||||
if self.__match_state(self.store.INSUFFICIENT_FUNDS):
|
||||
return
|
||||
self.state.move(self.k, self.store.INSUFFICIENT_FUNDS)
|
||||
|
||||
|
||||
def fubar(self):
|
||||
if self.__match_state(self.store.UNKNOWN_ERROR):
|
||||
return
|
||||
self.state.set(self.k, self.store.UNKNOWN_ERROR)
|
||||
|
||||
|
||||
def reject(self):
|
||||
if self.__match_state(self.store.NODE_ERROR):
|
||||
return
|
||||
self.state.set(self.k, self.store.NODE_ERROR)
|
||||
|
||||
|
||||
def override(self):
|
||||
self.state.set(self.k, self.store.OBSOLETE)
|
||||
|
||||
|
||||
def manual(self):
|
||||
self.state.set(self.k, self.store.MANUAL)
|
||||
|
||||
|
||||
def retry(self):
|
||||
if self.__match_state(self.store.QUEUED):
|
||||
return
|
||||
self.state.change(self.k, self.store.QUEUED, self.store.INSUFFICIENT_FUNDS)
|
||||
|
||||
|
||||
def readysend(self):
|
||||
if self.__match_state(self.store.QUEUED):
|
||||
return
|
||||
self.state.change(self.k, self.store.QUEUED, self.store.INSUFFICIENT_FUNDS)
|
||||
|
||||
|
@ -40,6 +40,12 @@ class TestShep(TestShepBase):
|
||||
logg.debug('file {}'.format(self.path))
|
||||
|
||||
|
||||
def test_shep_valid(self):
|
||||
self.state.put('foo', 'bar')
|
||||
self.state.set('foo', self.state.IN_NETWORK)
|
||||
self.state.set('foo', self.state.FINAL)
|
||||
|
||||
|
||||
def test_shep_invalid(self):
|
||||
self.state.put('foo', 'bar')
|
||||
self.state.set('foo', self.state.FINAL)
|
||||
|
Loading…
Reference in New Issue
Block a user