Skip to content

Commit

Permalink
refactor(tap_agent): trim_start_matches addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <alexis@semiotic.ai>
  • Loading branch information
aasseman committed Oct 30, 2023
1 parent 91e7d56 commit f7447f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 61 deletions.
6 changes: 2 additions & 4 deletions common/src/tap_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?,
Expand Down
30 changes: 8 additions & 22 deletions tap_agent/src/tap/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions tap_agent/src/tap/rav_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})?
Expand All @@ -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
Expand Down
18 changes: 4 additions & 14 deletions tap_agent/src/tap/receipt_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions tap_agent/src/tap/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?,
Expand All @@ -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)
Expand Down

0 comments on commit f7447f7

Please sign in to comment.