Skip to content

Commit

Permalink
Merge pull request #58 from xian-network/storage-home-as-argument
Browse files Browse the repository at this point in the history
storage-home is now an optional arg for classes Driver & ContractingClient
  • Loading branch information
duelingbenjos authored Jul 23, 2024
2 parents 67a2d40 + 1689c29 commit de010c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/contracting/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ def __init__(
self,
signer='sys',
submission_filename=os.path.join(os.path.dirname(__file__), 'contracts/submission.s.py'),
driver=Driver(),
storage_home=constants.STORAGE_HOME,
driver:Driver=None,
metering=False,
compiler=ContractingCompiler(),
environment={}
environment={},
):

driver = driver if driver is not None else Driver(storage_home=storage_home)
self.executor = Executor(metering=metering, driver=driver)
self.raw_driver = driver
self.signer = signer
Expand Down
4 changes: 4 additions & 0 deletions src/contracting/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

RECURSION_LIMIT = 1024

DELIMITER = ':'
Expand Down Expand Up @@ -25,3 +27,5 @@
FILENAME_LEN_MAX = 255

DEFAULT_STAMPS = 1000000

STORAGE_HOME = Path().home().joinpath(".cometbft/xian")
7 changes: 3 additions & 4 deletions src/contracting/storage/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
FILE_EXT = ".d"
HASH_EXT = ".x"

STORAGE_HOME = Path().home().joinpath(".cometbft/xian")
DELIMITER = "."
HASH_DEPTH_DELIMITER = ":"

Expand All @@ -30,14 +29,14 @@


class Driver:
def __init__(self, bypass_cache=False):
def __init__(self, bypass_cache=False, storage_home=constants.STORAGE_HOME):
self.pending_deltas = {}
self.pending_writes = {}
self.pending_reads = {}
self.cache = TTLCache(maxsize=1000, ttl=6*3600)
self.bypass_cache = bypass_cache
self.contract_state = STORAGE_HOME.joinpath("contract_state")
self.run_state = STORAGE_HOME.joinpath("run_state")
self.contract_state = storage_home.joinpath("contract_state")
self.run_state = storage_home.joinpath("run_state")
self.__build_directories()

def __build_directories(self):
Expand Down

0 comments on commit de010c1

Please sign in to comment.