From d8eb4be348923b2f78d522bbb148cb43737ea9a7 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Sat, 26 Oct 2024 23:25:51 -0300 Subject: [PATCH] is_finalized property --- src/demo_substrate_events/handlers/on_transfer.py | 11 ++++++----- src/dipdup/context.py | 5 +++++ .../demo_substrate_events/handlers/on_transfer.py.j2 | 11 ++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/demo_substrate_events/handlers/on_transfer.py b/src/demo_substrate_events/handlers/on_transfer.py index 964199a1d..cf1d39664 100644 --- a/src/demo_substrate_events/handlers/on_transfer.py +++ b/src/demo_substrate_events/handlers/on_transfer.py @@ -47,8 +47,9 @@ async def on_transfer( if not amount: return - await sql_update(ctx, event.payload['from'], -amount, event.data.level) - await sql_update(ctx, event.payload['to'], amount, event.data.level) - - # await orm_update(ctx, event.payload['from'], -amount, event.data.level) - # await orm_update(ctx, event.payload['to'], amount, event.data.level) + if ctx.is_finalized: + await sql_update(ctx, event.payload['from'], -amount, event.data.level) + await sql_update(ctx, event.payload['to'], amount, event.data.level) + else: + await orm_update(ctx, event.payload['from'], -amount, event.data.level) + await orm_update(ctx, event.payload['to'], amount, event.data.level) diff --git a/src/dipdup/context.py b/src/dipdup/context.py index 4f3906df5..402490baf 100644 --- a/src/dipdup/context.py +++ b/src/dipdup/context.py @@ -878,3 +878,8 @@ def _wrap( ) ctx._link(new_ctx) return new_ctx + + @property + def is_finalized(self) -> bool: + # FIXME: check the datasource + return 1 diff --git a/src/dipdup/projects/demo_substrate_events/handlers/on_transfer.py.j2 b/src/dipdup/projects/demo_substrate_events/handlers/on_transfer.py.j2 index ffc3c8686..d7cfed4c9 100644 --- a/src/dipdup/projects/demo_substrate_events/handlers/on_transfer.py.j2 +++ b/src/dipdup/projects/demo_substrate_events/handlers/on_transfer.py.j2 @@ -47,8 +47,9 @@ async def on_transfer( if not amount: return - await sql_update(ctx, event.payload['from'], -amount, event.data.level) - await sql_update(ctx, event.payload['to'], amount, event.data.level) - - # await orm_update(ctx, event.payload['from'], -amount, event.data.level) - # await orm_update(ctx, event.payload['to'], amount, event.data.level) + if ctx.is_finalized: + await sql_update(ctx, event.payload['from'], -amount, event.data.level) + await sql_update(ctx, event.payload['to'], amount, event.data.level) + else: + await orm_update(ctx, event.payload['from'], -amount, event.data.level) + await orm_update(ctx, event.payload['to'], amount, event.data.level)