diff --git a/common/src/tap_manager.rs b/common/src/tap_manager.rs index 35074555..400f1812 100644 --- a/common/src/tap_manager.rs +++ b/common/src/tap_manager.rs @@ -1,6 +1,7 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use alloy_primitives::hex::ToHex; use alloy_primitives::Address; use alloy_sol_types::Eip712Domain; use anyhow::anyhow; @@ -133,13 +134,8 @@ impl TapManager { INSERT INTO scalar_tap_receipts (allocation_id, signer_address, timestamp_ns, value, receipt) VALUES ($1, $2, $3, $4, $5) "#, - format!("{:?}", allocation_id) - .trim_start_matches("0x") - .to_owned(), - receipt_signer - .to_string() - .trim_start_matches("0x") - .to_owned(), + allocation_id.encode_hex::(), + receipt_signer.encode_hex::(), BigDecimal::from(receipt.message.timestamp_ns), BigDecimal::from_str(&receipt.message.value.to_string())?, serde_json::to_value(receipt).map_err(|e| anyhow!(e))? @@ -351,7 +347,7 @@ mod test { INSERT INTO scalar_tap_denylist (sender_address) VALUES ($1) "#, - TAP_SENDER.1.to_string().trim_start_matches("0x").to_owned() + TAP_SENDER.1.encode_hex::() ) .execute(&pgpool) .await @@ -390,7 +386,7 @@ mod test { INSERT INTO scalar_tap_denylist (sender_address) VALUES ($1) "#, - TAP_SENDER.1.to_string().trim_start_matches("0x").to_owned() + TAP_SENDER.1.encode_hex::() ) .execute(&pgpool) .await @@ -409,7 +405,7 @@ mod test { DELETE FROM scalar_tap_denylist WHERE sender_address = $1 "#, - TAP_SENDER.1.to_string().trim_start_matches("0x").to_owned() + TAP_SENDER.1.encode_hex::() ) .execute(&pgpool) .await diff --git a/tap-agent/src/tap/mod.rs b/tap-agent/src/tap/mod.rs index 11f2f647..d4075924 100644 --- a/tap-agent/src/tap/mod.rs +++ b/tap-agent/src/tap/mod.rs @@ -1,7 +1,7 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use alloy_primitives::Address; +use alloy_primitives::{hex::ToHex, Address}; use anyhow::anyhow; use eventuals::Eventual; use indexer_common::escrow_accounts::EscrowAccounts; @@ -26,7 +26,7 @@ async fn signers_trimmed( .map_err(|e| anyhow!("Error while getting escrow accounts: {:?}", e))? .get_signers_for_sender(&sender)? .iter() - .map(|s| s.to_string().trim_start_matches("0x").to_owned()) + .map(|s| s.encode_hex::()) .collect::>(); Ok(signers) diff --git a/tap-agent/src/tap/rav_storage_adapter.rs b/tap-agent/src/tap/rav_storage_adapter.rs index 9e0b0a94..dbd74fbc 100644 --- a/tap-agent/src/tap/rav_storage_adapter.rs +++ b/tap-agent/src/tap/rav_storage_adapter.rs @@ -1,6 +1,7 @@ // Copyright 2023-, GraphOps and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 +use alloy_primitives::hex::ToHex; use alloy_primitives::Address; use anyhow::Result; use async_trait::async_trait; @@ -34,11 +35,8 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter { ON CONFLICT (allocation_id, sender_address) DO UPDATE SET rav = $3 "#, - self.allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - self.sender.to_string().trim_start_matches("0x").to_owned(), + self.allocation_id.encode_hex::(), + self.sender.encode_hex::(), serde_json::to_value(rav).map_err(|e| AdapterError::AdapterError { error: e.to_string() })? @@ -58,11 +56,8 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter { FROM scalar_tap_ravs WHERE allocation_id = $1 AND sender_address = $2 "#, - self.allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - self.sender.to_string().trim_start_matches("0x").to_owned() + self.allocation_id.encode_hex::(), + self.sender.encode_hex::() ) .fetch_optional(&self.pgpool) .await diff --git a/tap-agent/src/tap/receipt_storage_adapter.rs b/tap-agent/src/tap/receipt_storage_adapter.rs index 71d10e8b..d34859c3 100644 --- a/tap-agent/src/tap/receipt_storage_adapter.rs +++ b/tap-agent/src/tap/receipt_storage_adapter.rs @@ -6,7 +6,7 @@ use std::{ ops::{Bound, RangeBounds}, }; -use alloy_primitives::Address; +use alloy_primitives::{hex::ToHex, Address}; use async_trait::async_trait; use eventuals::Eventual; use indexer_common::escrow_accounts::EscrowAccounts; @@ -116,10 +116,7 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter { WHERE allocation_id = $1 AND signer_address IN (SELECT unnest($2::text[])) AND $3::numrange @> timestamp_ns "#, - self.allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), + self.allocation_id.encode_hex::(), &signers, rangebounds_to_pgrange(timestamp_range_ns) ) @@ -162,10 +159,7 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter { WHERE allocation_id = $1 AND signer_address IN (SELECT unnest($2::text[])) AND $3::numrange @> timestamp_ns "#, - self.allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), + self.allocation_id.encode_hex::(), &signers, rangebounds_to_pgrange(timestamp_ns) ) diff --git a/tap-agent/src/tap/sender_allocation_relationship.rs b/tap-agent/src/tap/sender_allocation_relationship.rs index 232dcff9..c941a8ac 100644 --- a/tap-agent/src/tap/sender_allocation_relationship.rs +++ b/tap-agent/src/tap/sender_allocation_relationship.rs @@ -3,7 +3,7 @@ use std::{str::FromStr, sync::Arc, time::Duration}; -use alloy_primitives::Address; +use alloy_primitives::{hex::ToHex, Address}; use alloy_sol_types::Eip712Domain; use anyhow::{anyhow, ensure, Result}; @@ -249,12 +249,8 @@ impl SenderAllocationRelationship { rav ) ELSE TRUE END "#, - inner - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - inner.sender.to_string().trim_start_matches("0x").to_owned(), + inner.allocation_id.encode_hex::(), + inner.sender.encode_hex::(), &signers ) .fetch_one(&inner.pgpool) @@ -415,12 +411,8 @@ impl SenderAllocationRelationship { WHERE allocation_id = $1 AND sender_address = $2 RETURNING * "#, - inner - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - inner.sender.to_string().trim_start_matches("0x").to_owned(), + inner.allocation_id.encode_hex::(), + inner.sender.encode_hex::(), ) .fetch_all(&inner.pgpool) .await?; @@ -451,12 +443,8 @@ impl SenderAllocationRelationship { ) VALUES ($1, $2, $3, $4, $5) "#, - inner - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - inner.sender.to_string().trim_start_matches("0x").to_owned(), + inner.allocation_id.encode_hex::(), + inner.sender.encode_hex::(), BigDecimal::from(received_receipt.signed_receipt().message.timestamp_ns), BigDecimal::from_str(&received_receipt.signed_receipt().message.value.to_string())?, serde_json::to_value(received_receipt)? @@ -486,12 +474,8 @@ impl SenderAllocationRelationship { ) VALUES ($1, $2, $3, $4, $5) "#, - inner - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - inner.sender.to_string().trim_start_matches("0x").to_owned(), + inner.allocation_id.encode_hex::(), + inner.sender.encode_hex::(), serde_json::to_value(expected_rav)?, serde_json::to_value(rav)?, reason @@ -922,11 +906,8 @@ mod tests { FROM scalar_tap_ravs WHERE allocation_id = $1 AND sender_address = $2 "#, - ALLOCATION_ID - .to_string() - .trim_start_matches("0x") - .to_owned(), - SENDER.1.to_string().trim_start_matches("0x").to_owned() + ALLOCATION_ID.encode_hex::(), + SENDER.1.encode_hex::() ) .fetch_optional(&pgpool) .await @@ -1008,11 +989,8 @@ mod tests { FROM scalar_tap_ravs WHERE allocation_id = $1 AND sender_address = $2 "#, - ALLOCATION_ID - .to_string() - .trim_start_matches("0x") - .to_owned(), - SENDER.1.to_string().trim_start_matches("0x").to_owned() + ALLOCATION_ID.encode_hex::(), + SENDER.1.encode_hex::() ) .fetch_optional(&pgpool) .await diff --git a/tap-agent/src/tap/test_utils.rs b/tap-agent/src/tap/test_utils.rs index c538d17b..4e0c0d6b 100644 --- a/tap-agent/src/tap/test_utils.rs +++ b/tap-agent/src/tap/test_utils.rs @@ -3,6 +3,7 @@ use std::str::FromStr; +use alloy_primitives::hex::ToHex; use alloy_primitives::Address; use alloy_sol_types::{eip712_domain, Eip712Domain}; use anyhow::Result; @@ -98,18 +99,11 @@ pub async fn store_receipt(pgpool: &PgPool, signed_receipt: SignedReceipt) -> Re VALUES ($1, $2, $3, $4, $5) RETURNING id "#, - signed_receipt - .message - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), + signed_receipt.message.allocation_id.encode_hex::(), signed_receipt .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) .unwrap() - .to_string() - .trim_start_matches("0x") - .to_owned(), + .encode_hex::(), BigDecimal::from(signed_receipt.message.timestamp_ns), BigDecimal::from_str(&signed_receipt.message.value.to_string())?, serde_json::to_value(signed_receipt)? @@ -130,13 +124,8 @@ pub async fn store_rav(pgpool: &PgPool, signed_rav: SignedRAV, sender: Address) ) VALUES ($1, $2, $3) "#, - signed_rav - .message - .allocation_id - .to_string() - .trim_start_matches("0x") - .to_owned(), - sender.to_string().trim_start_matches("0x").to_owned(), + signed_rav.message.allocation_id.encode_hex::(), + sender.encode_hex::(), serde_json::to_value(signed_rav).unwrap(), ) .execute(pgpool)