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

Add classes to interact with Safe APIs #292

Merged
merged 3 commits into from
Jul 14, 2022
Merged

Add classes to interact with Safe APIs #292

merged 3 commits into from
Jul 14, 2022

Conversation

Uxio0
Copy link
Member

@Uxio0 Uxio0 commented Jul 7, 2022

- Support Tx Service
- Support Relay Service (deprecated)
- Closes #284
@coveralls
Copy link

coveralls commented Jul 7, 2022

Pull Request Test Coverage Report for Build 2670131465

  • 93 of 162 (57.41%) changed or added relevant lines in 3 files are covered.
  • 85 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-1.2%) to 89.58%

Changes Missing Coverage Covered Lines Changed/Added Lines %
gnosis/safe/api/base_api.py 24 28 85.71%
gnosis/safe/api/relay_service_api.py 25 44 56.82%
gnosis/safe/api/transaction_service_api.py 44 90 48.89%
Files with Coverage Reduction New Missed Lines %
gnosis/safe/proxy_factory.py 1 98.81%
gnosis/eth/multicall.py 2 95.15%
gnosis/safe/safe_creation_tx.py 4 94.21%
gnosis/eth/ethereum_client.py 78 86.91%
Totals Coverage Status
Change from base Build 2621788923: -1.2%
Covered Lines: 3069
Relevant Lines: 3426

💛 - Coveralls

Copy link

@bh2smith bh2smith left a comment

Choose a reason for hiding this comment

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

Looks pretty great!

if not response.ok:
raise SafeAPIException(f"Cannot remove delegate: {response.content}")

def post_transaction(self, safe_tx: SafeTx):
Copy link

Choose a reason for hiding this comment

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

Love it!

Comment on lines 11 to 13
self.transaction_service = TransactionServiceApi(
self.ethereum_client, EthereumNetwork.RINKEBY
)
Copy link

Choose a reason for hiding this comment

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

So I guess then I would create an instance like this and then call transaction_service.post_transaction(safe_tx)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right


import requests

from gnosis.eth.ethereum_client import EthereumClient, EthereumNetwork

Choose a reason for hiding this comment

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

I thought you didn't like this kind of import?

Copy link
Member Author

Choose a reason for hiding this comment

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

What kind of import?

Other day I was talking about absolute import: from something import *

Choose a reason for hiding this comment

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

You were saying that we should be able to

from gnosis.eth import EthereumClient, EthereumNetwork

(as it is stated in the docs here https://gnosis-py.readthedocs.io/en/latest/quickstart.html#safe)

I was pointing out that this kind of import doesn't satisfy mypy, but here I see you doing it the way I was suggesting.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, missed that 👍🏻

Comment on lines 28 to 30
ethereum_network = ethereum_client.get_network()
if ethereum_network in cls.URL_BY_NETWORK:
return cls(ethereum_network, ethereum_client=ethereum_client)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about moving this to the __init__. Do we consider SafeBaseAPI to be in a valid state if the result from from_ethereum_client is None?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not, we should raise an error. Problem is that if we move that to __init__ we need to make EthereumNetwork optional. WDYT?

Choose a reason for hiding this comment

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

I personally like the idea of having these network parameters optional since they are not needed to encode transactions. And there are some use cases which only want to make use of transaction encoding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an exception if network is not found and the possibility of setting a custom base URL

- Raise exception if Network is not found
Copy link
Contributor

@fmrsabino fmrsabino left a comment

Choose a reason for hiding this comment

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

🚀

@Uxio0 Uxio0 merged commit 8727a7c into master Jul 14, 2022
@Uxio0 Uxio0 deleted the add-tx-service-api branch July 14, 2022 14:44
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce method SafeTx.api_post_data
4 participants