Skip to content

Commit a854c95

Browse files
committed
Use null for empty data instead of b''
- Add a migration to modify current existing data
1 parent de1d42b commit a854c95

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

safe_transaction_service/history/indexers/tx_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def __process_decoded_transaction(self, internal_tx_decoded: InternalTxDecoded)
168168
logger.debug('Executing Tx from Module')
169169
module_internal_tx = internal_tx.get_previous_module_trace()
170170
module_address = module_internal_tx.to if module_internal_tx else NULL_ADDRESS
171+
module_data = HexBytes(arguments['data'])
171172
ModuleTransaction.objects.get_or_create(
172173
internal_tx=internal_tx,
173174
defaults={
@@ -176,7 +177,7 @@ def __process_decoded_transaction(self, internal_tx_decoded: InternalTxDecoded)
176177
'module': module_address,
177178
'to': arguments['to'],
178179
'value': arguments['value'],
179-
'data': HexBytes(arguments['data']),
180+
'data': module_data if module_data else None,
180181
'operation': arguments['operation']
181182
}
182183
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django.db import migrations
2+
3+
4+
def set_data_none(apps, schema_editor):
5+
MultisigTransaction = apps.get_model('history', 'MultisigTransaction')
6+
ModuleTransaction = apps.get_model('history', 'ModuleTransaction')
7+
EthereumTx = apps.get_model('history', 'EthereumTx')
8+
for Model in (MultisigTransaction, ModuleTransaction, EthereumTx):
9+
Model.objects.filter(data=b'').update(data=None)
10+
11+
12+
class Migration(migrations.Migration):
13+
14+
dependencies = [
15+
('history', '0018_multisigtransaction_trusted'),
16+
]
17+
18+
operations = [
19+
migrations.RunPython(set_data_none),
20+
]

safe_transaction_service/history/models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def set_confirmed(self):
138138
class EthereumTxManager(models.Manager):
139139
def create_from_tx_dict(self, tx: Dict[str, Any], tx_receipt: Optional[Dict[str, Any]] = None,
140140
ethereum_block: Optional[EthereumBlock] = None) -> 'EthereumTx':
141+
data = HexBytes(tx.get('data') or tx.get('input'))
141142
return super().create(
142143
block=ethereum_block,
143144
tx_hash=HexBytes(tx['hash']).hex(),
@@ -148,7 +149,7 @@ def create_from_tx_dict(self, tx: Dict[str, Any], tx_receipt: Optional[Dict[str,
148149
logs=tx_receipt and [clean_receipt_log(log) for log in tx_receipt.get('logs', list())],
149150
status=tx_receipt and tx_receipt.get('status'),
150151
transaction_index=tx_receipt and tx_receipt['transactionIndex'],
151-
data=HexBytes(tx.get('data') or tx.get('input')),
152+
data=data if data else None,
152153
nonce=tx['nonce'],
153154
to=tx.get('to'),
154155
value=tx['value'],
@@ -328,6 +329,13 @@ def _trace_address_to_str(self, trace_address) -> str:
328329
return ','.join([str(address) for address in trace_address])
329330

330331
def build_from_trace(self, trace: Dict[str, Any], ethereum_tx: EthereumTx) -> 'InternalTx':
332+
"""
333+
Build a InternalTx object from trace, but it doesn't insert it on database
334+
:param trace:
335+
:param ethereum_tx:
336+
:return: InternalTx not inserted
337+
"""
338+
data = trace['action'].get('input') or trace['action'].get('init')
331339
tx_type = EthereumTxType.parse(trace['type'])
332340
call_type = EthereumTxCallType.parse_call_type(trace['action'].get('callType'))
333341
trace_address_str = self._trace_address_to_str(trace['traceAddress'])
@@ -336,7 +344,7 @@ def build_from_trace(self, trace: Dict[str, Any], ethereum_tx: EthereumTx) -> 'I
336344
trace_address=trace_address_str,
337345
_from=trace['action'].get('from'),
338346
gas=trace['action'].get('gas', 0),
339-
data=trace['action'].get('input') or trace['action'].get('init'),
347+
data=data if data else None,
340348
to=trace['action'].get('to') or trace['action'].get('address'),
341349
value=trace['action'].get('value') or trace['action'].get('balance', 0),
342350
gas_used=(trace.get('result') or {}).get('gasUsed', 0),

0 commit comments

Comments
 (0)