Skip to content

Commit 1e255e8

Browse files
authored
refactor: implement sender account for horizon (#627)
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 49c804b commit 1e255e8

7 files changed

+143
-12
lines changed

.sqlx/query-1b12436e72e588d745645c4c5286b3503319e12ac9bdf25ef67942d86aa68508.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-27a9c5a16714c8551c8921e4012bceda54664d0f41228f60b3a0f7f601cf9923.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-712d6c51098b981a3a84908eda1b4530d70a5c1a9d6ecaeed59f20a63914d723.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-75125066518ed99d12c1cf4e738ca058c0d7886ca33932434c72ca82a8073567.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,18 @@ impl State {
609609
.await
610610
.expect("Should not fail to delete from denylist");
611611
}
612-
SenderType::Horizon => unimplemented!(),
612+
SenderType::Horizon => {
613+
sqlx::query!(
614+
r#"
615+
DELETE FROM tap_horizon_denylist
616+
WHERE sender_address = $1
617+
"#,
618+
self.sender.encode_hex(),
619+
)
620+
.execute(&self.pgpool)
621+
.await
622+
.expect("Should not fail to delete from denylist");
623+
}
613624
}
614625
self.denied = false;
615626

@@ -726,7 +737,7 @@ impl Actor for SenderAccount {
726737
.get_balance_for_sender(&sender_id)
727738
.unwrap_or_default();
728739
async move {
729-
let last_non_final_ravs = match sender_type {
740+
let last_non_final_ravs: Vec<_> = match sender_type {
730741
// Get all ravs from v1 table
731742
SenderType::Legacy => sqlx::query!(
732743
r#"
@@ -738,11 +749,25 @@ impl Actor for SenderAccount {
738749
)
739750
.fetch_all(&pgpool)
740751
.await
741-
.expect("Should not fail to fetch from scalar_tap_ravs"),
752+
.expect("Should not fail to fetch from scalar_tap_ravs")
753+
.into_iter()
754+
.map(|record| (record.allocation_id, record.value_aggregate))
755+
.collect(),
742756
// Get all ravs from v2 table
743-
SenderType::Horizon => {
744-
unimplemented!()
745-
}
757+
SenderType::Horizon => sqlx::query!(
758+
r#"
759+
SELECT allocation_id, value_aggregate
760+
FROM tap_horizon_ravs
761+
WHERE payer = $1 AND last AND NOT final;
762+
"#,
763+
sender_id.encode_hex(),
764+
)
765+
.fetch_all(&pgpool)
766+
.await
767+
.expect("Should not fail to fetch from scalar_tap_ravs")
768+
.into_iter()
769+
.map(|record| (record.allocation_id, record.value_aggregate))
770+
.collect(),
746771
};
747772

748773
// get a list from the subgraph of which subgraphs were already redeemed and were not marked as final
@@ -754,7 +779,7 @@ impl Actor for SenderAccount {
754779
unfinalized_transactions::Variables {
755780
unfinalized_ravs_allocation_ids: last_non_final_ravs
756781
.iter()
757-
.map(|rav| rav.allocation_id.to_string())
782+
.map(|rav| rav.0.to_string())
758783
.collect::<Vec<_>>(),
759784
sender: format!("{:x?}", sender_id),
760785
},
@@ -785,8 +810,8 @@ impl Actor for SenderAccount {
785810
.into_iter()
786811
.filter_map(|rav| {
787812
Some((
788-
Address::from_str(&rav.allocation_id).ok()?,
789-
rav.value_aggregate.to_bigint().and_then(|v| v.to_u128())?,
813+
Address::from_str(&rav.0).ok()?,
814+
rav.1.to_bigint().and_then(|v| v.to_u128())?,
790815
))
791816
})
792817
.filter(|(allocation, _value)| {
@@ -827,7 +852,20 @@ impl Actor for SenderAccount {
827852
.denied
828853
.expect("Deny status cannot be null"),
829854
// Get deny status from the tap horizon table
830-
SenderType::Horizon => unimplemented!(),
855+
SenderType::Horizon => sqlx::query!(
856+
r#"
857+
SELECT EXISTS (
858+
SELECT 1
859+
FROM tap_horizon_denylist
860+
WHERE sender_address = $1
861+
) as denied
862+
"#,
863+
sender_id.encode_hex(),
864+
)
865+
.fetch_one(&pgpool)
866+
.await?
867+
.denied
868+
.expect("Deny status cannot be null"),
831869
};
832870

833871
let sender_balance = escrow_accounts
@@ -1327,8 +1365,17 @@ impl SenderAccount {
13271365
.expect("Should not fail to insert into denylist");
13281366
}
13291367

1330-
async fn deny_v2_sender(_pool: &PgPool, _sender: Address) {
1331-
unimplemented!()
1368+
async fn deny_v2_sender(pool: &PgPool, sender: Address) {
1369+
sqlx::query!(
1370+
r#"
1371+
INSERT INTO tap_horizon_denylist (sender_address)
1372+
VALUES ($1) ON CONFLICT DO NOTHING
1373+
"#,
1374+
sender.encode_hex(),
1375+
)
1376+
.execute(pool)
1377+
.await
1378+
.expect("Should not fail to insert into denylist");
13321379
}
13331380
}
13341381

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add down migration script here
2+
DROP TABLE IF EXISTS tap_horizon_denylist CASCADE;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Add up migration script here
2+
CREATE TABLE IF NOT EXISTS tap_horizon_denylist (
3+
sender_address CHAR(40) PRIMARY KEY
4+
);

0 commit comments

Comments
 (0)