-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(draft): add deployment logs to network mode #312
feat(draft): add deployment logs to network mode #312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested functions
Seems like a good start! The following I think would be desirable:
Class: DeploymentsDB
def _run_sql(sql: str) -> ??:
"""Runs raw sql on the db, returns whatever the sql command returns"""
def unset_db():
"""unsets the global DB"""
# Convenience methods
# most of the defauls here are grabbed from the active boa env. So like, `rpc_or_chain_name_or_chain_id` or whatever that is, is grabbed from boa.env
def get_deployment(contract_name = None, contract_address=None, rpc_or_chain_name_or_chain_id=None, from_=None, tx_hash=None, broadcast_ts=None, tx_dict=None, receipt_dict=None, source_code=None) -> Deployment | None:
"""Essentially runs get_deployments, and returns the most recent deployment or None based on the arguments (and sorts by broadcast_ts)"""
def get_deployments(contract_name = None, contract_address=None, rpc_or_chain_name_or_chain_id=None, from_=None, tx_hash=None, broadcast_ts=None, tx_dict=None, receipt_dict=None, source_code=None) -> list[Deployment]:
"""Returns a list of deployments based on the arguments"""
## Extra convenience method
def get_contract(module=VyperContract, contract_name = None, contract_address=None, rpc_or_chain_name_or_chain_id=None, from_=None, tx_hash=None, broadcast_ts=None, tx_dict=None, receipt_dict=None, source_code=None) -> VyperContract | VyperDeployer | ABIContract...:
"""Essentially runs get_deployment, but then converts it to a VyperContract, VyperDeployer, or other similar type depending on user input, defaults to `VyperContract`. I'd expect there to be a set list of "stuff" it could return There will be a `convert_to` function on a deployment."""
def get_contract() # Same as `get_vyper_contract` but returns a list
Class: Deployment
def convert_to(module=VyperContract) -> VyperContract | VyperDeployer | ABIContract..:
"""Converts a deployment to the boa type specified"""
Then, we can have a moccasin
api that looks like the following:
from moccasin.config import get_config, get_db
from contracts import BuyMeACoffee
def withdraw_funds():
active_network = get_config().get_active_network()
deployment_db = get_db() # Calls get_deployments_db, or sets it if not initialized
coffee = deployment_db.get_contract(BuyMeACoffee.name)
# If BuyMeACoffee has been deployed, the below line will return the same `coffee` object as above
# coffee = active_network.get_or_deploy_contract(BuyMeACoffee.name)
coffee.withdraw()
def moccasin_main() -> VyperContract:
return withdraw_funds()
Other API nice-to-haves
Network.py
It would be great to save a save_deployment = false
so that even if a DB was set, you could not save.
Additional thoughts
Chain Name > RPC
The rpc
might not be a desierable column. RPCs can have sensitive information like API keys, and often, projects like to push their deployments DB to source (or some portion of them), so others can use the data in them. It would be better to have like "chain id" or "chain name". Could use the name
function of the EthereumRPC
class.
note
in SQL DB
I bet you hate this, but having a note
or a nickname
in the DB would be cool, so I could do something like:
db.get_nicknamed_deployment("DAI")
And have it return the ERC20 contract deployed with a nickname of DAI
, or a note or something. And I deploy with a note
or nickname
.
LGTM |
* feat(draft): add deployment logs to network mode if the deployments db is initialized, insert all deployed contracts into the deployments db. include information like tx data, ts, source bundle (for verification), session id
Add the option to log every deployment to a sql database