Skip to content

Commit

Permalink
Merge pull request #371 from Concordium/fix-non-existing-account-bug-…
Browse files Browse the repository at this point in the history
…in-account-tokens-table

Fix bug when processing buggy cis2 contract event logs
  • Loading branch information
DOBEN authored Jan 9, 2025
2 parents 50990a8 + 857253f commit e9afee3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 37 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 29 additions & 21 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2666,12 +2666,14 @@ async fn process_cis2_event(
sqlx::query!(
"
INSERT INTO account_tokens (index, account_index, token_index, balance)
VALUES (
(SELECT COALESCE(MAX(index) + 1, 0) FROM account_tokens),
(SELECT index FROM accounts WHERE address = $1),
(SELECT index FROM tokens WHERE token_address = $2),
SELECT
COALESCE((SELECT MAX(index) + 1 FROM account_tokens), 0),
accounts.index,
tokens.index,
$3
)
FROM accounts, tokens
WHERE accounts.address = $1
AND tokens.token_address = $2
ON CONFLICT (token_index, account_index)
DO UPDATE SET balance = account_tokens.balance + EXCLUDED.balance",
owner.to_string(),
Expand Down Expand Up @@ -2743,12 +2745,14 @@ async fn process_cis2_event(
sqlx::query!(
"
INSERT INTO account_tokens (index, account_index, token_index, balance)
VALUES (
(SELECT COALESCE(MAX(index) + 1, 0) FROM account_tokens),
(SELECT index FROM accounts WHERE address = $1),
(SELECT index FROM tokens WHERE token_address = $2),
SELECT
COALESCE((SELECT MAX(index) + 1 FROM account_tokens), 0),
accounts.index,
tokens.index,
$3
)
FROM accounts, tokens
WHERE accounts.address = $1
AND tokens.token_address = $2
ON CONFLICT (token_index, account_index)
DO UPDATE SET balance = account_tokens.balance + EXCLUDED.balance",
owner.to_string(),
Expand Down Expand Up @@ -2787,12 +2791,14 @@ async fn process_cis2_event(
sqlx::query!(
"
INSERT INTO account_tokens (index, account_index, token_index, balance)
VALUES (
(SELECT COALESCE(MAX(index) + 1, 0) FROM account_tokens),
(SELECT index FROM accounts WHERE address = $1),
(SELECT index FROM tokens WHERE token_address = $2),
SELECT
COALESCE((SELECT MAX(index) + 1 FROM account_tokens), 0),
accounts.index,
tokens.index,
$3
)
FROM accounts, tokens
WHERE accounts.address = $1
AND tokens.token_address = $2
ON CONFLICT (token_index, account_index)
DO UPDATE SET balance = account_tokens.balance + EXCLUDED.balance",
from.to_string(),
Expand All @@ -2811,14 +2817,16 @@ async fn process_cis2_event(
sqlx::query!(
"
INSERT INTO account_tokens (index, account_index, token_index, balance)
VALUES (
(SELECT COALESCE(MAX(index) + 1, 0) FROM account_tokens),
(SELECT index FROM accounts WHERE address = $1),
(SELECT index FROM tokens WHERE token_address = $2),
SELECT
COALESCE((SELECT MAX(index) + 1 FROM account_tokens), 0),
accounts.index,
tokens.index,
$3
)
FROM accounts, tokens
WHERE accounts.address = $1
AND tokens.token_address = $2
ON CONFLICT (token_index, account_index)
DO UPDATE SET balance = account_tokens.balance + EXCLUDED.balance",
DO UPDATE SET balance = account_tokens.balance + EXCLUDED.balance",
to.to_string(),
token_address,
tokens_transferred
Expand Down

0 comments on commit e9afee3

Please sign in to comment.