Skip to content

Commit 8f71904

Browse files
committed
fix: gracefully handle sorocarbon memos longer than 64 bytes
1 parent 7e28f6f commit 8f71904

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

sc_audit/loader/sink_events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sc_audit.config import settings
1212
from sc_audit.db_schema.impact_project import get_vcs_project
1313
from sc_audit.db_schema.sink import SinkingTx
14+
from sc_audit.loader.utils import truncate_sorocarbon_memo
1415
from sc_audit.session_manager import Session
1516
from sc_audit.sources.sink_events import get_sink_events
1617

@@ -45,6 +46,9 @@ def load_sink_events(cursor: int=settings.FIRST_SINK_CURSOR) -> int:
4546
# with the TOID (paging_token). Not done yet, because it requires a data migration.
4647

4748
memo = sink_event.memo_text or None
49+
if memo:
50+
memo = truncate_sorocarbon_memo(memo)
51+
4852
session.add(
4953
SinkingTx(
5054
hash=sink_event.transaction,

sc_audit/loader/sink_invocations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sc_audit.config import settings
88
from sc_audit.db_schema.sink import SinkingTx
99
from sc_audit.loader.sink_events import try_project_id
10+
from sc_audit.loader.utils import truncate_sorocarbon_memo
1011
from sc_audit.session_manager import Session
1112
from sc_audit.sources.sink_invocations import InvocationSource
1213

@@ -24,6 +25,9 @@ def load_sink_invocations(cursor: int=settings.FIRST_SINK_CURSOR) -> int:
2425
for sink_invoke in InvocationSource.get_sink_invocations(cursor):
2526
vcs_project_id = try_project_id(sink_invoke.project_id)
2627
memo = sink_invoke.memo_text or None
28+
if memo:
29+
memo = truncate_sorocarbon_memo(memo)
30+
2731
session.add(
2832
SinkingTx(
2933
hash=sink_invoke.tx_hash,

sc_audit/loader/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def parse_iso_datetime(iso_datetime: str) -> datetime.datetime:
1313
def decode_hash_memo(b64_hash_memo: str) -> str:
1414
return base64.b64decode(b64_hash_memo).hex()
1515

16+
def truncate_sorocarbon_memo(text_memo: str) -> str:
17+
return text_memo.encode()[:64].decode()
18+
1619

1720
class VcsSerialNumber(BaseModel):
1821
batch_number: int

tests/data_fixtures/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"recipient": "GAN4FQZL5P7B7OGW4KMYA6B2V34W7E6C7NL7K4P6ZNNWQ6UZD6I7GABC",
106106
"amount": 109999,
107107
"project_id": "VCS1360",
108-
"memo_text": "testing",
108+
"memo_text": "testing a memo that is longer than 64 bytes 🏠🏠 truncated | this will be sliced off",
109109
"ledger": 50189018,
110110
"timestamp": 1717875054,
111111
"contract_id": "CBW45IZ3W5BBDIKTIXQEAOR3TAHPCFIAVQMD4NO2YPX2FA4LKGLJLWYL",

tests/data_fixtures/invocations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_items() -> list[SinkInvocation]:
5959
recipient='GC53JCXZHW3SVNRE4CT6XFP46WX4ACFQU32P4PR3CU43OB7AKKMFXZ6Y',
6060
amount=4444444,
6161
project_id='VCS1360',
62-
memo_text='tri',
62+
memo_text='tri testing a memo that is longer than 64 bytes 🏠 truncated | this will be sliced off',
6363
processed_at=dt.datetime(2025, 8, 24, 12, 30, 34, 920249, tzinfo=gmt_zoneinfo),
6464
schema_name='carbon_sink_v1',
6565
successful=True,

tests/test_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_load_sink_events(self, mock_session):
119119
'early support',
120120
'offset tokens',
121121
'gift',
122-
'testing'
122+
'testing a memo that is longer than 64 bytes 🏠🏠 truncated |'
123123
]
124124

125125
def test_load_sink_txs_and_events(self, mock_http, mock_session):

tests/test_invocation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_invoke_list_full(self):
8686
assert tri.tx_hash == "e7d68ab7c57e38e2e103b81926db97731eb9ca861de5282eaf1bcc97e1605deb"
8787
assert tri.amount == 4444444
8888
assert tri.ton_amount == Decimal("0.444")
89-
assert tri.memo_text == "tri"
89+
assert tri.memo_text == "tri testing a memo that is longer than 64 bytes 🏠 truncated | this will be sliced off"
9090

9191
def test_returns_the_same_when_repeated(self):
9292
res_1 = InvocationSource.get_sink_invocations(cursor=0)
@@ -138,7 +138,9 @@ def test_load_sink_invocations(self, mock_session):
138138
)
139139

140140
memos = [tx.memo_value for tx in loaded_invocations]
141-
assert memos == ["one", "two", "tri"]
141+
assert memos == [
142+
"one", "two", "tri testing a memo that is longer than 64 bytes 🏠 truncated |"
143+
]
142144

143145
def test_load_sink_txs_and_invocations(self, mock_http, mock_session):
144146
sink_loader.load_sinking_txs(cursor=999)

0 commit comments

Comments
 (0)