Skip to content

Commit 88f8548

Browse files
authored
bugfix: do not count irrelevant tokens transfer to ICS validator count
1 parent 3ebe421 commit 88f8548

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

toolkit/data-sources/db-sync/src/db_model.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -851,17 +851,19 @@ pub(crate) async fn get_native_token_transfers(
851851
let query = sqlx::query_as::<_, BlockTokenAmount>(
852852
"
853853
SELECT
854-
block.hash as block_hash, COALESCE(SUM(ma_tx_out.quantity), 0) as amount
854+
block.hash as block_hash, COALESCE(a.amount, 0) as amount
855855
FROM block
856-
LEFT JOIN tx ON block.id = tx.block_id
857-
LEFT JOIN tx_out ON tx.id = tx_out.tx_id AND tx_out.address = $1
858-
LEFT JOIN ma_tx_out ON ma_tx_out.tx_out_id = tx_out.id
859-
LEFT JOIN multi_asset ON multi_asset.id = ma_tx_out.ident AND multi_asset.policy = $2 AND multi_asset.name = $3
860-
WHERE
861-
$4 <= block.block_no AND block.block_no <= $5
862-
GROUP BY block.block_no, block.hash
863-
ORDER BY block.block_no ASC;
864-
",
856+
LEFT JOIN (SELECT tx.block_id as block_id, SUM(ma_tx_out.quantity) as amount FROM tx
857+
INNER JOIN tx_out ON tx.id = tx_out.tx_id AND tx_out.address = $1
858+
INNER JOIN ma_tx_out ON ma_tx_out.tx_out_id = tx_out.id
859+
INNER JOIN multi_asset ON multi_asset.id = ma_tx_out.ident
860+
WHERE multi_asset.policy = $2 AND multi_asset.name = $3
861+
GROUP BY tx.block_id
862+
) as a ON block.id = a.block_id
863+
WHERE
864+
$4 <= block.block_no AND block.block_no <= $5
865+
ORDER BY block.block_no ASC;
866+
",
865867
)
866868
.bind(&illiquid_supply_address.0)
867869
.bind(&asset.policy_id.0)

toolkit/data-sources/db-sync/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ pub(crate) type Result<T> = std::result::Result<T, DataSourceError>;
188188
mod tests {
189189
use ctor::{ctor, dtor};
190190
use std::sync::OnceLock;
191-
use testcontainers_modules::testcontainers::Container;
191+
use testcontainers_modules::testcontainers::{Container, RunnableImage};
192192
use testcontainers_modules::{postgres::Postgres as PostgresImg, testcontainers::clients::Cli};
193193

194194
static POSTGRES: OnceLock<Container<PostgresImg>> = OnceLock::new();
195195
static CLI: OnceLock<Cli> = OnceLock::new();
196196

197197
fn init_postgres() -> Container<'static, PostgresImg> {
198198
let docker = CLI.get_or_init(Cli::default);
199-
docker.run(PostgresImg::default())
199+
docker.run(RunnableImage::from(PostgresImg::default()).with_tag("17.2"))
200200
}
201201

202202
#[ctor]

toolkit/data-sources/db-sync/testdata/native-token/migrations/2_data.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ INSERT INTO tx_out
8888
VALUES
8989
( transfer_utxo_id_1 , transfer_tx_id_1 , 0 , validator_addr , '' , TRUE , NULL , NULL , 0 , NULL ),
9090
( transfer_utxo_id_2 , transfer_tx_id_2 , 1 , validator_addr , '' , TRUE , NULL , NULL , 0 , NULL ),
91-
( irrelevant_utxo_id_1 , irrelevant_tx_id , 0 , 'other_addr' , '' , TRUE , NULL , NULL , 0 , NULL ),
91+
( irrelevant_utxo_id_1 , irrelevant_tx_id , 0 , validator_addr , '' , TRUE , NULL , NULL , 0 , NULL ),
9292
( irrelevant_utxo_id_2 , irrelevant_tx_id , 1 , 'another_addr' , '' , TRUE , NULL , NULL , 0 , NULL ),
9393
( transfer_utxo_id_3 , transfer_tx_id_3 , 2 , validator_addr , '' , TRUE , NULL , NULL , 0 , NULL ),
9494
( transfer_utxo_id_4 , transfer_tx_id_4 , 0 , validator_addr , '' , TRUE , NULL , NULL , 0 , NULL ),

0 commit comments

Comments
 (0)