2021-02-01 18:12:51 +01:00
|
|
|
# local imports
|
2021-03-06 18:55:51 +01:00
|
|
|
from cic_eth.db.models.nonce import (
|
|
|
|
Nonce,
|
|
|
|
NonceReservation,
|
|
|
|
)
|
2021-02-01 18:12:51 +01:00
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
class CustodialTaskNonceOracle():
|
2021-02-01 18:12:51 +01:00
|
|
|
"""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
|
|
|
|
"""
|
2021-03-29 15:27:53 +02:00
|
|
|
def __init__(self, address, uuid, session=None):
|
2021-02-01 18:12:51 +01:00
|
|
|
self.address = address
|
2021-03-29 15:27:53 +02:00
|
|
|
self.uuid = uuid
|
|
|
|
self.session = session
|
2021-02-01 18:12:51 +01:00
|
|
|
|
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
def get_nonce(self):
|
|
|
|
return self.next_nonce()
|
|
|
|
|
|
|
|
|
|
|
|
def next_nonce(self):
|
2021-02-01 18:12:51 +01:00
|
|
|
"""Get next unique nonce.
|
|
|
|
|
|
|
|
:returns: Nonce
|
|
|
|
:rtype: number
|
|
|
|
"""
|
2021-03-29 15:27:53 +02:00
|
|
|
r = NonceReservation.release(self.address, self.uuid, session=self.session)
|
|
|
|
return r[1]
|