Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <[email protected]>
  • Loading branch information
aasseman committed Oct 4, 2023
1 parent 66802fe commit d1d2dee
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 785 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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

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

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

53 changes: 51 additions & 2 deletions Cargo.lock

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

9 changes: 7 additions & 2 deletions common/src/escrow_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use alloy_primitives::Address;
use anyhow::Result;
use ethereum_types::U256;
use ethers::types::U256;
use log::{error, info};
use serde::Deserialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -170,7 +170,12 @@ impl EscrowMonitor {
}

pub async fn get_account_balance(&self, address: &Address) -> Option<U256> {
self.inner.sender_accounts.read().await.get(address).copied()
self.inner
.sender_accounts
.read()
.await
.get(address)
.copied()
}

/// Returns true if the given address has a non-zero balance in the escrow contract.
Expand Down
1 change: 1 addition & 0 deletions migrations/20230912220523_tap_receipts.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS scalar_tap_receipts (
id BIGSERIAL PRIMARY KEY,
allocation_id CHAR(40) NOT NULL,
timestamp_ns NUMERIC(20) NOT NULL,
signature CHAR(130) NOT NULL,
receipt JSON NOT NULL
);

Expand Down
9 changes: 5 additions & 4 deletions migrations/20230915230734_tap_ravs.up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE TABLE IF NOT EXISTS scalar_tap_ravs (
allocation_id CHAR(40) PRIMARY KEY,
timestamp_ns NUMERIC(20) NOT NULL,
rav JSON NOT NULL
CREATE TABLE IF NOT EXISTS scalar_tap_latest_ravs (
allocation_id CHAR(40) NOT NULL,
sender_address CHAR(40) NOT NULL,
rav JSON NOT NULL,
PRIMARY KEY (allocation_id, sender_address)
);
2 changes: 1 addition & 1 deletion service/src/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use ethers_core::types::{Signature, U256};
use log::error;

use serde::{Deserialize, Serialize};
use tap_core::tap_manager::SignedReceipt;

Expand Down
8 changes: 4 additions & 4 deletions service/src/tap_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ impl TapManager {
// TODO: consider doing this in another async task to avoid slowing down the paid query flow.
sqlx::query!(
r#"
INSERT INTO scalar_tap_receipts (allocation_id, timestamp_ns, receipt)
VALUES ($1, $2, $3)
INSERT INTO scalar_tap_receipts (allocation_id, timestamp_ns, signature, receipt)
VALUES ($1, $2, $3, $4)
"#,
format!("{:?}", allocation_id)
.strip_prefix("0x")
.unwrap()
.to_owned(),
BigDecimal::from(receipt.message.timestamp_ns),
receipt.signature.to_string(),
serde_json::to_value(receipt).map_err(|e| QueryError::Other(anyhow::Error::from(e)))?
)
.execute(&self.pgpool)
Expand Down Expand Up @@ -152,8 +153,7 @@ mod test {
.unwrap()
}

#[ignore]
#[sqlx::test]
#[sqlx::test(migrations = "../migrations")]
async fn test_verify_and_store_receipt(pgpool: PgPool) {
// Listen to pg_notify events
let mut listener = PgListener::connect_with(&pgpool).await.unwrap();
Expand Down
Loading

0 comments on commit d1d2dee

Please sign in to comment.