-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[db] add num_transfers for evm_tokens
[analyzer] dead-reckon numTransfers [api] update with evmtokens.numTransfers linter address comment rename migration
- Loading branch information
1 parent
087ac66
commit d753ce1
Showing
9 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE chain.evm_tokens ADD COLUMN num_transfers UINT63 NOT NULL DEFAULT 0; | ||
ALTER TABLE analysis.evm_tokens ADD COLUMN num_transfers UINT63 NOT NULL DEFAULT 0; | ||
|
||
-- Backfill chain.evm_tokens.num_transfers | ||
WITH transfers AS ( | ||
SELECT runtime, DECODE(body ->> 'address', 'base64') AS eth_addr, COUNT(*) AS num_xfers | ||
FROM chain.runtime_events | ||
GROUP BY runtime, eth_addr | ||
) | ||
UPDATE chain.evm_tokens as tokens | ||
SET num_transfers = transfers.num_xfers | ||
FROM transfers | ||
LEFT JOIN chain.address_preimages as preimages | ||
ON | ||
preimages.address_data = transfers.eth_addr AND | ||
preimages.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' AND | ||
preimages.context_version = 0 | ||
WHERE | ||
tokens.runtime = transfers.runtime AND | ||
tokens.token_address = preimages.address; | ||
|
||
-- Backfill analysis.evm_tokens.num_transfers for tokens that haven't been processed yet. | ||
-- These values will be inserted into chain.evm_tokens when the token is downloaded. | ||
WITH transfers AS ( | ||
SELECT runtime, DECODE(body ->> 'address', 'base64') AS eth_addr, COUNT(*) AS num_xfers | ||
FROM chain.runtime_events | ||
GROUP BY runtime, eth_addr | ||
) | ||
UPDATE analysis.evm_tokens as tokens | ||
SET num_transfers = transfers.num_xfers | ||
FROM transfers | ||
LEFT JOIN chain.address_preimages as preimages | ||
ON | ||
preimages.address_data = transfers.eth_addr AND | ||
preimages.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' AND | ||
preimages.context_version = 0 | ||
WHERE | ||
tokens.runtime = transfers.runtime AND | ||
tokens.token_address = preimages.address AND | ||
tokens.last_download_round IS NULL; | ||
|
||
COMMIT; |