Skip to content

Commit

Permalink
Merge 31a4dde into ac122bb
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Jul 22, 2022
2 parents ac122bb + 31a4dde commit 58f439f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
44 changes: 24 additions & 20 deletions gnosis/safe/api/transaction_service_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import time
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.parse import urljoin

import requests
from eth_account.signers.local import LocalAccount
from eth_typing import HexStr
from hexbytes import HexBytes
from web3 import Web3

Expand Down Expand Up @@ -102,7 +103,7 @@ def get_balances(self, safe_address: str) -> List[Dict[str, Any]]:
return response.json()

def get_safe_transaction(
self, safe_tx_hash: bytes
self, safe_tx_hash: Union[bytes, HexStr]
) -> Tuple[SafeTx, Optional[HexBytes]]:
"""
:param safe_tx_hash:
Expand All @@ -122,27 +123,30 @@ def get_safe_transaction(
logger.warning(
"EthereumClient should be defined to get a executable SafeTx"
)
return (
SafeTx(
self.ethereum_client,
result["safe"],
result["to"],
int(result["value"]),
HexBytes(result["data"]) if result["data"] else b"",
int(result["operation"]),
int(result["safeTxGas"]),
int(result["baseGas"]),
int(result["gasPrice"]),
result["gasToken"],
result["refundReceiver"],
signatures=signatures if signatures else b"",
safe_nonce=int(result["nonce"]),
chain_id=self.network.value,
),
safe_tx = SafeTx(
self.ethereum_client,
result["safe"],
result["to"],
int(result["value"]),
HexBytes(result["data"]) if result["data"] else b"",
int(result["operation"]),
int(result["safeTxGas"]),
int(result["baseGas"]),
int(result["gasPrice"]),
result["gasToken"],
result["refundReceiver"],
signatures=signatures if signatures else b"",
safe_nonce=int(result["nonce"]),
chain_id=self.network.value,
)
tx_hash = (
HexBytes(result["transactionHash"])
if result["transactionHash"]
else None,
else None
)
if tx_hash:
safe_tx.tx_hash = tx_hash
return (safe_tx, tx_hash)

def get_transactions(self, safe_address: str) -> List[Dict[str, Any]]:
response = self._get_request(
Expand Down
6 changes: 3 additions & 3 deletions gnosis/safe/safe_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class EIP712LegacySafeTx(EIP712Struct):


class SafeTx:
tx: TxParams # If executed, `tx` is set
tx_hash: bytes # If executed, `tx_hash` is set

def __init__(
self,
ethereum_client: EthereumClient,
Expand Down Expand Up @@ -131,6 +128,9 @@ def __init__(
self._safe_version = safe_version
self._chain_id = chain_id and int(chain_id)

self.tx: Optional[TxParams] = None # If executed, `tx` is set
self.tx_hash: Optional[bytes] = None # If executed, `tx_hash` is set

def __str__(self):
return (
f"SafeTx - safe={self.safe_address} - to={self.to} - value={self.value} - data={self.data.hex()} - "
Expand Down

0 comments on commit 58f439f

Please sign in to comment.