From f7447f7f27a8436b74b4d20ce7abb878e576c354 Mon Sep 17 00:00:00 2001 From: Alexis Asseman Date: Mon, 30 Oct 2023 13:43:34 -0700 Subject: [PATCH] refactor(tap_agent): trim_start_matches addresses Signed-off-by: Alexis Asseman --- common/src/tap_manager.rs | 6 ++-- tap_agent/src/tap/account.rs | 30 ++++++-------------- tap_agent/src/tap/rav_storage_adapter.rs | 18 +++--------- tap_agent/src/tap/receipt_storage_adapter.rs | 18 +++--------- tap_agent/src/tap/test_utils.rs | 11 +++---- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/common/src/tap_manager.rs b/common/src/tap_manager.rs index 556c81c2..755ccdf1 100644 --- a/common/src/tap_manager.rs +++ b/common/src/tap_manager.rs @@ -90,13 +90,11 @@ impl TapManager { VALUES ($1, $2, $3, $4, $5) "#, format!("{:?}", allocation_id) - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), receipt_signer .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), BigDecimal::from(receipt.message.timestamp_ns), BigDecimal::from_str(&receipt.message.value.to_string())?, diff --git a/tap_agent/src/tap/account.rs b/tap_agent/src/tap/account.rs index d8d985a7..df2b7d5b 100644 --- a/tap_agent/src/tap/account.rs +++ b/tap_agent/src/tap/account.rs @@ -242,15 +242,9 @@ impl Account { inner .allocation_id .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), - inner - .sender - .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned() + inner.sender.to_string().trim_start_matches("0x").to_owned() ) .fetch_one(&inner.pgpool) .await?; @@ -370,15 +364,9 @@ impl Account { inner .allocation_id .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned(), - inner - .sender - .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), + inner.sender.to_string().trim_start_matches("0x").to_owned(), ) .fetch_all(&inner.pgpool) .await?; @@ -768,10 +756,9 @@ mod tests { "#, ALLOCATION_ID .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), - SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned() + SENDER.1.to_string().trim_start_matches("0x").to_owned() ) .fetch_optional(&pgpool) .await @@ -832,10 +819,9 @@ mod tests { "#, ALLOCATION_ID .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), - SENDER.1.to_string().strip_prefix("0x").unwrap().to_owned() + SENDER.1.to_string().trim_start_matches("0x").to_owned() ) .fetch_optional(&pgpool) .await diff --git a/tap_agent/src/tap/rav_storage_adapter.rs b/tap_agent/src/tap/rav_storage_adapter.rs index f2dcd578..ad8115fc 100644 --- a/tap_agent/src/tap/rav_storage_adapter.rs +++ b/tap_agent/src/tap/rav_storage_adapter.rs @@ -36,14 +36,9 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter { "#, self.allocation_id .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned(), - self.sender - .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), + self.sender.to_string().trim_start_matches("0x").to_owned(), serde_json::to_value(rav).map_err(|e| AdapterError::AdapterError { error: e.to_string() })? @@ -65,14 +60,9 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter { "#, self.allocation_id .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), - self.sender - .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned() + self.sender.to_string().trim_start_matches("0x").to_owned() ) .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 4d911659..615aa54d 100644 --- a/tap_agent/src/tap/receipt_storage_adapter.rs +++ b/tap_agent/src/tap/receipt_storage_adapter.rs @@ -106,14 +106,9 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter { "#, self.allocation_id .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned(), - self.sender - .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), + self.sender.to_string().trim_start_matches("0x").to_owned(), rangebounds_to_pgrange(timestamp_range_ns) ) .fetch_all(&self.pgpool) @@ -150,14 +145,9 @@ impl ReceiptStorageAdapterTrait for ReceiptStorageAdapter { "#, self.allocation_id .to_string() - .strip_prefix("0x") - .unwrap() - .to_owned(), - self.sender - .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), + self.sender.to_string().trim_start_matches("0x").to_owned(), rangebounds_to_pgrange(timestamp_ns) ) .execute(&self.pgpool) diff --git a/tap_agent/src/tap/test_utils.rs b/tap_agent/src/tap/test_utils.rs index 5bd592f7..e641f042 100644 --- a/tap_agent/src/tap/test_utils.rs +++ b/tap_agent/src/tap/test_utils.rs @@ -101,15 +101,13 @@ pub async fn store_receipt(pgpool: &PgPool, signed_receipt: SignedReceipt) -> Re .message .allocation_id .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), signed_receipt .recover_signer(&TAP_EIP712_DOMAIN_SEPARATOR) .unwrap() .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), BigDecimal::from(signed_receipt.message.timestamp_ns), BigDecimal::from_str(&signed_receipt.message.value.to_string())?, @@ -135,10 +133,9 @@ pub async fn store_rav(pgpool: &PgPool, signed_rav: SignedRAV, sender: Address) .message .allocation_id .to_string() - .strip_prefix("0x") - .unwrap() + .trim_start_matches("0x") .to_owned(), - sender.to_string().strip_prefix("0x").unwrap().to_owned(), + sender.to_string().trim_start_matches("0x").to_owned(), serde_json::to_value(signed_rav).unwrap(), ) .execute(pgpool)