• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-eth-py / 13833295596

13 Mar 2025 11:14AM UTC coverage: 93.983% (+0.03%) from 93.95%
13833295596

Pull #1589

github

web-flow
Merge 6f53fc5d9 into 918a582b0
Pull Request #1589: Fix tx-service api url builder

25 of 27 new or added lines in 3 files covered. (92.59%)

9513 of 10122 relevant lines covered (93.98%)

4.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/safe_eth/safe/api/base_api.py
1
from abc import ABC
5✔
2
from typing import Dict, Optional
5✔
3

4
import requests
5✔
5

6
from safe_eth.eth.ethereum_client import (
5✔
7
    EthereumClient,
8
    EthereumNetwork,
9
    EthereumNetworkNotSupported,
10
)
11
from safe_eth.util.http import build_full_url, prepare_http_session
5✔
12

13

14
class SafeAPIException(Exception):
5✔
15
    pass
5✔
16

17

18
class SafeBaseAPI(ABC):
5✔
19
    URL_BY_NETWORK: Dict[EthereumNetwork, str] = {}
5✔
20

21
    def __init__(
5✔
22
        self,
23
        network: EthereumNetwork,
24
        ethereum_client: Optional[EthereumClient] = None,
25
        base_url: Optional[str] = None,
26
        request_timeout: int = 10,
27
    ):
28
        """
29
        :param network: Network for the transaction service
30
        :param ethereum_client:
31
        :param base_url: If a custom transaction service is used
32
        :raises: EthereumNetworkNotSupported
33
        """
34
        self.network = network
5✔
35
        self.ethereum_client = ethereum_client
5✔
36
        self.base_url = base_url or self.URL_BY_NETWORK.get(network, "")
5✔
37
        if not self.base_url:
5✔
38
            raise EthereumNetworkNotSupported(network)
5✔
39
        self.http_session = prepare_http_session(10, 100)
5✔
40
        self.request_timeout = request_timeout
5✔
41

42
    @classmethod
5✔
43
    def from_ethereum_client(cls, ethereum_client: EthereumClient) -> "SafeBaseAPI":
5✔
44
        ethereum_network = ethereum_client.get_network()
5✔
45
        return cls(ethereum_network, ethereum_client=ethereum_client)
5✔
46

47
    def _get_request(self, url: str) -> requests.Response:
5✔
48
        full_url = build_full_url(self.base_url, url)
5✔
49
        return self.http_session.get(full_url, timeout=self.request_timeout)
5✔
50

51
    def _post_request(self, url: str, payload: Dict) -> requests.Response:
5✔
NEW
52
        full_url = build_full_url(self.base_url, url)
×
53
        return self.http_session.post(
×
54
            full_url,
55
            json=payload,
56
            headers={"Content-type": "application/json"},
57
            timeout=self.request_timeout,
58
        )
59

60
    def _delete_request(self, url: str, payload: Dict) -> requests.Response:
5✔
NEW
61
        full_url = build_full_url(self.base_url, url)
×
62
        return self.http_session.delete(
×
63
            full_url,
64
            json=payload,
65
            headers={"Content-type": "application/json"},
66
            timeout=self.request_timeout,
67
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc