Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver rewrite #85

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/xian/driver_api.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import xian.constants as c

from contracting.db.driver import (
ContractDriver,
Driver,
)
from contracting.stdlib.bridge.decimal import ContractingDecimal


def get_latest_block_hash(driver: ContractDriver):
def get_latest_block_hash(driver: Driver):
latest_hash = driver.get(c.LATEST_BLOCK_HASH_KEY)
if latest_hash is None:
return b""
return latest_hash


def set_latest_block_hash(h, driver: ContractDriver):
def set_latest_block_hash(h, driver: Driver):
driver.set(c.LATEST_BLOCK_HASH_KEY, h)


def get_latest_block_height(driver: ContractDriver):
def get_latest_block_height(driver: Driver):
h = driver.get(c.LATEST_BLOCK_HEIGHT_KEY, save=False)
if h is None:
return 0
Expand All @@ -28,11 +28,11 @@ def get_latest_block_height(driver: ContractDriver):
return int(h)


def set_latest_block_height(h, driver: ContractDriver):
def set_latest_block_height(h, driver: Driver):
driver.set(c.LATEST_BLOCK_HEIGHT_KEY, int(h))


def get_value_of_key(item: str, driver: ContractDriver):
def get_value_of_key(item: str, driver: Driver):
return driver.get(item)


Expand Down
5 changes: 2 additions & 3 deletions src/xian/storage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import xian.constants as c

from contracting import config
from contracting.db.driver import FSDriver


class NonceStorage:
def __init__(self, root=None):
def __init__(self, root=None, driver=None):
root = root if root is not None else c.STORAGE_HOME
self.driver = FSDriver(root=root)
self.driver = driver

# Move this to transaction.py
def get_nonce(self, sender):
Expand Down
6 changes: 3 additions & 3 deletions src/xian/xian_abci.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from abci.application import BaseApplication

from contracting.client import ContractingClient
from contracting.db.driver import ContractDriver
from contracting.db.driver import Driver

from xian.methods import (
init_chain,
Expand Down Expand Up @@ -69,8 +69,8 @@ def __init__(self):
raise SystemExit()

self.client = ContractingClient()
self.driver = ContractDriver()
self.nonce_storage = NonceStorage()
self.driver = Driver()
self.nonce_storage = NonceStorage(driver=self.driver)
self.upgrader = UpgradeHandler(self)
self.xian = Node(self.client, self.driver, self.nonce_storage)
self.validator_handler = ValidatorHandler(self)
Expand Down