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

feat: Make contract class object-oriented #461

Merged
merged 2 commits into from
Jan 12, 2023

Conversation

YoshihitoAso
Copy link
Member

@YoshihitoAso YoshihitoAso commented Jan 11, 2023

The current contract classes (model layer for blockchain) is stateless, where the contract address is entered for each function execution, but this is difficult for developers to understand, so I refactored them.

@YoshihitoAso YoshihitoAso marked this pull request as ready for review January 11, 2023 12:37
Comment on lines 451 to +466
# When using the cache
if TOKEN_CACHE:
token_cache: TokenCache = db_session.query(TokenCache). \
filter(TokenCache.token_address == contract_address). \
filter(TokenCache.token_address == self.token_address). \
first()
if token_cache is not None:
is_updated = IbetStraightBondContract.check_attr_update(
is_updated = self.check_attr_update(
db_session=db_session,
contract_address=contract_address,
base_datetime=token_cache.cached_datetime
)
if is_updated is False and token_cache.expiration_datetime > datetime.utcnow():
# Get data from cache
bond_token = IbetStraightBondContract()
for k, v in token_cache.attributes.items():
setattr(bond_token, k, v)
setattr(self, k, v)
db_session.close()
return bond_token
return AttributeDict(self.__dict__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a byproduct of this refactoring, the get() now returns only properties instead of the contract class itself.

@YoshihitoAso YoshihitoAso self-assigned this Jan 11, 2023
@YoshihitoAso YoshihitoAso added the enhancement New feature or request label Jan 11, 2023
@YoshihitoAso YoshihitoAso merged commit 0b44789 into dev-23.3 Jan 12, 2023
@YoshihitoAso YoshihitoAso deleted the feature/object_oriented_contract branch January 12, 2023 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants