Skip to content

Commit

Permalink
Revert "Fix structure of dataDecoded"
Browse files Browse the repository at this point in the history
This reverts commit 9cb8c8a.
  • Loading branch information
Uxio0 committed Aug 31, 2020
1 parent ed55bb5 commit 230f500
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 140 deletions.
34 changes: 17 additions & 17 deletions safe_transaction_service/history/indexers/tx_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ def _generate_selectors_with_abis_from_contracts(self, contracts: Iterable[Contr
supported_fn_selectors.update(self._generate_selectors_with_abis_from_contract(supported_contract))
return supported_fn_selectors

def _parse_decoded_arguments(self, value_decoded: Any) -> Any:
def _parse_decoded_arguments(self, decoded_value: Any) -> Any:
"""
Parse decoded arguments, like converting `bytes` to hexadecimal `str` or `int` and `float` to `str` (to
prevent problems when deserializing in another languages like JavaScript
:param value_decoded:
:param decoded_value:
:return: Dict[str, Any]
"""
if isinstance(value_decoded, bytes):
value_decoded = HexBytes(value_decoded).hex()
return value_decoded
if isinstance(decoded_value, bytes):
decoded_value = HexBytes(decoded_value).hex()
return decoded_value

@cached_property
def supported_fn_selectors(self) -> Dict[bytes, ContractFunction]:
Expand Down Expand Up @@ -232,19 +232,19 @@ def __init__(self):
+ sight_contracts + erc_contracts
+ self.multisend_contracts + self.supported_contracts)

def _parse_decoded_arguments(self, value_decoded: Any) -> Any:
def _parse_decoded_arguments(self, decoded_value: Any) -> Any:
"""
Decode integers also
:param value_decoded:
:param decoded_value:
:return:
"""
# TODO Decode on serializer, but it's tricky as it has a nested decoding
value_decoded = super()._parse_decoded_arguments(value_decoded)
if isinstance(value_decoded, (int, float)):
value_decoded = str(value_decoded)
elif isinstance(value_decoded, (list, tuple)):
value_decoded = list([self._parse_decoded_arguments(e) for e in value_decoded])
return value_decoded
decoded_value = super()._parse_decoded_arguments(decoded_value)
if isinstance(decoded_value, (int, float)):
decoded_value = str(decoded_value)
elif isinstance(decoded_value, (list, tuple)):
decoded_value = list([self._parse_decoded_arguments(e) for e in decoded_value])
return decoded_value

@cached_property
def multisend_fn_selectors(self) -> Dict[bytes, ContractFunction]:
Expand All @@ -259,14 +259,14 @@ def decode_transaction_with_types(self, data: Union[bytes, str]) -> Tuple[str, L

# If multisend, decode the transactions
if data[:4] in self.multisend_fn_selectors:
parameters[0]['value_decoded'] = self.get_data_decoded_for_multisend(data)
parameters[0]['decoded_value'] = self.get_data_decoded_for_multisend(data)

# If Gnosis Safe `execTransaction` decode the inner transaction
# function execTransaction(address to, uint256 value, bytes calldata data...)
# selector is `0x6a761202` and parameters[2] is data
if data[:4] == HexBytes('0x6a761202') and len(parameters) > 2 and (data := HexBytes(parameters[2]['value'])):
try:
parameters[2]['value_decoded'] = self.get_data_decoded(data)
parameters[2]['decoded_value'] = self.get_data_decoded(data)
except TxDecoderException:
logger.warning('Cannot decode `execTransaction`', exc_info=True)

Expand All @@ -280,11 +280,11 @@ def get_data_decoded_for_multisend(self, data: Union[bytes, str]) -> List[Dict[s
"""
try:
multisend_txs = MultiSend.from_transaction_data(data)
return [{'operation': multisend_tx.operation.value,
return [{'operation': multisend_tx.operation.name,
'to': multisend_tx.to,
'value': multisend_tx.value,
'data': multisend_tx.data.hex(),
'data_decoded': self.get_data_decoded(multisend_tx.data),
'decoded_data': self.get_data_decoded(multisend_tx.data),
} for multisend_tx in multisend_txs]
except ValueError:
logger.warning('Problem decoding multisend transaction with data=%s', HexBytes(data).hex(), exc_info=True)
12 changes: 6 additions & 6 deletions safe_transaction_service/history/services/safe_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ def get_safe_info(self, safe_address: str) -> SafeInfo:

def _decode_proxy_factory(self, data: Union[bytes, str]) -> Optional[Tuple[str, bytes]]:
try:
_, data_decoded = self.proxy_factory_contract.decode_function_input(data)
master_copy = data_decoded.get('masterCopy', data_decoded.get('_mastercopy'))
setup_data = data_decoded.get('data', data_decoded.get('initializer'))
_, decoded_data = self.proxy_factory_contract.decode_function_input(data)
master_copy = decoded_data.get('masterCopy', decoded_data.get('_mastercopy'))
setup_data = decoded_data.get('data', decoded_data.get('initializer'))
return master_copy, setup_data
except ValueError:
return None

def _decode_cpk_proxy_factory(self, data) -> Optional[Tuple[str, bytes]]:
try:
_, data_decoded = self.cpk_proxy_factory_contract.decode_function_input(data)
master_copy = data_decoded.get('masterCopy')
setup_data = data_decoded.get('data')
_, decoded_data = self.cpk_proxy_factory_contract.decode_function_input(data)
master_copy = decoded_data.get('masterCopy')
setup_data = decoded_data.get('data')
return master_copy, setup_data
except ValueError:
return None
Loading

0 comments on commit 230f500

Please sign in to comment.