cic-stack/apps/cic-eth/cic_eth/eth/nonce.py

24 lines
714 B
Python
Raw Normal View History

2021-02-01 18:12:51 +01:00
# local imports
from cic_eth.db.models.nonce import Nonce
class NonceOracle():
"""Ensures atomic nonce increments for all transactions across all tasks and threads.
:param address: Address to generate nonces for
:type address: str, 0x-hex
:param default_nonce: Initial nonce value to use if no nonce cache entry already exists
:type default_nonce: number
"""
def __init__(self, address, default_nonce):
self.address = address
self.default_nonce = default_nonce
2021-03-01 21:15:17 +01:00
def next(self, session=None):
2021-02-01 18:12:51 +01:00
"""Get next unique nonce.
:returns: Nonce
:rtype: number
"""
2021-03-01 21:15:17 +01:00
return Nonce.next(self.address, self.default_nonce, session=session)